开发者

How to split and convert videos using PHP & FFMPEG

I wan开发者_JS百科t the users to only upload a video, then write a code that splits this video into user-defined segments, then convert those segments to .flv and .mp4 videos.

Is there any way I can do that?


I don't think there is any way to do this directly within PHP. Even if there was, it wouldn't be the most sensible thing to do.

Your best bet is to hook your web application up to a command line program, such as ffmpeg, and call your system commands from the PHP script.

I'd approach this by building a job queue with your web application adding jobs to the queue and dedicated worker processes pulling from the queue, performing the task and recording the completion of the task somewhere else.

This means that your users won't have to wait for the video to be re-encoded in real time.


I dont no way to split the video into segments. For convert videos look the examples here - http://www.ffmpeg.org/ffmpeg-doc.html#SEC18.


Actually, you could check into FFMPEG-PHP for grabbing still shots from the video at defined times using the $movie->getFrame() method on an ffmpeg_movie object, even to the point of allowing a user to adjust the times.

Once you know the keyframes you want to split the videos on, you could execute the ffmpeg command from your PHP application.

I would suggest integrating PHP Resque (based on Ruby's Resque, which I use frequently) to queue the actual execution of ffmpeg commands, since that would otherwise stall your application. Simply set up a class with a perform() method to execute ffmpeg, and you can use PHP Resque to monitor the job status.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜