I've always used ffmpeg to create simple GIFs, never worked with superimposing a transparent PNG on an image. How do I do that?
Asked
Active
Viewed 257 times
-1
3N4N
- 128
- 6
-
1What have you done so far to achieve this? This site doesn’t provide step-by-step tutorials for those who cannot even show the minimal effort. This site helps those who have at least started to do something and is stuck. – Giacomo1968 Jun 13 '21 at 17:37
-
Also see [How do I convert a video to GIF using ffmpeg, with reasonable quality?](https://superuser.com/q/556029/) – llogan Jun 14 '21 at 18:30
-
@llogan, thank you, but that question doesn't concern with overlays. – 3N4N Jun 14 '21 at 18:50
-
@klaus No, it does not, but you were asking about creating GIFs. The default GIF output from ffmpeg is poor. I assumed you didn't want a poor quality output. – llogan Jun 14 '21 at 19:16
1 Answers
6
You can use the overlay filter to superimpose. It takes care of the transparency in the foreground image automatically. Example:
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
Syed Andaleeb Roomy
- 176
- 2
-
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
