Repeat/loop Input Video with ffmpeg?
Concat demuxer

This allows you to loop an input without needing to re-encode.


Make a text file. Contents of an example text file to repeat 4 times.

file 'input.mp4'
file 'input.mp4'
file 'input.mp4'
file 'input.mp4'

Then run ffmpeg:

ffmpeg -f concat -i list.txt -c copy output.mp4



For Linux users

This example is the same as above but you don't have to manually make list.txt:

for i in {1..4}; do printf "file '%s'\n" input.mp4 &gt;&gt; list.txt; done
ffmpeg -f concat -i list.txt -c copy output.mp4


With most commonly-used modern shells, you can even avoid the creation of the list.txt file entirely. For example, with bash:

ffmpeg -f concat -i &lt;(for i in {1..4}; do printf "file '%s'\n" input.mp4; done) -c copy output.mp4


Also see:


FFmpeg concat demuxer documentation
FFmpeg Wiki: Concatenate




loop filter

Example using the loop filter to loop 4 times, each loop is 75 frames, each loop skips the first 25 frames of the input:

ffmpeg -i input -filter_complex loop=loop=3:size=75:start=25 output



Or use the shorthand: loop=3:75:25
Filtering requires re-encoding.
This filter places all frames into memory.
Using loop=3 will loop 4 times.
To loop infinitely use -1.
You must list the number of frames to loop (shown as 75 in the example above). Max value is 32767.
Also see ffmpeg -h filter=loop.




movie filter

The movie filter has a loop option. See answer below by Monah Tuk. Filtering requires re-encoding. For audio use the amovie filter.



-stream_loop option

See answer below by Thingy and answer by Gyan.

Note that this option was buggy (see bug reports #5719, #6121, and #7043) so may not work for old builds (anything older than 2018 06-27 including the FFmpeg 4.0.x release branch). For users of old builds, as mentioned by mulvya in ticket #6121, one workaround is to first re-mux to MKV or TS then use -stream_loop in the next command.



-loop option

The -loop option is specific to the image file demuxer and gif muxer, so it can't be used for typical video files, but it can be used to infinitely loop a series of input images. This example will loop over and over but the -t 30 will limit the output duration to 30 seconds:

ffmpeg -loop 1 -i %03d.png -t 30 output.mkv


Or to loop a GIF output:

ffmpeg -i input -loop 3 output.gif