I work with video creation, animation, or fix video elements for several broadcasters in my area. My pipeline includes ffmpeg suite of libraries, and I have written one plugin specifically for ffmpeg to take care of one of the elements of my video editing.
One thing I found myself struggling with is to preserve the format of the original video, and since this is one of the requirements to return edited video in the same format as the source, my biggest challenge is to:
- programmatically extract parameters of the source video (I use ffprobe)
- run my editing pipeline, one of which is my ffmpeg-plugin, then
- re-compress the video using the parameters extracted in step 1.
I've managed to automate big part of steps 1 & 3 with python, and I have a series of calls to extract elements of each video, my code looks like this:
color_string = 'ffprobe -v error -select_streams v:0 -show_entries stream=' \
'color_space,color_primaries,color_range -of default=nw=1:nk=1 "' + filename + '"'
# following running of subprocess:
color = subprocess.run(color_string, shell=True, capture_output=True)
# then parse:
color_array = str(color.stdout).split('\\n')
color_primaries = color_array[1]
color_range = color_array[2]
The problem is, every broadcaster uses their own coding standards, and while I don't care about audio at all, meaning, I can -c:a copy, all the video parameters are different from broadcaster to broadcaster. progressive/interlaced, DVCPRO which sometimes includes screen sizes of 1280x1080 (which drives me insane), prores with all its profiles and even deeper with -qscale and -bits_per_mb options, some codecs have vtag and some don't, and there are about 100+ others. And my list of ffprobe queries keeps growing, I have about 1k lines of extraction and then putting it all together for ffmpeg to run.
My question is, is there a library to extract video parameters from a source, then once the processing is done, use that library to populate all the arguments for ffmpeg? As it turned out, I'm building one for myself, but I have a feeling I'm wasting my time.
I know that many adobe applications use this logic, and provide an option to preserve source on re-encoding a video, but I am building one with python, and I believe this would be a great utility application as an open source, since there are simply too many options to consider for one person.
I originally posted this question on superuser site, and was advised by @Tetsujin to migrate my question to this site, since it is specifically video related.