Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Why FLAC level 5 was chosen as the default and recommended setting? (Read 1181 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Why FLAC level 5 was chosen as the default and recommended setting?

Hello folks,

This got me wondering. Is there any particular reason that level 5 was chosen the "default" and, in some applications, "recommended" level of compression? Because, in my view, there are 9 levels: 0 to 8. The the exact half is 4. Compared to the 5th level, the 4th level not only compress slightly faster (that you can notice) but it also decompresses a lot faster than 5, and the amount of storage compared between 5 and 4 is negligible being so small. If one goes all the way from 3 to 0 levels, then you will see the storage numbers really increase, not being so much practical.

I know that for most hardware these days, it doesn't matter much whether is 0 or 8. But why 5 is recommended over 4. 

Thanks.

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #1
it also decompresses a lot faster than 5, and the amount of storage compared between 5 and 4 is negligible being so small.

I don't think that is right.  Never tested -4 specifically, but for 5 and higher decode speed is constant (~5 MHz CPU required for real time decode, so fast its negligible).

As for -5, I think its chosen since it is roughly where compression starts to show diminishing returns.

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #2
FLAC -4 / -5 / -6 decode alike: http://www.audiograaf.nl/losslesstest/Lossless%20audio%20codec%20comparison%20-%20revision%204.pdf , figure 1.2. -7 and -8 use the -l 12 switch (higher order for the prediction), which in that study costs about 10 percent decoding speed. Shouldn't bother a Monkey's user at all ... *cough* I just learned something about that codec.

And saratoga could very well be right about the diminishing returns as well, it makes sense - though I don't know what were the actual considerations made.

But also take note that the lowest order modes have a special purpose. Explained at https://hydrogenaud.io/index.php?topic=120158.msg999755#msg999755 .  Maybe to facilitate decoding on special low-end hardware.
(-3 is also quite special, in that it does not do stereo decorrelation at all. Well you could in the early years call -8 "quite special" in that it included -e, and was for the particularly patient user.)

So FLAC actually has opportunities for ultra-light decoding, that no other codec has (well maybe if TBeck wanted, TAK could come close) - and so other codecs don't have switches in that end of the scale, to do what they are unable to. FLAC can, so FLAC has.
Last two months' worth of foobar2000.org ad revenue has been donated to support war refugees from Ukraine: https://www.foobar2000.org/

 

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #3
Thanks for the replies.

It took some time for me to figure out these graphs. Indeed, 4, 5, 6 are virtually the same decoding speed and use same CPU cycles.

Actually, I am using Monkey's Audio for quite a few albums, and I am testing them through network playback. FLAC is virtually indiscernible whatever setting I use, so yes, it's pretty fast. APE also decodes very well, but I notice that the apps that supports it, the "Insane" setting chokes a little in VLC (ATV4K) and the time progress halts and continues, then halts again - it is unable to map exactly where the timing is. However, it does decode. "Extra High" is better, does gapless in Poweramp (Android) and saves usually 12 to 22 MB for each album compared to FLAC -8. What annoys me is that MAC stores its own MD5 in the tag, which is not like FLAC (stores the MD5 PCM raw data).


Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #4
You can force FLAC to go slower - if you are truly sadistic, you can make it encode much slower than Monkey's Insane or WavPack -hhx6 (... still decode ultra-fast).
But the developers of the reference encoder chose not to assign anything slower than -l 12 -b 4096 -m -r 6 -A tukey(0.5);partial_tukey(2);punchout_tukey(3) to a preset number. Well if you merely consider the -p and -e switches as part of FLAC's "presets" menu, and take into account that -p has no effect on -0/-1/-2 (so that the "presets" then can be considered to be -0, -0e, -1, -1e, -2, -2e and then four of each of rest: -3, -3e, -3p, -3pe up to for -8) - then there are more heavier-than-default than there are lighter-than-default! ;-)

The philosophy of what should be available in presets or at all to end-users, vary among codecs. FLAC allows the end-user to pick and choose from the filter bank. On the other end of the spectrum, TTA runs in one single "option".
Last two months' worth of foobar2000.org ad revenue has been donated to support war refugees from Ukraine: https://www.foobar2000.org/

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #5
I kinda suspect it has to do with encode time.
But FLAC encoding got to the point where when ripping a CD to FLAC -8 ripping the CD is the bottleneck even on low-end hardware years ago.

EDIT: I downloaded a random 13m23s FLAC file from the Live Music Archive and it encoded to FLAC in 1m40s (Approximately 8x) on a Raspberry Pi 400 running the 64 bit version of Raspberry Pi OS using the powersave governor, basically in practice one ARM Cortex A72 core locked to 600 MHz)
EDIT #2: one core in practice since the FLAC encoder is more or less single-threaded, at least for the heavy lifting parts..

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #6
I know that for most hardware these days, it doesn't matter much whether is 0 or 8. But why 5 is recommended over 4. 
No clue.

If I look at the old lossless format comparison on the FLAC homepage some years back I'd say 6 was a better trade-off for FLAC 1.2.1: that seems to be the point past which returns diminish quickly. ( I think the graph plots -4 through -8 from right to left) Perhaps this choice was made way earlier and it just stuck around. Maybe if you do a comparison of different presets with FLAC 1.0 you get a clear answer. Things have changed with FLAC 1.3.1 again.

If you look at that page even further back, only -3, -5 and -8 are compared, not -4 and -6.

At the very least I can say I'm pretty sure it is a compression/encoding time trade-off, and has nothing to do with compatibility nor with decoding speed, which are pretty much equal for all compression levels.

it encoded to FLAC in 1m40s (Approximately 8x) on a Raspberry Pi 400 running the 64 bit version of Raspberry Pi OS
And there are even ARM64 intrinsics routines waiting to be merged into FLAC that speed up by at least a factor 2.
Music: sounds arranged such that they construct feelings.

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #7
I just did a few more tests, on a similar setup to what I described, when decoded to WAV the file was 138476 KB I got about 73x encode speed and an 86196 KB file at flac -0, about 32x and an 80152 KB file at flac -5 and about 8x and a 79404 KB file at flac -8.

Also, in practice I'd probably get ~3x the speed if I weren't using the powersave governor.  And if I had a bunch of files, I probably could get about 4x that since I could run one flac encoder per core.

If I were ripping a bunch of files from CD, I'd still use FLAC -8 since unless you have multiple CD drives going at once you're not ripping at ~96x total.  If I had a bunch of files to convert at once (like, files with a total length of weeks to convert to FLAC, I'd probably do more investigation as to what preset is actually the sweet spot between -5 and -8.  However, if I were converting a little bit at a time, like, say, a live concert recording at a time, I'd certainly go -8.

EDIT: Also, if speed were really that important, I probably could spin up multiple Raspberry Pis and do some sort of distributed audio encoding setup.

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #8
Quote
If I look at the old lossless format comparison on the FLAC homepage some years back I'd say 6 was a better trade-off for FLAC 1.2.1: that seems to be the point past which returns diminish quickly. ( I think the graph plots -4 through -8 from right to left) Perhaps this choice was made way earlier and it just stuck around. Maybe if you do a comparison of different presets with FLAC 1.0 you get a clear answer. Things have changed with FLAC 1.3.1 again.

That's what I thought for a minute before getting the first reply. Choice made earlier and stuck and things have changed.

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #9
Not releated to FLAC but anyway...
MP3 is still very popular. Why is LAME encoding to 128 kbit/s CBR by default?
Why not switch to V2? Maybe even V3 or V4?
128 kbit/s CBR is archaic.

Every other encoder seems to target normal bitrates.
QAAC targets 192 VBR.
Opus targets 96 VBR.
x264 (yes, video :P) targets 23 CRF.
gold plated toslink fan

Re: Why FLAC level 5 was chosen as the default and recommended setting?

Reply #10
If you look at that page even further back
Hot damn, flac 1.0 encoded slower at -1 than Monkey's high?! 

... OK, on second thought I realize that Monkey's did change its format and doesn't support these old files anymore. For the hell of it, I fired up the Cannibal Corpse track. The "new" Monkey's version compresses to 0.723 / 0.696 / 0.695 (high) / 0.685 / 0.684, so understandably it is a heavier thing.
flac -1 encodes to 0.782 (as back then, actually!), but -8 is down to 0.710 (and at 40 percent of -1 speed).

Last two months' worth of foobar2000.org ad revenue has been donated to support war refugees from Ukraine: https://www.foobar2000.org/