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.mp4

How the Parameters Work