【问题标题】:FFMPEG running in Command Line but not PHPFFMPEG 在命令行中运行但不是 PHP
【发布时间】:2010-03-24 01:46:49
【问题描述】:

我正在使用 ffmpeg build for windows 来制作视频缩略图。该命令在命令行中运行良好,但不适用于 PHP exec 方法。我正在使用 PHP 5.2.11

这是命令。

"E:/Documents and Settings/x/WINDOWS/ffmpeg" -itsoffset -4 -v "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs/bs/files/videogal/c08c3d20eeb9083ed033577bd154cba6.flv" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs/bs/files/gallery/8ff43b72b932d2a34e7a6733672ad4d6.jpg" 2>&1

有人可以帮忙吗?我检查了他们似乎很好的权限。 GD 已安装。

错误信息是'E:/Documents' is not recognized as an internal or external command, operable program or batch file

我在路径中使用正斜杠,除非转义双引号

PHP 函数

function ExtractThumb($in, $out)
{$path=dbconf::FFMPEG_PATH;
    $thumb_stdout;
    $errors;
    $retval = 0;
 echo $in;
    // Delete the file if it already exists
    if (file_exists($out)) { unlink($out); }

    // Use ffmpeg to generate a thumbnail from the movie
    $cmd = "$path -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";
   echo $cmd;

   exec($cmd, $thumb_stdout, $retval);

    // Queue up the error for processing
    if ($retval != 0) { $errors[] = "FFMPEG thumbnail generation failed"; }

    if (!empty($thumb_stdout))
    {
        foreach ($thumb_stdout as $line)
        {
            echo $line . "\n";
        }
    }

    if (!empty($errors))
    {
        foreach ($errors as $error)
        {
            echo $error . "\n";
        }
    }
}

如果我在没有 $in 和 $out 绝对路径的情况下运行这就是我得到的,那就够有趣了

Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --extra-cflags=-fno-common --enable-memalign-hack --enable-pthreads --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaac --enable-libgsm --enable-libx264 --enable-libschroedinger --enable-avisynth --enable-swscale --enable-gpl libavutil 49.12. 0 / 49.12. 0 libavcodec 52.10. 0 / 52.10. 0 libavformat 52.23. 1 / 52.23. 1 libavdevice 52. 1. 0 / 52. 1. 0 libswscale 0. 6. 1 / 0. 6. 1 built on Jan 13 2009 02:57:09, gcc: 4.2.4 822ae86a93810dade2843e822390d723.flv: no such file or directory

【问题讨论】:

  • 展示你是如何使用 PHP 执行它的。你有什么错误信息。您是否在 Web 服务器上运行它。如果是,你可以去E:\Documents and Settings ?etc 等等。你必须显示更多信息!
  • 我使用的是 Windows XP,所以我怀疑是否存在权限问题

标签: php ffmpeg


【解决方案1】:
exec("\"E:\\Documents and Settings\\x\\WINDOWS\\ffmpeg\" -i <inputfile> <options> <outfile>");

这是我过去使用过的一个(假设我在 LAMP 堆栈上):

$cmd = "/usr/bin/ffmpeg -i ".$in." -y -an -sameq -vframes 1 -s 100x56 -ss 3 -t 0.001 ".$out;

您也可以考虑:http://ffmpeg-php.sourceforge.net/

【讨论】:

    【解决方案2】:

    你需要正确地转义你的命令:

    exec(escapeshellcmd($cmd), $thumb_stdout, $retval);
    

    你还开启了 PHP 安全模式吗? 在尝试编码之前,您应该检查 $in 是否是真实文件。

    【讨论】:

    • +1 开启安全模式。它可能会应用默认的 open_basedir 限制,排除 exec 命令到达 ffmpeg 命令。
    【解决方案3】:

    您是否正确地转义了反斜杠、引号等?有错误提示吗?

    【讨论】:

      【解决方案4】:

      错误消息说它不能将其识别为命令。它很可能是您的报价。检查您对空格的引用。必要时使用斜杠“\”转义空格。你调用exec()的代码sn-p在哪里?

      【讨论】:

        【解决方案5】:

        不妨试试这个:

        $cmd = "\"$path\" -itsoffset -4 -i \"$in\" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 \"$out\" 2>&1";
        

        【讨论】:

          【解决方案6】:

          我是这样用的::

          exec("C:/wamp/bin/ffmpeg -i ./output4.mp4 -sameq -acodec libmp3lame -ar 22050 -ab 32 -f flv -s 320x240 ./output8.flv -vcodec mjpeg -vframes 4 -an -f rawvideo -s 320x240 ./pic008.jpg 2>&1");
          

          从 WAMP SERVER 直接连接。

          注意:

          ./output4.mp4

          这告诉 PHP 我正在处理当前目录。

          --万事如意

          【讨论】:

            猜你喜欢
            • 2013-08-19
            • 2015-05-08
            • 1970-01-01
            • 1970-01-01
            • 2011-07-04
            • 2017-01-30
            • 2011-09-21
            • 2020-07-02
            • 1970-01-01
            相关资源
            最近更新 更多