Configure FFmpeg lagfun Decay for Luma and Chroma
The FFmpeg lagfun filter generates glowing or
persistence trails by blending previous frames with the current frame
according to a specified decay factor. While lagfun does
not provide separate decay arguments for individual color channels
within a single filter instance, you can independently configure luma
(Y) and chroma (U/V) decay factors by chaining multiple
lagfun instances using the planes
parameter.
How the lagfun
Parameters Work
The lagfun filter relies on two primary options:
decay: A floating-point number between0.0and1.0(default is0.95). Higher values make trails linger longer, while lower values make the effect fade out rapidly.planes: A bitmask integer specifying which image planes to process (default is15, which targets all four possible planes: Y, U, V, and Alpha).
The bitmask values for video planes correspond to:
- 1 (binary
0001): Luma (Y) - 2 (binary
0010): Chroma (U / Cb) - 4 (binary
0100): Chroma (V / Cr) - 6 (binary
0110, combining2 + 4): Both Chroma channels (U and V)
Setting Independent Luma and Chroma Decay
Because decay affects all active planes assigned to that
filter instance, you must chain two lagfun filters in
sequence. Set the first instance to target only the luma plane
(planes=1), and the second instance to target only the
chroma planes (planes=6).
Example Filtergraph Syntax
lagfun=decay=0.95:planes=1,lagfun=decay=0.50:planes=6
In this configuration:
lagfun=decay=0.95:planes=1applies a heavy trail (0.95 decay) exclusively to the brightness and detail channel (Luma).lagfun=decay=0.50:planes=6applies a faster-fading trail (0.50 decay) to the color channels (Chroma).
Complete FFmpeg Command
To run this inside an FFmpeg encoding command, pass the chained
filtergraph to the -vf (video filter) option:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.92:planes=1,lagfun=decay=0.40:planes=6" -c:a copy output.mp4Isolating Individual Chroma Channels
If you need different decay factors for each color channel individually (for example, to separate Cb from Cr for an intentional chromatic aberration look), chain three instances:
ffmpeg -i input.mp4 -vf "lagfun=decay=0.90:planes=1,lagfun=decay=0.60:planes=2,lagfun=decay=0.30:planes=4" -c:a copy output.mp4planes=1modifies Luma (Y).planes=2modifies the U (Cb) component.planes=4modifies the V (Cr) component.