Skip to main content

Topic: Java FLAC encoder compression better than flac.exe 1.3.2 level 8 (Read 991 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • stigc
  • [*][*][*]
Java FLAC encoder compression better than flac.exe 1.3.2 level 8
I am using this cool Java lib to stream audio in FLAC format. I noticed that with a single sample it compresses better than "flac.exe -8" around 3.5%. Surely I must be doing something wrong but I cannot see what? I am linking the flac file compressed with javaFlacEncoder. The file is stripped from tags.

http://javaflacencoder.sourceforge.net

http://stigc.dk/javaflacencode.flac

Flac.exe commandline

flac.exe -8 javaflacencode.flac --output-name flac1.3.2encode.flac

  • Deathcrow
  • [*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #1
There's actually a higher compression setting for flac: -8e. It reduces the difference to a few kilobytes, which is probably just the file format or tags or something like that.

  • bennetng
  • [*][*][*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #2
Quote from: http://javaflacencoder.sourceforge.net
File sizes comparable to flac reference encoder, typically <5% difference.


  • stigc
  • [*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #3
There's actually a higher compression setting for flac: -8e. It reduces the difference to a few kilobytes, which is probably just the file format or tags or something like that.

Thanks, that helped a lot.

flac.exe -8e javaflacencode.flac --output-name flac1.3.2encode.flac

2177 KB flac1.3.2encode.flac
2169 KB javaflacencode.flac

Still funny that the Java implementation is 8Kb smaller ~ 0,3%



  • stigc
  • [*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #4
If i encode the whole file (the link is only a portion of it) I see a greater difference.

flac.exe -8e javaflacencode.flac --output-name flac1.3.2encode.flac

4822 KB flac1.3.2encode.flac
4739 KB javaflacencode.flac

FLAC 1.3.2 creates a 1,75% larger file that the java implementation, which is quite a bit.                                                

I have bit-compared the files and the output is the same.

  • DVDdoug
  • [*][*][*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #5
Quote
FLAC 1.3.2 creates a 1,75% larger file that the java implementation, which is quite a bit.     
Personally, I'd call that insignificant.     For example, I wouldn't choose ALAC over FLAC (or vice-versa) just to get a 2% smaller file...   There are other considerations when choosing a format.  I wouldn't re-encode my entire music library to save 2% if there was a "newer-better" version of FLAC...  It's just not that important to me.    It would only be a problem if you are very-very tight on memory/storage.   

If I gave you two weighs and one was 2% heavier or lighter than the other, do you think you could feel the difference?  If I showed you a length of rope and then showed you another an hour later do you think you could tell which one was 2% longer/shorter?  Would you wait a week to buy something to save 2%?   (OK, you might wait a week to save 2% on a car or house but you probably wouldn't walk across the street to save 2% on a cup of coffee.)

  • lithopsian
  • [*][*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #6
Quote
I have bit-compared the files and the output is the same.

The same or smaller?  Can't have it both ways.  What is smaller and what bit-matches exactly?

This is a tiny difference, but enough that it should either be accounted for by metadata, some non-default flac parameters, or would be desirable to incorporate (assuming it is always an improvement and not just random variation).

  • bryant
  • [*][*][*][*][*]
  • Developer (Donating)
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #7
I think it's pretty clear that what stigc meant is that the decoded output was identical while the encoded version was smaller. If the output wasn't identical then the discussion would be something else entirely.

I would also agree that 1.75% is pretty significant, especially if that's referenced to the original file size (not the compressed size). Isn't that bigger than the difference between FLAC -5 and FLAC -8? If someone produced a WavPack file that showed that improvement I would fall out of my chair. Even if it's "random variation" it could be an interesting avenue to improvement.

What is possible (and probably likely) is that there is something "weird" about this file that happens to trigger this, and the vast majority of regular files will not show this. Then it becomes much less interesting.

  • stigc
  • [*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #8
What is possible (and probably likely) is that there is something "weird" about this file that happens to trigger this, and the vast majority of regular files will not show this. Then it becomes much less interesting.

Byrant, I think you're right. I encoded the whole album, and only this songs compresses better with the Java implementation. Also i tried flake.exe that did a even better job

4822 KB flac1.3.2encode.flac
4739 KB javaflacencode.flac
4671 KB flake.flac

I also noticed that the reference encoder (flac.exe) uses fixed block size, maybe this is the real explanation?

https://xiph.org/flac/format.html#architecture

  • stigc
  • [*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #9
I would also agree that 1.75% is pretty significant, especially if that's referenced to the original file size (not the compressed size).

Right again, I should compare with the original size


flac.exe 16125 4822 0,299038759689922
java         16125 4739 0,293891472868217
flake.exe 16125 4671 0,289674418604651


  • bryant
  • [*][*][*][*][*]
  • Developer (Donating)
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #10
The thing I notice is the < 30% compression ratio, which is already a little weird.

If that's the only track that compresses that much (whether it's really quiet or has periods of silence) then the reason is probably related to that (and could be related to block size).

  • Porcus
  • [*][*][*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #11
flac.exe -8e javaflacencode.flac --output-name flac1.3.2encode.flac

2177 KB flac1.3.2encode.flac
2169 KB javaflacencode.flac
-8e, is that a good option?  And I don't think the -e and -p are related to tags ...?

Anyway, I get the following with flac 1.3.2 (Windows, downloaded from xiph):
2 221 407 bytes using flac.exe -8 -p -e
2 221 363 bytes using flac.exe -8 -p -e --nopadding
2 220 416 bytes for the javaencode download.

Using metaflac --dontusepadding --remove-all, the javaencode is reduced to 2220 372 and the smallest of the flac.exe's from 363 to 225.  Not much explanation there, but the filesize difference is then down to 843 bytes.

I also noticed that the reference encoder (flac.exe) uses fixed block size, maybe this is the real explanation?

No. Both files (edit: the java encoded and the smallest flac.exe encoded ... presumably all, but I haven't checked) use blocksize of 4096, except the last (2188).


Edit: --remove-all removes both SEEKTABLE and APPLICATION, right?
  • Last Edit: 27 November, 2017, 03:20:53 PM by Porcus

  • Wombat
  • [*][*][*][*][*]
Re: Java FLAC encoder compression better than flac.exe 1.3.2 level 8
Reply #12
2.220.416 Bytes for javaencode
2.168.449 Bytes for CUEtools flake 2.16 -8 (is 4096 blocksize default. Old flake may be non standard)
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!