mencoder libx264 through php

encoding to h264 through mencoder, using libx264 and mp3 support. via php scripting.

convertToFlv( "some-input-video.avi", "output.mp4" );

function convertToFlv( $input, $output ) {
   echo "Converting $input to $output<br />";
   $command = "mencoder $input -o $output -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=500:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame";
   echo "$command<br />";
   shell_exec( $command );
   echo "Converted<br />";


This script is depended on the following packages and operating system

Ubuntu 8.10 desktop or Server editions

Line 2, is where you can input the name of video file you wish to convert to h264, output file is where the completed encoded video file will be placed. and named.

Line 6, is where the mencoder code starts to do its encoding command, you can change the bitrate via this configuration on line 6 bitrate=500 to improve the video quality you can change 500 to 800 or higher. it's recommended you do not change this setting aspect 16:9 from the command line, as new laptops and video players are designed to be wide screen ratio of 16:9 this will give you a nice look on your videos.

thats it, have fun improving this code, and please post back here if you have improved it so everybody can share the code, thanks


Add your comment