Converting video files uploaded by user & serving

2019-05-04 12:37发布

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,

  1. Get the just uploaded file by the user.
  2. In django backend somehow send the file for processing?
  3. 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!

1条回答
\"骚年 ilove
2楼-- · 2019-05-04 13:13

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:

>>> os.system("/bin/ls")
api-manual.pdf  C++  GUI  Java  README

or os.popen:

>>> f=os.popen("/bin/ls")
>>> f.read()
'api-manual.pdf\nC++\nGUI\nJava\nREADME\n'
>>> f.close()

there's a section on inter-process communication and so on in the python docs. I'm sure.

查看更多
登录 后发表回答