Hassan Baig
Hassan Baig

Reputation: 15824

Lossy compression for video files before being uploaded on server (Django web app)

I need a bit of guidance. I have a Django app, where users upload photos and captions.

I want to integrate video uploading and playback as well. My question revolves specifically around video file size.

Most of my users have bandwidth issues. It's best if uploaded videos are as small a size as possible (quality can be compromised upon, it can be lossy). What's the best currently-supported Python library to get me started on this (an illustrative example)? I do something similar for photos uploaded on my site using Python Imaging Library.


Pyffmpeg seems to be the closest fit so far. But it doesn't seem to be supported any longer, nor do I find examples of what I'm trying to achieve. ffmpeg seems to be well documented however.

Upvotes: 1

Views: 5814

Answers (1)

anonDuck
anonDuck

Reputation: 1437

I'm doing quite a similar task on my website using ffmpeg and subprocess. To get you started this might help -

subprocess.check_call(
            ['ffmpeg', '-v', '-8', '-i', input_video, '-vf', 'scale=-2:480', '-preset', 'slow',
             '-c:v', 'libx264', '-strict', 'experimental', '-c:a', 'aac', '-crf', '20', '-maxrate', '500k',
             '-bufsize', '500k', '-r', '25', '-f', 'mp4', output_video_mp4, '-y'])

This would call ffmpeg to convert 'input_video' (with full path) into file 'output_video_mp4' (with full path) having mp4 format at 480p.

Refer to this link for more information - https://ffmpeg.org/ffmpeg-all.html

Upvotes: 3

Related Questions