Loop a video overlay with ffmpeg

4

4

I have two videos, one of which is overlaid onto the other. The one that is overlaid is only a few seconds long, and I want it to keep looping whilst the main video plays. I have tried everything I can think of, but nothing seems to work in ffmpeg

Loop video background - Example:

  1. "main_video" long time 56:00:00
  2. "video_bg_overlay" long time 00:00:30

How to have "video_bg_overlay" auto loop by the time "main_video"?

Ffmpeg fans

Posted 2016-06-25T18:25:17.357

Reputation: 55

@ Mulvya : help me, pls – Ffmpeg fans – 2016-06-26T00:46:44.137

Answers

5

The loop option in the movie filter does not set new timestamps for the looped extension, so that has to be done manually.

ffmpeg -i "main_video" -af "pan=stereo|c0=FL|c1=FR,volume=1.5" \
    -vf "movie=video_bg_overlay.mp4:loop=0,setpts=N/FRAME_RATE/TB,hue=s=0[bg];[in]scale=iw/2:-1,pad=iw+20:ih+20:10:10:color=yellow[m]; [bg][m]overlay=shortest=1:x=(W-w)/2:y=(H-h)/2[out]" \
    -c:v libx264 Out_video

Gyan

Posted 2016-06-25T18:25:17.357

Reputation: 21 016

Using setpts=N/FRAME_RATE/TB with the movie filter is key here. Some other examples use setpts=PTS-STARTPTS, which doesn't work with loop. – Quantum7 – 2017-12-26T07:26:48.843

1

Use the -stream_loop option:

ffmpeg -stream_loop -1 -i bg.mp4 -i main.mp4 -filter_complex "[0][1]overlay=shortest=1[v]" -map "[v]" -map 1:a -c:a copy output.mp4

llogan

Posted 2016-06-25T18:25:17.357

Reputation: 31 929