Configure Individual Bitrates in FFmpeg Tee Muxer
This article explains how to configure individual video bitrates for
different outputs when using the FFmpeg tee muxer. While
the tee muxer is typically used to split a single encoded
stream to multiple destinations without re-encoding, you can achieve
different bitrates for each output by encoding multiple stream variants
simultaneously and using the select option to route
them.
The Limitation of the Tee Muxer
By default, the tee muxer copies identical packets to
all specified outputs. It cannot dynamically re-encode or change the
bitrate of a single stream for different destinations. To output
different bitrates, you must perform multiple encodings inside the same
FFmpeg command and then map each encoded stream to its respective
output.
The Solution: Multi-Map and Select
To send different bitrates to different outputs, follow these steps:
1. Map the input stream multiple times. 2. Define different encoder
settings (bitrates) for each mapped stream. 3. Use the
select option within the tee muxer payload to
assign specific video and audio streams to specific outputs.
Example FFmpeg Command
Here is a practical command that takes an input file, encodes it into
two different bitrates (4000k and 1500k), and outputs them to two
different destinations using the tee muxer:
ffmpeg -i input.mp4 \
-map 0:v -map 0:v -map 0:a \
-c:v:0 libx264 -b:v:0 4000k \
-c:v:1 libx264 -b:v:1 1500k \
-c:a aac -b:a 128k \
-f tee "[select=\'v:0,a:0\']high_bitrate.mp4|[select=\'v:1,a:0\']low_bitrate.mp4"Command Breakdown
-map 0:v -map 0:v -map 0:a: This maps the source video twice (creating two independent video streams,v:0andv:1) and the audio once (a:0).-c:v:0 libx264 -b:v:0 4000k: This configures the first video stream (v:0) to use the H.264 codec at a bitrate of 4000 kbps.-c:v:1 libx264 -b:v:1 1500k: This configures the second video stream (v:1) to use the H.264 codec at a lower bitrate of 1500 kbps.-f tee: This invokes theteemuxer.[select=\'v:0,a:0\']high_bitrate.mp4: Theselectoption filters the output so that only the high-bitrate video (v:0) and the audio stream (a:0) are written tohigh_bitrate.mp4.[select=\'v:1,a:0\']low_bitrate.mp4: This filters the second output so that only the low-bitrate video (v:1) and the audio stream (a:0) are written tolow_bitrate.mp4.
Note: Depending on your command-line shell (such as Bash, zsh, or
Windows CMD), you may need to adjust the escaping of the single quotes
(\' or ') around the select filters.