|
@@ -0,0 +1,54 @@
|
|
|
|
|
+#!/usr/bin/env python3
|
|
|
|
|
+import sys, subprocess, pprint
|
|
|
|
|
+
|
|
|
|
|
+# Static config
|
|
|
|
|
+DEBUG = True
|
|
|
|
|
+lang_undef = 'und'
|
|
|
|
|
+
|
|
|
|
|
+# CLI config
|
|
|
|
|
+if len(sys.argv) < 2:
|
|
|
|
|
+ print(f"Usage: {sys.argv[0]} input_file", file=sys.stderr)
|
|
|
|
|
+ sys.exit(-1)
|
|
|
|
|
+
|
|
|
|
|
+# Parse to array of dicts of stream data
|
|
|
|
|
+def ffprobe(path):
|
|
|
|
|
+ streams = []
|
|
|
|
|
+
|
|
|
|
|
+ # ffprobe
|
|
|
|
|
+ args = [ 'ffprobe', '-show_streams', path ]
|
|
|
|
|
+ if DEBUG:
|
|
|
|
|
+ print(f"Running command: {args}", file=sys.stderr)
|
|
|
|
|
+ probe = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
|
+ if DEBUG:
|
|
|
|
|
+ print(f"ffprobe result: {probe}", file=sys.stderr)
|
|
|
|
|
+ data = probe.stdout.decode('utf-8')
|
|
|
|
|
+ if probe.returncode !=0:
|
|
|
|
|
+ print(f"ffprobe error ({probe.returncode}): {data}", file=sys.stderr)
|
|
|
|
|
+ sys.exit(probe.returncode)
|
|
|
|
|
+
|
|
|
|
|
+ # Process streams
|
|
|
|
|
+ stream = None
|
|
|
|
|
+ for line in data.splitlines():
|
|
|
|
|
+ if line == "[STREAM]":
|
|
|
|
|
+ if DEBUG:
|
|
|
|
|
+ print('Stream start', file=sys.stderr)
|
|
|
|
|
+ stream = {}
|
|
|
|
|
+ elif line == "[/STREAM]":
|
|
|
|
|
+ if DEBUG:
|
|
|
|
|
+ print('Stream end', file=sys.stderr)
|
|
|
|
|
+ streams.append(stream)
|
|
|
|
|
+ steam = None
|
|
|
|
|
+ elif stream is not None:
|
|
|
|
|
+ if DEBUG:
|
|
|
|
|
+ print(f"\tStream data: {line}", file=sys.stderr)
|
|
|
|
|
+ try:
|
|
|
|
|
+ (key, val) = line.split('=', 1)
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ print(f"Skipping unexpected stream data: {line}", file=sys.stderr)
|
|
|
|
|
+ continue
|
|
|
|
|
+ stream[key] = val
|
|
|
|
|
+
|
|
|
|
|
+ return streams
|
|
|
|
|
+
|
|
|
|
|
+# Execute
|
|
|
|
|
+pprint.pp(ffprobe(sys.argv[1]))
|