FFmpeg
normalize.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 
3 import sys, subprocess
4 
5 if len(sys.argv) > 2:
6  ifile = sys.argv[1]
7  encopt = sys.argv[2:-1]
8  ofile = sys.argv[-1]
9 else:
10  print 'usage: %s <input> [encode_options] <output>' % sys.argv[0]
11  sys.exit(1)
12 
13 analysis_cmd = 'ffprobe -v error -of compact=p=0:nk=1 '
14 analysis_cmd += '-show_entries frame_tags=lavfi.r128.I -f lavfi '
15 analysis_cmd += "amovie='%s',ebur128=metadata=1" % ifile
16 try:
17  probe_out = subprocess.check_output(analysis_cmd, shell=True)
18 except subprocess.CalledProcessError, e:
19  sys.exit(e.returncode)
20 loudness = ref = -23
21 for line in probe_out.splitlines():
22  sline = line.rstrip()
23  if sline:
24  loudness = sline
25 adjust = ref - float(loudness)
26 if abs(adjust) < 0.0001:
27  print 'No normalization needed for ' + ifile
28 else:
29  print "Adjust %s by %.1fdB" % (ifile, adjust)
30  norm_cmd = ['ffmpeg', '-i', ifile, '-af', 'volume=%fdB' % adjust]
31  norm_cmd += encopt + [ofile]
32  print ' => %s' % ' '.join(norm_cmd)
33  subprocess.call(norm_cmd)
abs
#define abs(x)
Definition: cuda_runtime.h:35
len
int len
Definition: vorbis_enc_data.h:452