FFmpeg: Add alpha channel to a video using a PNG mask

Rodrigo Polo picture Rodrigo Polo · Apr 7, 2016 · Viewed 12k times · Source

I saw that FFmpeg can merge/blend two videos with alpha channel and can encode video with alpha channel using the qtrle codec, but, It is possible to apply a PNG file mask, either a black and white or a PNG with an alpha channel to a video in order to have a video with the alpha channel of the PNG applied?

Here is the concept in images

Original video: Original video

PNG file with alpha channel, the "mask": PNG file with alpha channel

And the result: Result

Or even a black and white image as a mask for alpha channel: bnw image

Any help would be appreciated, thank you!

Answer

Gyan picture Gyan · Apr 7, 2016

Use the alphaextract and alphamerge filters:

ffmpeg -i video -vf "movie='image',alphaextract[a];[in][a]alphamerge" -c:v qtrle output.mov