FFmpeg Negate Filter: How to Invert Video Colors

This article provides a quick, step-by-step guide on how to use the negate video filter in FFmpeg to invert the colors of an RGB video. You will learn the basic command syntax, how to handle alpha channels, and how to apply the filter to achieve a negative film effect in your video projects.

The Basic Negate Command

To invert the colors of a video, you need to use the -vf (video filter) option followed by the negate filter. The basic command syntax is as follows:

ffmpeg -i input.mp4 -vf "negate" output.mp4

In this command: * -i input.mp4 specifies your source video file. * -vf "negate" applies the color inversion filter. * output.mp4 is the name of the resulting inverted video file.

By default, this filter inverts all color components (Red, Green, and Blue) by subtracting each pixel’s color value from the maximum possible value (for 8-bit video, this translates to subtracting the value from 255).

Handling Alpha (Transparency) Channels

If your video contains an alpha channel (transparency) and you want to choose whether or not to invert the transparency along with the colors, you can use the negate_alpha parameter.

By default, the alpha channel is not inverted (negate_alpha=0). If you want to invert the transparency as well, use the following command:

ffmpeg -i input.mov -vf "negate=negate_alpha=1" output.mov

Specifying Pixel Formats

While FFmpeg automatically handles color space conversion for most video formats, you can explicitly force an RGB pixel format to ensure maximum compatibility with the negate filter. You can do this by chaining the format filter before the negate filter:

ffmpeg -i input.mp4 -vf "format=rgb24,negate" output.mp4

This converts the video frames to 24-bit RGB before applying the inversion, ensuring the color transformation behaves exactly as expected for RGB color spaces.