How to Clamp Luma in FFmpeg Using lutyuv

This article demonstrates how to use the FFmpeg lutyuv filter to clamp the luminance (luma) channel of a video to a specific range while leaving the chrominance (chroma) channels completely untouched. You will learn the correct command-line syntax and the mathematical expressions required to restrict luma values without altering the color information of your video.

The lutyuv Filter Syntax

The lutyuv filter allows you to apply lookup table (LUT) equations to individual YUV channels: y (luma), u (blue-difference chroma), and v (red-difference chroma). Inside the filter, val represents the input pixel value for the channel being processed.

To clamp the luma channel while keeping the chroma channels unmodified, use the following FFmpeg command:

ffmpeg -i input.mp4 -vf "lutyuv=y='clip(val, 16, 235)':u='val':v='val'" output.mp4

How the Equation Works

  • y='clip(val, 16, 235)': This equation evaluates the luma channel. The clip(val, min, max) function constrains the input pixel value (val). Any pixel with a luma value lower than 16 is set to 16, and any value higher than 235 is set to 235. You can adjust the numbers 16 and 235 to fit your desired clamping range.
  • u='val': This passes the original blue-difference chroma values through without any modifications.
  • v='val': This passes the original red-difference chroma values through without any modifications.

Adjusting for Different Bit Depths

The example above assumes standard 8-bit video, where pixel values range from 0 to 255. If you are working with high-bit-depth video (such as 10-bit video, where values range from 0 to 1023), you must scale your clamping values accordingly.

For 10-bit broadcast-safe clamping, use:

ffmpeg -i input.mp4 -vf "lutyuv=y='clip(val, 64, 940)':u='val':v='val'" output.mp4