I am trying to use ffmpeg to zoom in & out an image with its center as origin & overlay the animation over a background image.
Details: The background image is a 300x250 jpeg file, the button is a 134×44 png file, the zoom animation is defined as follows: from 0 to 1s -> zoom in ; from 2s to 3s -> zoom out.
I managed to do this with a mix of pan
, zoompan
& overlay
filters. However it seems to me that zoompan
is quite limited as it only supports a zoom range of 1-10. Here is the video & the corresponding command line:
ffmpeg -y -i background.jpeg -framerate 25 -loop 1 -i button.png -filter_complex "[0]scale=300:250:in_range=jpeg[s0];[s0]fps=25[s1];[1]pad=iw*10:ih*10:(ow-iw)/2:(oh-ih)/2:color=black@0,zoompan='if(between(ot,0,1), min(1+on/25*10,10), if(gte(ot,2), max(10-(on-50)/25*10,1), 10))':x='iw/2-iw/2/zoom':y='(ih-(ih/zoom))/2':d=75:s=134x44,format=gbrap[s2];[s1][s2]overlay=eof_action=repeat:x=(W-w)/2:y=200:enable=between(t\,0.04\,2.95)[s4]" -map "[s4]" -c:v libx264 -crf 0 -pix_fmt yuv420p -t 3.0 video_zoompan.mp4 -hide_banner
This is just a test, my goal is to make it work even if the zoom effect has a wider range.
So, I tried with the scale
& overlay
filters. Here is the video & the corresponding command line:
ffmpeg -y -i background.jpeg -framerate 25 -loop 1 -i button.png -filter_complex "[0]scale=300:250:in_range=jpeg[s0];[s0]fps=25[s1];[1]format=gbrap[s2];[s2]scale=eval=frame:h=-1:w=if(between(t\,0.0\,0.8)\,lerp(iw*0.0\,iw*1.0\,t/0.76)\,if(lte(t\,2.0)\,lerp(iw*1.0\,iw*1.0\,(t-0.8)/1.16)\,if(lte(t\,3.0)\,lerp(iw*1.0\,iw*0.0\,(t-2.0)/0.96))))[s3];[s1][s3]overlay=eof_action=repeat:x=(W-w)/2:y=(200-h/2):enable=between(t\,0.04\,2.95)[s4]" -map "[s4]" -c:v libx264 -crf 0 -pix_fmt yuv420p -t 3.0 video_scale.mp4 -hide_banner
As you can see, using the scale & overlay (with a center origin) filters make the animation jerky.
Is there a way to fix this, as it seems to me that using the scale
filter allows more possibilities (even if it is more time/process consuming?)?
UPDATE 15nov23: Using format=yuv444
as the overlay
option solves my problem (overlay=format=yuv444).