1

I want to share my script to do this with Media Info CLI and python. At first I tried with pure bash but should have just gone python at first, much quicker and adaptable (for me).

My task was to recursively go through all files in a specified folder (in this case on a NAS), and print as well as store in a txt file all the video codec and profile level used in each.

The reason be I found some older Samsung TV wont play H264 with profile level greater than 4.1 , so some re-encoding was in order, also the latest Samsung TV have dropped support for xvid/divx.

1 Answer 1

1

usage: ./your_script_name.py ./your_path | tee output.txt

if you want different/additional details from media info check those available with "mediainfo --Info-Parameters"

#! /usr/bin/env python3 from glob import glob import os import sys import subprocess codecSummary = set() #dictionary path = sys.argv[1] print(path) files = [f for f in glob(path+'/**', recursive=True) if os.path.isfile(f)] #print(files) for file in files: result = subprocess.check_output('mediainfo "'+file+'" "--Inform=Video;%Format% %Format_Profile%"', shell=True).decode().rstrip() if result: codecSummary.add(result) print(result + ' '+ file) 

print(codecSummary)

2
  • 1
    +1. nice idea, but you might want to look into pymediainfo, a library module which allows python programs to gather the same information without having to fork an external program (mediainfo) and then parse the text results. If you're running debian (or ubuntu, etc) you can install it with sudo apt install python3-pymediainfo. Other distros may have it packaged too, with a similar package name. Commented Oct 20, 2021 at 5:53
  • pymediainfo uses mediainfo so not sure what @cas is talking about. Commented Jul 28, 2024 at 18:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.