Â
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.
Using ffmpeg in converting php video to mp4
Â
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>