summaryrefslogtreecommitdiff
authorClément Bœsch <ubitux@gmail.com>2013-03-18 03:02:51 (GMT)
committer Clément Bœsch <ubitux@gmail.com>2013-03-26 00:50:13 (GMT)
commitec1ef0838c0d05398032274fe3272fcfe50ea85c (patch)
tree6758082dd2045a01f1e532d4b67c899cef28feb0
parent133035c40d28a6ae745a9c00f928a306fcbd0878 (diff)
downloadffmpeg-ec1ef0838c0d05398032274fe3272fcfe50ea85c.zip
ffmpeg-ec1ef0838c0d05398032274fe3272fcfe50ea85c.tar.gz
ffmpeg-ec1ef0838c0d05398032274fe3272fcfe50ea85c.tar.bz2
tools: add audio normalize script example.
Diffstat
-rwxr-xr-xtools/normalize.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/normalize.py b/tools/normalize.py
new file mode 100755
index 0000000..e015913
--- a/dev/null
+++ b/tools/normalize.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python2
+
+import sys, subprocess
+
+if len(sys.argv) > 1:
+ ifile = sys.argv[1]
+ encopt = sys.argv[2:-1]
+ ofile = sys.argv[-1]
+else:
+ print 'usage: %s <input> [encode_options] <output>' % sys.argv[0]
+ sys.exit(1)
+
+analysis_cmd = 'ffprobe -v error -of compact=p=0:nk=1 '
+analysis_cmd += '-show_entries frame_tags=lavfi.r128.I -f lavfi '
+analysis_cmd += "amovie='%s',ebur128=metadata=1" % ifile
+try:
+ probe_out = subprocess.check_output(analysis_cmd, shell=True)
+except subprocess.CalledProcessError, e:
+ sys.exit(e.returncode)
+loudness = ref = -23
+for line in probe_out.splitlines():
+ sline = line.rstrip()
+ if sline:
+ loudness = sline
+adjust = ref - float(loudness)
+if abs(adjust) < 0.0001:
+ print 'No normalization needed for ' + ifile
+else:
+ print "Adjust %s by %.1fdB" % (ifile, adjust)
+ norm_cmd = ['ffmpeg', '-i', ifile, '-af', 'volume=%fdB' % adjust]
+ norm_cmd += encopt + [ofile]
+ print ' => %s' % ' '.join(norm_cmd)
+ subprocess.call(norm_cmd)