简体   繁体   English

当我上传mp4文件时,PHP FFMPEG无法正常工作

[英]PHP FFMPEG not working when I upload mp4 file

To convert video to formats compatible with HTML5 video I wrote the following script: 要将视频转换为与HTML5视频兼容的格式,我编写了以下脚本:

    $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. 它应该采用任何输入视频类型并将其转换为mp4,ogv和webm。 When I run the script on a .mov file it returns a mp4 and ogv file, but not webm. 当我在.mov文件上运行脚本时,它返回mp4和ogv文件,但不返回webm。 When I run it on a .mp4 file it returns no converted files at all. 当我在.mp4文件上运行它时,它根本不返回任何已转换的文件。 Is there something wrong with the way I am converting the files? 我转换文件的方式有问题吗? Any help? 有帮助吗?

you could run the CMDs in commandline to see whats wrong, or add a variable end of each EXEC in the php code 您可以在命令行中运行CMD以查看错误,或者在PHP代码中添加每个EXEC的变量结尾

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 ); 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); 后续代码var_dump($变量);

and look what kind of error you get :) 看看你得到了什么样的错误:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM