Configure FFmpeg Loop Filter Start Frame and Count
This guide explains how to use the FFmpeg loop video
filter to repeat a specific sequence of frames within a video. You will
learn how to configure the exact number of frames to loop (the
size/frame count) and define the precise starting frame for the loop
effect using practical command-line examples.
The FFmpeg loop filter allows you to repeat a specific
segment of a video. To control the segment’s length and where the loop
begins, you must configure three primary parameters: loop,
size, and start.
The Filter Parameters
loop: The number of times the selected sequence should repeat. Set this to-1for infinite loops, or a positive integer (e.g.,3to repeat three times).size: The total number of frames in the loop sequence (the frame count).start: The 0-based index of the first frame where the loop sequence begins.
Command Syntax
The basic syntax for applying the filter is:
ffmpeg -i input.mp4 -vf "loop=loop=N:size=S:start=F" -c:a copy output.mp4Step-by-Step Configuration Example
Suppose you want to loop a segment of a 30 FPS video. You want the loop to start at the 5-second mark, last for 2 seconds, and repeat 3 times.
- Calculate the Start Frame (
start): Multiplying the start time by the frame rate gives the start frame index.- 5 seconds × 30 FPS = Frame index
150.
- 5 seconds × 30 FPS = Frame index
- Calculate the Frame Count (
size): Multiplying the duration of the loop by the frame rate gives the size.- 2 seconds × 30 FPS =
60frames.
- 2 seconds × 30 FPS =
- Define the Loop Count (
loop):- Set to
3repetitions.
- Set to
Using these values, your FFmpeg command will look like this:
ffmpeg -i input.mp4 -vf "loop=loop=3:size=60:start=150" -c:a copy output.mp4Key Considerations
- Audio Sync: The
loopfilter only affects video frames. To keep audio in sync or to loop audio, you must use additional audio filters likealoop. If audio sync is not required, use-anto disable audio, or copy the audio stream using-c:a copy. - Buffer Limit: The
sizeparameter defines the size of the internal frame buffer. Setting an extremely high frame count can consume a significant amount of system memory.