[Flac] FLAC: compressing data

Nicholas Wilson nicholas.c.wilson at ntlworld.com
Mon Sep 3 10:23:10 PDT 2007


On Mon 3 Sep 4:04 pm Ivo Emanuel Gonçalves wrote:
> > can the flac encoder be used to compress non-wave data?
> No, it's not possible.  That's actually very silly.

Actually, there is no reason it should not run on the data fine, if presented 
to it appropriately.  Input data is a binary stream, and any input will work 
correctly.  With music data, most algorithms rely on the fact that adjacent 
samples are close to each other in value, so flac works out an equation that 
fits the data closely, then relies on knowing that the error (the residuals) 
are small, so it uses a nifty encoding scheme (Golomb-Rice I think) using 
extra 'padding' bits at the start to efficiently store the small numbers 
without needing to write the leading zeros as well.  This process will work 
on any data, but for most inputs the output will probably be a bit bigger, as 
the polynomials will not fit the data well.  The compression algorithm you 
use should really be tailored to the application for which you need it, but 
any input will work.

I checked this on a pdf file:

flac --force-raw-format --endian=little --channels=2 --bps=24 --sample-rate=24000 --sign=unsigned 
Arsene\ Lupin\ contre\ Herlock\ Sholmes.pdf

The values you choose for channels etc are purely arbitrary, but will affect 
the compression (I got a ratio of 1.004, only slightly larger than the 
input).

To decompress:

flac -d --force-raw-format --endian=little --sign=unsigned Arsene\ Lupin\ 
contre\ Herlock\ Sholmes.flac -o test.pdf

The output file was perfectly readable, and bit-perfect as expected.

Nicholas


More information about the Flac mailing list