-1

I've always used ffmpeg to create simple GIFs, never worked with superimposing a transparent PNG on an image. How do I do that?

3N4N
  • 128

1 Answers1

6

You can use the overlay filter to superimpose. It takes care of the transparency in the foreground image automatically. Example:

Animated GIF with transparent foreground

ffmpeg -loop 1 -i background.jpg -i foreground-with-transparent-regions.png -filter_complex "overlay=x=0:y=H-(H+h)*t/3" -t 3 output.gif

-loop 1 makes it repeat the image so that we have a duration despite using single image.

The overlay filter (added with filter_complex syntax here) places the foreground image at the (x, y) position, where x is constant here (0), and y is a calculated over time with an expression involving the background and foreground heights, as well as the current time in seconds denoted by t in the expression, to produce the slide-up animation as shown above.

-t defines the duration of the output

  • Thanks! I only had to add an if-else condition to your solution to get what I needed. Something like keeping the cookies stuck in the middle instead of keep sliding up. ffmpeg -loop 1 -i background.png -i cookies.png -filter_complex "overlay=x=0:y='if(lt(H-(H+h)*t/3\,0)\,0\,H-(H+h)*t/3)'" -t 3 output.gif – 3N4N Jun 13 '21 at 19:32