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
- Stream Mapping (
-map):-map 0:vmaps the input video stream.-map 0:a -map 0:amaps the input audio stream twice. This tells FFmpeg to create two independent audio encoding pipelines from the single source audio.
- Bitrate Allocation (
-b:a):-b:a:0 128ksets the bitrate of the first mapped audio stream (a:0) to 128 kbps.-b:a:1 256ksets the bitrate of the second mapped audio stream (a:1) to 256 kbps.
- Tee Muxer Selection (
select):- The
teemuxer outputs are separated by the pipe (|) character. [f=mp4:select=\'v,a:0\']out_low.mp4selects the video stream (v) and the first audio stream (a:0at 128k) for the first output file.[f=mp4:select=\'v,a:1\']out_high.mp4selects the video stream (v) and the second audio stream (a:1at 256k) for the second output file.
- The
Important Syntax Notes
- Escaping Quotes: Depending on your operating system
shell (bash, zsh, or Windows Command Prompt), you may need to escape the
single quotes around the
selectparameters. In Linux/macOS bash, use\'v,a:0\'as shown above. - Stream Order: The index numbers in
a:0anda:1refer to the order of the encoded output audio streams, not necessarily the input streams. Ensure your mapping sequence matches your bitrate assignments.