[Libav-user] Handling of 24 bit audio in libav* and libswresample

Hendrik Schreiber hs at tagtraum.com
Tue Jun 11 10:50:07 CEST 2013

> Note that dithering should be done when doing 32bit to 24bit case
> and source audio have >24bits used.

Yes - definitely.

>> Dithering is only necessary, when converting the data somewhere in between
>> (e.g. changing the sample rate while it's in 32bit format), as the code in
>> pcm.c (macro ENCODE) simply shifts the 32bit representation by 8bit,
>> essentially just dropping the last 8bits.
> Because last 8bits are always zero for that particular case.


Thanks, Paul, for adding the extra clarifications for the more general case.

I saw that you added some more documentation for output_sample_bits (http://patches.libav.org/patch/38964/).
Unfortunately, I'm still not entirely sure how to use the parameter - a simple example would be great.

Let's say I want to convert 32bit audio to 24bit.
The input AVSampleFormat is AV_SAMPLE_FMT_S32, the output sample format as well.
But, when writing the result to a file, I want to use AV_CODEC_ID_PCM_S24LE, i.e. the least significant byte is cut off.

Therefore, for SWR, I'm calling:

av_opt_set_int(swr_context, "dither_method", SWR_DITHER_TRIANGULAR, 0);
av_opt_set_int(swr_context, "output_sample_bits", ???, 0);

What should I set ??? to?
24, since I'm only using 24bit?



More information about the Libav-user mailing list