Use tee to write to multiple outputs at once
The `tee` muxer writes the same encoded output to multiple destinations in a single command. It is the right tool for a live stream that needs to go to YouTube and Twitch simultaneously, or a transcoded file that needs to land in two locations.
The command
ffmpeg -i in.mp4 -c:v libx264 -crf 20 -f tee -map 0:v "out1.mp4|out2.mp4" -map 0:a -c:a aac "out1.mp4|out2.mp4"What it does
The command encodes the input once, then writes the same encoded output to two files. The `tee` muxer takes a list of destinations separated by `|`. Each destination can be a file or a network URL. The encode runs once; the writes are parallel. The flag is most useful for live streaming, where the same encode can be sent to multiple ingest servers.
Requirements
A muxer built into FFmpeg (most are). The encode runs once, so the CPU cost is the same as a single output. The disk or network cost is multiplied by the number of destinations. For very high resolutions, the disk write can become the bottleneck.
Things to avoid
- Using `tee` with mismatched codecs per destination. The `tee` muxer writes the same encoded output to each destination, so all destinations must support the codec.
- Forgetting the `-map` flag. The muxer will try to write all streams to each destination, which may fail if the destination does not support the stream type (e.g., a file with no audio track).
- Using `tee` on a piped output. The muxer writes the same data to each destination, but the pipe consumes the data once; use the `tee` muxer for file outputs and the `tee` filter for pipe outputs.
- Expecting the muxer to handle different container formats. The same encoded output is written to each destination, so all destinations must support the codec and the muxer must support the container.