FFmpeg Lagfun Filter: Apply Temporal Lag Effects
This guide explains how to use the lagfun video filter
in FFmpeg to create a temporal lag effect, often recognized as ghosting,
motion trails, or video echoing. You will learn the filter's syntax, its
core parameters, and practical command examples to control how fast or
slow motion trails decay in your video projects.
What is the Lagfun Filter?
The lagfun filter computes a temporal decaying sum
across video frames. Instead of moving objects disappearing instantly
from their previous positions, each pixel value slowly fades over time.
This generates an artistic visual trail behind moving elements, making
it ideal for simulating long exposure, light painting, or psychedelic
motion blur.
Syntax and Parameters
The basic syntax for using the filter is:
-vf "lagfun=decay=<value>:planes=<value>"The filter accepts two primary parameters:
decay: Sets the decay factor for the temporal lag. The value must be a floating-point number between0.0and1.0. The default value is0.95. A higher number keeps trailing pixels visible for longer, while a lower number makes trails fade quickly.planes: Specifies which color planes to filter. By default, it applies to all planes (15or all channels). You can limit it to luminance or specific chroma channels if you want stylized color-lag effects.
Basic Command Example
To apply a standard temporal lag effect to a video, run the following command:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.95" -c:a copy output.mp4In this command, -vf "lagfun=decay=0.95" applies the
default decay factor, and -c:a copy preserves the original
audio stream without re-encoding.
Adjusting Trail Length
You can customize the intensity and length of the trail by modifying
the decay value:
Subtle Motion Blur / Short Trails: A lower decay value creates a subtle smearing effect suitable for fast action.
ffmpeg -i input.mp4 -vf "lagfun=decay=0.7" -c:a copy output_subtle.mp4Extreme Ghosting / Long Light Trails: A value close to
1.0makes the trails linger for several seconds, which works best on high-contrast videos with light elements against dark backgrounds.ffmpeg -i input.mp4 -vf "lagfun=decay=0.99" -c:a copy output_extreme.mp4
Isolating Color Planes
You can apply the lag effect exclusively to specific color components. For example, to apply the effect only to the luminance channel (plane 1 in YUV) while leaving the color unaffected:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.9:planes=1" -c:a copy output_luma.mp4Alternatively, targeting only the chroma channels (planes 2 and 4, or
planes=6) will cause color trails to smear while
maintaining sharp edge details in the luminance channel.