-stream_loop option

ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4
  • This can avoid re-encoding because it can use stream copy.
  • 0 means no loop, -1 means infinite loop.
  • This may not work with anything older than FFmpeg 4.0.

concat demuxer

The concat demuxer allows you to loop an input without needing to re-encode because it can use stream copy.

  1. 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'
    
  2. Then run ffmpeg:

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

If you want to add additional inputs make sure they all have the same attributes.

Automatically make list.txt in Linux/macOS

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 >> 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 <(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.mp4 -filter_complex "loop=loop=3:size=75:start=25" output.mp4
  • 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 and amovie filters have a loop option:

ffmpeg -f lavfi -i "movie=filename=input.mp4:loop=4,setpts=N/FRAME_RATE/TB" -f lavfi -i "amovie=filename=input.mp4:loop=4,asetpts=N/SR/TB" output.mp4
  • Filtering requires re-encoding.
  • 1 means no loop, 0 means infinite loop.

-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 single image or a series of images.

single image

This example will loop a single image over and over but the -t 30 will limit the output duration to 30 seconds:

ffmpeg -loop 1 -i input.png -t 30 -vf format=yuv420p output.mp4

-vf format=yuv420p is for compatibility reasons.

series of images

ffmpeg -loop 1 -i %03d.jpg -t 30 -vf format=yuv420p output.mp4

GIF output

Or to loop a GIF:

ffmpeg -i input -loop 3 output.gif

For GIF output also see How do I convert a video to GIF using ffmpeg, with reasonable quality?

Answer from llogan on Stack Exchange
Top answer
1 of 6
164

-stream_loop option

ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4
  • This can avoid re-encoding because it can use stream copy.
  • 0 means no loop, -1 means infinite loop.
  • This may not work with anything older than FFmpeg 4.0.

concat demuxer

The concat demuxer allows you to loop an input without needing to re-encode because it can use stream copy.

  1. 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'
    
  2. Then run ffmpeg:

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

If you want to add additional inputs make sure they all have the same attributes.

Automatically make list.txt in Linux/macOS

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 >> 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 <(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.mp4 -filter_complex "loop=loop=3:size=75:start=25" output.mp4
  • 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 and amovie filters have a loop option:

ffmpeg -f lavfi -i "movie=filename=input.mp4:loop=4,setpts=N/FRAME_RATE/TB" -f lavfi -i "amovie=filename=input.mp4:loop=4,asetpts=N/SR/TB" output.mp4
  • Filtering requires re-encoding.
  • 1 means no loop, 0 means infinite loop.

-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 single image or a series of images.

single image

This example will loop a single image over and over but the -t 30 will limit the output duration to 30 seconds:

ffmpeg -loop 1 -i input.png -t 30 -vf format=yuv420p output.mp4

-vf format=yuv420p is for compatibility reasons.

series of images

ffmpeg -loop 1 -i %03d.jpg -t 30 -vf format=yuv420p output.mp4

GIF output

Or to loop a GIF:

ffmpeg -i input -loop 3 output.gif

For GIF output also see How do I convert a video to GIF using ffmpeg, with reasonable quality?

2 of 6
32

With ffmpeg 2.8.4, the following command creates output.mp4 that is a repeating copy of input.mp4 until the ffmpeg process is stopped:

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

This command won't terminate on its own, and the output file will grow infinitely.

🌐
Ask Ubuntu
askubuntu.com › questions › 1253573 › ffmpeg-how-to-repeat-certain-frames
video - ffmpeg - how to repeat certain frames - Ask Ubuntu
June 25, 2020 - For example, the first instance where this happens is at time T1= 00:01:10 and the video disappears for D1=2 seconds. I wish to do the following. Take the frame at time point T1 and keep the same frame for the next 2 seconds.
Discussions

Repeat last frame in video using ffmpeg - Stack Overflow
Hi i'm trying to concatenate few mp4 clips each of 2 secs length, created using drawtext filter, but before that I want to extend length of some of these by repeating the last frames.How can I do it? More on stackoverflow.com
🌐 stackoverflow.com
Report repeated frames
https://ibb.co/gJwn97r https://ibb.co/Rc32KpN More on reddit.com
🌐 r/ffmpeg
3
1
September 30, 2023
Fill middle of video with repeating a single frame in ffmpeg - Stack Overflow
I have 49 rendered frames of png. I convert these frame to a video usingffmpeg: ffmpeg -r 24 -f image2 -s 1920x1080 -i d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test2.mp4 However this j... More on stackoverflow.com
🌐 stackoverflow.com
repeating the first frame of a video with ffmpeg - Stack Overflow
To repeat the first frame of a video, for example padding it to compensate for longer audio, the following pipeline can be used. ffmpeg -i video.mp4 -vframes 1 -f image2 image.jpg ffmpeg -loop 1 -i More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 43414641 › repeat-last-frame-in-video-using-ffmpeg
Repeat last frame in video using ffmpeg - Stack Overflow
Hi i'm trying to concatenate few mp4 clips each of 2 secs length, created using drawtext filter, but before that I want to extend length of some of these by repeating the last frames.How can I do it?
🌐
Reddit
reddit.com › r/ffmpeg › report repeated frames
r/ffmpeg on Reddit: Report repeated frames
September 30, 2023 -

Seems like my actioncam or card (?) has problem with repeated frames.

How can i check it with ffmpeg? First, i dont want to remove or fix, just show IF there are any repeated frames in mp4 video or not.

I found and already tried these commands, but seems it don't give answer to my question:

ffmpeg -i input.mp4 -vf "freezedetect=n=-60dB:d=2" -map 0:v:0 -f null -

ffmpeg -i input.mp4 -vf mpdecimate -loglevel debug -an -f null -

No info at the end of long list about repeated frames. What do i wrong? Have to use other parameters?

The video definetly has repeated frames in every few sec, as i see when i playback or step frame by frame with mpc-hc.

thanks a lot!

Find elsewhere
🌐
VideoHelp
forum.videohelp.com › forum home › video conversion
FFmpeg - How to delete frames repeated more than 1 time - VideoHelp Forum
June 18, 2023 - I mean, repeated 0 times (no equal frames) = ok, do nothing, repeated 1 time (2 equal frames) = ok, do nothing, repeated 2,3,4.......1000 times = remove frames after first repeat (after 2 equal frames) Example: if ffmpeg recognizes a 20 times repeated frame, which means 21 equal frames, it has to delete 19 frames because I want to keep at least 2 equal frames, which corresponds to one frame repetition I don't want any temporal interpolation, I don't want to keep the same number of frames.
🌐
Ffmpegbyexample
ffmpegbyexample.com › examples › fnjrnx47 › loop_images_at_specific_frame_rate_to_generate_video
Loop images at specific frame rate to generate a video - FFmpeg By Example
June 14, 2022 - [v]loop=loop=-1:size=9:start=0[out]' Take input stream ‘v’, and loop it. The loop should start on the 0 frames, with a size of 9 frames and it should repeat indefinitely (i.e. -1). You may specify how many times you want the loop to repeat.
🌐
FFmpeg
ffmpeg.org › pipermail › libav-user › 2014-September › 007467.html
[Libav-user] Repeating frame while encoding using ffmpeg api
If there is no > change on screen ... and want ffmpeg to keep the last displayed frame till > something changes on screen. I'm doing following steps. > 1. Check difference between previous and current frame, if difference == 0 > then skip frame else add frame to encoder.
🌐
Reddit
reddit.com › r/ffmpeg › i want to create a long video from one frame with no changes in ffmpeg, but really struggling
r/ffmpeg on Reddit: I want to create a long video from one frame with no changes in ffmpeg, but really struggling
June 14, 2020 - 1 frame for the entire duration. ffmpeg -loop 1 -i input.png -c:v libx264 -tune stillimage -shortest -preset ultrafast -t 3600 -filter_complex "fps=1/3600" frame_rate.mp4
🌐
Reddit
reddit.com › r/ffmpeg › detect repeating frames
r/ffmpeg on Reddit: Detect repeating frames
December 10, 2024 -

Recently, I transferred all my MiniDV tapes to my computer using a camcorder and a FireWire card.

The challenge I’m facing now is that some of the tapes only contained about 20 minutes of video, but the camcorder and software still created a 60-minute file. After the first 20 minutes, the same three frames keep repeating.

What would be the best way to detect this kind of repetition or duplication? I would absolutely love a solution that simply provides the timestamp when the repetition starts (and ends, as a bonus).

🌐
Stack Overflow
stackoverflow.com › questions › 26236559 › image-sequence-of-1500-frames-to-loop-30-times-in-a-30-min-video-ffmpeg
Image sequence of 1500 frames to loop 30 times in a 30 min video FFMPEG - Stack Overflow
Really struggling to get this to work, I just need to loop an image sequence. It is 25fps and exactly one second in duration (1500) I need this to basically loop for 30 mins, so it will loop 30 tim...