How to Loop Video Frames with FFmpeg Loop Filter

This article provides a straightforward guide on how to use the loop video filter in FFmpeg to repeat a specific sequence of frames within a video. You will learn the syntax of the filter, the key parameters required to define the loop, and see practical command-line examples to implement this effect in your projects.

The loop filter in FFmpeg allows you to repeat a specific segment of video frames. This is highly useful for creating GIFs, extending a static background, or repeating a specific action in a video clip.

The Loop Filter Syntax

The basic syntax for the loop filter is:

-vf "loop=loop=<count>:size=<frames>:start=<frame_number>"

Parameter Breakdown

Practical Examples

Example 1: Loop a 100-frame sequence 3 times starting at frame 50

To repeat a sequence of 100 frames three times, starting from the 50th frame of the input video, use the following command:

ffmpeg -i input.mp4 -vf "loop=loop=3:size=100:start=50" -c:a copy output.mp4

Example 2: Create an infinite loop of the first 50 frames

If you want to loop the first 50 frames of a video indefinitely (often used when outputting to formats like GIF), set the loop count to -1 and the start frame to 0:

ffmpeg -i input.mp4 -vf "loop=loop=-1:size=50:start=0" output.gif

Important Considerations