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, AIFF, 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 files ending in ".wav" or that have the RIFF WAVE header present are WAVE files, and files ending in ".aif" or ".aiff" or have the AIFF header present are in AIFF files. This may be overridden with a command-line option. It also assumes that files ending in ".ogg" are Ogg FLAC files. 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 .. -8 (or --fast and --best) 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 unless --delete-input-file is specified.
If you are encoding/decoding from stdin to a file, you should use the -o option like so:
-
flac [options] -o outputfile
-
flac -d [options] -o 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.
To encode or decode files that start with a dash, use -- to signal the end of options, to keep the filenames themselves from being treated as options:
-
flac -V -- -01-filename.wav
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 or AIFF file the format options are not needed since they are read from the AIFF/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
|
-v, --version
|
Show the flac version number.
|
-h, --help
|
Show basic usage and a list of all options. Running flac without arguments shows the short help screen by default.
|
-H, --explain
|
Show detailed explanation of usage and all options. Running flac without arguments shows the short help screen by default.
|
-d, --decode
|
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
|
Test (same as -d except no decoded file is written). The exit codes are the same as in decode mode.
|
-a, --analyze
|
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, --stdout
|
Write output to stdout.
|
-s, --silent
|
Silent: do not show encoding/decoding statistics.
|
--totally-silent
|
Do not print anything of any kind, including warnings or errors. The exit code will be the only way to determine successful completion.
|
-f, --force
|
Force overwriting of output files. By default, flac warns that the output file already exists and continues to the next file.
|
-o filename, --output-name=filename
|
Force the output file name (usually flac just changes the extension). May only be used when encoding a single file. May not be used in conjunction with --output-prefix.
|
--output-prefix=string
|
Prefix each output file name with the given string. This can be useful for encoding/decoding files to a different directory. Make sure if your string is a path name that it ends with a trailing '/' slash.
|
--delete-input-file
|
Automatically delete the input file after a successful encode or decode. If there was an error (including a verify error) the input file is left intact.
|
--skip={#|mm:ss.ss}
|
Skip over the first # of samples of the input. This works for both encoding and decoding, but not testing. The alternative form mm:ss.ss can be used to specify minutes, seconds, and fractions of a second.
Examples:
--skip=123 : skip the first 123 samples of the input
--skip=1:23.45 : skip the first 1 minute and 23.45 seconds of the input
|
--until={#|[+|-]mm:ss.ss}
|
Stop at the given sample number for each input file. This works for both encoding and decoding, but not testing. The given sample number is not included in the decoded output. The alternative form mm:ss.ss can be used to specify minutes, seconds, and fractions of a second. If a + sign is at the beginning, the --until point is relative to the --skip point. If a - sign is at the beginning, the --until point is relative to end of the audio.
Examples:
--until=123 : decode only the first 123 samples of the input (samples 0-122, stopping at 123)
--until=1:23.45 : decode only the first 1 minute and 23.45 seconds of the input
--skip=1:00 --until=+1:23.45 : decode 1:00.00 to 2:23.45
--until=-1:23.45 : decode everything except the last 1 minute and 23.45 seconds
--until=-0:00 : decode until the end of the input (the same as not specifying --until)
|
--ogg
|
When encoding, generate Ogg FLAC output instead of native FLAC. Ogg FLAC streams are FLAC streams wrapped in an Ogg transport layer. The resulting file should have an '.ogg' extension and will still be decodable by flac.
When decoding, force the input to be treated as Ogg FLAC. This is useful when piping input from stdin or when the filename does not end in '.ogg'.
NOTE: Ogg FLAC files created prior to flac 1.1.1 used an ad-hoc mapping and do not support seeking. They should be decoded and re-encoded with flac 1.1.1 or later.
|
--serial-number=#
|
When used with --ogg, specifies the serial number to use for the first Ogg FLAC stream, which is then incremented for each additional stream. When encoding and no serial number is given, flac uses a random number for the first stream, then increments it for each additional stream. When decoding and no number is given, flac uses the serial number of the first page.
|
|
Analysis Options
|
--residual-text
|
Includes the residual signal in the analysis file. This will make the file very big, much larger than even the decoded file.
|
--residual-gnuplot
|
Generates a gnuplot file for every subframe; each file will contain the residual distribution of the subframe. This will create a lot of files.
|
|
Decoding Options
|
--cue=[#.#][-[#.#]]
|
Set the beginning and ending cuepoints to decode. The optional first #.# is the track and index point at which decoding will start; the default is the beginning of the stream. The optional second #.# is the track and index point at which decoding will end; the default is the end of the stream. If the seekpoint does not exist, the closest one before it (for the start point) or after it (for the end point) will be used. If those don't exist, the start of the stream (for the start point) or end of the stream (for the end point) will be used. The cuepoints are merely translated into sample numbers then used as --skip and --until.
Examples:
--cue=- : decode the entire stream
--cue=4.1 : decode from track 4, index 1 to the end of the stream
--cue=4.1- : decode from track 4, index 1 to the end of the stream
--cue=-4.1 : decode from the beginning of the stream up to, but not including, track 4, index 1
--cue=2.1-2.4 : decode from track 2, index 1, up to, but not including, track 2, index 4
|
-F, --decode-through-errors
|
By default flac stops decoding with an error and removes the partially decoded file if it encounters a bitstream error. With -F, errors are still printed but flac will continue decoding to completion. Note that errors may cause the decoded audio to be missing some samples or have silent sections.
|
|
Encoding Options
|
-V, --verify
|
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.
|
--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.
|
--replay-gain
|
Calculate ReplayGain values and store in FLAC tags, similar to VorbisGain. Title gains/peaks will be computed for each input file, and an album gain/peak will be computed for all files. All input files must have the same resolution, sample rate, and number of channels. Only mono and stereo files are allowed, and the sample rate must be one of 8, 11.025, 12, 16, 22.05, 24, 32, 44.1, or 48 kHz. Also note that this option may leave a few extra bytes in a PADDING block as the exact size of the tags is not known until all files are processed.
Note that this option cannot be used when encoding to standard output (stdout).
|
--cuesheet=FILENAME
|
Import the given cuesheet file and store it in a CUESHEET metadata block. This option may only be used when encoding a single file. A seekpoint will be added for each index point in the cuesheet to the SEEKTABLE unless --no-cued-seekpoints is specified.
The cuesheet file must be of the sort written by CDRwin, CDRcue, EAC, et al.
|
--sector-align
|
Align encoding of multiple CD format WAVE files on sector boundaries. This option is only allowed when encoding WAVE files, all of which have a 44.1kHz sample rate and 2 channels. With --sector-align, the encoder will align the resulting .flac streams so that their lengths are even multiples of a CD sector (1/75th of a second, or 588 samples). It does this by carrying over any partial sector at the end of each WAVE file to the next stream. The last stream will be padded to alignment with zeroes.
This option will have no effect if the files are already aligned (as is the normally the case with WAVE files ripped from a CD). flac can only align a set of files given in one invocation of flac.
WARNING: The ordering of files is important! If you give a command like 'flac --sector-align *.wav' the shell may not expand the wildcard to the order you expect. To be safe you should 'echo *.wav' first to confirm the order, or be explicit like 'flac --sector-align 8.wav 9.wav 10.wav'.
|
-S {#|X|#x|#s}, --seekpoint={#|X|#x|#s}
|
Include a point or points in a SEEKTABLE:
-
# : a specific sample number for a seek point
-
X : a placeholder point (always goes at the end of the SEEKTABLE)
-
#x : # evenly spaced seekpoints, the first being at sample 0
-
#s : a seekpoint every # seconds; # does not have to be a whole number, it can be, for example, 9.5, meaning a seekpoint every 9.5 seconds
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 10s'. Use --no-seektable for no SEEKTABLE.
NOTE: -S #x and -S #s 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 #, --padding=#
|
Tell the encoder to write a PADDING metadata block of the given length (in bytes) after the STREAMINFO block. 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. Note that the total length of the PADDING block will be 4 bytes longer than the length given because of the 4 metadata block header bytes. You can force no PADDING block at all to be written with --no-padding. The encoder writes a PADDING block of 4096 bytes by default.
|
-T FIELD=VALUE, --tag=FIELD=VALUE
|
Add a FLAC tag. The comment must adhere to the Vorbis comment spec (which FLAC tags implement), i.e. the FIELD must contain only legal characters, terminated by an 'equals' sign. Make sure to quote the comment if necessary. This option may appear more than once to add several comments. NOTE: all tags will be added to all encoded files.
|
-b #, --blocksize=#
|
Specify the block size 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 reference encoder uses the same block size for the entire stream.
|
-m, --mid-side
|
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, --adaptive-mid-side
|
Enable adaptive 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 .. -8
|
Fastest compression .. highest compression. The default is -5.
|
-0, --compression-level-0
|
Synonymous with -l 0 -b 1152 -r 2,2
|
-1, --compression-level-1
|
Synonymous with -l 0 -b 1152 -M -r 2,2
|
-2, --compression-level-2
|
Synonymous with -l 0 -b 1152 -m -r 3
|
-3, --compression-level-3
|
Synonymous with -l 6 -b 4608 -r 3,3
|
-4, --compression-level-4
|
Synonymous with -l 8 -b 4608 -M -r 3,3
|
-5, --compression-level-5
|
Synonymous with -l 8 -b 4608 -m -r 3,3
|
-6, --compression-level-6
|
Synonymous with -l 8 -b 4608 -m -r 4
|
-7, --compression-level-7
|
Synonymous with -l 8 -b 4608 -m -e -r 6
|
-8, --compression-level-8
|
Synonymous with -l 12 -b 4608 -m -e -r 6
|
--fast
|
Fastest compression. Currently synonymous with -0
|
--best
|
Highest compression. Currently synonymous with -8
|
-e, --exhaustive-model-search
|
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 #, --max-lpc-order=#
|
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 #, --qlp-coeff-precision=#
|
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, --qlp-coeff-precision-search
|
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 [#,]#, --rice-partition-order=[#,]#
|
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 block sizes). 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.
|
|
Format Options
|
--endian={big|little}
|
Specify big-endian or little-endian byte order in the raw file.
|
--channels=#
|
Specify the number of channels in the raw file.
|
--bps=#
|
Specify the number of bits per sample in the raw file.
|
--sample-rate=#
|
Specify the sample rate of the raw file.
|
--sign={signed|unsigned}
|
Specify that the samples in the raw file are signed or unsigned (the default is signed).
|
--force-aiff-format
|
Force the decoder to output AIFF format. This option is not needed if the output filename (as set by -o) ends with .aiff. Also, this option has no effect when encoding since input AIFF is auto-detected.
|
--force-raw-format
|
Treat the input file (or output file if decoding) as a raw file, regardless of the extension.
|
|
Negative Options
|
--no-adaptive-mid-side
--no-decode-through-errors
--no-delete-input-file
--no-escape-coding
--no-exhaustive-model-search
--no-lax
--no-mid-side
--no-ogg
--no-padding
--no-qlp-coeff-precision-search
--no-residual-gnuplot
--no-residual-text
--no-sector-align
--no-seektable
--no-silent
--no-verify
|
can all be used to turn off a particular option.
|
|
|