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:

  1. take one infinite input where each frame is image.jpg
  2. 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!


1 Answer 1


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
  • Works like a charm! Any idea why stream_loop doesn't work ?
    – user361526
    Commented Apr 28, 2016 at 20:44
  • I'm speculating here, but stream_loop value will be registered in the same shared variable as the image demuxer's loop argument, and does not actually get successfully registered. The movie filter creates its own local context. But this is just a guess.
    – Gyan
    Commented Apr 29, 2016 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.