转换用户上传的视频文件使用 django、python 提供服务
我需要获取用户上传的任何视频文件,将其转换为 flv 或 webM &然后将其显示给用户。现在,经过一些研究,我得出的结论是,我必须使用 ffmpeg 进行转换,但我不确定如何处理整个管道。即
- 获取用户刚刚上传的文件。
- 在 django 后端以某种方式发送文件进行处理?
- 处理完成后删除用户上传的原始文件&将其替换为转换后的文件。
我只知道这个广泛的步骤,但喜欢如何以简化的方式连接每个步骤?例如,如何从 python 和 CLI 上启动对 ffmpeg 的系统调用继续等待,直到转换过程完成。另外,如何更新数据库以现在指向新的转换后的文件&删除旧的。如何(实时)告诉用户文件已转换,正在转换等,就像进度条一样?
我知道这是一个首要问题,但对任何/所有方面的帮助都会很棒!
I need to take any video file uploaded by the user, convert it into flv or webM & then display it to the user. Now after doing some research I came to the conclusion that I must use ffmpeg to do the conversion but I am unsure on how to take care of the entire pipeline. Namely,
- Get the just uploaded file by the user.
- In django backend somehow send the file for processing?
- After processing is complete remove the original file uploaded by the user & replace it with the converted file.
I just know of this broad steps but like how to connect each step in a streamlined fashion? e.g. how to start a system call to ffmpeg on CLI from python & keep on waiting till the conversion process is done. Also how to update the DB to now point to the new converted file & delete the old one. How to tell the user (live) that the file is converted, in conversion etc, like a progress bar?
I know that this is kind of an overarching question but help with any/all bits will be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果转换需要很长时间,您可能需要考虑将它们传递给任务处理程序:
http://celeryproject。 org/
可能就是这样。 python中的系统调用可以使用os模块中的函数来完成,例如os.system:
或os.popen:
python文档中有关于进程间通信等的部分。我敢肯定。
If a conversion is going to take a long time, you might want to consider passing them off to a task handler:
http://celeryproject.org/
might be just the thing. System calls in python can be done with functions in the os module, such as os.system:
or os.popen:
there's a section on inter-process communication and so on in the python docs. I'm sure.