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

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.mp4

Step-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.

  1. 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.
  2. Calculate the Frame Count (size): Multiplying the duration of the loop by the frame rate gives the size.
    • 2 seconds × 30 FPS = 60 frames.
  3. Define the Loop Count (loop):
    • Set to 3 repetitions.

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.mp4

Key Considerations