Map Specific Streams to Outputs in FFmpeg Tee Muxer
This article explains how to use the FFmpeg tee muxer to
route specific audio, video, or subtitle streams to different outputs
within a single command execution. You will learn the precise syntax for
the select option, how stream indexing works inside the
tee muxer, and how to handle shell escaping to avoid syntax
errors.
To map specific streams to individual outputs using the
tee muxer, you must combine global FFmpeg -map
options with the internal [select=...] option for each
output destination.
The Basic Syntax
The tee muxer first receives a pool of streams defined
by the global -map options. From this pool, you use the
select option inside brackets [] before each
output path to filter which streams are written to that specific
destination.
ffmpeg -i input.mp4 -map 0:v -map 0:a -f tee "[select='v,0:a:0']output_1.mp4|[select='v,0:a:1']output_2.mp4"Step-by-Step Breakdown
Map the Source Streams: First, map all the streams you want to process to the
teemuxer using the standard-mapflag.-map 0:v -map 0:aThis command sends all video and audio streams from the first input file into the
teemuxer.Define the Tee Muxer and Outputs: Specify the
teeformat using-f tee, followed by a double-quoted string containing your outputs separated by the pipe (|) character.Use the
selectOption: Before each output filename, add[select=...]. Inside the select brackets, you can specify streams using:- Stream types:
vfor video,afor audio,sfor subtitles. - Explicit stream indices:
0:vfor the first video stream,0:a:1for the second audio stream of the first input. - Tee-input indices: Numbers representing the order
of streams mapped to the
teemuxer (e.g.,0for the first mapped stream,1for the second).
- Stream types:
Example: Multi-Language Audio Routing
Imagine an input file input.mkv containing: * Stream
#0:0: Video * Stream #0:1: English Audio
(first audio) * Stream #0:2: Spanish Audio (second
audio)
To create two separate outputs—one with English audio and one with Spanish audio, both sharing the same video stream—use the following command:
ffmpeg -i input.mkv -map 0:v -map 0:a -f tee "[select='v,0:a:0']english.mp4|[select='v,0:a:1']spanish.mp4"In this command: * select='v,0:a:0' selects the video
stream and the English audio stream for english.mp4. *
select='v,0:a:1' selects the video stream and the Spanish
audio stream for spanish.mp4.
Handling Shell Escaping
Shell escaping is the most common point of failure when using the
tee muxer. Depending on your operating system and
command-line shell, you may need to escape the single quotes inside the
select brackets.
For Linux/macOS (bash/zsh): Use double quotes for
the entire tee argument and escape the single quotes
inside:
-f tee "[select=\'v,0:a:0\']output.mp4"For Windows (Command Prompt): Double quotes must be escaped using backslashes:
-f tee "[select='v,0:a:0']output.mp4"