Modify YUV Channels in FFmpeg with lutyuv
This article explains how to use the FFmpeg lutyuv
filter to manipulate individual Y (luminance), U (blue-difference
chroma), and V (red-difference chroma) channels of a video. You will
learn the basic syntax of the filter, how to target specific channels
using mathematical expressions, and see practical examples for adjusting
brightness, contrast, and color.
Understanding the lutyuv Filter
The lutyuv filter applies a Look-Up Table (LUT) to the
YUV channels of an input video. It allows you to modify the pixel values
of each channel independently using specific mathematical equations.
The basic syntax for the filter is:
lutyuv=y='expression':u='expression':v='expression'In these expressions, the keyword val represents the
original pixel value of the channel currently being processed. For
standard 8-bit video, these values range from 0 to 255. For chroma
channels (U and V), the neutral (grayscale) value is 128.
Modifying the Y (Luminance) Channel
The Y channel controls the brightness and contrast of the video without affecting the color hue.
Adjusting Brightness
To increase the brightness, you can add a constant value to the Y channel. To decrease it, subtract a value.
Increase brightness:
ffmpeg -i input.mp4 -vf "lutyuv=y='val+30'" output.mp4Decrease brightness:
ffmpeg -i input.mp4 -vf "lutyuv=y='val-30'" output.mp4
Adjusting Contrast
To adjust contrast, scale the pixel values around the midpoint of the luminance range (128). Multiplying by a factor greater than 1 increases contrast, while a factor less than 1 decreases it.
Increase contrast:
ffmpeg -i input.mp4 -vf "lutyuv=y='(val-128)*1.5+128'" output.mp4
Modifying U and V (Chroma) Channels
The U and V channels contain the color difference information. Modifying these channels allows you to adjust saturation, tint, or completely strip color from the video.
Desaturating Video (Grayscale)
To completely remove color, set both the U and V channels to their neutral midpoint value of 128.
ffmpeg -i input.mp4 -vf "lutyuv=u=128:v=128" output.mp4Adjusting Saturation
To increase saturation, scale the U and V channels away from their neutral midpoint (128).
Increase saturation:
ffmpeg -i input.mp4 -vf "lutyuv=u='(val-128)*1.5+128':v='(val-128)*1.5+128'" output.mp4
Color Tinting
You can shift the color balance by adding or subtracting values from the U or V channels. For example, adding to the V channel introduces a reddish/magenta tint, while subtracting introduces a greenish tint.
Warm/Red tint (increase V):
ffmpeg -i input.mp4 -vf "lutyuv=v='val+20'" output.mp4Cool/Blue tint (increase U):
ffmpeg -i input.mp4 -vf "lutyuv=u='val+20'" output.mp4
Combining Y, U, and V Modifications
You can combine modifications to all three channels in a single filter chain to achieve complex color grading effects. The following command increases the overall contrast of the image while simultaneously boosting the blue tones (U channel) and slightly dimming the brightness:
ffmpeg -i input.mp4 -vf "lutyuv=y='(val-128)*1.2+110':u='(val-128)*1.3+128':v='val'" output.mp4