View Full Version : Zoom plugin (Pan/Zoom/Rotate)
WarpEnterprises
24th March 2003, 08:44
As there is often the need for moving a video around I made a plugin for this. (it should help shorten some of Wilbert's monster-Animate-scripts :) ).
It has the following syntax:
Zoom(string "srcx", string "srcy", string "dstx", string "dsty", string "factorX", string "factorY", string "angle")
As you see there are no number arguments. You can insert every script function AviSynth knows of which returns a number.
srcx/srcy are the "center" coordinates in the original frame,
dstx/dsty are the center coordinates in the moved frame,
factorX, factorY are the magnification factors,
angle is the rotation angle in radian.
Sounds complicated?
Not really, try this:
version().converttorgb32().zoom(dstx="n", angle="n/10")
Here you see that the variable "n" can be used to reference to the current frame number (and this is of course the most important thingie).
Or try:
version().converttorgb32()
zoom(factorx="n<41 ? pow((n+1)/41,0.5) : 1", factory="n<41 ? pow((n+1)/41,0.5) : 1", dstx="n<41 ? width/2 : width/2+5*(n-41)", angle="n<41 ? 3.1415*n/10 : 0")
And the new image gets a defined alpha layer (black=transparent, else opaque), so you can layer the result on top of another video.
This was the good news.
The bad news:
-only RGB32 (I want to use alpha)
-quite slow (but it's only a trick filter for not so many frames)
-the resizer is poor, and I think I've got some rounding errors still present.
Get is here: http://members.aon.at/archi/warpenterprises.html
Wilbert
24th March 2003, 10:26
Very cool! I will try it when I have some time ...
Bidoche
24th March 2003, 17:28
sounds great, especially the string configurable args.
(I hope your parser can be trusted, unlike avisynth's one)
WarpEnterprises
25th March 2003, 08:31
Would have sitten much longer at my PC if I had not used the AviSynth parser :p
What do you mean with "cannot trust" ?
The bug that "-" and "/" was treated in the wrong order ist gone now.
----------
Uploaded new version.
Changes:
- no rounding errors anymore (most calculations in float)
- fixed small bug with default values
- added two parameters: width, height now you can specify the dimensions of the final image (e.g. to "make room" for the rotation)
Improving the resizer (in downscale mode) seems not feasible to me, so if there are no more bugs found it seems finished.
Of course it can be used e.g. as plain rotate:
e.g. Zoom(angle=...) will do nothing but rotate your image.
Get is here: http://members.aon.at/archi/warpenterprises.html
PS: 2.5 version coming soon
kilg0r3
25th March 2003, 09:21
@Warp...:)
Thank You very much for this plugin! It is basically just what I was waiting for. :):):)
Bidoche
25th March 2003, 11:24
@Warp
I guess that's just me being paranoid then :p
WarpEnterprises
3rd April 2003, 13:06
AviSynth 2.5 version uploaded.
Look at the "www" button under the message.
WarpEnterprises
4th April 2003, 10:19
Another addition made to ZOOM.DLL (only 2.0x version so far)
Zoom(show=true): prints the calculated values on the screen
CHR.DLL (2.0 and 2.5) now has a function
Spline (X, x1,y1, x2,y2, ...)
which interpolates the given X with a bicubic spline and gives back the corresponding Y (useful mainly together with Zoom)
E.g. try:
version().converttorgb32()
zoom(factor="Spline(n, 0,0, 10,1, 30,0.5,31,0.5, 100,0.5)", \
dstx="Spline(n, 0,200, 30,200, 100,400)", \
show=true)
So you can give a simple "path" to the parameters instead of fiddling with sin, cos, exp,...
DDogg
15th April 2003, 19:06
Sounds complicated?
Not really, try this:
version().converttorgb32().zoom(dstx="n", angle="n/10")
Since I see version as source? I am assuming the above is a standalone example of a simple avs script that should yield a video result. Using the April 15 2.51 csv build I get: "Avisynth: caught an access violation at 0x77e7650d, attempting to read from 0x00a7e578" when I attemp to run it, both with and without a loadplugin ("zoom.dll")line
DDogg
17th April 2003, 15:07
WE, consider this a bump. Perhaps my question was just dumb but I am trying to trace this access violation with the latest build of avisynth and the zoom function and spline function. Can you check it or just give me a standalone example script that will run on your machine so that I may also check on mine to see if it is machine specific or a general anomaly?
WarpEnterprises
17th April 2003, 21:40
I was not shure if you really tested it against my functions and not got a "false" alarm caused by general convert... problems.
(I'm still mentally not @ 2.5)
I will see if I can reproduce it.
[EDIT]:
No, can't reproduce it.
- zoom_25_dll_20030402.zip
- AviSynth 2.51 15.4.2003
Spline is built-in since this release and works, too.
Which OS?
Dark-Cracker
10th October 2003, 12:10
Hi,
just a few comments/questions :)
1) can we expect an yuy2 or yv12 version of this filter ? :)
2) apparently there is an acces violation if u use the zoom after the resize. (i use the version 20030518 dll).
----------------
this cause access memory violation
video=video.Crop(2,96,0,-40)
video=video.BicubicResize(640,372,0,0.5)
video=video.Zoom(factor="1")
this work fine (but it's hard to adjust zoom :) )
video=video.Crop(2,96,0,-40)
video=video.Zoom(factor="1")
video=video.BicubicResize(640,372,0,0.5)
----------------
3) another suggestion is to add msg restriction on parameters , for exemple if i set factor=0 i will obtain a black screen , perhaps sould u add min and max value in the readme file , and add a avisynth msg if the params are not corrects :)
keep up the good work.
Bye.
WarpEnterprises
11th October 2003, 21:47
1) No, sorry, it would be too hard for me.
2) This is bad, I will take a look at this.
[edit] what resolution has "video"? I can't reproduce an error so far. Send me a piece of your video (3 frames should be enough) and the script, if you don't mind.
3) As the parameters are evaluated for each frame, an error would occur during runtime and would stop the scipt from executing. And if I didn't overlooked anything, all values should be "in principle" possible, e.g. factor=0 results in a reduction to a point.
4) I found that I handle alpha not very well, I will correct this.
(setting alpha to transparent where the resulting image has no source counterpart)
thanks for your suggestions!
Holomatrix
15th January 2004, 23:55
Thank you for this filter. I was messing around with Crop and some other filters to try and keep aspect and just zoom in but got all messed up. I like to keep it simple and that's what your filter lets me do :) By doing for example Zoom(factor="1.5") zooms in just nicely. I just have two questions :) I AM getting the same aspect ratio, correct? and I notice it blurs when I zoom, is that caused by the filter or just the natural outcome of resizing bigger?
Thank again
WarpEnterprises
16th January 2004, 08:25
- it assumes 1:1 aspect (the input must be square aspect)
- the resizer is not very good, it is like linear upsize and nearest neighbour downsize. I don't know how to make this better as I use one simple formula for all operations. It would require much more logic and/or mathematic.
Holomatrix
16th January 2004, 13:15
Darn, I would only use it for thoes really wide screen flicks
WarpEnterprises
16th January 2004, 13:20
you can resize it to 1:1, then Zoom, then resize it to 16:9 again.
Holomatrix
16th January 2004, 15:55
Can you give me an example of what I would plug into my script.
Thanks
WarpEnterprises
19th January 2004, 22:05
Assume a 16:9 video, res. e.g. 704x576.
Resizing to 4/3*576 = 768 gives 1:1 AR.
Now do the Zoom'ing and then resize back to 704x576:
lanczosresize(width,height*4/3)
zoom(angle="90",factor="1.3")
lanczosresize(width,height*3/4)
The 1.3-factor is to avoid the black borders in this example.
AsTimeGoesBy
30th July 2005, 00:57
Belong my first impression and other threads it's quite tricky to handle. :(
I could imagine a zoom movement would freshen up movementless sequences.
That rotation feature of zoom() is interesting too although i already fail with trivial zooming to a special position.
The examples in the readme zoom.txt are amazing to watch but didn't enlighten me enough.
Even i understand it zoom() complete wrong or i must look for a brain-update...
An example. How to zoom on Mrs. Bride's eyes in the following frame (http://killbill.movies.go.com/wallpapers/kill_bill_a_12.jpg) (=>sequence) ?
http://homepage.hispeed.ch/audio/temp/zoom-kb1a-nozoom.jpg => http://homepage.hispeed.ch/audio/temp/zoom-kb1a-zoomed.jpg
I have prepared the values. However the script below doesn't create the intended effect.
I really would be glad if somebody could tell me the correct syntax or just give me some hints.
LoadPlugin("D:\Programs\Video\AviSynth\Plugins\zoom.dll")
#
# Zoom(string "srcx", string "srcy", string "dstx", string "dsty",
# \ string "factorX", string "factorY", string "factor",
# \ string "angle", int "height", int "width", bool "show" )
#
# www.kill-bill.com/wallpapers/kill_bill_a_12.jpg
imagereader("kill_bill_a_12.jpg",0,500,fps=25)
converttorgb32()
# src size : 1280 x 960
# src center : srcx="640", srcy="480"
# dst size : 320 x 240
# dst coord left/top : 574/204
# dst coord right/down: 894/444
# center dst : dstx="734", dsty="324"
ReduceBy2() # now...:
# src size : 640 x 480
# src center : srcx="320", srcy="240"
# dst size : 160 x 120
# dst coord left/top : 287/102
# dst coord right/down: 447/222
# center dst : dstx="367", dsty="162"
zoom(srcx="320", srcy="240", dstx="367", dsty="162", angle="0") # width=160, height=120
WarpEnterprises
31st July 2005, 14:17
Indeed, you missed that you have to tell Zoom the variation with the frame number.
Try this:
imagereader("kill_bill.bmp",0,500,fps=25)
converttorgb32()
#srcx/y is the CENTER of the source picture which is then mapped to a destination picture at dstx/dsty.
#zoom(srcx="640", srcy="480", factor="1") #this gives the start picture
#zoom(srcx="734", srcy="320", factor="4") #this gives the final picture
#but you want to zoom so use variable "n" to vary the arguments (n is the same as "current_frame" in scriptClip)
#best you use Spline as your function
sf=10 #startframe
ef=30 #endframe
srcx = "spline(n, sf-1,640, sf,640, ef,734, ef+1,734, false)"
srcy = "spline(n, sf-1,480, sf,480, ef,320, ef+1,320, false)"
factor="spline(n, sf-1,1, sf,1, ef,4, ef+1,4, false)"
zoom(srcx=srcx, srcy=srcy, factor=factor) #this varies factor, dstx, dsty from frame 10 to frame 20.
ReduceBy2() # now...: downsize afterwards gives better antialiasing but is slower
All variables are strings which are evaluated when the frame is rendered (quite similar to ScriptClip). So you can put into those strings a constant or a function which depends on "n" (the frame number).
It's that complicated to allow any "path" functions (e.g. you can spiral or sine your picture by using srcx/y=sin/cos)
AsTimeGoesBy
31st July 2005, 15:11
Thanks for re-writing that script! :) - It works fine although i don't know exaclty how and why... ;)
It's great the zoom length can be easily defined now, initially i had no idea where to do this...
At first sight i have the impression the zoom is flying a 'skyward bow' onto the eyes!?
But before i post more thoughts i guess i have to learn more about these internal Avisynth functions (http://www.avisynth.org/ScriptFunctions#spline) like spline()...
ll4ever
25th September 2005, 03:21
I've been trying to make this work...but it's not doing what I want.
I have a 640X480 video made from a bmp using imagereader. I want it to zoom out instead of in. If I play it backwards, it does what I want but how do you make it work the other way?
imagereader("E:\LM\IMG00022.bmp",0,100,fps=20)
converttorgb32()
sf=0 #startframe
ef=100 #endframe
srcx = "spline(n, sf-1,320, sf,320, ef,320, ef+1,240, false)"
srcy = "spline(n, sf-1,240, sf,240, ef,240, ef+1,240, false)"
factor="spline(n, sf-1,1, sf,1, ef,8, ef+1,8, false)"
zoom(srcx=srcx, srcy=srcy, factor=factor)
WarpEnterprises
26th September 2005, 07:09
exchange the values from the number pairs with "sf" with those "ef":
srcx = "spline(n, sf-1,240, sf,320, ef,320, ef+1,320, false)"
srcy = "spline(n, sf-1,240, sf,240, ef,240, ef+1,240, false)"
factor="spline(n, sf-1,8, sf,8, ef,1, ef+1,1, false)"
should work.
I think the srcx, srcy lines are not necessary as it centers the picture as default.
mikeytown2
8th June 2008, 10:29
Sorry to dig this up.
I'm trying to make a clip move in a arc/circle (orbit), how could this be done?
Math-wise to draw a circle: x^2+y^2= r^2
in zoom: +-Sq(#frames^2-n^2) ???
the last line is wrong, but i believe the top 2 are good. This is of course missing startF and endF which are the desired start and end points.
String((endFrame-startFrame)/2.0) + ">n?"
\+ " pow(" + String(pow((endFrame-startFrame)/2.0,2)) + "-pow(n,2),0.5)" +
\" : pow(" + String(pow((endFrame-startFrame)/2.0,2)) + "-pow(" + String(endFrame-startFrame) + "-n,2),0.5)" + ""
This will draw a straight line
"spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
Using this for my KenBurnsEffect Function (http://forum.doom9.org/showthread.php?t=135776)
Here is a function that i am currently developing
Function SplineCalc(clip c, int mode, int startFrame, float startF, int endFrame, float endF)
{
splineString = mode==1 ?
\ "spline(n, "
\ + String(startFrame-1) + "," + String(startF) + ", "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String(endFrame) + "," + String(endF) + ", "
\ + String(endFrame+1) + "," + String(endF) + ", true)"
\ : mode==2 ? "spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String(startFrame+(endFrame-startFrame)/3.0) + "," + String(startF) + ", "
\ + String(endFrame-(endFrame-startFrame)/3.0) + "," + String(endF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
\ : mode==3 ? "spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String(startFrame+(endFrame-startFrame)/3.0) + "," + String(endF) + ", "
\ + String(endFrame-(endFrame-startFrame)/3.0) + "," + String(startF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
\ : mode==4 ? "spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String((endFrame-startFrame)/2.0) + "," + String(startF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
\ : mode==5 ? "spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String((endFrame-startFrame)/2.0) + "," + String(endF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
\ : "spline(n, "
\ + String(startFrame) + "," + String(startF) + ", "
\ + String(endFrame) + "," + String(endF) + ", true)"
Return splineString
}
By setting srcx to mode 4 and srcy to mode 5 it will sorta draw a arc.
Any example would be helpful, demonstrating a circle/arc. The example doesn't have to use my syntax, i just need anything. Doing a search got me this (http://forum.doom9.org/showthread.php?p=375580#post375580)
EDIT:
Found an old script (http://forum.doom9.org/showthread.php?t=32884) that uses layer to do this
Here is my take on that code
a = Colorbars().Trim(0,199)
b = a.Invert().BilinearResize(320,240)
Animate(0,199, "circlee", a,b,320,240,60.0,0.0 , a,b,320,240,0.0,50.0 )
# circle: gives a clip which is moved along (by varying "t") a circle with center (centerX,centerY)
# with radius "axis" the resulting clip on a black background.
function circlee(clip clip, clip "LClip", int "centerX", int "centerY", float "axis", float "t")
{
x = round((centerX-LClip.width/2)+axis*cos(Pi*t*0.5))
y = round((centerY-LClip.height/2)+axis*sin(Pi*t*0.5)-axis)
return clip.Layer(LClip, "Add", 255, x,y)
}
Gavino
8th June 2008, 20:13
Sorry to dig this up.
I'm trying to make a clip move in a arc/circle (orbit), how could this be done?
Here's the basic idea to get you started:
A point (x, y) on the circle of radius r centred at (x0, y0) satisfies the equation (x-x0)^2 + (y-y0)^2 = r^2.
This can be recast as x= x0 + r*cos(theta), y= x0+ r*sin(theta) for some angle theta.
To trace out a circle, vary theta from 0 to 2*Pi.
To trace out an arc, vary theta over some continuous range.
The variation (of theta) can be done linearly with Animate, or in some arbitrary way with the Zoom plugin by deciding how you want theta to vary in terms of 'n' (the frame number); for linear variation (constant rotation speed) you would use theta = k*(n-startFrame) for some constant k. Then use the earlier equations to derive x and y from theta.
Paser
16th February 2014, 19:13
Here's a version I've compiled to work with 64-bit AviSynth.
l33tmeatwad
9th May 2015, 19:24
Link in the first post is broken so here is the current location for the original x86 download:
http://www.avisynth.nl/users/warpenterprises/
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.