Loop Video Overlays in FFmpeg Using movie and amovie

This guide explains how to use FFmpeg’s movie and amovie source filters to overlay a looping video and audio file onto a primary video. You will learn the exact command-line syntax required to repeat an overlay clip indefinitely and sync it seamlessly with your main media.

The Looping Command

To overlay a looping video (with audio) onto a main video, you must load the overlay file directly inside the filtergraph using the movie (for video) and amovie (for audio) filters. This allows you to utilize the loop parameter.

Here is the complete command to achieve this:

ffmpeg -i main_video.mp4 -filter_complex \
"movie=overlay.mp4:loop=0,setpts=N/FRAME_RATE/TB[over_v]; \
 amovie=overlay.mp4:loop=0,asetpts=N/SR/TB[over_a]; \
 [0:v][over_v]overlay=10:10:shortest=1[out_v]; \
 [0:a][over_a]amix=inputs=2:duration=first[out_a]" \
 -map "[out_v]" -map "[out_a]" -c:v libx264 -c:a aac output.mp4

How the Filters Work

Using movie and amovie requires resetting the presentation timestamps (PTS) of the looping stream so FFmpeg knows how to render the repeating frames and audio samples.

1. Loading and Looping the Streams

2. Merging the Streams

3. Mapping and Encoding