[FFmpeg-devel] [PATCH] avfilter: add loudnorm

Kyle Swanson k at ylo.ph
Mon May 9 21:40:09 CEST 2016

On Tue, Apr 5, 2016 at 7:01 PM, Kyle Swanson <k at ylo.ph> wrote:
> Here's another audio filter. I hinted at this a few months ago, but I found out that
> finishing the last 5% took almost as long as the first 95%. This is an EBU R128
> dynamic loudness normalization filter. This filter uses libebur128 v1.1.0[1] and must be
> configured with `--enable-libebur128'. Please also see the accompanying blog post[2]
> which has an algorithm description, as well as some usage instructions.
> [1] https://github.com/jiixyj/libebur128
> [2] http://k.ylo.ph/2016/04/04/loudnorm.html
> Thanks!
> Kyle


I think there was a little bit of confusion about what this filter
does, and why exactly it links libebur128. I'm not sure if anyone
actually reviewed the patch, since all of the discussion was about
libebur128. I didn't quite provide it the first time, so here's some
background information and rationale for linking libebur128.

Most broadcasters are now specifying mandatory loudness targets for
source material, which is usually supplied as a target integrated
loudness value and a target maximum true peak. Loudness normalization
is easy for files with sufficient headroom for linear gain
adjustments, difficult for files with not enough headroom, and even
more difficult for live streams – this filter handles all these
situations. The loudnorm algo is basically a loudness-tuned AGC which
was designed to honor local dynamics, followed by a look-ahead true
peak limiter. Using normal parameters the result is usually
imperceptible, even with very dynamic source material such as
classical music. This filter should be a major boon to broadcasters
and digital distribution people, since the only software currently
available that does this kind of thing is commercial, and for the most
part very expensive (Minnetonka, Skylark, Nugen, etc.)

FFmpeg has a native ebur128 filter which already has all the EBU R128
logic baked in, but I chose to link libebur128 with the loudnorm
filter for a couple of reasons. If all it needed was an input
measurement, it would certainly be easy to just export the frame meta
from the ebur128 filter, but the loudnorm algorithm needs loudness
measurements from a couple of different places in the signal chain
making this solution impossible. I thought about extracting the FFmpeg
ebur128 functions so they could be reused elsewhere in FFmpeg, but the
R128 logic from the ebur128 filter is quite tangled, tied to filter
functions, internal states are spread out between several structs, and
is not easily extracted into a reusable API. Ideally, someone could
take a crack at extracting the FFmpeg ebur128 logic, but in the
meantime I chose to link libebur128 with the loudnorm filter.
libebur128 is well known and used R128 library.

True this adds a dependency and seems a little redundant, but this is
a filter and not a core part of FFmpeg. Many filters link special
libraries, users can choose to either configure and compile with the
library or not, and if they don't then the filter won't be enabled on
their builds. Maybe I'm wrong, but I don't see it as a huge issue. If
I or someone else gets the time to rewrite FFmpeg's ebur128 filter
down the road, it should be easy to update this filter to use FFmpeg's
ebur128 measurements.

Updated and rebased patch is attached, please review.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avfilter-add-loudnorm.patch
Type: application/octet-stream
Size: 38744 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160509/a77fac50/attachment.obj>

More information about the ffmpeg-devel mailing list