Adding srt support in php for mencoder

User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Adding srt support in php for mencoder

Post by Neo » Sat Dec 19, 2009 1:16 am

mysoogal wrote:thanks again, i thought when you add // blaaa blaa in php it doesnt get executed
Commented codes are not getting executed in php.

If you are not going to use IDX, then you need to remove that from the function as well.
To be sure, I'll paste the code without using idx.

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.' -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'; 
    $res = shell_exec($cmd);
}
?>
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Adding srt support in php for mencoder

Post by Neo » Sat Dec 19, 2009 1:41 am

Looks like we missed a quotation mark. Can you post the line $cmd = 'mencoder '.$in..... that you use in the php file?
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: Adding srt support in php for mencoder

Post by Mysoogal » Sat Dec 19, 2009 1:47 am

$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:bfr$
im using the first code you posted , to test this http://89.238.172.210/Contact/

inside i change dir to ./Contact so i can fire e.php from /var/www/e.php

but i get white page the srt is in english
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Adding srt support in php for mencoder

Post by Neo » Sat Dec 19, 2009 2:06 am

Try, $dir = '/Contact/';
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: Adding srt support in php for mencoder

Post by Mysoogal » Sat Dec 19, 2009 2:09 am

still getting this
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /var/www/e.php on line 35

Parse error: syntax error, unexpected T_STRING in /var/www/e.php on line 35
soon my download completes i will try with the idx and with srt :mrgreen:
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Adding srt support in php for mencoder

Post by Neo » Sat Dec 19, 2009 2:14 am

paste you whole code, so I can give a quick try in terms of php syntax.
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: Adding srt support in php for mencoder

Post by Mysoogal » Sat Dec 19, 2009 2:25 am

this is for srt and avi i assume

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:bfr$
    $res = shell_exec($cmd);
}
?>
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: Adding srt support in php for mencoder

Post by Mysoogal » Sat Dec 19, 2009 2:30 am

the above code, not working here

http://89.238.172.210/Cocktail/

i've tested it, without idx support
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Adding srt support in php for mencoder

Post by Neo » Sat Dec 19, 2009 2:32 am

As suspected, a part of mencoder command line is missing.

Make sure you have this. (Use Select All t copy the code correctly)

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'; 
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: Adding srt support in php for mencoder

Post by Mysoogal » Sat Dec 19, 2009 2:44 am

ninja reporting in lol

i just knew it had to do something with the php not being executing right in another directory,

the really weird thing is, now it works only in /var/www/e.php if the file was inside a folder like so /var/www/example/e.php when i try to execute it, i get a white page, now i think probably due to the ffmpeg, not having full path to binary ? like so /usr/bin/ffmpeg and /usr/bin/mencoder is this the issue why i cant execute outside the www folder :D

Its Working now, just need to check if the fonts are alright guess i have to wait little longer until i get enough subtitles encoded to check it out
Post Reply

Return to “PHP & MySQL”