Using ffmpeg in converting php video to mp4

Asked By 20 points N/A Posted on -
qa-featured

 

Hi guys,

I am designing a website and I was looking to add video conversion utility to my website such as FFMPEG and use this through PHP to handle video conversion from multiple formats to mp4. This converting PHP video to mp4 should be stable and be able to handle large file sizes.

What I need is a detailed description on how to do this, anyone who can assist me on this please reply to the post.

SHARE
Answered By 0 points N/A #142052

Using ffmpeg in converting php video to mp4

qa-featured

 

You can use this sample script to have a FFMpeg conversion working on your website:
 
/* looping through all files in the directory */
if ($handle = opendir('assets/uploaded_videos')) {
    while (false !== ($entry = readdir($handle))) {
 
        /* filtering the desired extensions */
        if ($entry != "." && $entry != ".." && in_array(substr($entry, strrpos($entry, '.')), array(".wmv", ".mpg", ".mpeg", ".flv", ".ogg", ".mp4")))
        {
            $filename = substr($entry, 0, strrpos($entry, '.'));
 
            //$command = "ffmpeg -i assets/uploaded_videos/$entry -vcodec libx264 assetss/videos/$filename.mp4";
 
           $command = "ffmpeg -i files/uploaded_videos/$entry -vcodec libx264 -profile:v baseline -level 3 files/videos/$filename.mp4";
 
 
            echo $command."<br />";
 
            shell_exec($command."> /dev/null 2>/dev/null &");
        }
    }
    closedir($handle);
}
 
 
And then you can use below code to embed the video:
 
<video width="350" poster="<?php echo $first_video['thumb_path'];?>" controls>
    <source src="<?php echo $first_video['video_path']; ?>" />
    <span id="silverlight_player_for_fallback"></span>
</video>

Login/Register to Answer

Related Questions