3

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.

  1. Look up local filesystem.
  2. If a 'new' file appears, add it to database with modified time and its size.
  3. After 5 seconds, check the modified time and size again,
    1. Not changed : Set status as [DONE], and encode the video into './output' directory. ( 'output' is explicitly excluded from monitoring )
    2. 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?

5
  • @Iqez What's your OS and does it have to be done in PHP? Also, when you say "encode the video into './output' directory", do you mean copy it to the output directory? Commented Dec 21, 2011 at 8:00
  • 1
    if you can, install inotify then its super easy via a bash script. otherwise a bash script may still be more efficient. Commented Dec 21, 2011 at 8:05
  • @Abbas It runs on Linux and I'd like to do it in PHP or python. 'encode' means the video is encoded by ffmpeg and its result will be stored into './output' directory - not to be encoded again. Commented Dec 21, 2011 at 8:06
  • As Dagon said, inotify would be the best approach if you are conversant in C, otherwise I think your current approach is an effective solution. Commented Dec 21, 2011 at 8:10
  • Thanks @Dagon! Could you write it again as 'answer'? ( And php:inotify implementation is also available, wow. : php.net/manual/en/book.inotify.php ) Commented Dec 21, 2011 at 9:44

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

Try making a perl daemon that checks for new files, i think it would be less resource intensive. Also, another more unix like alternative, and i think better overall: http://en.wikipedia.org/wiki/File_Alteration_Monitor

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.