Skip to content

Audio Options

patrickenfuego edited this page Jan 29, 2022 · 14 revisions

FFEncoder supports the mapping/transcoding of 2 distinct audio streams to the output file. For audio that is transcoded, the primary audio stream is used as it's generally lossless (TrueHD, DTS-HD MA, LPCM, etc.). It is never recommended to transcode from one lossy codec to another; if the primary audio stream is lossy compressed, it is best to stream copy it instead of forcing a transcode.

FFEncoder currently supports the following audio options wih the -Audio/-Audio2 parameters. When selecting a named codec (like EAC3, AC3, etc.) the script will go through the following checks:

  1. If either of the -AudioBitrate parameters are selected, the corresponding stream will be transcoded to the selected codec, regardless if an existing stream is present in the input file
  2. If the -AudioBitrate parameters are not present, the script will search the input file for a matching stream and stream copy it to the output file if found
  3. If no bitrate is specified and no existing stream is found, then the script will transcode to the selected codec at the default bitrates listed below:
Type Values Default Description
Copy copy, c N/A Passes through the primary audio stream without re-encoding
Copy All copyall, ca N/A Passes through all audio streams from the input to the output without re-encoding
AAC aac 512 kb/s Converts the primary audio stream to AAC using ffmpeg's native CBR encoder. Compatible with the -AudioBitrate parameters
FDK AAC fdkaac, faac Variable (VBR) Converts the primary audio stream to AAC using libfdk_aac. Compatible with the -AudioBitrate parameters. See note below for more info
AAC_AT aac_at Variable (VBR) Converts the primary audio stream to AAC using Apple Core Audio Toolbox (MacOS only). Compatible with the -AudioBitrate parameters
AC3 ac3, dd 640 kb/s Dolby Digital. Compatible with the -AudioBitrate parameters
E-AC3 eac3 448 kb/s Dolby Digital Plus. Compatible with the -AudioBitrate parameters
DTS dts Variable (VBR) DTS Core audio. Warning: ffmpeg's DTS encoder is "experimental". Compatible with the -AudioBitrate parameters
FLAC flac, f Variable (VBR) Converts the primary audio stream to FLAC lossless audio using ffmpeg's native FLAC encoder
Stream # 0-5 N/A Select an audio stream using its stream identifier in ffmpeg/ffprobe. Not compatible with the -Stereo parameters
None none, n N/A No audio streams will be added to the output file

Using the libfdk_aac Encoder

FFEncoder includes support for Fraunhofer's libfdk_aac, even though it is not included in a standard ffmpeg executable. Due to a conflict with ffmpeg's GPL, libfdk_aac cannot be distributed with any official ffmpeg binaries, but it can be included when compiling ffmpeg manually from source. For more info, see Dependencies.

One of the benefits of the FDK encoder is that it supports variable bitrate (VBR). When using the -AudioBitrate/-AudioBitrate2 parameters with fdkaac, values 1-5 are used to signal VBR. 1 = lowest quality and 5 = highest quality.


Using the aac_at Encoder

When running FFEncoder on a Mac computer, you gain access to the AudioToolbox AAC encoder (open source port of Apple's high quality encoder) via the aac_at argument. AudioToolbox is, by default, a variable Bitrate (VBR) encoder, but can accept the following values using -AudioBitrate/-AudioBitrate2:

  • -1 - Auto (VBR)
  • 0 - Constant bitrate (CBR)
  • 1 - Long-term Average bitrate (ABR)
  • 2 - Constrained variable bitrate (VBR)
  • 3 - Variable bitrate (VBR)

Downmixing Multi-Channel Audio to Stereo

With FFEncoder, you can downmix either of the two output streams to stereo using the -Stereo/-Stereo2 parameters. The process uses an audio filter that retains the LFE (bass) track in the final mix, which is discarded when using -ac 2 in ffmpeg directly.

When using any combination of copy/c/copyall/ca and -Stereo/-Stereo2, the script will multiplex the primary audio stream out of the container and encode it separately; this is because ffmpeg cannot stream copy and filter at the same time. See here for a nice explanation. Once the primary encode finishes, the external audio file (now converted to stereo) is multiplexed back into the primary container with the other streams selected.

Clone this wiki locally