Configure Individual Audio Bitrates in FFmpeg Tee Muxer

This article explains how to configure individual audio bitrates for different outputs when using the FFmpeg tee muxer. You will learn how to duplicate and encode your audio streams at different bitrates within a single command execution, and then use the tee muxer’s selection syntax to route each specific audio stream to its respective output destination.

The Challenge with the Tee Muxer

The tee muxer is designed to split a single encoded stream to multiple outputs without re-encoding it multiple times. Because of this, you cannot directly apply different encoder settings (like bitrate) inside the tee output options.

To achieve different bitrates for each output, you must: 1. Encode multiple audio streams at different bitrates in the main body of the FFmpeg command. 2. Map these streams to the tee muxer. 3. Use the select option within the tee muxer to send the correct audio stream to each output.

Step-by-Step Configuration

Here is the template command to achieve this:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac \
-map 0:v -map 0:a -map 0:a \
-b:a:0 128k -b:a:1 256k \
-f tee "[f=mp4:select=\'v,a:0\']out_low.mp4|[f=mp4:select=\'v,a:1\']out_high.mp4"

How the Command Works

  1. Stream Mapping (-map):
    • -map 0:v maps the input video stream.
    • -map 0:a -map 0:a maps the input audio stream twice. This tells FFmpeg to create two independent audio encoding pipelines from the single source audio.
  2. Bitrate Allocation (-b:a):
    • -b:a:0 128k sets the bitrate of the first mapped audio stream (a:0) to 128 kbps.
    • -b:a:1 256k sets the bitrate of the second mapped audio stream (a:1) to 256 kbps.
  3. Tee Muxer Selection (select):
    • The tee muxer outputs are separated by the pipe (|) character.
    • [f=mp4:select=\'v,a:0\']out_low.mp4 selects the video stream (v) and the first audio stream (a:0 at 128k) for the first output file.
    • [f=mp4:select=\'v,a:1\']out_high.mp4 selects the video stream (v) and the second audio stream (a:1 at 256k) for the second output file.

Important Syntax Notes