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] [input_file...]

Common usage examples:
flac [options] -d input.flac -o output.wav
flac [options] -e input.wav -o output.flac
flac [options] -t input.flac

PARAMETERS

-d, --decode
    Decode a FLAC file to an uncompressed audio file (default: WAV) or standard output.

-e, --encode
    Encode an uncompressed audio file (default: WAV) or standard input to FLAC.

-t, --test
    Test a FLAC file for errors by decoding it and checking its integrity. No output file is created.

-a, --analyze
    Analyze a FLAC file and print various stream statistics to standard output.

-c, --stdout
    Write the decoded or encoded audio to standard output (useful for piping to other commands).

-o FILE, --output=FILE
    Write the output audio to the specified FILE instead of the default naming convention.

-f, --force
    Force overwriting of existing output files without prompting for confirmation.

-s, --silent
    Suppress all console output except for essential messages or errors.

-0 to -8, --compression-level=N
    Set the compression level for encoding, where 0 is fastest (least compression) and 8 is best (most compression, slowest encoding).

--delete-input-file
    Delete the input file after successful encoding or decoding.

--ignore-existing-metadata
    When encoding, do not copy metadata blocks (e.g., WAV chunks) from the input file to the FLAC file.

--ogg
    Encode or decode Ogg FLAC files instead of native FLAC streams. This embeds FLAC data within an Ogg container.

DESCRIPTION

flac is the command-line utility for the Free Lossless Audio Codec (FLAC).

It can encode uncompressed audio files (such as WAV, AIFF, or raw PCM) into the FLAC format, decode FLAC files back to uncompressed formats, verify the integrity of existing FLAC files, and analyze their properties. FLAC is an open, royalty-free audio compression format designed to reduce file size significantly without any loss of audio information, making it an excellent choice for archiving high-fidelity audio. It supports various bit depths and sample rates, offering flexibility for different audio sources. The flac command provides a comprehensive set of options for detailed control over the encoding process, stream verification, and basic metadata management.

CAVEATS

While FLAC is a lossless format, converting FLAC files to other lossy formats (such as MP3 or Ogg Vorbis) will inevitably result in a permanent loss of audio quality.
Higher compression levels (e.g., -8) significantly increase the time and CPU resources required for encoding, although decoding speed is generally unaffected by the compression level.
When working with raw audio input (without a header), it is crucial to explicitly specify audio parameters like --channels, --sample-rate, and --bps to ensure correct interpretation and processing.

RAW AUDIO INPUT/OUTPUT

For raw audio files lacking a header (e.g., raw PCM streams), flac requires explicit command-line options to correctly interpret the audio data. These essential options include --channels (number of channels), --sample-rate (sample rate in Hz), --bps (bits per sample), and optionally --endian (byte order).

METADATA HANDLING

While flac can embed basic metadata during encoding and display some during analysis, for comprehensive editing and manipulation of FLAC metadata tags (e.g., Vorbis comments, cuesheets, pictures), the dedicated utility metaflac(1) is generally the preferred and more powerful tool.

HISTORY

The FLAC (Free Lossless Audio Codec) project was initiated in 2000 by Josh Coalson, with its first stable version released in 2001. It quickly gained traction as an open-source, royalty-free alternative to proprietary lossless audio formats. The development of FLAC is now overseen by the Xiph.Org Foundation. The flac command-line utility serves as the official and reference encoder/decoder for the FLAC format, becoming a cornerstone in Linux and other open-source environments for lossless audio archiving and high-fidelity playback.

SEE ALSO

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

Copied to clipboard