Encode video with Srt support

Encoding video and Subtitles together using Php5 and mencoder, ffmpeg

$dir = './'; // set to current folder
if ($handle = opendir($dir)) {
 while(false!== ($file = readdir($handle))) {
 if ( is_file($dir.$file) ){
 if (preg_match("'\.(avi)$'", $file) ){
 $sub_file = str_ireplace(".avi", ".srt", $dir.$file);
 $idx_file = str_ireplace(".avi", ".idx", $dir.$file);
 $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
 $out_file = str_ireplace(".avi", ".mp4", $dir.$file);
 flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);

//flv_convert_get_thumb('input.avi', 'input.srt', 'output.jpg', 'output.ogm');
// code provided and updated by steve of phpsnaps ! thanks
// accepts:
// 1: the input video file
// 2: path to thumb jpg
// 3: path to transcoded mpeg?
function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){
 // get thumbnail
 $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb;
 $res = shell_exec($cmd);
 // $res is the output of the command
 // transcode video
$cmd = 'mencoder '.$in.' -o '.$out_vid.' -sub '.$in_sub.' -subfont-text-scale 3.0 -subpos 99 -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encop$
 $res = shell_exec($cmd);


usage : copy code above into encoder.php place this file into your web server root directory, install all the requried tools needed to use ffmpeg-php now place some video.avi and video.srt or video.sub etc video.idx subtitle ,to encode video with srt visit your script http://yourip/encoder.php it should grab thumbnail then start the encoding job, refresh page and thats it this encoding script has been tested on a bare bone VPS ubuntu 8.04 server with the following tools installed Apache2 PHP5 Php-cli ffmpeg-php ffmpeg mencoder optional : mplayer - could be used instead of ffmpeg to grab thumbnails thanks for neo from expcore for helping me complete code trackback url : http://www.expertcore.org/viewtopic.php?f=67


Add your comment