[FFmpeg-devel] [PATCH 2/2] lavfi/volume: support volume normalization through metadata.

Clément Bœsch ubitux at gmail.com
Wed Feb 27 14:15:38 CET 2013


On Sun, Feb 24, 2013 at 11:53:38PM +0100, Stefano Sabatini wrote:
[...]
> > @@ -183,13 +188,13 @@ static void volume_init(VolumeContext *vol)
> >  
> >      switch (av_get_packed_sample_fmt(vol->sample_fmt)) {
> >      case AV_SAMPLE_FMT_U8:
> > -        if (vol->volume_i < 0x1000000)
> > +        if (vol->volume_i < 0x1000000 && !vol->metadata)
> >              vol->scale_samples = scale_samples_u8_small;
> >          else
> >              vol->scale_samples = scale_samples_u8;
> >          break;
> >      case AV_SAMPLE_FMT_S16:
> > -        if (vol->volume_i < 0x10000)
> > +        if (vol->volume_i < 0x10000 && !vol->metadata)
> >              vol->scale_samples = scale_samples_s16_small;
> 
> Uhm so this basically it's setting scale_samples_u8_small only in case
> metadata is not used? Can you say which are the optimization
> implications (I ask because this affects also another patch from me).
> 

No, I have no idea. I'm disabling the optimization with vol->metadata
because I have no idea at that point if the volume will reach that value
or not. Another solution would be to re-init after each frame in
filter_frame() in case of metadata.

> >          else
> >              vol->scale_samples = scale_samples_s16;
> > @@ -228,11 +233,24 @@ static int config_output(AVFilterLink *outlink)
> >  
> >  static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
> >  {
> > -    VolumeContext *vol    = inlink->dst->priv;
> > -    AVFilterLink *outlink = inlink->dst->outputs[0];
> > +    AVFilterContext *ctx  = inlink->dst;
> > +    VolumeContext *vol    = ctx->priv;
> > +    AVFilterLink *outlink = ctx->outputs[0];
> >      int nb_samples        = buf->audio->nb_samples;
> >      AVFilterBufferRef *out_buf;
> >  
> > +    if (vol->metadata) {
> > +        double loudness, new_volume;
> 
> > +        AVDictionaryEntry *e = av_dict_get(buf->metadata, vol->metadata, NULL, 0);
> > +        if (e) {
> > +            loudness = av_strtod(e->value, NULL);
> > +            new_volume = -23 - loudness;
> 
> can you explain the magic number?
> 

Yes, it comes from the -23 LUFS from the EBU standard. It should be made
configurable. Or the logic could be changed to make the EBU filter
directly send the volume adjustement to make.

> > +            //av_log(0,0,"loudness=%f => %f => volume=%f\n", loudness, new_volume, pow(10, new_volume / 20));
> 
> av_log DEBUG?
> 

Yeah well the patchset is an RFC, I left some personal debug info floating
around.

-- 
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/20130227/faece555/attachment.asc>


More information about the ffmpeg-devel mailing list