Blend Videos with FFmpeg Mix Filter and Weights

The FFmpeg mix filter allows you to combine multiple video streams into a single video frame-by-frame, applying custom weight factors to control the transparency and dominance of each input. This guide explains how the mix filter functions, how to define input counts and custom weights, and how to properly format your FFmpeg commands for seamless multi-video blending.

Basic Syntax of the Mix Filter

The mix filter accepts several configuration options. The two most critical parameters for weighted blending are:

  • inputs: The number of input streams to blend (default is 2).
  • weights: A space-separated list of floating-point or integer weights assigned to each input stream sequentially.
  • scale: A floating-point divisor applied to the weighted sum. If set to 0 (the default), FFmpeg automatically sets the scale to the sum of all specified weights, normalizing the output so it does not overexpose or clip pixel values.

The basic structure of a filter_complex mix command is:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "mix=inputs=2:weights=W1 W2" output.mp4

Blending Two Videos with Custom Weights

When combining two videos, the weights parameter determines the proportion each video contributes to the final frame.

For an even 50/50 blend:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "mix=inputs=2:weights='1 1'" -c:a copy output.mp4

To make the first video more prominent (75%) and the second video subtle (25%), assign proportional weights:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "mix=inputs=2:weights='3 1'" -c:a copy output.mp4

FFmpeg sums 3 + 1 = 4, automatically scaling input1 by 3/4 (0.75) and input2 by 1/4 (0.25).

Blending Three or More Videos

You can blend any number of inputs by updating the inputs count and matching the number of values in the weights string.

For example, blending three videos where the primary video receives 60% visibility and two background elements receive 20% visibility each:

ffmpeg -i main.mp4 -i layer1.mp4 -i layer2.mp4 -filter_complex "mix=inputs=3:weights='6 2 2'" -c:a copy output.mp4

Manual Scaling and Brightness Control

By default, automatic scaling ensures output luminance matches standard dynamic ranges. However, you can explicitly define the scale factor if you want to alter the overall brightness or combine raw pixel values manually:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "mix=inputs=2:weights='1 1':scale=1.5" -c:a copy brighter_mix.mp4

A smaller scale value brightens the output by dividing the sum by a smaller number, while a larger scale value darkens the output.

Preparing Inputs for the Mix Filter

The mix filter requires all input streams to have identical resolutions, pixel formats, and durations to avoid synchronization errors. If your sources differ, normalize them prior to applying the mix filter using a filter chain:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]scale=1920:1080,format=yuv420p[v0]; \
 [1:v]scale=1920:1080,format=yuv420p[v1]; \
 [v0][v1]mix=inputs=2:weights='2 1'[outv]" \
-map "[outv]" -c:v libx264 -crf 18 output.mp4