How to Use FFmpeg lutrgb Filter to Edit RGB Channels
The lutrgb filter in FFmpeg is a powerful tool for
pixel-level color manipulation, allowing you to independently adjust the
red, green, and blue channels of a video using Look-Up Tables (LUTs).
This article provides a straightforward guide on how the
lutrgb filter works, its syntax, and practical command-line
examples for modifying specific color channels to achieve custom color
grading and effects.
Understanding the lutrgb Filter Syntax
The lutrgb filter works by applying an expression to one
or more of the RGB channels: Red (r), Green
(g), and Blue (b). If you omit a channel from
the filter configuration, that channel remains unchanged.
The basic syntax is:
-vf "lutrgb=r='expression':g='expression':b='expression'"Inside the expressions, you can use several built-in variables: *
val: The input value of the current pixel
(ranging from 0 to 255 for standard 8-bit video). *
maxval: The maximum possible value for the
channel (typically 255). * minval: The
minimum possible value for the channel (typically 0).
Practical Examples
1. Adjusting Channel Brightness
To boost or reduce the intensity of a specific color, you can add or
subtract values from the input pixel value (val).
To increase the red channel by 50 units while keeping green and blue the same:
ffmpeg -i input.mp4 -vf "lutrgb=r=val+50" -c:a copy output.mp4To decrease the blue channel by 30 units:
ffmpeg -i input.mp4 -vf "lutrgb=b=val-30" -c:a copy output.mp42. Scaling Channel Values (Contrast and Tinting)
Multiplying the input value scales the channel’s intensity. This is useful for color tinting or shifting the white balance.
To multiply the green channel by 1.2 (adding a green tint) and reduce the blue channel by multiplying by 0.8:
ffmpeg -i input.mp4 -vf "lutrgb=g=val*1.2:b=val*0.8" -c:a copy output.mp43. Inverting Color Channels
You can invert individual channels or the entire video by subtracting
the current pixel value from the maximum value
(maxval).
To invert only the red channel:
ffmpeg -i input.mp4 -vf "lutrgb=r=maxval-val" -c:a copy output.mp4To invert all three RGB channels (creating a classic negative effect):
ffmpeg -i input.mp4 -vf "lutrgb=r=maxval-val:g=maxval-val:b=maxval-val" -c:a copy output.mp44. Isolating a Single Color Channel
To view only a specific color channel, you can set the other two
channels to a constant value of 0 (or
minval).
To isolate the red channel (rendering green and blue completely black):
ffmpeg -i input.mp4 -vf "lutrgb=g=0:b=0" -c:a copy output.mp4Negotiation of Clip Limits
FFmpeg automatically clips the output values of your expressions to
ensure they stay within the valid 0 to 255 range. If an expression like
val+100 results in a value of 300 for a bright pixel,
FFmpeg will automatically cap it at 255 to prevent rendering errors.