在服务器上运行FFMpeg(以避免用户等待)



我制作了一个简单的页面,让用户上传视频,然后显示使用HTML5 <video>标签上传的所有视频。但为了给用户提供完整的浏览器支持,我需要将上传的所有视频转码为一些新格式。问题是,现在我正在将所有视频代码转换为两种不同的格式,这反过来又需要很长时间,而且用户不得不等待视频代码转换。有没有一种简单的方法可以让我在"后台"运行这个脚本,这样用户体验就不会因为长时间的等待而受到影响?

我正在使用PHPexec命令运行FFMpeg脚本。

实现这一点有几个步骤。

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.   

您可以创建cron作业并在后台执行。此外,如果您正在使用FPM,您可以使用fastcgi_finish_request()

您可以在后台运行进程,这样您的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/

最新更新