Sunday, February 17, 2019

FFMpeg Zoom



I won't embarrass myself referring to being an amateur videographer but I have set up a video camera, pointed it at something worthwhile and hitting record.  With a high-def camera and a wide angle lens you can capture life in the making.  While cameras offer zoom capabilities I'm far more likely to lose the subject so I've made the habit of setting the camera up on a tripod, zooming out to capture the entire scene and adding digital zoom effects post-processing.  In the age of high-def cameras.....why not?  I'm less likely to miss the shot and have numerous tries in adding effects afterwords.

Let's grab a video, apply a text target overlay (to make sure we're zooming where we think we are) and then zoom to that location.

$ youtube-dl https://www.youtube.com/watch?v=PJ5xXXcfuTc -o input 

Let's slap a 'X' at 560,400 so we can confirm we're zooming to where we expect;
$ ffmpeg -y -i input.mkv -ss 30 -t 15 -vf drawtext="fontfile=/usr/share/fonts/truetype/droid/DroidSans.ttf:text='X':fontcolor=black:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=560:y=400" -codec:a copy target.mp4

Finally, let's zoom to 560,400

$ ffmpeg -y -i target.mp4 -vf "scale=iw*2.0:ih*2.0,zoompan=z='min(max(zoom,pzoom)+0.05,5.0)':d=1:x='560*2.0-(560*2.0/zoom)':y='400*2.0-(400*2.0/zoom)'" -an output.mp4

In the above example, we're using the following values for scalars;
S=2.0
Z=5.0
K=0.050

Experiment with the scalars to get your desired affect;

Safe intellectual travels my fair reader.

4 comments:

  1. if i want myvideo zoom in for 5s then it back original video, plese help me

    ReplyDelete
    Replies
    1. ffmpeg -i test.mp4 -vf "zoompan=z='1+(0.005*in/24)':d=1" -threads 0 -preset superfast crop-100-fc.mp4

      Delete
  2. Take a peek at my follow-up post that was written in response to your question.
    https://dragonquest64.blogspot.com/2019/08/dynamic-zoom-in-out-video-effect.html

    ReplyDelete
  3. how to zoom out from a video FOr example : in sugarcrash tiktok video

    ReplyDelete