How to Use FFmpeg Premultiply Filter

This article explains how to use the FFmpeg premultiply filter to multiply RGB color channels by an alpha (transparency) channel. You will learn how to apply this filter to single inputs containing built-in alpha channels, composite separate color and alpha inputs, and reverse the process using the unpremultiply option.

Understanding the Premultiply Filter

In digital imaging, “straight” alpha keeps RGB color data independent of transparency, while “premultiplied” alpha multiplies the RGB values by the alpha value beforehand. Premultiplication is essential for preventing dark or light fringing artifacts around the edges of transparent objects during compositing.

FFmpeg’s premultiply filter offers two primary modes of operation depending on your input files: * Inplace processing (Single Input): Premultiplies an existing alpha channel within a single file. * Two-stream processing (Double Input): Takes color data from the first stream and an alpha map from a second stream to create a premultiplied output.


Method 1: Premultiply a Single Input (Inplace)

If you have an image or video file that already contains an unassociated (straight) alpha channel, you can premultiply it directly by setting the inplace option to 1.

Use the following command:

ffmpeg -i input.png -vf "premultiply=inplace=1" output.png

Method 2: Premultiply Using Separate Color and Alpha Inputs

If your color data and alpha matte are in two separate files, you can merge and premultiply them using filter_complex. By default, the inplace parameter is set to 0, which expects two input streams.

Use the following command:

ffmpeg -i color.mp4 -i alpha.mp4 -filter_complex "[0:v][1:v]premultiply=inplace=0[out]" -map "[out]" output.mov

Method 3: Unpremultiplying (Reverse Process)

If you have a premultiplied image or video and need to restore it to straight alpha (for editing or color grading), you can use the inverse parameter.

To unpremultiply a single input file, run:

ffmpeg -i premultiplied_input.png -vf "premultiply=inplace=1:inverse=1" straight_output.png