How to Use the lutrgb Filter in FFmpeg
This guide provides a practical overview of how to use the
lutrgb (Lookup Table RGB) filter in FFmpeg to manipulate
the red, green, and blue color channels of a video. You will learn the
basic syntax of the filter, the variables available for creating custom
color effects, and step-by-step examples for common tasks like color
inversion, brightness adjustment, and color tinting.
Understanding the lutrgb Filter
The lutrgb filter allows you to modify the RGB channels
of an image or video by applying a specific mathematical expression to
each pixel value. Because it uses a lookup table, FFmpeg calculates the
expression once for every possible pixel value (0–255 for 8-bit video)
rather than recalculating it for every single pixel in every frame. This
makes it highly efficient.
The basic syntax for the filter is:
ffmpeg -i input.mp4 -vf "lutrgb=r='expression':g='expression':b='expression'" output.mp4In these expressions, you can use the variable val to
represent the original input value of the pixel for that channel.
Common Examples of lutrgb
1. Inverting Video Colors
To invert the colors of a video, you subtract the current pixel value from the maximum possible value (255 for 8-bit color).
ffmpeg -i input.mp4 -vf "lutrgb=r='255-val':g='255-val':b='255-val'" output.mp42. Adjusting Brightness
You can adjust the overall brightness of the video by adding or subtracting a constant value from all three channels.
To increase brightness:
ffmpeg -i input.mp4 -vf "lutrgb=r='val+30':g='val+30':b='val+30'" output.mp4To decrease brightness:
ffmpeg -i input.mp4 -vf "lutrgb=r='val-30':g='val-30':b='val-30'" output.mp43. Creating a Warm Color Tint
To apply a warm, reddish-yellow tint to your video, you can increase the intensity of the red channel, slightly increase the green channel, and decrease the blue channel.
ffmpeg -i input.mp4 -vf "lutrgb=r='val*1.2':g='val*1.05':b='val*0.8'" output.mp44. Removing a Single Color Channel
If you want to completely strip a color channel from the video (for
example, removing all blue to create a yellow/green duotone effect), set
that channel’s expression to 0.
ffmpeg -i input.mp4 -vf "lutrgb=b=0" output.mp4Useful Expression Variables
When writing expressions for lutrgb, you can use several
built-in variables and functions:
val: The input value for the pixel.maxval: The maximum allowed value for the channel (typically 255).minval: The minimum allowed value for the channel (typically 0).clip(val, min, max): A function that limits the output value to stay within the specified minimum and maximum range, preventing distortion.