How to Use FFmpeg Tee Muxer for Multiple Outputs

The tee muxer in FFmpeg allows you to take a single audio/video stream, encode it once, and distribute the resulting packets to multiple destinations simultaneously. This guide explains how to use the tee muxer to output to multiple local files and network streams in parallel, saving processing power, system memory, and encoding time.


What is the FFmpeg tee Muxer?

Normally, specifying multiple output files in FFmpeg causes it to encode the media separately for each output, heavily taxing your CPU or GPU. The tee muxer solves this by acting as a virtual output format that duplicates the encoded packets and sends them to multiple destinations at the same time.

Basic Syntax

To use the tee muxer, set the format flag to -f tee and provide the target paths separated by a vertical pipe character (|), enclosed in quotes to prevent your command shell from interpreting the pipe:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f tee "output1.mp4|output2.mkv"

In this command, the input is transcoded once using H.264 video and AAC audio, and then written simultaneously to output1.mp4 and output2.mkv.


Applying Format-Specific Options

Different file containers or streaming protocols often require different container formats or flags. You can pass options to individual outputs using brackets [...] before the output filename.

Example: Multiple Local Containers with Explicit Formats

ffmpeg -i input.mov -c:v libx264 -c:a aac -f tee "[f=mp4]output.mp4|[f=matroska]output.mkv"

The f=mp4 and f=matroska specifiers force the correct muxer for each individual destination.


Simultaneous Local Recording and Live Streaming

A common use case for the tee muxer is saving a high-quality local archive while streaming to a platform like Twitch, YouTube, or an RTMP server.

ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
  -c:a aac -b:a 128k -f tee \
  "[f=flv:onfail=ignore]rtmp://live.example.com/app/streamkey|[f=mp4]archive.mp4"

Key features in this example:

  • [f=flv]: Specifies the Flash Video muxer required for standard RTMP streams.
  • onfail=ignore: Tells FFmpeg to continue writing to the local archive.mp4 even if the RTMP network connection drops. Without this, an error on one output halts the entire process.

Handling Bitstream Filters (BSFs)

Some containers require specific bitstream filters to handle codecs correctly. For instance, streaming H.264 over FLV or MPEG-TS might require converting packet headers.

You can apply bitstream filters to specific streams within an output:

ffmpeg -i input.mp4 -c:v copy -c:a copy -f tee \
  "output.mp4|[f=mpegts:bsfs/v=dump_extra]udp://127.0.0.1:1234"
  • bsfs/v=dump_extra: Applies the dump_extra bitstream filter specifically to the video stream going to the UDP destination, leaving the local MP4 copy untouched.

Summary Checklist for Using tee

  • Wrap in quotes: Always place the entire output list in quotation marks ("...") to prevent shell pipe redirection errors.
  • Match codecs: Ensure all outputs can accept the codecs you choose; the tee muxer duplicates encoded data and cannot transcode to different codecs per output.
  • Use onfail=ignore: Always add this flag to network outputs if you want local recordings to survive internet interruptions.