How to Use FFmpeg Tee Muxer for Multiple Outputs

This article explains how to use the FFmpeg tee muxer to split an audio or video stream and write it to multiple output files in different formats simultaneously. By using this tool, you can save CPU cycles by encoding your media only once while saving it to various containers, such as MP4, MKV, or FLV, or streaming it to multiple destinations at the same time.

The Basic Syntax of the Tee Muxer

To use the tee muxer, you must specify -f tee as the output format, followed by the output destinations separated by the pipe character (|). The entire list of outputs must be enclosed in quotes to prevent your command line shell from misinterpreting the pipe characters.

Here is a basic example of duplicating an input stream into two different container formats:

ffmpeg -i input.mp4 -map 0 -c:v libx264 -c:a aac -f tee "output.mp4|output.mkv"

In this command, FFmpeg encodes the input video and audio once and hands the compressed packets to the tee muxer, which writes them directly to both output.mp4 and output.mkv.

Applying Format-Specific Options

Different container formats often require different muxer options. You can specify options for individual outputs by placing them inside brackets [] right before the respective file path. Use the f option to explicitly declare the container format if FFmpeg cannot guess it from the file extension.

ffmpeg -i input.mp4 -map 0 -c:v libx264 -c:a aac -f tee "[f=mp4]local_backup.mp4|[f=flv]rtmp://live.twitch.tv/app/stream_key"

In this setup: * [f=mp4]local_backup.mp4 forces the first output to use the MP4 container. * [f=flv]rtmp://live.twitch.tv/app/stream_key forces the second output to use the FLV container, which is ideal for RTMP streaming.

Selecting Specific Streams for Different Outputs

You can control which audio, video, or subtitle streams go to which output by using the select option inside the brackets. This is useful if you want one output to have both audio and video, but another output to be video-only.

ffmpeg -i input.mp4 -map 0:v -map 0:a -c:v libx264 -c:a aac -f tee "[select=v,a]full_media.mp4|[select=v]video_only.mkv"

In this example: * select=v,a ensures both video and audio are written to full_media.mp4. * select=v filters out the audio, writing only the video stream to video_only.mkv.

Handling Special Characters and Escaping

Because the tee muxer relies on characters like [, ], and | to parse the command, you must escape these characters with a backslash \ if they appear as part of your actual file path or stream URL.

For example, if an output URL contains a option with a pipe or a bracket, escape it like this:

ffmpeg -i input.mp4 -map 0 -c:v copy -f tee "output1.mp4|[f=flv]rtmp://example.com/live/stream\?option1\=val1\|option2\=val2"