I am working on developing a video streaming site where users can upload videos to the site (multiple videos at once using the uploadify jquery plugin).
Now, I am faced with the question of encoding the videos to FLV for streaming them online.
When should the video encoding process take place ? Should it take place immediately after uploads have finished (i.e redirect the user to upload success page, and then start encoding in the background using exec command for ffmpeg ?) However, using this approach, how do i determine if the encoding has finished successfully ? What if users upload a corrupt video and ffmpeg fails to encode it ? How do i handle this in PHP ?
How do i queue encoding of videos since multiple users can upload videos at the same ? Does FFMpeg has its own encoding queue ?
I also read about gearman and message queueing options such as redis and AMQP in another related SO thread. Are these one of the potential solutions ?
I would really appreciate if someone could give answers to my questions.
You should use a software called gearman. It is a job server and you can call functions using PHP. You can transfer the process to background and it automatically handles queuing. Many processes can be run parallel also.
I've used it and it is very easy to install and operate.
For your use case,
Wrap the ffmpeg process in a php file with exec. Save the uploaded file to db and give it an id. Call the encode function after a user uploads file. As soon as the encode function starts, update the db to reflect that the file was "picked". First run the ffmpeg info on the file to see if it is fine. Then encode the file and after it is done, update db flag to "done".
After the process is done, you can call another function to send an email, tweet etc to the user that the encoding is complete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With