2010-03-24 34 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

相關問題