#!/usr/bin/env python import sys import subprocess import json from pprint import pprint streams=json.loads(subprocess.run(["ffprobe", "-v", "error", "-show_streams", "-print_format", "json", sys.argv[1]], capture_output=True).stdout.decode("utf-8"))["streams"] for i in streams: matched=True match i["codec_type"]: case "video": out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+str(i["width"])+" "+str(i["height"])+" "+i["pix_fmt"]+" "+i["r_frame_rate"] try: out=out+" "+str(int(i["bit_rate"])/1000) except KeyError: try: out=out+" "+str(int(i["tags"]["BPS"])/1000) except KeyError: out=out+" unknown" case "audio": try: if sys.argv[2]!="" and sys.argv[2]!=i["tags"]["language"]: matched=False except: pass out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+str(i["sample_rate"])+" "+i["channel_layout"] try: out=out+" "+str(int(i["bit_rate"])/1000) except KeyError: try: out=out+" "+str(int(i["tags"]["BPS"])/1000) except KeyError: out=out+" unknown" out=out+" "+i["tags"]["language"] if i["disposition"]["default"]==1: out=out+" default" case "subtitle": try: if sys.argv[3]!="" and sys.argv[3]!=i["tags"]["language"]: matched=False except: pass out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+i["tags"]["language"] if i["disposition"]["default"]==1: out=out+" default" if i["disposition"]["hearing_impaired"]==1: out=out+" hi" try: if i["tags"]["title"].find("SDH")!=-1: out=out+" hi" except KeyError: pass case _: out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"] if matched==True: print(out)