Sam
Sam

Reputation: 765

ffmpeg scale down video dynamically (squeeze-back) or zoompan out to smaller than original

I have 2 videos, I'm trying to overlay one on top of the other, and have it shrink down in an animated fashion until it appears like a picture-in-picture setup. Then, after a few seconds it should scale back up.

This is what I am trying to achieve (these would be videos, not images): enter image description here

This is the closest I've been able to get, but, crucially, zoompanning "out" (as opposed to "in") does not appear to work; so, of course, this does not work:

ffmpeg -i bg.mov -i top.mov -filter_complex "[0:v]zoompan=z='pzoom-0.1':d=1, setpts=PTS-STARTPTS[top]; [1:v]setpts=PTS-STARTPTS+2/TB, scale=1920x1080, format=yuva420p,colorchannelmixer=aa=1.0[bottom]; [top][bottom]overlay=shortest=0" -vcodec libx264 out.mp4

Is this achievable with ffmpeg?

Upvotes: 5

Views: 3219

Answers (1)

Gyan
Gyan

Reputation: 93068

Use the scale filter with animation, available since v4.3.

Here's something to get you started. This will expand the top layer from 480 px height to 1080 height in 2 seconds and then back to 480 px in 2 seconds.

ffmpeg -i bg.mov -i top.mov -filter_complex "[0:v]scale=1920x1080,setpts=PTS-STARTPTS[bg]; [1:v]setpts=PTS-STARTPTS+2/TB, scale=-1:'480+600*abs(sin((t-2)*2*PI/8))':eval=frame[top]; [bg][top]overlay" -vcodec libx264 out.mp4

Upvotes: 5

Related Questions