In Python-Django, I’ve got a Model with a FileField member in it. This member stores video files.
I’d like to “interfere” with the standard “add model row/object/instance” proecdure of Django, and manipulate each video I’m adding, before actually committing or adding it to database.
The manipulation is to convert the video to a specific uniform format. Thus, all added videos will eventually be stored in the same format (WebM).
How can I do that? I’ve looked into Django’s custom managers, but I don’t think that’s what I’m looking for.
Thanks. 🙂
I am actually doing this very same thing. You don’t want to process the video file on the same request as it comes in on for several reasons:
1) You will hang the user on a non-responsive page for a long time, possibly timing them out and wondering if it worked.
2) And if they go to see if it uploaded – it still hasn’t finished and saved in the DB (non-consistent) they’ll think it is broken.
You want to initially save the record and file on your server. Mark it as needs-to-be-worked-on. And fire off a celery task that will do that work and update that flag when it is complete. I am actually doing this very same thing with zencoder for a project I am working on right now. It works wonderfully.
Celery: http://pypi.python.org/pypi/django-celery
Ghettoq (for local): http://pypi.python.org/pypi/ghettoq