FLAC
37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0FLAC (Free Lossless Audio Codec) compresses PCM audio to roughly half its size and decodes back to identical samples. It is open, fast to decode, plays almost everywhere, has good tagging, and is the default choice for music archives and lossless downloads. Use it unless you are locked into Apple’s ecosystem (ALAC) or need something FLAC lacks, such as WavPack’s float support or hybrid mode.
FLAC holds 4–32-bit integer PCM with 1–8 channels. It cannot store floating-point audio or DSD. Encoding a lossy source (MP3, AAC, Opus) to FLAC only preserves the damage at several times the size, so don’t.
Encoding
Section titled “Encoding”With the reference encoder:
flac -8 -V input.wav -o output.flacOr with FFmpeg:
ffmpeg -i input.wav output.flac-V verifies the encode by decoding it as it goes. Use flac -t file.flac any time to test a file; it checks the MD5 of the audio stored in the header.
Compression levels
Section titled “Compression levels”The levels only trade encoding time against file size. Every level decodes to the same samples, and decoding speed barely changes.
| Tool | Levels | Default | Notes |
|---|---|---|---|
flac | -0 … -8 | -5 | -8 is --best. Add -e for an exhaustive model search, which is very slow for a tiny gain. |
| FFmpeg | -compression_level 0 … 12 | 5 | 0–8 roughly mirror flac’s levels. 11 and 12 allow LPC orders up to 32, which takes the file outside the streamable subset at 48 kHz and below. |
The gap between -5 and -8 is typically a percent or two, so the default is fine for most work. FLAC 1.5.0 can use several threads (-j) when encoding.
Tags, cover art and metadata
Section titled “Tags, cover art and metadata”FLAC stores tags in a Vorbis comment block, cover art in a PICTURE block and seek points in a SEEKTABLE. metaflac edits these without touching the audio:
metaflac --list output.flacmetaflac --set-tag="ARTIST=Name" --import-picture-from=cover.jpg output.flacContainers and compatibility
Section titled “Containers and compatibility”Plain .flac is the normal form. FLAC can also live in Ogg (flac --ogg, usually .oga), Matroska/.mka, and MP4. Native FLAC plays in all current browsers and most hardware; Ogg FLAC and FLAC in MP4 are less widely supported.
The format has a “streamable subset” that restricts block sizes, LPC order and sample-rate signalling so hardware decoders can cope. flac stays inside it unless you pass --lax, and FFmpeg does up to -compression_level 10; stay there if the files are headed for hardware players.
Check 5.1 and 7.1 files on the device you care about, since some players ignore the channel layout.
Decoding and converting
Section titled “Decoding and converting”flac -d input.flac -o output.wavffmpeg -i input.flac output.wavTo get the original WAV back byte for byte, including non-audio chunks, pass --keep-foreign-metadata to both the encode and the decode.