2010-03-24 33 views
10

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

这是命令。

"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"; 
     } 
    } 
} 

搞笑不够的,如果我没有在$和$运行时除外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 
+0

显示如何使用PHP执行它。你有什么错误信息。你是否在网络服务器上运行它。如果是的话,你是否可以去'E:\ Documents and Settings'等等等等。你必须显示更多信息! – ghostdog74 2010-03-24 01:54:02

+0

我正在使用Windows XP,因此我怀疑是否存在权限 – Freeman 2010-03-24 02:40:52

回答

1

你是否正确地逃避你的反斜杠,引号等?有没有错误信息?

1

该错误消息表示它不会将其识别为命令。它最可能是你的报价。检查你的空白的引用。必要时使用斜杠“\”逃脱白色空间。你的代码段在哪里调用exec()

3
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/

1

也许试试这个:

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

您需要正确地逃脱你的命令:

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

你也有PHP安全模式吗? 在尝试编码之前,您应该检查$in是否是一个真正的文件。

+0

+1的安全模式问题。它可能会应用默认的open_basedir限制,该限制排除exec命令以达到ffmpeg命令。 – Giuseppe 2018-02-28 03:08:04

1

我使用这种方式::

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服务器直接连接。

注意的:

./output4.mp4

,并且告诉我处理当前目录下的PHP。

- All the Best

相关问题