How to run FFMPEG commands in Django?
Asked Answered
E

1

7

I've spent several weeks of my free time trying to figure out this issue or search for it to no avail and I'm not sure if it is a Python or Django issue and was wondering if anyone could guide me in the right direction.

I understand uploading video files and querying them, but I am inexperienced in using FFMPEG with Django (specifically converting video to FLV). How do I call the command in Django view to convert the video and how do I do that action in between when the submit button is clicked and when it is saved the video to database.

Thank you for any help! I haven't been able to find any articles/literature on this and its killing me!

Erepsin answered 21/11, 2012 at 4:49 Comment(0)
C
14

You can use subprocess python module to call ffmpeg once the file is uploaded.

import subprocess
subprocess.call('ffmpeg -i video.mp4 video.flv') # check the ffmpeg command line :)

ffmpeg is quite cpu intensive. You should be careful of this point on a real world web app. The subprocess call will block the app until the conversion is done (it may be long in some cases). celery can be a solution for running it as an non-blocking asynchronous task.

There are several apps for video management. I've never used one of them but I think you should have a look to django-multimedia. It seems to be what you are looking for.

Cattish answered 21/11, 2012 at 5:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.