简体   繁体   中英

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. 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.

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

Thank you for your time!

You can use > /dev/null & instead of 2>&1 &

This will execute $cmd in the background without PHP waiting for it to finish.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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