Configure Video Sizes in FFmpeg Tee Muxer
This article explains how to output different video resolutions to
multiple destinations using the FFmpeg tee muxer. Because
the tee muxer duplicates encoded packets rather than raw
video frames, achieving different video sizes requires scaling and
encoding multiple streams before passing them to the tee
muxer for distribution.
The Core Concept
The tee muxer operates at the container level. It cannot
resize, transcode, or filter video on its own; it merely duplicates the
encoded packets it receives and writes them to multiple outputs.
To output different video sizes using tee, you must: 1.
Split the input video stream. 2. Scale each split stream to your desired
resolutions using video filters. 3. Encode each scaled stream
individually. 4. Use the tee muxer’s select
option to route the correct encoded stream to its respective output.
The Command Structure
Below is an example command that takes a single input, scales it to
both 1080p and 720p, encodes both versions, and uses the
tee muxer to save them to separate files.
ffmpeg -i input.mp4 -filter_complex \
"[0:v]split=2[v1][v2]; \
[v1]scale=1920:1080[v1scaled]; \
[v2]scale=1280:720[v2scaled]" \
-map "[v1scaled]" -c:v:0 libx264 -b:v:0 4000k \
-map "[v2scaled]" -c:v:1 libx264 -b:v:1 2000k \
-map 0:a -c:a aac \
-f tee "[select='v:0,a']output_1080p.mp4|[select='v:1,a']output_720p.mp4"How It Works
-filter_complex:split=2creates two identical copies of the input video stream, labeled[v1]and[v2].scale=1920:1080resizes the first stream to Full HD, outputting[v1scaled].scale=1280:720resizes the second stream to HD, outputting[v2scaled].
- Mapping and Encoding:
-map "[v1scaled]" -c:v:0 libx264maps the 1080p stream to the first video encoder stream (v:0).-map "[v2scaled]" -c:v:1 libx264maps the 720p stream to the second video encoder stream (v:1).-map 0:a -c:a aaccopies the audio stream to be shared by both outputs.
- The
teeMuxer Selection:-f teeinvokes the tee muxer.[select='v:0,a']output_1080p.mp4selects only the first video stream (v:0) and the audio stream for the 1080p output file.[select='v:1,a']output_720p.mp4selects only the second video stream (v:1) and the audio stream for the 720p output file.- The pipe character (
|) separates the different outputs.