FFmpeg lutrgb Filter Red Channel Contrast Equation
This article explains how to use the FFmpeg lutrgb
filter to increase the contrast of the red channel in a video. You will
learn the specific mathematical equation required to adjust the
contrast, how the lookup table (LUT) variables work, and how to apply
the complete command-line syntax to your video files.
To increase contrast in a specific color channel, you need to apply a mathematical formula that pushes values below the midpoint (128 in an 8-bit system) lower, and values above the midpoint higher.
The Contrast Equation
The standard formula for adjusting contrast is:
New_Value = Factor * (Input_Value - Midpoint) + Midpoint
For an 8-bit video, the midpoint is 128. To increase contrast, the
factor must be greater than 1.0 (for example, 1.5). Because this
calculation can result in values below 0 or above 255, you must wrap the
equation in a clip() function to keep the output within the
valid 8-bit range.
In FFmpeg’s lutrgb filter, the input pixel value is
represented by the variable val.
The FFmpeg Command
To apply this equation to the red channel while leaving the green and blue channels untouched, use the following FFmpeg command:
ffmpeg -i input.mp4 -vf "lutrgb=r='clip(1.5*(val-128)+128,0,255)'" -c:a copy output.mp4How the Parameters Work
lutrgb: This filter modifies the Red, Green, and Blue channels of the video using lookup tables.r='...': This specifies that the equation inside the single quotes will only be applied to the red channel.val: This is the input value of each red pixel, ranging from 0 to 255.1.5: This is the contrast multiplier. Increasing this number (e.g., to 1.8) will increase the contrast further. Decreasing it closer to 1.0 (e.g., 1.2) will result in a more subtle contrast boost.clip(..., 0, 255): This function ensures that any value resulting from the math that goes below 0 is set to 0, and any value that goes above 255 is set to 255, preventing rendering artifacts.