0

I'm looking for a way to implement a gif overlay on top of an mp4, having the following characteristics:

  • Maintaining GIF transparency on video
  • Having the GIF only showing up for a certain time interval (etc. 0:02-0:06)
  • Positioning the GIF on the bottom left corner of the MP4 file

1 Answers1

0

You may use x=between(t, 2, 6), 0, NAN) Expression Evaluation and y=(H-h).
See overlay filter documentation (read the examples - they are close enough).

ffmpeg -y -i in.mp4 -i in.gif -filter_complex "[0][1]overlay=x='if(between(t, 2, 6), 0, NAN):y=(H-h)':format=yuv444" -vcodec libx264 -pix_fmt yuv444p -crf 17 -acodec copy out.mp4

format=yuv444 and -pix_fmt yuv444p are used for improving the output quality.

I used the transparent gif from my following post, and overlay with synthetic pattern.

Output frame sample:
enter image description here


Building the synthetic pattern (used for testing):

ffmpeg -y -f lavfi -r 10 -i testsrc=size=640x480:rate=1:duration=300 -vf setpts=N/10/TB -vcodec libx264 -pix_fmt yuv444p -crf 17 in.mp4

GIF image with transparency:
enter image description here

Rotem
  • 3,346