FFMPEG 在命令行中运行,但不在 PHP 中运行

2023-11-23

我正在使用 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

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/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

FFMPEG 在命令行中运行,但不在 PHP 中运行 的相关文章