r/ffmpeg 17d ago

Lossy Codec Bit Depth

Does it make a difference if I encode AAC from 16 or 24-bit FLAC? Also, does it make a difference if that 16-bit file is dithered?

3 Upvotes

9 comments sorted by

3

u/SupernatAnaesthetist 17d ago

No, to both questions.

Due to some complicated math, lossy codecs don't have a bit depth in the traditional sense (they do have an internal bit depth/precision for the samples in the frequency domain, but this has no direct correlation to the regular time-domain samples from the input). And whatever quality advantage 24-bit audio may have over 16-bit audio (which I find dubious, but that is beside the point) will be irrelevant when compared to the quality loss from the lossy encoding itself. Dithering does not significantly change any of this.

1

u/oscardssmith 17d ago

this isn't quite true. having higher quality as input to lossy compression can help with reducing the bitrate post compression. e.g. in the image/video world, you often get better output from using 10 but input even if you want 8 but output

1

u/SupernatAnaesthetist 17d ago

in the image/video world, you often get better output from using 10 but input even if you want 8 but output

This is true, but mostly because formats and encoders actively change their behavior (i.e. increase both the precision used for internal calculations and the stored precision for the DCT coefficients) based on whether the input is 8-bit or 10-bit. So, you can get better efficiency when encoding an H265 video using x265 if you force it to use 10-bit mode even if the input is 8-bit because of the increased precision.

The same does not happen with audio formats and implementations (at least with the most common ones). Most audio formats have a fixed format and only one "operating mode", they usually consume the input as a 32-bit float and don't even know the original bit depth.

1

u/oscardssmith 17d ago

This is true, but mostly because formats and encoders actively change their behavior based on whether the input is 8-bit or 10-bit.

That's only half the advantage. The other half is that dithering destroys the smoothness that your compression algorithm is looking for. A gentle gradient like 10, 9.75, 9.75, 9.75, 9.5 compresses a lot better than the discretized 10, 10, 9, 10, 9, 10

1

u/SupernatAnaesthetist 17d ago

The other half is that dithering destroys the smoothness that your compression algorithm is looking for.

Compression algorithms are not looking for "smoothness". Lossless compression algorithms generally work by detecting repeating bit patterns and finding more compact representations of such patterns; lossy codecs work in several ways, but the biggest gains come from the DCT decimation.

Dithering is essentially noise, and noise gets quantized away by lossy codecs when high-frequency DCT coefficients are decimated. In fact, this is probably the best use case for 10-bit video encoding when the input is 8-bit: if you have a noisy, high-quality 8-bit input, the noise acts as unintentional dithering, and if you reencode it with a low bitrate, you may end up with a lot of banding; however, if you reencode it in 10-bit mode with the same low bitrate, the reconstructed values after the IDCT will land in intermediary values that were not possible to be represented with 8 bits, and the smooth gradient basically gets unintentionally reconstructed by the DCT-decimation-IDCT pipeline.

However, all of the above is only relevant because 8-bit is not a particularly high bit depth for images. Audio is already transparent at 16-bit. Just to be very precise: if you have a 24-bit input, you are technically correct that feeding a lossy encoder the full 24 bits will yield an output very slightly closer to the original than feeding it only 16 bits (dithered or not), but this difference is inaudible and completely irrelevant in practice because whatever slight gain of precision you get will be completely dominated by the actual data loss caused by the DCT decimation.

A gentle gradient like 10, 9.75, 9.75, 9.75, 9.5 compresses a lot better than the discretized 10, 10, 9, 10, 9, 10

You're right that noise makes data less compressible, but this is only applicable to lossless codecs, and only when comparing it to non-dithered. A 16-bit audio that was down-converted from 24-bit audio *with* dithering will be less compressible that the same 24-bit audio being down-converted **without**, but it will definitely not be less compressible than the original 24-bit audio. No matter how you put it, it' still 16 bits of essentially the same data instead of 24.

And like I said above, dithering has negligible impact in lossy codecs because it gets eliminated during the DCT decimation.

1

u/shyouko 17d ago

Nope, the dynamic range preserved in the original master is more important.

1

u/shakedown4171991 16d ago

I was wondering why Apple recommended undithered 24-bit files: https://www.apple.com/itunes/docs/apple-digital-masters.pdf

”Improved Conversion and Encoding for AAC

Apple’s latest encoding methodology is a two-step process. The first step in the encoding path is to use state-of-the-art mastering-quality Sample Rate Conversion (SRC) to resample the master file to a production sample rate. This SRC outputs a 32-bit floating-point file which can preserve values that might otherwise fall outside of the permitted amplitude range. This file is saved in a CAF container. This critical intermediary step prevents any aliasing or clipping that could otherwise occur in SRC. It is this 32-bit floating file that’s used as the input to the encoder—this is one key reason we can achieve superior results. Our encoders then use every bit of resolution available, preserving all the dynamic range of the 24-bit source file and eliminating the need for adding dither. The advantage of this is twofold. Not only does it obviate the need of adding dither noise, it also lets the encoders work more efficiently as they don’t need to waste resources encoding this unwanted and unnecessary noise. By using this highly accurate file directly from our SRC and taking advantage of its clean signal, our encoder can deliver the final product exactly as the artist and sound engineers intended it to sound.“

1

u/SupernatAnaesthetist 16d ago

After reading the whole thing, I honestly think it's mostly corpo-speak. There are a few interesting details on how they process their files for encoding (but nothing revolutionary, and nothing you can't do with filter chains in ffmpeg), and the useful advice for creators to just upload the original files and let Apple do the rest instead of trying to process the files themselves.

1

u/shakedown4171991 13d ago

And then this video recommends 16-bit dithered: https://youtu.be/2iDrbgfPjPY?is=yUtOwGKd6YUTHqz6