Convert videos in background php ffmpeg?

邮差的信 提交于 2020-01-07 04:27:13

问题


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:

  1. Create a queue database table.
  2. If a new ffmpeg conversion should be done add a job to the queue table.
  3. On the server add a cronjob which automatically looks for new jobs and executes your ffmpeg conversion. More details here.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!