How to Set Loop Start Frame in FFmpeg Loop Filter
This article explains how to configure the loop start frame using the
FFmpeg loop video filter. You will learn the exact
parameter syntax required to define the starting frame of a loop, how to
calculate the frame index from a timestamp, and see practical
command-line examples.
To configure the loop start frame in FFmpeg, you must use the
loop video filter (-vf loop) and define its
three primary parameters: loop, size, and
start.
The starting frame is controlled specifically by the
start parameter, which uses a 0-based frame index.
The Loop Filter Syntax
The basic syntax for the filter is:
loop=loop=<count>:size=<frames>:start=<frame_index>
loop: The number of times the sequence should repeat. Set this to-1for an infinite loop, or a positive integer (e.g.,3to repeat three times).size: The total number of frames to include in the loop.start: The 0-based index of the first frame of the loop. This is the parameter that sets the loop start frame.
Practical Example
If you have a 30 fps video and want to loop a 3-second segment (90
frames) starting at the 5-second mark, you first need to calculate the
start frame: * Start Frame = 5 seconds * 30 fps = 150
To loop this 90-frame segment 5 times, use the following command:
ffmpeg -i input.mp4 -vf "loop=loop=5:size=90:start=150" -c:a copy output.mp4Key Considerations
- Audio Sync: The
loopvideo filter only loops the video stream. If your input has audio, the audio will continue to play normally while the video loops. To keep them in sync, you may need to loop the audio separately using thealoopfilter. - Frame Rate: Always verify the frame rate of your
input video to accurately calculate the
startframe index from a specific time in seconds.