Configure Frame Count and Weights in FFmpeg tmix
This article provides a straightforward guide on how to configure the
frame count and weight factors using the FFmpeg tmix
filter. You will learn the exact syntax for the frames and
weights parameters, understand how they interact to blend
successive video frames, and see practical command-line examples to
achieve smooth motion blur or temporal mixing effects.
Understanding the tmix Filter Parameters
The tmix (temporal mix) filter in FFmpeg blends
successive video frames together. To control how many frames are blended
and how much influence each frame has on the final output, you must
configure two primary parameters: frames and
weights.
frames: This parameter defines the number of consecutive frames to mix. The default value is3.weights: This parameter defines the weight factor for each frame in the mix, separated by spaces. The default is1for all frames, which results in an equal average.
An optional but important parameter is
scale. By default, scale is
set to 0, which automatically scales the output by the sum
of the weights to prevent the video from becoming oversaturated or blown
out.
Configuration Syntax and Rules
The basic syntax for the tmix filter is:
tmix=frames=N:weights="w1 w2 w3 ... wN":scale=SRule 1: Match Weights to Frame Count
If you specify a certain number of frames, you should
ideally provide the same number of space-separated values in the
weights string. For example, to mix 5 frames with a
fade-in/fade-out weight distribution:
tmix=frames=5:weights="1 2 3 2 1"Rule 2: Handling Fewer Weight Values
If you specify fewer weight values than the number of frames, the filter will automatically use the last specified weight value for all the remaining frames. For example:
tmix=frames=5:weights="1 2"In this scenario, FFmpeg interprets the weights as
"1 2 2 2 2".
Rule 3: Enclosing Weights in Quotes
Because the weight values are separated by spaces, you must enclose the weight sequence in quotes (either single or double depending on your command-line shell) so FFmpeg does not parse the spaces as command delimiters.
Practical Command Examples
Example 1: Equal Blend (Simple Motion Blur)
To blend 7 successive frames equally to create a smooth motion blur,
you can set the frame count to 7. Since the default weight is
1 for all frames, you do not need to specify the weights
manually:
ffmpeg -i input.mp4 -vf "tmix=frames=7" output.mp4Example 2: Weighted Blend (Emphasizing the Current Frame)
If you want to blend 5 frames but keep the center (current) frame sharper than the surrounding temporal frames, you can assign a higher weight to the middle frame:
ffmpeg -i input.mp4 -vf "tmix=frames=5:weights='1 2 4 2 1'" output.mp4In this command, the third frame (index 2) has a weight of 4, making it twice as prominent as the adjacent frames and four times as prominent as the outer frames.
Example 3: Temporal Fade-Out
To create an effect where past frames trail off progressively, you can decrease the weights from the newest frame to the oldest frame:
ffmpeg -i input.mp4 -vf "tmix=frames=4:weights='4 3 2 1'" output.mp4Example 4: Manual Scaling
If you want to manually adjust the brightness of the mixed frames
rather than relying on automatic normalization, set the
scale factor. For example, to scale the output to 80% of
the sum of weights:
ffmpeg -i input.mp4 -vf "tmix=frames=3:weights='1 2 1':scale=0.2" output.mp4