LinuxCommandLibrary

flac

Encode or decode FLAC audio files

TLDR

Encode a WAV file to FLAC (this will create a FLAC file in the same location as the WAV file)

$ flac [path/to/file.wav]
copy

Encode a WAV file to FLAC, specifying the output file
$ flac [[-o|--output-name]] [path/to/output.flac] [path/to/file.wav]
copy

Decode a FLAC file to WAV, specifying the output file
$ flac [[-d|--decode]] [[-o|--output-name]] [path/to/output.wav] [path/to/file.flac]
copy

Test a FLAC file for the correct encoding
$ flac [[-t|--test]] [path/to/file.flac]
copy

SYNOPSIS

flac [options] [infile[s]]
flac -d[e] | -t | -D [options] [infile[s]]

PARAMETERS

-0 .. -8, --compression-level-N
    Set compression level from fastest/lowest (0) to slowest/best (8); default 5

--best
    Highest compression level (equivalent to -8)

-d, --decode
    Decode FLAC files to PCM (default is encode)

-t, --test
    Test FLAC files by decoding silently to /dev/null

-D, --decode-through-decoder
    Decode using external flac decoder for analysis

-c, --stdout
    Write output to stdout (pipe mode)

-o , --output-file=
    Specify output filename (single input only)

--output-prefix=
    Prefix for output files (multiple inputs)

--delete-input-file
    Delete input after successful encode

-V, --verify
    Verify encoding by decoding in parallel

-s, --silent
    Silent mode; no stats or progress

-v, --verbose
    Verbose output with progress and stats

-q, --quiet
    Suppress non-error messages (deprecated)

--no-filename
    Exclude filename from MD5 checksum

R, --recurse
    Recurse into subdirectories

-l , --blocksize=
    Specify block sizes in samples

--lax
    Allow lax decoder for non-standard streams

--replay-gain
    Calculate ReplayGain tags

--force
    Overwrite output files

-r , --repair=
    Repair corrupted FLAC file

DESCRIPTION

The flac command is the reference implementation for the Free Lossless Audio Codec (FLAC), a popular open-source format for compressing audio without any loss in quality. It supports encoding WAV, AIFF, and other PCM formats into FLAC streams and decoding FLAC back to PCM. Key features include high compression ratios (typically 40-70% size reduction), fast seekability with metadata blocks, and embedded MD5 checksums for verification.

Usage spans archiving music collections, streaming, and embedded devices. It verifies integrity during encoding with -V, supports ReplayGain for volume normalization, and handles cuesheets for CD ripping. Multi-channel audio up to 8 channels and sample rates up to 655350 Hz are supported. The tool is efficient, with variable block sizes and rice partitioning for optimal compression. Output can be piped, recursed into directories, or repaired. Compared to lossy formats like MP3, FLAC preserves full fidelity, ideal for audiophiles and professionals.

CAVEATS

FLAC files are significantly larger than lossy formats like MP3; requires more storage and bandwidth. Not suitable for real-time streaming without buffering. MD5 checksums detect bit errors but not all corruptions. High compression levels (-8) are CPU-intensive.

COMMON EXAMPLES

Encode: flac song.wav
Decode: flac -d song.flac
Test: flac -t *.flac
Best compression: flac -8 -V song.wav

METADATA

Use metaflac(1) for tags, cuesheets; flac embeds ReplayGain with --replay-gain.

HISTORY

FLAC developed by Josh Coalson starting in 2000; first public release in 2001. Became Xiph.Org reference codec by 2004. Widely adopted for CDs/DVD-Audio rips. Maintained post-Coalson by Erik de Castro Lopo; current version 1.4.3 (2022) adds FFmpeg/AVI support.

SEE ALSO

metaflac(1), ffmpeg(1), lame(1), oggenc(1), sox(1)

Copied to clipboard