8

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!

1 Answer 1

7

Use the alphaextract and alphamerge filters:

ffmpeg -i video -vf "movie='image',alphaextract[a];[in][a]alphamerge" -c:v qtrle output.mov
5
  • 1
    Thank you, it worked for one frame, but your settings give me the understanding, so here is the command that worked: ffmpeg -y -i input.mp4 -loop 1 -i mask_with_alpha.png -filter_complex "[1:v]alphaextract[alf];[0:v][alf]alphamerge" -c:v qtrle -an output.mov Apr 7, 2016 at 7:12
  • Hi. I asked a similar question here: stackoverflow.com/questions/38951088/… What is the programmatic way to do this ?
    – Mic
    Aug 15, 2016 at 11:55
  • 1
    Did you use the mask file or the black and white file , I couldnt quite get the output you have got
    – Jeffin
    Jul 8, 2017 at 12:54
  • 1
    I was attempting to mask off an already-transparant video, and it required blending together alpha channels. Adding another alphaextract filter and setting a blend filter to darken did the trick: -filter_complex "[1:v]alphaextract[alf];[0:v]alphaextract[oalf];[alf][oalf]blend=all_mode=darken[res];[0:v][res]alphamerge" Doing this removes the need for -loop 1 on the input.
    – Tyzoid
    Jun 19, 2020 at 22:42
  • How to do the same just for single image?
    – pete
    Jun 4 at 4:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.