1

While compressing all my FLAC files with the latest version of FFMPEG with maximum (12) compression level, it turns out that some of them become LARGER afterwards.

How is this possible? Even if a non-FFMPEG software was used to encode the FLAC, and they "do things more efficiently" than FFMPEG, it's still a FLAC (lossless sound) file. How can they both produce a valid FLAC, adhering to the same standard, yet get different sizes?

Some of those FLACs are from 2007 and used libFLAC or something. How can a tool from 2007 be better than FFMPEG from 2022 at compressing it? And how can it be possible that they have different sizes if it's the same data and both are lossless and both use the FLAC file format/standard?

This truly boggles my mind.

3
  • Did you check all other parameters are equal, input to output?
    – Tetsujin
    Commented Nov 14, 2022 at 17:02
  • I am not sure that the compression levels are standardized in the specification of the format, and I am sure that the implementation is not. In principle, some implementations may do a better job at compressing the data. That said I agree with you that one would expect a 2022 ffmpeg to do at least as well as a 2007 xxx software. Could you paste the full ffmpeg command and the full terminal output for a file that gets bigger?
    – PierU
    Commented Nov 14, 2022 at 17:26
  • @Tetsujin Which parameters?
    – Kiedrowski
    Commented Nov 14, 2022 at 17:31

1 Answer 1

3

The concept FLAC uses is pretty simple: the input audio is split up into blocks and the audio in that block is approximated with one (simple) mathematical model per channel. This model is called a predictor. As this approximation isn't exact, the difference (the so-called residual) is also stored, this makes FLAC lossless.

When the predictor (the mathematical model) fits well to the audio data, the residual takes up much less space than the original audio data. In that case, the predictor removes redundancy from the signal. However, if a predictor is chosen that doesn't fit the audio data well, the residual takes up much more space than the original audio data. So, it is also possible to 'inflate' the data instead of compressing it!

However, finding the predictor that leads to the smallest residual is no easy task. There are a few different ways a suitable predictor can be found, but no method is 'the best'. It doesn't matter that the predictor isn't the best for FLAC to remain lossless: as long as the residual signal is the right one for that particular predictor, the data is stored losslessly.

This means that an old FLAC compressor might use a method that is superior to one in a new FLAC compressor (ffmpeg in this case). Perhaps it was found that the new method produces smaller files for 95% of all inputs, but larger files for 5% of the inputs.

Also, ffmpeg and FLAC have compression levels. Lower levels either limit the complexity of the predictor (for example to have faster decoding) or limit the way the encoder searches for the best predictor. Lower compression levels usually just pick a predictor and compress with that, higher compression levels usually try a few (or many) different predictors to find the best one. Trying all possible predictors would take hundreds of years for just a short audio file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .