Overlay GIF on MP4 at certain time interval (while maintaining GIF transparency) [FFMPEG]

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

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like