Invert Video Luma Channel with FFmpeg lut Filter

Inverting only the luminance (luma) channel of a video produces a photo-negative effect while keeping the original chrominance (color) intact. This guide demonstrates how to target and invert the Y channel using FFmpeg’s lut filter family while leaving the U and V channels untouched.

The FFmpeg Command

To invert only the luma channel, use either the generic lut filter targeting the first channel (c0) or the specialized lutyuv filter targeting the y component.

Using the lutyuv filter:

ffmpeg -i input.mp4 -vf "lutyuv=y=negval" -c:a copy output.mp4

Alternatively, using the generic lut filter:

ffmpeg -i input.mp4 -vf "lut=c0=negval" -c:a copy output.mp4

How It Works

  • -vf "lutyuv=y=negval": The lutyuv filter applies a lookup table computation to YUV video streams.
  • y=negval / c0=negval: The expression negval evaluates to maxval + minval - val. This inverts the pixel value dynamically based on the pixel format's bit depth and range.
  • Preserving Color: Because the other channels (u and v, or c1 and c2) are omitted from the filter string, they default to val, leaving the color information unchanged.
  • -c:a copy: Copies the audio stream directly without re-encoding, preserving audio quality and speeding up processing.

Handling Specific Ranges with Mathematical Expressions

If your input requires explicit control over the inversion formula rather than using negval, you can use arithmetic expressions. For standard 8-bit full-range video, the inversion can be written as:

ffmpeg -i input.mp4 -vf "lutyuv=y='255-val'" -c:a copy output.mp4

For standard 8-bit limited (TV) range video, where valid luma levels span from 16 to 235, use:

ffmpeg -i input.mp4 -vf "lutyuv=y='235+16-val'" -c:a copy output.mp4

Using negval remains the recommended approach, as FFmpeg automatically respects the video stream's underlying color range metadata without requiring manual arithmetic.