Majid
Majid

Reputation: 336

How to overlay multiple animated images on a video using ffmpeg

I'm trying to overlay multiple images on a video after I animate them using "rotate" filter. I'm using t parameter in the rotate filter to make the animation a bit arbitrary, so I had to flag the input video as loop (using a -loop flag). The problem is when I only perform one single overlay the result is what it is expected, but when the second overlay comes in the command, it ends suddenly and an empty output video is being generated. below is the command I'm using:

ffmpeg -y -i template.mp4 -loop 1 -i Image_1.jpg -i Image_2.jpg -filter_complex " \
[1:v]scale=186:136[scaled1]; \
[scaled1]format=rgba,colorchannelmixer=aa=0.7[transp1]; \
[transp1]rotate=20*sin(2*PI/(t-9)):c=0xFFFFFF00:ow=250:oh=250,fade=in:st=1:d=5[ANIM_F1]; \
[2:v]scale=136:186[scaled2]; \
[scaled2]format=rgba,colorchannelmixer=aa=0.7[transp2]; \
[transp2]rotate=20*cos(2*PI/(t-9)):c=0xFFFFFF00:ow=250:oh=250,fade=in:st=1:d=5[ANIM_F2]; \
[0][ANIM_F1] overlay=x=1:y=190:shortest=1:enable='between(t,5,15)'[PHASE1]; \
[PHASE1][ANIM_F2] overlay=x=480:y=380:shortest=1:enable='between(t,10,20)'[out]" \
-map [out] output.mp4

Upvotes: 0

Views: 1193

Answers (1)

Gyan
Gyan

Reputation: 92928

In this section,

-i template.mp4 -loop 1 -i Image_1.jpg -i Image_2.jpg

The video is not being looped, the first image is, and the 2nd image isn't. Since the 2nd image isn't being looped, rotate or overlay filters have only one frame to work with. Assuming your video is longer than 20 seconds, you just have to loop the 2nd image.

-i template.mp4 -loop 1 -i Image_1.jpg -loop 1 -i Image_2.jpg

Upvotes: 1

Related Questions