[FFmpeg-user] "Extracting" Alpha Channel

Dan Flett dflett at bigpond.net.au
Thu Jul 28 04:00:36 CEST 2011


In television graphics or vision mixing, it's often necessary to "extract"
the alpha channel from a graphics file and turn it into a separate "Key" or
"Matte" clip.

The Key video is a grayscale representation of the alpha channel - black is
fully transparent and white is fully opaque.

It is possible to do this the using "lut" filter (I use lutrgb):

-vf "[in] format=rgba, split [T1], fifo, lutrgb=r=minval:g=minval:b=minval,
[T2] overlay [out]; [T1] fifo, lutrgb=r=maxval:g=maxval:b=maxval [T2]" 

This filter first converts the input video to the rgba colorspace.

It then splits the input video into 2 streams (as per the turorial in the
libavilfter docs).  The "background" stream is set to a fully black frame by
setting the r,g,b values to "minval".  The foreground stream is set to a
fully white frame by setting the r,g,b values to "maxval".  In both streams
the alpha channel is untouched.

At the end of the first stream, the "overlay" filter overlays the white
stream over the black one, using the untouched alpha channel as the mask.
The result is a grayscale representation of the alpha channel - the actual
rgb video content is thrown away.

Dan



More information about the ffmpeg-user mailing list