Loop a video overlay with ffmpeg
5,236
Solution 1
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
Solution 2
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
Related videos on Youtube
Author by
Ffmpeg fans
Updated on September 18, 2022Comments
-
Ffmpeg fans almost 2 years
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
- Example:
- "main_video" long time 56:00:00
- "video_bg_overlay" long time 00:00:30
How to have "video_bg_overlay" auto loop by the time "main_video"?
-
Ffmpeg fans about 8 years@ Mulvya : help me, pls
-
Quantum7 over 6 yearsUsing
setpts=N/FRAME_RATE/TB
with the movie filter is key here. Some other examples usesetpts=PTS-STARTPTS
, which doesn't work with loop.