-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.
0means no loop,-1means 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.
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
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=3will 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.
1means no loop,0means 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-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.
0means no loop,-1means 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.
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
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=3will 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.
1means no loop,0means 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?
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.
Repeat last frame in video using ffmpeg - Stack Overflow
Report repeated frames
Fill middle of video with repeating a single frame in ffmpeg - Stack Overflow
repeating the first frame of a video with ffmpeg - Stack Overflow
Maybe this will help - enter it all on a single line and it will stream a single image (called test.jpg) repeatedly. See: https://stackoverflow.com/a/71885708/18795194 for my post and an explanation of the parameters.
ffmpeg
-loop 1
-fflags +genpts
-framerate 1/30
-i test.jpg
-c:v libx264
-vf fps=25
-pix_fmt yuvj420p
-crf 30
-f fifo -attempt_recovery 1 -recovery_wait_time 1
-f flv rtmp://localhost:5555/video/test
You can do this in two steps:
1) Encode a short loop, say, 30 seconds.
ffmpeg -loop 1 -framerate 5 -i image.jpg -pix_fmt yuv420p -c:v libx264 -t 30 looped.mp4
2) Loop the encode for desired duration.
ffmpeg -stream_loop -1 -i looped.mp4 -c copy -t 3600 output.mp4
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!
I have individual frames that I want to duplicate into new frames renamed. I've tried a few different things but nothing has been working for me. Has anyone done something like this before? thank you!
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).
Use
ffmpeg -i ~/Desktop/file.mpg -vsync 0 ~/Desktop/file.mp4
This skips duplication.
-vsync passthrough is synonymous with -vsync 0.
-vsync is deprecated now, so you should use -fps_mode instead.
By default, the fps_mode is auto, so it may change your fps automatically. For example, the original source is variable frame rate, but ffmpeg may decide to change it to constant frame rate automatically, which may result in duplicated and dropped frames.
To prevent any fps change, set -fps_mode passthrough. (It's the same as -vsync 0 or -vsync passthrough).
For more info, see ffmpeg documentation.
ffmpeg -i ~/Desktop/file.mpg -fps_mode passthrough ~/Desktop/file.mp4
Create a text file list containing all your image file names, but duplicating the first and last 100 times:
1.jpeg
1.jpeg
1.jpeg
......
2.jpeg
3.jpeg
....
Then:
cat $(cat list.txt) | ffmpeg -y -framerate 25/1 -i - -f image2pipe -c:v libx264 -pix_fmt yuv420p out.mp4
Try
ffmpeg -framerate 23 -loop 1 -i location_of_image_folder/frame2_0000.jpeg
-framerate 23 -start_number 1 -i location_of_image_folder/frame2_%04d.jpeg
-framerate 23 -loop 1 -i location_of_image_folder/frame2_1000.jpeg
-filter_complex "[0]trim=start_frame=0:end_frame=100[pre];
[2]trim=start_frame=0:end_frame=99[post];
[pre][1][post]concat,scale=1280:1024,setsar=1"
-c:v libx264 -movflags faststart location_of_output_location.mp4"
I've assumed the first image is frame2_0000.jpeg and last is frame2_1000.jpeg. Change accordingly. You'll have to alter start_number as well to have a number of the file after the first image file.