问题
I would like to convert videos with exec(), FFMPEG php. I would like to run the script in background. How can I do that?
/*** convert video to flash ***/
$v = date('H-i-s');
// exec("ffmpeg -i uploaded_files/770530705510e88ec723a3-20130111_1221_43.avi -ar 22050 -ab 32 -f flv -s 320x240 flash/".microtime()."video.flv 1> flash/".$v."_block.txt 2>&1");
$cmd = 'ffmpeg -i uploaded_files/770530705510e88ec723a3-20130111_1221_43.avi -ar 22050 -ab 32 -f flv -s 320x240 flash/'.microtime().'.flv';
$outputfile = $v.'.txt.';
$pidfile = $v.'_id.txt.';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
This is my code, but don't do anything. I would like to run the script with the php, but I don't want to wait the http loading time until the script is finished...
OR how can I run something.php with exec(); ? If I could run php that was easy me to make all what I needed. (linux debian, apache2, php5)
回答1:
The best way is to add a job to a queue and let the server handle the ffmpeg conversion in asynchronous way.
The users has to manually recheck if the server has already finished the job.
You have to do something like this:
- Create a queue database table.
- If a new ffmpeg conversion should be done add a job to the queue table.
- On the server add a cronjob which automatically looks for new jobs and executes your ffmpeg conversion. More details here.
- When the cronjob has finished the conversion then mark the job as done, delete it, or whatever.
来源:https://stackoverflow.com/questions/14789136/convert-videos-in-background-php-ffmpeg