[FFmpeg-user] "Extracting" Alpha Channel

Dan Flett dflett at bigpond.net.au
Thu Jul 28 13:47:59 CEST 2011


-----Original Message-----
From: ffmpeg-user-bounces at ffmpeg.org [mailto:ffmpeg-user-bounces at ffmpeg.org]
On Behalf Of Stefano Sabatini
Sent: Thursday, 28 July 2011 19:13
To: FFmpeg user questions and RTFMs
Subject: Re: [FFmpeg-user] "Extracting" Alpha Channel

On date Thursday 2011-07-28 12:00:36 +1000, Dan Flett encoded:
> 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
> The result is a grayscale representation of the alpha channel - the 
> actual rgb video content is thrown away.

Another interesting possibility (simpler, faster) would be to implement a
decomposer and a composer filter, for splitting RGBA channels into separate
gray video streams and re-composing them.


How about being able to do something like this?

format=yuva, lutyuv=y=a:u=minval:v=minval

Basically, being able to specify that the y (luma) channel output is equal
to the a (alpha) channel of the input?

Being able to swap color channels around would be good:

format=rgb, lutrgb=r=b:g=r:b=g

More information about the ffmpeg-user mailing list