gpt4 book ai didi

当我上传 mp4 文件时,PHP FFMPEG 不工作

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:20 24 4
gpt4 key购买 nike

为了将视频转换为与 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 文件上运行它时,它根本不返回任何转换后的文件。我转换文件的方式有问题吗?有帮助吗?

最佳答案

您可以在命令行中运行 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);

看看你得到了什么样的错误:)

关于当我上传 mp4 文件时,PHP FFMPEG 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8459625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com