3

To convert video to formats compatible with HTML5 video I wrote the following script:

    $srcFile = "name/of/the/video.mp4";
    $destFile = "/media/video/newfilename";
    $ffmpegPath = "/usr/local/bin/ffmpeg";
    $flvtool2Path = "/usr/local/bin/flvtool2";

    // Create our FFMPEG-PHP class
    $ffmpegObj = new ffmpeg_movie($srcFile);
    // Save our needed variables
    $srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
    $srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
    $srcFPS = $ffmpegObj->getFrameRate();
    $srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
    $srcAR = $ffmpegObj->getAudioSampleRate();
    $srcVB = floor($ffmpegObj->getVideoBitRate()/1000); 


    // Call our convert using exec() to convert to the three file types needed by HTML5
    exec($ffmpegPath . " -i ". $srcFile ." -vcodec libx264 -vpre hq -vpre ipod640 -b ".$srcVB."k -bt 100k -acodec libfaac -ab " . $srcAB . "k -ac 2 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".mp4");

    exec($ffmpegPath . " -i ". $srcFile ." -vcodec libvpx -r ".$srcFPS." -b ".$srcVB."k -acodec libvorbis -ab " . $srcAB . " -ac 2 -f webm -g 30 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".webm");

    exec($ffmpegPath . " -i ". $srcFile ." -vcodec libtheora -r ".$srcFPS." -b ".$srcVB."k -acodec libvorbis -ab " . $srcAB . "k -ac 2 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".ogv");

It is supposed to take any input video type and convert it to mp4, ogv and webm. When I run the script on a .mov file it returns a mp4 and ogv file, but not webm. When I run it on a .mp4 file it returns no converted files at all. Is there something wrong with the way I am converting the files? Any help?

Chris
  • 374
  • 1
  • 5
  • 16
  • Capture the error output. That might give some hints. – mario Dec 10 '11 at 20:31
  • Invoke the ffmpeg with the desired parameters from the command line and post the error messages that you get. – jap1968 Dec 10 '11 at 20:43
  • There are no errors? array(0) { } array(0) { } array(0) { } – Chris Dec 10 '11 at 20:46
  • Try echoing out all the `$src*` variables you get from `$ffmpegObj` and make sure they contain sensible values. It's also worth echoing out the commands themselves, running them from the command line and seeing what happens. – DaveRandom Dec 10 '11 at 20:55
  • Found an error caused by unwanted symbols in the video name. Sanitized the name of the file before converting and now it all works except for webm – Chris Dec 11 '11 at 01:44

1 Answers1

0

you could run the CMDs in commandline to see whats wrong, or add a variable end of each EXEC in the php code

exec($ffmpegPath . " -i ". $srcFile ." -vcodec libx264 -vpre hq -vpre ipod640 -b ".$srcVB."k -bt 100k -acodec libfaac -ab " . $srcAB . "k -ac 2 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".mp4", $VARIABLE);

var_dump($VARIABLE);

and look what kind of error you get :)

user1015314
  • 384
  • 3
  • 11
  • in PHP there are no error messages, but when run in commandline the problem returned as an error caused by unwanted symbols. Now the only problem is with converting to webm. There are no errors being returned. – Chris Dec 11 '11 at 01:47