insert loopable video into another video using ffmpeg
We may complete the time of logovid to 30 seconds, then loop it over using loop filter, and use the looped video as [over]:
ffmpeg -y -i "input.mp4" -i "logo\logovid.mov" -filter_complex "[1:v]scale=in_w/2:-2,format=rgba[logo];color=black@0:100x100:r=30:d=30,format=rgba[c];[c][logo]scale2ref[c0][logo0];[c0][logo0]overlay=repeatlast=0[logo1];[logo1]loop=-1:30000[over];[0:v][over]overlay=main_w-overlay_w-5:50:shortest=1" -codec:v libx264 -b:v 3M "final\gotovo.mp4"
For testing, download vecteezy_countdown-leader-movie-intro-graphic-saber-fire-transparent_16911493.mov from here, and rename to logovid.mov.
We may also use the following input.mp4 for testing:ffmpeg -y -f lavfi -i testsrc=s=1920x1080:r=30:d=250 input.mp4
Explaining the stages:
First stage: Overlay logovid over transparent background (Set the duration of the transparent background to 30 seconds):
ffmpeg -y -i logo\logovid.mov -filter_complex "[0:v]format=rgba[logo];color=black@0:100x100:r=30:d=30,format=rgba[c];[c][logo]scale2ref[c0][logo0];[c0][logo0]overlay=repeatlast=0" -c:v prores -pix_fmt yuva444p10le test30sec.mov
The result is 10 seconds logovid followed by 20 seconds of transparent video.
Second stage: Loop the output of the first stage multiple times using loop filter:
ffmpeg -y -i logo\logovid.mov -filter_complex "[0:v]format=rgba[logo];color=black@0:100x100:r=30:d=30,format=rgba[c];[c][logo]scale2ref[c0][logo0];[c0][logo0]overlay=repeatlast=0[logo1];[logo1]loop=-1:30000" -t 250 -c:v prores -pix_fmt yuva444p10le test250sec.mov
The result is: 10sec,20sec,10sec,20sec,10sec,20sec…
Third stage: Use the output of the second stage as [over] (also apply the original scale filer):
ffmpeg -y -i "input.mp4" -i "logo\logovid.mov" -filter_complex "[1:v]scale=in_w/2:-2,format=rgba[logo];color=black@0:100x100:r=30:d=30,format=rgba[c];[c][logo]scale2ref[c0][logo0];[c0][logo0]overlay=repeatlast=0[logo1];[logo1]loop=-1:30000[over];[0:v][over]overlay=main_w-overlay_w-5:50:shortest=1" -codec:v libx264 -b:v 3M "final\gotovo.mp4"
Read more here: Source link
