Add small tool to check for broken audio in video files master github/master
authorMagnus Hagander <[email protected]>
Fri, 12 Dec 2025 17:51:49 +0000 (18:51 +0100)
committerMagnus Hagander <[email protected]>
Fri, 12 Dec 2025 17:51:49 +0000 (18:51 +0100)
tools/videos/check/check_video_audio.py [new file with mode: 0755]

diff --git a/tools/videos/check/check_video_audio.py b/tools/videos/check/check_video_audio.py
new file mode 100755 (executable)
index 0000000..05da9d8
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+import subprocess
+import os
+import sys
+
+
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print("Usage: check_video_audio.py <video_file> [video_file2 ...]")
+        sys.exit(1)
+
+    for v in sys.argv[1:]:
+        sys.stdout.write("{}: ".format(os.path.basename(v)))
+        sys.stdout.flush()
+
+        r = subprocess.run([
+            'ffmpeg',
+            '-i', v,
+            '-map', '0:a:0',
+            '-af', 'astats',
+            '-f', 'null',
+            '-',
+            ], capture_output=True, check=True)
+        currchannel = 'unknown'
+        for line in r.stderr.decode().splitlines():
+            if 'Channel: ' in line:
+                currchannel = line.split(':')[-1]
+            if 'RMS peak dB' in line:
+                val = line.split(':')[-1]
+                if 'inf' in val:
+                    print("Channel {} is silent.".format(currchannel))
+                    break
+        else:
+            print("All channels have sound")