2012-01-22 115 views
9

我有ffmpeg在PHP文件中進行視頻轉換,它的工作原理應該如此。問題是這需要花費一分鐘才能完成。我想這可能是容易做,但我只能得到它在後臺工作時,我只使用一個命令(不mp4box如單程轉化率)這樣如何使shell exec在後臺運行而php繼續

exec("nohup " . $ffmpegPath . " -i " . $srcFile . " -f mp4 -vcodec libx264 -crf 27 -s " . $srcWidth . "x" . $srcHeight . " -an -r 20 " . $destFile . ".mp4 > /dev/null 2>&1 &"); 

的問題是我需要用三不同的命令來做適當的轉換。到目前爲止,我的命令看起來像這樣在PHP文件,它的工作原理,但有大量的延遲:

exec($ffmpegPath . " -y -i " . $srcFile . " -f mp4 -pass 1 -passlogfile " . $video_pass_log . " -vcodec libx264 -vpre ipod640 -b:v 2M -bt 4M -an " . $destFile . ".mp4"); 
exec($ffmpegPath . " -y -i " . $srcFile . " -f mp4 -pass 2 -passlogfile " . $video_pass_log . " -vcodec libx264 -vpre ipod640 -b:v 2M -bt 4M -acodec libfaac -ac 2 -ar 44100 -ab 96k " . $destFile . ".mp4"); 
exec($mp4boxpath . " -tmp /tmp -hint " . $destFile . ".mp4"); 

我怎樣才能讓殼EXEC在後臺運行,而PHP繼續?

回答

24

參見Is there a way to use shell_exec without waiting for the command to complete?

添加> /dev/null 2>/dev/null &將刪除輸出,而在另一個進程中運行的命令(&創建新的進程,>2>重定向正常和錯誤輸出)

+1

感謝您的,這後也幫助解決了這個問題http://stackoverflow.com/questions/6402658/php-shell-exec-multiple-commands-at-once-in-background。看來我需要使用&&連接所有三個命令,然後在重定向輸出之前將所有內容包裝在括號中。 –

+0

+1用於解釋解決方案的每個部分的作用,而不是類似於類似問題的答案。 – AntonChanning

相關問題