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 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.mp4format=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.
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