[Libav-user] Audio quality loss while encoding

Claudio Freire klaussfreire at gmail.com
Wed May 1 12:58:42 CEST 2013


On Wed, May 1, 2013 at 7:53 AM, Claudio Freire <klaussfreire at gmail.com> wrote:
> On Wed, May 1, 2013 at 4:26 AM, Claudio Freire <klaussfreire at gmail.com> wrote:
>>> 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.
>
>
> Ok... I had to forfeit my right to sleep, but here it is. Managed to
> make both the fast and 2loop methods work reasonably well (albeit I
> don't know why anyone would use fast, because it's not faster. I
> assume it's an experiment?).
>
> I don't have access to AAC standards, though, since they're paywalled
> (at least the ones I found), so most of the changes were done blind,
> assuming from what I know of audio codecs, and by trial and error.
>
> In particular, fast has some magic numbers there that I got from trial
> and error, and nothing more... profound.
>
> In any case, attached it is, git diff.


Oh, forgot to explain a bit. I believe the reason why it works for
channels=2 and not so much for >2, is that psy already does some rate
control by adapting the model to the bit rate and bit reservoire. But
that doesn't work for channels > 2, since psy doesn't see all channels
at once in those cases, only pairs of channels, and it ends up
introducing some significant bias towards an over-estimation.

There's the lambda parameter compensating that... except AAC
quantization parameter search methods mostly ignored it, save faac
(which I didn't try).

Fast had some rather nasty bugs too, resulting in entirely zeroed out
zones in complex passages. Fixed that somewhat by tweaking numbers,
adding bias against zeroing.


More information about the Libav-user mailing list