[Libav-user] Audio quality loss while encoding

Claudio Freire klaussfreire at gmail.com
Wed May 1 08:42:34 CEST 2013


On Tue, Apr 30, 2013 at 9:26 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> Claudio Freire <klaussfreire at ...> writes:
>
>> Surely I could and would like to give it a try,
>> I've written an AC3 encoder way back so there
>> should be no surprises.
>
> That sounds incredibly promising!
>
>> However, I do have my plate overly full.
>
>> Any docs to read about its current limitations
>> and perhaps previous experience working on it
>> that you have handy?
>
> Sorry, not more than git log and possibly some
> discussion on ffmpeg-devel that I do not remember;-(
>
> There is a real test somewhere that shows that
> the stereo encoding is not as bad, the quality
> issues with >2 channels should be easily
> reproducible.


Well.. didn't test the test, but I did find something. Still not all
seems fixed, for I can still find some artifacts, and a very important
symptom: it doesn't achieve the target bitrate. That's weird isn't it?

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.


More information about the Libav-user mailing list