【问题标题】:PHP FFMPEG not working when I upload mp4 file当我上传 mp4 文件时 PHP FFMPEG 不起作用
【发布时间】:2012-01-17 13:54:55
【问题描述】:

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

【问题讨论】:

  • 捕获错误输出。这可能会给出一些提示。
  • 从命令行使用所需参数调用 ffmpeg 并发布您收到的错误消息。
  • 没有错误?数组(0){}数组(0){}数组(0){}
  • 尝试回显您从$ffmpegObj 获得的所有$src* 变量,并确保它们包含合理的值。同样值得回显命令本身,从命令行运行它们并查看会发生什么。
  • 发现视频名称中包含不需要的符号导致的错误。在转换之前清理文件的名称,现在除了 webm 之外一切正常

标签: php ffmpeg html5-video ffmpeg-php


【解决方案1】:

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

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

【讨论】:

  • 在 PHP 中没有错误消息,但是在命令行中运行时,问题返回为由不需要的符号引起的错误。现在唯一的问题是转换为 webm。没有返回错误。
猜你喜欢
  • 2023-03-10
  • 2016-03-20
  • 2012-03-22
  • 1970-01-01
  • 2011-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
相关资源
最近更新 更多