php继续时如何让shell exec在后台运行

Jiz*_*nez 9 ffmpeg exec background-process

ffmpeg在PHP文件中进行了视频转换,它可以正常工作.问题是这需要一分钟才能完成.我认为它可能很容易但我只能在后台工作时只使用一个命令(例如没有mp4box的单通道转换)

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

问题是我需要使用三个不同的命令来进行正确的转换.到目前为止,我的命令在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");
Run Code Online (Sandbox Code Playgroud)

当PHP继续时,如何让shell exec在后台运行?

Jer*_*oen 25

请参阅是否有办法在不等待命令完成的情况下使用shell_exec?

添加> /dev/null 2>/dev/null &将删除输出并在另一个进程中运行命令(&创建新进程,>2>重定向正常和错误输出)