Loop Image and Add Dynamic Overlay with FFmpeg

This guide explains how to use FFmpeg to convert a single static image into a video of a specific duration while applying a dynamic, moving overlay. You will learn the exact FFmpeg commands needed to loop the image input, define the output duration, and overlay an animated element or apply motion coordinates to create a dynamic visual effect.

Looping a Static Image for a Set Duration

To loop a static image, you must place the -loop 1 option before the input image, and set the desired output duration using the -t parameter (in seconds) or -to (in HH:MM:SS format).

Here is the basic syntax to loop an image for 10 seconds:

ffmpeg -loop 1 -t 10 -i background.png -pix_fmt yuv420p output.mp4

Adding a Dynamic Overlay

You can add a dynamic overlay in two ways: by making a static watermark move across the screen using mathematical expressions, or by overlaying an animated video/GIF.

Method 1: Overlaying an Animated GIF or Video

To overlay an animated asset (like a looping GIF or transparent video) over your looped background, use the -ignore_loop 0 flag for GIFs or -stream_loop -1 for videos to loop the overlay infinitely, then merge them using filter_complex.

ffmpeg -loop 1 -t 15 -i background.jpg -ignore_loop 0 -i animated_overlay.gif -filter_complex "[0:v][1:v]overlay=x=10:y=10:shortest=1[out]" -map "[out]" -pix_fmt yuv420p output.mp4

Method 2: Creating a Moving Overlay Using Math Expressions

If you want a static overlay image to move dynamically across the looped background, use variable expressions inside the overlay filter.

The command below moves a watermark horizontally across the screen over a 10-second looped image:

ffmpeg -loop 1 -t 10 -i background.jpg -i watermark.png -filter_complex "[0:v][1:v]overlay=x='t*100':y='H/2-h/2'[out]" -map "[out]" -pix_fmt yuv420p output.mp4

Method 3: Bouncing or Custom Trajectory Movement

For a more complex dynamic movement, such as bouncing, use trigonometric functions within the coordinate values:

ffmpeg -loop 1 -t 10 -i background.jpg -i watermark.png -filter_complex "[0:v][1:v]overlay=x='(W-w)/2 + sin(t)*100':y='(H-h)/2 + cos(t)*100'[out]" -map "[out]" -pix_fmt yuv420p output.mp4