要将视频转换为与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");
它应该采用任何输入视频类型并将其转换为mp4,ogv和webm。当我在.mov文件上运行脚本时,它返回mp4和ogv文件,但不返回webm。当我在.mp4文件上运行它时,它根本不返回任何已转换的文件。我转换文件的方式有问题吗?有什么帮助吗?
答案 0 :(得分:0)
您可以在命令行中运行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 );
的var_dump($ VARIABLE);
看看你得到了什么样的错误:)