Invert Video Colors with FFmpeg LUT Filter
This article provides a quick, step-by-step guide on how to use the
FFmpeg lut filter to invert the colors of a video. You will
learn the exact command-line syntax required to apply this effect, how
the lookup table (LUT) filter processes color values, and how to run the
command to achieve a negative film effect on your video files.
To invert the colors of a video, you can use the lutrgb
filter, which allows you to manipulate the Red, Green, and Blue channels
of a video individually. By setting each channel to the
negval expression, FFmpeg subtracts the current pixel value
from the maximum possible value (e.g., 255 in 8-bit color), effectively
inverting the colors.
The Basic Command
Use the following command to invert your video’s colors:
ffmpeg -i input.mp4 -vf "format=rgb24,lutrgb=r=negval:g=negval:b=negval,format=yuv420p" output.mp4Command Breakdown
-i input.mp4: Specifies the input video file.-vf: Introduces the video filtergraph.format=rgb24: Forces the video frame format to 24-bit RGB. This step ensures that thelutrgbfilter can accurately process the red, green, and blue color channels.lutrgb=r=negval:g=negval:b=negval: This is the core filter.lutrgbapplies a lookup table to the RGB channels. Settingr,g, andbtonegvalinverts the intensity of each channel.format=yuv420p: Converts the pixel format back to YUV420p. This is a crucial step for compatibility, ensuring the output video plays correctly on most media players and web browsers.output.mp4: The name of the resulting inverted video file.
Alternative for YUV Videos
If you prefer to work directly in the YUV color space without
converting to RGB, you can invert the luma (brightness) channel using
the lutyuv filter. Note that this only inverts the
brightness (creating a grayscale-like negative) unless you also shift
the chroma channels:
ffmpeg -i input.mp4 -vf "lutyuv=y=negval:u=negval:v=negval" output.mp4For most standard color inversion needs, the RGB method
(lutrgb) is recommended as it delivers the expected
photographic negative result.