我允许用户上传视频,然后使用 ffmpeg 进行转换.视频转换需要很长时间,这通常会导致错误.我已经完成了我的研究,但不知道应该从哪里开始.
I allow users to upload videos and then they get converted using ffmpeg. The video takes a really long time to convert which usually results in an error. I have done my research with no luck as to where I should get started.
基本上我想要做的是允许用户上传视频,然后显示一条消息,表示正在处理视频,您将在可用时收到通知.同时,我希望视频在幕后进行转换,并允许用户离开页面甚至关闭浏览器.我使用的是 Windows 服务器.
Basically what I want to do is allow the user to upload the video and then display a message that says video is being processed and you will be notified when available. In the meantime I want the video to be converted behind the scenes and allow the user to leave the page or even close the browser. I am using a Windows server.
我怎样才能做到这一点?
How can I accomplish this?
以下是如何使用 Cron 等调度系统创建自己的队列的基本概要:
Here is a basic run-down of how to make your own queue using a scheduling system such as Cron:
(id, created_at, file_path, id_user, result, error)
的数据库表queue
.file_path
包含要处理的上传视频的位置,处理前结果为null
,然后根据成功情况为true/false
,以及如果失败 error
包含任何消息.如果合适,用户表的主键也可以保存在这里.ps aux | 的输出.如果您在类似 *nix 的操作系统中运行,grep (scriptname)
可以提供帮助.queue
containing (id, created_at, file_path, id_user, result, error)
. The file_path
contains the location of the uploaded video to process, the result is null
before processing and then true/false
afterwards depending on success, and if it failed error
contains any messages. The primary key of the user table can be saved here too, if appropriate.ps aux | grep (scriptname)
to help here, if you are running in a *nix-like operating system.在您的 Web 应用程序中,您需要稍微修改工作流程 - 而不是期望立即处理视频,您需要:
Inside your web application, you need to somewhat modify the workflow - rather than expecting a video to be processed immediately, you need to:
这种方法对于无法安装自己的队列处理器的共享主机非常有用.但是,如果您使用的是 VPS 或云系统,您可能希望查看 Gearman 或许多其他排队系统之一.它们比上面的要复杂一些,但具有更多用于管理工作队列的功能.
This approach is very useful for shared hosting where you cannot install your own queue processors. However, if you are on a VPS or cloud system, you may wish to look into Gearman or one of many other queueing systems. They are a bit more complex than the above, but have more features for managing queues of work.
这篇关于如何使用 PHP 和 ffmpeg 在后台转换视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!