[FFmpeg-devel] [PATCH] tools: add audio normalize script example.
Clément Bœsch
ubitux at gmail.com
Tue Mar 26 01:52:47 CET 2013
On Mon, Mar 25, 2013 at 11:31:18AM +0100, Stefano Sabatini wrote:
[...]
> > +analysis_cmd = 'ffprobe -v error -of compact=p=0:nk=1 '
> > +analysis_cmd += '-show_entries frame=metadata:tags=lavfi.r128.I -f lavfi '
>
> -show_entries frame_tags=lavfi.r128.I
>
> looks more correct.
>
> -show_entries "frame=metadata : tags=lavfi.r128.I"
>
> means show frame=metadata ("metadata" field in frame, which is
> non-existing), and tags=lavfi.r128.I, that is all the tags matching
> the key "lavfi.r128.I", while we only want to show the one in
> frame_tags.
>
Ah, indeed, thanks.
> > +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
>
> A potentially simpler approach would consist into sending the last
> value when we close the filter (such as lavfi.r128.eof.I), so we don't
> have to process all the previous values just to find the last one.
>
We might not have a frame when closing/flushing. Ideally we should have
overall "stream" metadata at libavfilter level. That's not the case yet,
so I keep the script as is now.
> > +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)
>
> Looks good oterwise.
Thanks, pused.
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130326/f8a76be9/attachment.asc>
More information about the ffmpeg-devel
mailing list