As you might have guessed from the title of this article, FLAC is an abbreviation of Free Lossless Audio Codec. The first word (“free”) should be pretty clear (it’s an open-source project), but what is a “lossless audio codec”? Well, the well-known MP3 format is an audio codec. It is used to compress raw audio data. MP3 is a so-called “lossy” codec, meaning that, for example, if you would convert a wav file to an mp3, and then convert the mp3 file back to wav, you won’t end up with the same audio data. MP3 reduces the quality of the audio while encoding. On the other hand, FLAC is “lossless”. If you would convert a wav file to a flac, and then convert the flac file back to wav, you will end up with exactly the same wav file. Nevertheless, a flac file is a lot smaller than a wav file.

You could see a flac file as some kind of zip file (or, for the linux lovers, a .tar.gz file): if you compress some data with it and extract that data from the archive later on, you will just have your old data back. You won’t lose any “quality”. However, because FLAC is entirely optimized for audio data, it will compress audio a lot better than winzip or gzip. Also, flac is designed to be played directly. You don’t have to extract it, you can just tell your music player to play the flac.

Because FLAC gives you cd-quality playback at a lower filesize than, for example, wav. I am a regular FLAC user and as far as I have been working with it, it regularly features a compression rate of about 0.6, or, in other words, the flac file usually is 40% smaller than the wav file I encoded it from. Also, my favourite media players (MPlayer and xmms2) support it. The latter one even plays gapless!

You can both encode and decode a flac file, so the explanation is separated in those two aspects:

Encoding a flac file: I personally mainly use Sound Juicer to rip my cd’s to FLAC. It’s very easy to use and has got some useful features. However, it is not able to encode a wav file somewhere on your disc to FLAC. Although there is a range of frontends for flac-encoding, I use the commandline utility flac for encoding. Have a look at the following example:

[rechosen@localhost ~]$ flac –best examplefile.wav

This is about the easiest way to encode a wav file to flac. The flac program will start encoding examplefile.wav to examplefile.flac with options that should result in as much compression as possible (note: it will not remove the wav file afterwards). The encoding will take some time, depending on the speed of your system and the length of the audio file. Although you can shorten the time it takes to encode the flac file (by specifying –fast instead of –best, for example), this is not recommended. You will only have to encode the file once, and the better the encoding, the smaller the flac file. After encoding the file, you can play it as many times as you want. Note that playing is actually just a form of decoding.

Decoding a flac file (usually playing it): if you want to play a FLAC file, make sure the player you want to play it with supports flac. Some players do not support flac by default, but do once you installed the corresponding plug-in (for example, older versions of Winamp need this plug-in). When dealing with it on Linux, it usually depends on your distro whether you have FLAC support by default or not: some distros require you to install a plug-in, other already have it installed. You will mostly be able to find and install the right plug-in using your favourite package manager. If you just want to decode your flac file to a wav again, you can use the decoding function of the flac command:

[rechosen@localhost ~]$ flac -d examplefile.flac

This will decode the examplefile.flac to examplefile.wav, allowing you to use it with other programs that don’t use flac again. Note that the flac command will not remove the source file: after running this command, both examplefile.flac and examplefile.wav will exist.

The flac command features loads of options for tweaking the encoding and specifying locations. I’ll list a few of them here, embedded in examples:

Anthony James

Development Guides

About Us

The Linux Academy by Pinehead.tv™ is a site dedicated to the proliferation and education surrounding Linux and Linux Administration. We live and work in the world of technology and want to share the depth and breadth of our experience with the community. Linux Academy is more than just the instructors; we are a community of professionals dedicated to our craft and our common success.