简体   繁体   English

php exec ffmpeg未在后台运行

[英]Php exec ffmpeg not running in background

I am trying to start a ffmpeg process from a php script and I know it has been asked a lot of times but I tried many solutions and none of them seem to work, each time the php script never finishes unless I kill the ffmpeg process. 我正在尝试从php脚本启动ffmpeg进程,我知道已经问了很多遍了,但是我尝试了许多解决方案,但是似乎没有一个可行的方法,每次php脚本永远不会完成,除非我杀死ffmpeg进程。 At the moment I am using this script which indeed starts ffmpeg and writes info in the designated files but the php script is loading forever. 目前,我正在使用该脚本,该脚本的确启动了ffmpeg并在指定文件中写入了信息,但是php脚本却永远加载。

What am I missing? 我想念什么?

$cmd = 'cd cache && ffmpeg -y -i "rtsp://stream" -r 20 -f image2 a%6d.jpg >/dev/null 2>/dev/null &';

exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, 'log.txt', 'error.txt' . '.pid')); 

A little more info: I am running FFMpeg 0.6.5, PHP 5.3.3 on CentOS 6.5 更多信息:我在CentOS 6.5上运行FFMpeg 0.6.5,PHP 5.3.3

Thank you for your time! 感谢您的时间!

You can use > /dev/null & instead of 2>&1 & 您可以使用> /dev/null &代替2>&1 &

This will execute $cmd in the background without PHP waiting for it to finish. 这将在后台执行$cmd ,而无需PHP等待其完成。

Ref: http://php.net/manual/en/function.exec.php 参考: http : //php.net/manual/en/function.exec.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM