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

  1. Map the Source Streams: First, map all the streams you want to process to the tee muxer using the standard -map flag.

    -map 0:v -map 0:a

    This command sends all video and audio streams from the first input file into the tee muxer.

  2. Define the Tee Muxer and Outputs: Specify the tee format using -f tee, followed by a double-quoted string containing your outputs separated by the pipe (|) character.

  3. Use the select Option: Before each output filename, add [select=...]. Inside the select brackets, you can specify streams using:

    • Stream types: v for video, a for audio, s for subtitles.
    • Explicit stream indices: 0:v for the first video stream, 0:a:1 for the second audio stream of the first input.
    • Tee-input indices: Numbers representing the order of streams mapped to the tee muxer (e.g., 0 for the first mapped stream, 1 for the second).

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"