# FLAC

Canonical URL: https://encode.wiki/codecs/audio/flac/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): 0968a68dc25dce115ebc6643375888691fbb25d736e54fb627581926c934113e

FLAC (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](/codecs/audio/alac/)) or need something FLAC lacks, such as [WavPack](/codecs/audio/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

With the reference encoder:

```sh
flac -8 -V input.wav -o output.flac
```

Or with FFmpeg:

```sh
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

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

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:

```sh
metaflac --list output.flac
metaflac --set-tag="ARTIST=Name" --import-picture-from=cover.jpg output.flac
```

## 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

```sh
flac -d input.flac -o output.wav
ffmpeg -i input.flac output.wav
```

To get the original WAV back byte for byte, including non-audio chunks, pass `--keep-foreign-metadata` to both the encode and the decode.

## See also

- [ALAC](/codecs/audio/alac/) and [WavPack](/codecs/audio/wavpack/) for the other lossless options
- [Opus](/codecs/audio/opus/) and [AAC](/codecs/audio/aac/) for lossy delivery from a FLAC master
