Zoom video using ffmpeg commands

7

1

Is it possible to zoom a video and save it using ffmpeg commands?

I searched a lot but I did not find any solution.

Gururaj

Posted 2013-12-06T10:20:37.493

Reputation: 155

3Yes it is possible to zoom. Does that help? Your questions are too vague. They cannot be answered unless you are more specific. – Rajib – 2013-12-06T13:01:19.730

Answers

12

Zooming is a two step process. You want to:

  1. Scale the video by a factor of your choice.
  2. Crop the video back to its original size.

That'd look something like this, e.g. to zoom in with a factor of 2, assuming an input video of 1280×720 pixels:

ffmpeg -i input.mp4 -vf "scale=2*iw:-1, crop=iw/2:ih/2" output.mp4

Of course, you can change the factor here. The -1 means that the height will be set automatically.

You can use two additional parameters for the crop filter to set the position of the cropping window.

Have a look at the x264 encoding guide if you need to change the output quality (it will be reduced compared to the original, of course).

slhck

Posted 2013-12-06T10:20:37.493

Reputation: 182 472

scale=2*iw:-1,crop=iw/2:ih/2 could be used for 2x zoom. – llogan – 2013-12-10T00:36:35.357

Slhck thanks for ypur reply. That command is working perfectly, but where can I change the amount of zooming, and how can I use this command for zoo out?. – Gururaj – 2013-12-10T11:25:53.250

@Gururaj I mentioned that in my example the factor would be 2, so you simply have to choose another factor. I'm not sure if zooming out is that easily accomplished with a factor between 0 and 1. I can't try it now. – slhck – 2013-12-10T11:38:54.547

slhck I am getting some bars on video after zooming. – Gururaj – 2013-12-12T05:38:10.327

@Gururaj If there's an issue with the command, you should probably post a new question, mention exactly what command you're using, and show the full, uncut command line output. Note that if you want to zoom out you have to scale down first and then pad the output. – slhck – 2013-12-12T08:40:13.360