Closed whargrove closed 1 year ago
I don't know if there is a guarantee that the video is an mp4 so how about a fast check of the format and IF it is an mp4, add this codec="copy"
otherwise, keep the re-encode to mp4 imo.
Feel free to open a PR!
@evamaxfield I was going to naively use the file extension, but it's a fair point that the ext might be lies!
Using file ext + ffmpeg.probe
should be sufficient here.
I'll submit a PR soon with the change.
@whargrove once this build is done, wait ~5 minutes, then update your instance to use the new release: https://github.com/CouncilDataProject/cdp-backend/actions/runs/4916882908
Describe the Bug
In clip_and_reformat_video if the video is already mp4 ffmpeg will encode the output stream as mp4.
Expected Behavior
Use ffmpeg StreamCopy to avoid re-encoding an already mp4 encoded video.
Reproduction
Proof of concept with ffmpeg-python:
Existing implementation:
using
time python main.py
shows real ~3s. I didn't benchmark this so it's anecdotal. On my machine, the encode speed is ~20x (60 / 20 ~= 3).Use StreamCopy:
(Note the only difference is
codec='copy'
arg in output.)When using StreamCopy, the pipeline on my machine takes ~200ms.
Environment
Linux ld1 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
4.1.0.rc0