How to Use FFmpeg lagfun Filter for Temporal Lag
This guide explains how to use the lagfun filter in
FFmpeg to apply a temporal lag or motion blur effect to your videos. You
will learn the core syntax, key parameters of the filter, and practical
command-line examples to help you customize the intensity of the
trailing, ghostly visual effect.
Understanding the lagfun Filter
The lagfun filter in FFmpeg is a temporal video filter
that blends the current frame with previous frames. This process creates
a trailing “ghost” effect on moving objects while leaving static
backgrounds unaffected. It is highly effective for simulating
long-exposure motion, psychedelic visual effects, or stylized motion
blur.
Key Parameters
The lagfun filter accepts two primary parameters to
control the output:
decay: This controls the persistence of the lag effect. The value ranges from0.0to1.0. A higher value (e.g.,0.95) means the trails stay on screen longer, creating a more dramatic ghosting effect. A lower value (e.g.,0.5) results in a faster fade and a more subtle lag. The default value is0.95.planes: This specifies which color planes to filter. The value is a bitmask where1is for the Y (luma) plane,2is for the U plane,4is for the V plane, and8is for the Alpha plane. By default, it filters all planes (0xf).
Practical Command Examples
To apply the filter with its default settings, use the following command:
ffmpeg -i input.mp4 -vf "lagfun" output.mp4To increase the trail duration and make the motion blur highly
pronounced, increase the decay parameter closer to
1.0:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.98" output.mp4For a fast-fading, subtle lag effect that only slightly softens fast
motion, reduce the decay parameter:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.75" output.mp4If you want to apply the lag effect only to the brightness (luma) plane while keeping the color (chroma) planes sharp, target only the first plane:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.95:planes=1" output.mp4