我制作了一个简单的页面,让用户上传视频,然后显示使用HTML5 <video>
标签上传的所有视频。但是为了为用户提供完整的浏览器支持,我需要将所有上传的视频转码为几种新格式。问题是现在我正在将所有视频转码为两种不同的格式,这又需要很长时间,并且用户必须等待视频被转码。有没有人知道的简单方法让我在“后台”运行这个脚本,这样用户体验就不会因等待时间长而受到影响?
我正在使用命令运行FFMpeg
脚本。PHP
exec
您可以在后台运行进程,这样您的 php 脚本就不会等待完成新进程。您可以使用此示例:
<?
$command = "/usr/bin/php4 -f /var/www/myweb/start_ffmpeg.php";
exec( $command." > /dev/null &", $arrOutput );
?>
您可以创建cron作业并在后台执行。此外,如果您使用 FPM,您可以使用 fastcgi_finish_request()
有一些步骤可以实现这一目标。
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.