home  |   news  |   download  |   features  |   goals  |   format  |   id  |   comparison  |   documentation  |   developers  

This page describes the user-level view of the FLAC format (for a more detailed explanation see the format page). It also contains the user documentation for flac, which is the command-line file encoder/decoder, metaflac, the FLAC metadata editor, and the input plugins.

Keep in mind that the online version of this document will always apply to the latest release. For older releases, check the documentation included with the release package.


See the Scope, Architecture, Definitions, and Overview sections of the format page for a good introduction. This section will be expanded in the future.


flac is the command-line file encoder/decoder. The input to the encoder and the output to the decoder must either be RIFF WAVE format, or raw interleaved sample data. flac only supports linear PCM samples (in other words, no A-LAW, uLAW, etc.). Another restriction (hopefully short-term) is that the input must be 8, 16, or 24 bits per sample. This is not a limitation of the FLAC format, just the reference encoder/decoder.

flac assumes that RIFF WAVE files will have the extension ".wav"; this may be overridden with a command-line option. For piped-in data, flac tries to determine the type by looking at the beginning of the file. Other than this, flac makes no assumptions about file extensions, though the convention is that FLAC files have the extension ".flac" (or ".fla" on ancient file systems like FAT-16).

Before going into the full command-line description, a few other things help to sort it out: 1) flac encodes by default, so you must use -d to decode; 2) the options -0 .. -9 that control the compression level actually are just synonyms for different groups of specific encoding options (described later) and you can get the same effect by using the same options; 3) flac behaves similarly to gzip in the way it handles input and output files.

flac will be invoked one of four ways, depending on whether you are encoding, decoding, testing, or analyzing:

In any case, if no inputfile is specified, stdin is assumed. If only one inputfile is specified, it may be "-" for stdin. When stdin is used as input, flac will write to stdout. Otherwise flac will perform the desired operation on each input file to similarly named output files (meaning for encoding, the extension will be replaced with ".flac", or appended with ".flac" if the input file has no extension, and for decoding, the extension will be ".wav" for WAVE output and ".raw" for raw output). The original file is not deleted.

There are special forms for encoding/decoding from stdin to a file:

  • flac [options] - outputfile
  • flac -d [options] - outputfile
which are better than
  • flac [options] > outputfile
  • flac -d [options] > outputfile
since the former allows flac to seek backwards to write the STREAMINFO or RIFF WAVE header contents when necessary.

Also, you can force output data to go to stdout using -c.

The encoding options affect the compression ratio and encoding speed. The format options are used to tell flac the arrangement of samples if the input file (or output file when decoding) is a raw file. If it is a RIFF WAVE file the format options are not needed since they are read from the WAVE header.

In test mode, flac acts just like in decode mode, except no output file is written. Both decode and test modes detect errors in the stream, but they also detect when the MD5 signature of the decoded audio does not match the stored MD5 signature, even when the bitstream is valid.

General Options
-d Decode (flac encodes by default). flac will exit with an exit code of 1 (and print a message, even in silent mode) if there were any errors during decoding, including when the MD5 checksum does not match the decoded output. Otherwise the exit code will be 0.
-t Test (same as -d except no decoded file is written). The exit codes are the same as in decode mode.
-a Analyze (same as -d except an analysis file is written). The exit codes are the same as in decode mode. This option is mainly for developers; the output will be a text file that has data about each frame and subframe.
-c Write output to stdout
-s Silent: do not show encoding/decoding statistics.
--skip # Skip over the first # of samples of the input. This works for both encoding and decoding, but not testing.

Analysis Options
--a-rtext Includes the residual signal in the analysis file. This will make the file very big, much larger than even the decoded file.
--a-rgp Generates a gnuplot file for every subframe; each file will contain the residual distribution of the subframe. This will create a lot of files.

Encoding Options
--lax Allow encoder to generate non-Subset files. The resulting FLAC file may not be streamable, so you should only use this option in combination with custom encoding options meant for archival. File decoders will still be able play (and seek in) such files.
-S { # | X | #x } Include a point or points in a SEEKTABLE:
  • : a specific sample number for a seek point
  • : a placeholder point (always goes at the end of the SEEKTABLE)
  • #x : # evenly spaced seekpoints, the first being at sample 0
You may use many -S options; the resulting SEEKTABLE will be the unique-ified union of all such values.
With no -S options, flac defaults to '-S 100x'. Use -S- for no SEEKTABLE.
NOTE: -S #x will not work if the encoder can't determine the input size before starting.
NOTE: if you use -S # and # is >= samples in the input, there will be either no seek point entered (if the input size is determinable before encoding starts) or a placeholder point (if input size is not determinable)
-P # Tell the encoder to write a PADDING metadata block of the given length (in bytes) after the STREAMINFO block. -P 0 implies no PADDING block, which is the default. This is useful if you plan to tag the file later with an APPLICATION block; instead of having to rewrite the entire file later just to insert your block, you can write directly over the PADDING block.
-b # Specify the blocksize in samples. The default is 1152 for -l 0, otherwise 4608. Subset streams must use one of 192/576/1152/2304/4608/256/512/1024/2048/4096/8192/16384/32768. The current encoder uses the same blocksize for the entire stream.
-m Enable mid-side coding (only for stereo streams). Tends to increase compression by a few percent on average. For each block both the stereo pair and mid-side versions of the block will be encoded, and smallest resulting frame will be stored. Currently mid-side encoding is only available when bits-per-sample <= 16.
-M Enable loose mid-side coding (only for stereo streams). Like -m but the encoder adaptively switches between independent and mid-side coding, which is faster but yields less compression than -m (which does an exhaustive search).
-0 .. -9 Fastest compression .. highest compression. The default is -5.
-0 Synonymous with -l 0 -b 1152
-1 Synonymous with -l 0 -b 1152 -M -r 2,2
-2 Synonymous with -l 0 -b 1152 -m -r 3
-3 Synonymous with -l 6 -b 4608 -r 3,3
-4 Synonymous with -l 8 -b 4608 -M -r 3,3
-5 Synonymous with -l 8 -b 4608 -m -r 3,3
-6 Synonymous with -l 8 -b 4608 -m -r 4
-7 Synonymous with -l 8 -b 4608 -m -e -r 6
-8 Synonymous with -l 12 -b 4608 -m -e -r 6
-9 Synonymous with -l 32 -b 4608 -m -e -r 16 -R 32 -p. This is painfully slow but gives you the maximum compression flac can do for the given blocksize.
-e Exhaustive model search (expensive!). Normally the encoder estimates the best model to use and encodes once based on the estimate. With an exhaustive model search, the encoder will generate subframes for every order and use the smallest. If the max LPC order is high this can significantly increase the encode time but can shave off another 0.5%.
-l # Specifies the maximum LPC order. This number must be <= 32. If 0, the encoder will not attempt generic linear prediction, and use only fixed predictors. Using fixed predictors is faster but usually results in files being 5-10% larger.
-q # Specifies the precision of the quantized LP coefficients, in bits. The default is -q 0, which means let the encoder decide based on the signal. Unless you really know your input file it's best to leave this up to the encoder.
-p Do exhaustive LP coefficient quantization optimization. This option overrides any -q option. It is expensive and typically will only improve the compression a tiny fraction of a percent. -q has no effect when -l 0 is used.
-r [#,]# Set the [min,]max residual partition order. The min value defaults to 0 if unspecified.
By default the encoder uses a single Rice parameter for the subframe's entire residual. With this option, the residual is iteratively partitioned into 2^min# .. 2^max# pieces, each with its own Rice parameter. Higher values of max# yield diminishing returns. The most bang for the buck is usually with -r 2,2 (more for higher blocksizes). This usually shaves off about 1.5%. The technique tends to peak out about when blocksize/(2^n)=128. Use -r 0,16 to force the highest degree of optimization.
-R # Set the Rice parameter search distance. Defaults to 0. The residual coder will search for the best Rice parameter +/- this number for each residual partition. This option is expensive (run time for -R n will typically be (2n)*30% over that of -R 0) and doesn't give much of a gain. As a matter of fact, none of the -0..-9 options currently use it since -R > 1 is not consistently better like it should be.
-V Verify the encoding process. With this option, flac will create a parallel decoder that decodes the output of the encoder and compares the result against the original. It will abort immediately with an error if a mismatch occurs. -V increases the total encoding time but is guaranteed to catch any unforseen bug in the encoding process.
-S-, -m-, -e-, -p-, -V-, --lax- can all be used to turn off a particular option.

Format Options
-fb | -fl Specify big-endian | little-endian byte order in the raw file.
-fc # Specify the number of channels in the raw file.
-fp # Specify the number of bits per sample in the raw file.
-fs # Specify the sample rate of the raw file.
-fu Specify that the samples in the raw file are unsigned (the default is signed).
-fr Treat the input file (or output file if decoding) as a raw file, regardless of the extension.
-fw Treat the input file (or output file if decoding) as a RIFF WAVE file, regardless of the extension.


metaflac is the command-line .flac file metadata editor. Right now it just lists the contents of all metadata blocks in a .flac file, but soon it will allow you to insert, delete, and edit blocks.

Currently metaflac can be invoked only one way:

  • Listing: metaflac [-v] inputfile

inputfile may be "-" for stdin. If -v is used, you will get verbose output.

xmms plugin

All that is necessary is to copy libxmms-flac.so to the directory where XMMS looks for input plugins (usually /usr/lib/xmms/Input). There is nothing else to configure. Make sure to restart XMMS before trying to play any .flac files.

winamp plugin

All that is necessary is to copy in_flac.dll to the Plugins/ directory of your Winamp installation. There is nothing else to configure. Make sure to restart Winamp before trying to play any .flac files.

known bugs

Bug tracking is done on the Sourceforge project page here. If you submit a bug, please provide an email contact and/or use the Monitor feature.