我做了一个简单的页面,允许用户上传视频,然后显示所有使用HTML5 <video>标签上传的视频。但是为了给用户提供完整的浏览器支持,我需要将上传的所有视频转码为几种新格式。问题是,现在我正在将所有的视频转码为两种不同的格式,这反过来需要很长时间,这使得用户必须等待视频被转码。有没有一种简单的方法可以让我在“后台”运行这个脚本,这样用户体验就不会因为长时间的等待而受到影响?
我正在使用PHP和exec命令运行FFMpeg脚本。
发布于 2013-06-26 15:35:50
要实现这一点,需要采取一些步骤。
1. First enter videos into a queue table.
2. Setup a cron to transcode videos after small interval like after every 5-10 minutes.
3. Make a section to show status of videos transcode for user. You can also use javascript periodicalexecuter for repeat check and show status somewhere on your page. 发布于 2013-06-26 15:39:29
您可以创建cron作业并在后台执行。此外,如果您使用的是FPM,则可以使用fastcgi_finish_request()
发布于 2013-06-26 15:42:29
您可以在后台运行进程,这样您的php脚本就不会等待完成新进程。您可以使用此示例:
<?
$command = "/usr/bin/php4 -f /var/www/myweb/start_ffmpeg.php";
exec( $command." > /dev/null &", $arrOutput );
?>点击此处:http://www.sitecrafting.com/blog/to-run-php-code-in/
https://stackoverflow.com/questions/17314005
复制相似问题