Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zooming animation in FFMPEG

Tags:

ffmpeg

I need to make a zooming animation for a video input.

Making a panning animation is possible with the crop filter with something like this:

"crop=320:240:max(0\\,min(iw-ow\\,n)):0"

Where the first two parameters, width and height, are fixed, and the second two parameters, accept frame number n or timestamp t as expression parameters.

But width and height are evaluated only once (and cannot use n or t), so I cannot crop a size in function of time and then apply a scale filter to the original size.

I know I can:

  • Change the filter after pulling each frame from the buffersink (I'm not in the command line, I'm using the libraries in my software). I'm doing that already, but no for every frame, only by user request in an online application.
  • Use geq filter to "apply a generic equation to each frame".

Both approaches seem expensive. Is there another filter or approach I could use?

Note that I'm using zeranoe FFMPEG libraries in Windows. I'd rather not develop my own filters or modify FFMPEG source.

like image 575
dmcontador Avatar asked Apr 23 '14 09:04

dmcontador


1 Answers

You can apply a simple zoom by adding

"zoompan=z='zoom+0.001'"

to your video filters. It will, by default, zoom in to the top left corner slowly. If you want to do something a little more advanced, you can add the x and y arguments to start getting a zoom in other directions and variable speeds. An example of

"zoompan=z='zoom+0.001':x='if(gte(zoom,1.5),x,x+1)':y='y'"

would go to the top right and

"zoompan=z='zoom+0.001':y='if(gte(zoom,1.5),y,y+1)':x='x'"

would go to the bottom left.

like image 175
jrkt Avatar answered Oct 29 '22 16:10

jrkt