How to Use FFmpeg stream_loop to Loop Video

This article provides a quick and practical guide on how to use the -stream_loop option in FFmpeg to repeat an input video. You will learn the correct command syntax, how to set a specific number of loops, how to loop a video infinitely, and how to combine looping with duration limits for your video processing workflows.

The Basic Syntax

The -stream_loop option is an input option. This means it must be placed before the input file (-i) in your FFmpeg command. If you place it after the input file, FFmpeg will ignore it or throw an error.

The basic syntax is:

ffmpeg -stream_loop <number_of_loops> -i input.mp4 [output_options] output.mp4

Loop Count Values:


Practical Examples

1. Loop a Video a Specific Number of Times

To loop an input video 3 times (resulting in the video playing 4 times in total) without re-encoding the stream, use the following command:

ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4

Using -c copy stream-copies the packets without re-encoding, making the process extremely fast.

2. Loop a Video Infinitely

To loop a video endlessly, use -1. Because an infinite loop will run forever and create an infinitely large file, this is typically used for live streaming.

If you want to save an infinite loop to a local file, you must specify a target duration using the -t option (in seconds) so the command knows when to stop:

ffmpeg -stream_loop -1 -i input.mp4 -t 60 -c copy output.mp4

This command loops input.mp4 infinitely but stops the output exactly at the 60-second mark.


Key Considerations