How to Use FFmpeg tblend Filter for Consecutive Frames
The tblend (time blend) video filter in FFmpeg blends
successive frames of a single video stream to create visual effects such
as motion blur, frame differencing, and temporal transitions. This guide
provides a straightforward breakdown of how tblend works,
its primary blend modes, and practical command-line examples for
blending consecutive frames.
How the tblend Filter Works
Unlike the standard blend filter—which combines two
separate video inputs—the tblend filter operates across the
temporal domain of a single input stream. It compares the current frame
(the top layer, denoted as T) with the immediately
preceding frame (the bottom layer, denoted as B).
Basic Syntax
The most common way to configure tblend is through the
all_mode parameter, which sets the blending algorithm for
all video planes (Y, U, V or R, G, B):
ffmpeg -i input.mp4 -vf "tblend=all_mode=MODE" output.mp4Replace MODE with one of FFmpeg’s supported blend modes,
such as average, difference,
addition, multiply, or
screen.
Practical Examples
1. Creating Simulated Motion Blur
To smooth out high-framerate footage or create a ghosting/motion
trail effect, use the average mode. This blends the current
and previous frames with equal weight:
ffmpeg -i input.mp4 -vf "tblend=all_mode=average" motion_blur.mp4To soften the effect, adjust the all_opacity parameter
(values range from 0.0 to 1.0):
ffmpeg -i input.mp4 -vf "tblend=all_mode=average:all_opacity=0.5" subtle_blur.mp42. Temporal Frame Differencing (Motion Detection)
The difference mode subtracts the pixel values of the
previous frame from the current frame. Static areas become black, while
moving objects appear illuminated, making this useful for motion
analysis:
ffmpeg -i input.mp4 -vf "tblend=all_mode=difference" motion_mask.mp43. Light Trails Using Screen or Addition
For creative effects like glowing motion trails or light
accumulation, use screen or addition:
ffmpeg -i input.mp4 -vf "tblend=all_mode=addition" trails.mp4Advanced Custom Blending with Expressions
If predefined modes are insufficient, use the all_expr
parameter to define mathematical operations using pixel variables:
T: Pixel value from the current (top) frame.B: Pixel value from the previous (bottom) frame.
For example, to weight the current frame at 75% and the previous frame at 25%:
ffmpeg -i input.mp4 -vf "tblend=all_expr='0.75*T + 0.25*B'" custom_blend.mp4Blending Non-Adjacent Frames
By default, tblend compares frame \(N\) with frame \(N-1\). To blend across wider temporal
intervals, pair tblend with the framestep
filter:
ffmpeg -i input.mp4 -vf "framestep=2,tblend=all_mode=difference" stepped_diff.mp4