[Libav-user] Audio quality loss while encoding
Claudio Freire
klaussfreire at gmail.com
Wed May 1 09:26:53 CEST 2013
On Wed, May 1, 2013 at 3:42 AM, Claudio Freire <klaussfreire at gmail.com> wrote:
> What I found was a simple numeric bug in aacpsy.c:319
>
> float avg_chan_bits = chan_bitrate / ctx->avctx->sample_rate *
> (j ? 128.0f : 1024.0f);
>
> Should be
>
> float avg_chan_bits = chan_bitrate * (j ? 128.0f : 1024.0f) /
> ctx->avctx->sample_rate;
>
> Why? Rounding. chan_bitrate / sample_rate is an integer op, and can
> induce a lot of rounding error for many channels (low chan_bitrate) or
> high sample_rate. The perceptual difference is notorious, not
> everywhere, but when allocation is stressed, it now performs notably
> better. I didn't perform double-blind tests... I should. I've got a
> big family to shove test on ;^)
>
> But still, not perfect... I gave it 256k, and it produced 140k. Lots
> of room for improvement still, but I thought I'd share this bit. I'll
> keep looking.
Aaand mostly finally in aaccoder.c:713, search_for_quantizers_twoloop
ignores lambda, so there's no effective rate control.
Replacing
int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;
with
int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate /
avctx->channels * lambda;
Results in general bliss. Will check the other search methods.
More information about the Libav-user
mailing list