Search code examples
pythonregexpython-2.7subprocessmediainfo

Python 2.7 mediainfo --inform outputs full info rather than one string


Using the following in powershell produces the expected output of 01:22:02:03:

 MediaInfo --Language=raw --Full --Inform="Video;%Duration/String4%" filename

My following python 2.7 script always gives the full mediainfo output with every piece of metadata, not just the Duration String that I specified.. I've tried escaping the semi colons but it has no effect. What am I doing wrong?

import sys
import subprocess
filename = sys.argv[1]
test = subprocess.check_output(['MediaInfo', '--Language=raw', '--Full', '--inform="Video;%Duration/String4%"', filename])
print test

Solution

  • Lose the double-quotes in the --Inform argument. I can reproduce your problem with this code:

    import subprocess
    
    args =  [
        'mediainfo',
        '--Language=raw',
        '--Full',
        '--inform="Video;%Duration/String4%"',
        'tests/reference.mp4'
    ]
    
    bad_output = subprocess.check_output(args)
    line_count_bad = len(bad_output.splitlines())
    
    args[3] = args[3].replace('"', '')
    
    good_output = subprocess.check_output(args)
    line_count_good = len(good_output.splitlines())
    
    print(line_count_bad, line_count_good, sep='\t')
    print(good_output)
    

    The output is:

    204 1
    b'00:00:07:08\n'