Issues looping a stream with FFMpeg I'm trying to overlay a video on top of an image. The problem that I'm facing is that the video duration that I want is longer than my input video's duration.

To solve this issue, I try to generate a streaming loop and hardcode the duration that I want using the parameter "t".

I'm using the setpts filter to make sure that my container format (.mp4) accepts past frames by rewriting their timestamps:

ffmpeg -loop 1 -i image.jpg -stream_loop -1 -i video.mov  -filter_complex "[1:v]setpts=N/(FRAME_RATE*TB)[1v];[0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" -map [out] -t 00:00:15  out.mp4


So the command reads as follows:


take one infinite input where each frame is image.jpg
take another infinite input (video.mov) by looping (-stream_loop -1)


Each frame will go through the filter:


setpts will re-write the timestamps for source 1 (video.mov)
overlay will put each setpts-ed frame from video.mov on top of each frame from the initial input (image.jpg - 0:v)


This should continue until a file with 00:00:15 seconds is created.

This command does generate that file but the video.mov isn't looped, once the first loop finishes the last frame is repeated until the output movie ends.

FYI: I made a couple more tests:

ffmpeg -stream_loop -1 -i movie.mov -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4


This works fine, it generates a movie with 30 seconds duration with the input movie looped to fill the output movie

on the other hard, if I add one more input file:

ffmpeg -stream_loop -1 -i movie.mov -loop 1 -i image.jpg -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4


This will not create a movie with 30 seconds, although one of the inputs is never used, ffmpeg creates a movie file with just one loop of movie.mov and the same length of movie.mov.

Any advices please ?

Thank you very much!

Ze
Try with the movie filter instead

ffmpeg -loop 1 -i image.jpg -filter_complex \
        "movie=video.mov:loop=999,setpts=N/(FRAME_RATE*TB)[1v]; \
        [0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" \
       -map [out] -t 00:00:15  out.mp4