-1

I have this example video, recorded by Kazam: https://user-images.githubusercontent.com/1997316/178513325-98513d4c-49d4-4a45-bcb2-196e8a76fa5f.mp4

It's a 1022x728 video.

I need to add a drop shadow identical to the one generated by the "Drop shadow (legacy)" filter of Gimp with the default settings. So, I generated with Gimp a PNG containing only the drop shadow. It's a 1052x758 image:

enter image description here

Now I want to put the video over the image to get a new video with the drop shadow. The wanted effect for the first frame is:

enter image description here

So, the video must be placed over the image. The top-left corner of the video must be in the position 11x11 of the background image.

How can I achieve this result?

I tried without success the following command. What's wrong?

ffmpeg -i shadow.png -i example.mp4 -filter_complex "[0:v][1:v] overlay=11:11'" -pix_fmt yuv420p output.mp4

About the transparency of the PNG background image, if it can't be maintained, then it's okay for the shadow to be on a white background. Otherwise, if it can be maintained by using an animated GIF as the output format, it is better.

Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23
  • I have updated the question by adding a consideration of the transparency used by the PNG. – Francesco Galgani Jul 12 '22 at 15:23
  • H264 (which I'm assuming you're using as the encoder) does not support transparency. So, I'd add `-f lavfi -i color=c=white:s=1064x770` input as the background. Then overlay the shadow png at (11,11) and finally overlay the video at (0,0). – kesh Jul 12 '22 at 16:40

1 Answers1

0

The solution is to remove the transparency from shadow.png. Then:

ffmpeg -i example.mp4 -filter_complex "[0:v] palettegen" palette.png

ffmpeg -loop 1 -i shadow.png -i example.mp4 -i palette.png -filter_complex "[1:v] fps=1,scale=1022:-1[inner];[0:v][inner]overlay=11:11:shortest=1[new];[new][2:v] paletteuse[out]" -map '[out]' -y output.gif

The result is exactly what I wanted:

enter image description here

This solution is inspired by the answer https://stackoverflow.com/a/66318325 and by the article https://www.baeldung.com/linux/convert-videos-gifs-ffmpeg

Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23