Page 1 of 5
Adding srt support in php for mencoder
Posted: Thu Dec 17, 2009 7:26 am
by Mysoogal
working, but confused on adding srt support during the mencoder encoding stage.
Code: Select all
<?php
flv_convert_get_thumb('input.avi', '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, $out_thumb, $out_vid)
{
// get thumbnail
$cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 5 -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.' -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';
$res = shell_exec($cmd);
}
?>
i havve in /var/www/ list of example.avi and example.srt how would i add support so mencoder also includes the srt subtitles while encoding ? a user at digitalpoint has given this link to
https://robot.lk/viewtopic.php?f=67&t=1066
when i visit this page, it shows this code
Code: Select all
$dir = '/path/to/files';
if ($handle = opendir($dir)) {
while(false!== ($file = readdir($handle))) {
if ($file == '.' && $file == '..') continue;
// your code here
}
closedir($handle);
}
can somebody help me with it, how to change the big code above ?
thank you
Re: Adding srt support in php for mencoder
Posted: Fri Dec 18, 2009 12:42 pm
by Neo
I know your problem and here I write the code for you
This script will convert all the avi files in a given directory to mp4 with subtitles.
Copy this to a file with extension php and place it in the same folder with avi files. (If you want to place it in a different folder, make sure you set it to $dir.
Code: Select all
<?php
$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);
$thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
$out_file = str_ireplace(".avi", ".mp4", $dir.$file);
flv_convert_get_thumb($dir.$file, $sub_file, $thumb_file, $out_file);
}
else{
continue;
}
}
}
closedir($handle);
}
//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, $out_thumb, $out_vid){
// get thumbnail
$cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 5 -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.' -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';
$res = shell_exec($cmd);
}
?>
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:11 am
by Mysoogal
thank you very much, it works

great now don't have to type all in ssh
just wonder why the fonts seem to be so big
can i also add support for sub and idx i think this format is supported in mencoder
Code: Select all
$sub_file = str_ireplace(".avi", ".srt",.sub",.idx", $dir.$file); <------- like this ?
$thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
$out_file = str_ireplace(".avi", ".mp4", $dir.$file);
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:25 am
by Neo
Use following flags.
Code: Select all
-subfont-text-scale 3.3 -subpos 96
The first one to set the font size to 3.3%. The second setting will move the subtitles up a bit so it is clearly visible on a TV.
So change your command line of mencoder as below.
Code: Select all
$cmd = 'mencoder '.$in.' -o '.$out_vid.' -sub '.$in_sub.' -subfont-text-scale 3.3 -subpos 96 -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';
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:35 am
by Neo
For IDX support:
Code: Select all
$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);
Change function prototype as below:
Code: Select all
function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){
MEncoder syntax:
Code: Select all
$cmd = 'mencoder '.$in.' -o '.$out_vid.' -sub '.$in_sub.' -subfont-text-scale 3.3 -subpos 96 -idx '.$in_idx.' -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';
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:47 am
by Mysoogal
thanks for that, but when i changed the code, and went to test it out, i get a white page. when i go back and do refresh no thumbs and no mp4 and no encoding. i wonder if mencoder understand that part
the sub, and idx are from vobsub right ? do mencoder need to be complied with something to understand it ?
i think i missed something i will check again now

Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:51 am
by Neo
Did you place the idx file in the format of example.idx if your avi filename is example.avi?
I don't think you need to re-compile mencoder for this. Lets try!
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 12:56 am
by Mysoogal
i see, i was testing it on a file that is being downloaded, maybe that is the issue

guess i have to wait until file completes download then test it fully. yes everything is inside ,
http://89.238.172.210/Fatal.Move.2008.DVDRip.XViD-BiEN/
i didnt add the e.php until its complete , i've read somewhere that maybe you only need idx ? since this is like srt and sub not needed is this true
encoding script looking alright ?
Code: Select all
<?php
$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);
$thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
$out_file = str_ireplace(".avi", ".mp4", $dir.$file);
flv_convert_get_thumb($dir.$file, $sub_file, $thumb_file, $out_file);
}
else{
continue;
}
}
}
closedir($handle);
}
//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 5 -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.3 -subpos 96 -idx '.$in_idx.' -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';
$res = shell_exec($cmd);
}
?>
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 1:02 am
by Neo
looks correct except function call. You missed passing idx file parameter.
Change as below.
Code: Select all
flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
Re: Adding srt support in php for mencoder
Posted: Sat Dec 19, 2009 1:08 am
by Mysoogal
thanks again, i thought when you add // blaaa blaa in php it doesnt get executed
oh jesus lol i find problem
this line was // flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
so that didnt get executed right lol
something strange happend when i test on example.avi and example.srt
i get this
Code: Select all
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /var/www/Contact/e.php on line 35
Parse error: syntax error, unexpected T_DNUMBER in /var/www/Contact/e.php on line 35
is this due to the srt having not UTF8 thing ?