Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle queueing of video encoding during multiple video uploads?

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.

like image 204
YD8877 Avatar asked Jun 18 '11 18:06

YD8877


1 Answers

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.

like image 51
Mridul Kashatria Avatar answered Sep 30 '22 17:09

Mridul Kashatria