I created a video transcoder using ffmpeg. User uploads RAW videos – very big, about 20GB – via FTP.
Currently, a php script is monitoring local paths every 5 seconds with below strategy.
- Look up local filesystem.
- If a ‘new’ file appears, add it to database with modified time and its size.
- After 5 seconds, check the modified time and size again,
- Not changed : Set status as [DONE], and encode the video into ‘./output’ directory. ( ‘output’ is explicitly excluded from monitoring )
- Changed : Wait another 5 seconds.
It works very well, but it burns some cpu power to find ‘new file’. Is there any way to get the ‘exact timing’ when file uploading is being completed?
if you can, install inotify then its super easy via a bash script. otherwise a bash script may still be more efficient.
update: php supports inotify with: php.net/manual/en/book.inotify.php