user35938: 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.

user32358: ffprobe can output json, making it a lot simpler:
import json
from subprocess import run, PIPE, DEVNULL
import sys

def ffprobe_json(filename):
    proc = run(
        [ "ffprobe", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", filename ],
        stdin=DEVNULL, stdout=PIPE, stderr=PIPE
    )
    proc.check_returncode()
    return json.loads(proc.stdout.decode(sys.getdefaultencoding()))


35938: <p>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.</p>
<p>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:</p>
<ol>
<li>programmatically extract parameters of the source video (I use ffprobe)</li>
<li>run my editing pipeline, one of which is my ffmpeg-plugin, then</li>
<li>re-compress the video using the parameters extracted in step 1.</li>
</ol>
<p>I've managed to automate big part of steps 1 &amp; 3 with python, and I have a series of calls to extract elements of each video, my code  looks like this:</p>
<pre><code>color_string = 'ffprobe -v error -select_streams v:0 -show_entries stream=' \
                   'color_space,color_primaries,color_range -of default=nw=1:nk=1 &quot;' + filename + '&quot;'
# 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]
</code></pre>
<p>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.</p>
<p><strong>My question is</strong>, 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.</p>
<p>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.</p>
<p><em>I originally posted this question on superuser site, and was advised by</em> @Tetsujin <em>to migrate my question to this site, since it is specifically video related.</em></p>
 32358: <p>ffprobe can output json, making it a lot simpler:</p>
<pre><code>import json
from subprocess import run, PIPE, DEVNULL
import sys

def ffprobe_json(filename):
    proc = run(
        [ &quot;ffprobe&quot;, &quot;-hide_banner&quot;, &quot;-print_format&quot;, &quot;json&quot;, &quot;-show_format&quot;, &quot;-show_streams&quot;, filename ],
        stdin=DEVNULL, stdout=PIPE, stderr=PIPE
    )
    proc.check_returncode()
    return json.loads(proc.stdout.decode(sys.getdefaultencoding()))
</code></pre>
