I have 3 inputs:
- Video file: https://file.io/6jtUlnZ7TGmT
- Animated GIF with transparent background https://i.stack.imgur.com/nmJpw.gif
- Mask file (BW) the same resolution as the video https://i.stack.imgur.com/E1MCY.png
I want to put the image on the video, but throw out all GIF pixels that are transparent in the mask (replace them with transparent ones).
My current command, without masking (it works fine):
ffmpeg -i input.mp4 -ignore_loop 0 -i animation.gif \
-filter_complex "[1]scale=700x700[scaled_gif];\
[0][scaled_gif]overlay=50:30:shortest=1" \
-codec:a copy output.mp4
UPDATE #1
I managed to get closer to my goal with this command:
ffmpeg -y -i input.mp4 -loop 1 -i mask.png \
-filter_complex "[1:v]alphaextract[mask]; \
movie=animation.gif,scale=1920x1080[scaled_gif]; \
[scaled_gif][mask]alphamerge[masked]; \
[0:v][masked]overlay=0:0" \
-c:a copy output_masked.mp4
but it has 2 problems:
- GIF loses it's transparency. Transparent pixels become white.
- GIF plays only once (i.e. no loop)