Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
#1 | Link |
|
Registered User
Join Date: Jul 2013
Posts: 7
|
Zooming with Avisynth Help
Hello folks. I am sorry to bother with such a seemingly minor thing, but my skill with Avisynth is not so good, heh. I can't figure out how to Zoom with Avisynth smoothly.
Let's say I have a 1280x720 image. How would I be able to zoom in smoothly to let's say about 100 pixels down from directly in the center? I have tried using Animate, but the zooming is very rough. I also have installed the Zoom plugin, however, I don't understand how to use that. I looked at the creators thread for Zoom here, but I just don't understand it at all ![]() I just don't know what to do to get a smooth zoom effect... Any help will be appreciated. |
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Oct 2011
Posts: 24
|
I'm not sure if this is what your looking for but I quickly made this function:
Code:
function magnify(Clip clp, int x1, int y1, int x2, int y2, float magnification)
{
portion = clp.Crop(x1, y1, -(clp.width-x2), -(clp.height-y2))
return portion.Spline64Resize(portion.width*magnification, portion.height*magnification)
}
Example of what it does: ![]() Code:
magnify(154,114,264,166,6) ![]() EDIT: After reading your question properly I can see you want to slowly zoom in and not just magnify a specific segment. I'll leave this up here just incase you like it anyway :P |
|
|
|
|
|
#3 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,392
|
http://avisynth.nl/index.php/Animate
To do a smoothly varying zoom, you would need to take into account the number of frames. If you are zooming by eg 20 pixels per frame, it would not be smooth, to do it smoothly would require doing it over sufficient number of frames and that may make it tediously slow. Choose your poison.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 18th July 2013 at 13:04. |
|
|
|
|
|
#4 | Link | |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
If you are using the normal method of Animate'ing a resizer, be sure to pass floating-point values for the src_left, src_top, src_width and src_height arguments. For example, use 60.0 rather than 60. |
|
|
|
|
|
|
#6 | Link |
|
Retried Guesser
Join Date: Jun 2012
Posts: 1,371
|
Thank you Gavino, I had temporarily unquoted them. I withdrew the script because it is not zooming smoothly. How does one pass floating-point values to XXXResize? I get an error.
EDIT - here's the script in its current state. Slow zoom looks terrible. Maybe it's the mod-2 border trimming, will check... EDIT - try it now, it looks much better. A little unsteadiness remains. RGB32 source is required. Zooms with pan & tilt. Pan & tilt are a little rough but good enough to zoom in on a desired focal point. Code:
C=C.ConvertToRGB32(matrix="PC.709", chromaresample="spline36")
## zoom 1x to 5x
return Animate(C, 1, 280, "UUZoom", 1.0, 2.0)
return Animate(C,
\ 1,
\ 280,
\ "UUZoom",
\ 1.0, 0, 0,
\ 5.0, 0, 0)
/*
## zoom 3x, pan top-left to bottom-right
return Animate(C,
\ 150,
\ 180,
\ "UUZoom",
\ 3.0, -1.0, -1.0,
\ 3.0, 1.0, 1.0)
*/
/*
## zoom 1x, pan top-left to bottom-right (no effect)
return Animate(C,
\ 150,
\ 180,
\ "UUZoom",
\ 1.0, -1.0, -1.0,
\ 1.0, 1.0, 1.0)
*/
/*
## zoom 0.25x to 1.0, pan from top-left (motion needs refining)
return Animate(C,
\ 150,
\ 180,
\ "UUZoom",
\ 0.25, -1.0, -1.0,
\ 1.0, 1.0, 1.0)
*/
###############################
### zoom in on an image
#
#@param factor - range = 0.01 to 100 [default = 1.0]
#@param pan - range = -1.0 to +1.0: -1.0=left, 0.0=center, +1.0=right; [default = 0.0]
#@param tilt - range = -1.0 to +1.0: -1.0=up, 0.0=center, +1.0=down; [default = 0.0]
#
function UUZoom(clip C, float factor, float "pan", float "tilt")
{
Assert(C.IsRGB32, "UUZoom: clip must be RGB32")
factor = Default(factor, 1.0)
factor = (factor >= 0.01) ? factor : 0.01
factor = (factor < 100.0) ? factor : 100.0
inWid = C.Width
inHgt = C.Height
newWid = Round(factor * Float(inWid))
newHgt = Round(factor * Float(inHgt))
/*
dbgText = "c.Width = " + String(c.Width) + Chr(9) +
\ "c.Height = " + String(c.Height) + Chr(13) +
\ "newWid = " + String(newWid) + Chr(9) +
\ "newHgt = " + String(newHgt) + Chr(13) +
\ "factor = " + String(factor) + Chr(13) +
\ ""
return MessageClip(dbgText, width=640, shrink=false)
*/
C = C.Spline36Resize(newWid, newHgt)
C = C.UUSize2(inWid, inHgt, pan, tilt)
return C
}
##################################
### crop or add border to ensure clip is a certain size
#
#@param pan - range = -1.0 to +1.0: -1.0=left, 0.0=center, +1.0=right; [default = 0.0]
#@param tilt - range = -1.0 to +1.0: -1.0=up, 0.0=center, +1.0=down; [default = 0.0]
#
function UUSize2(clip C, int wid, int hgt, float "pan", float "tilt")
{
Assert(C.IsRGB32, "UUSize2: clip must be RGB32")
bdrWid = (wid - C.Width)
bdrHgt = (hgt - C.Height)
xctr = Default(pan, 0.0)
xctr = (xctr <= 1.0) ? xctr : 1.0
xctr = (xctr >= -1.0) ? xctr : -1.0
yctr = Default(tilt, 0.0)
yctr = (yctr <= 1.0) ? yctr : 1.0
yctr = (yctr >= -1.0) ? yctr : -1.0
bdrLt = Abs(Round(Float(bdrWid) / 2.0))
bdrLt = bdrLt + Round(bdrLt * xctr)
bdrLt = Sign(bdrWid) * bdrLt
bdrTp = Abs(Round(Float(bdrHgt) / 2.0))
bdrTp = bdrTp + Round(bdrTp * yctr)
bdrTp = Sign(bdrHgt) * bdrTp
bdrRt = (bdrWid - bdrLt)
bdrBt = (bdrHgt - bdrTp)
C = C.AddBorders(
\ ((bdrLt > 0) ? bdrLt : 0),
\ ((bdrTp > 0) ? bdrTp : 0),
\ ((bdrRt > 0) ? bdrRt : 0),
\ ((bdrBt > 0) ? bdrBt : 0))
C = C.Crop(
\ ((bdrLt < 0) ? -bdrLt : 0),
\ ((bdrTp < 0) ? -bdrTp : 0),
\ ((bdrRt < 0) ? bdrRt : wid),
\ ((bdrBt < 0) ? bdrBt : hgt))
return C
}
Last edited by raffriff42; 18th July 2013 at 14:37. Reason: script |
|
|
|
|
|
#7 | Link | |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
Normally when zooming, you Animate a resizer, resizing a clip to keep its original size while varying these parameters to select a smoothly changing source region from the frame. |
|
|
|
|
|
|
#10 | Link | |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
For an example, see mikeytown2's KenBurnsEffect(). I myself use something similar which I developed to suit my own requirements. |
|
|
|
|
|
|
#11 | Link |
|
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,783
|
I agree with this. Use the right tool for the job. AVISynth is a great tool for video manipulations that require programatically inspecting the content of the video and then doing something clever with the information found in all those pixels. While you can do simple cropping and re-sizing as part of a script, doing a smooth zoom is something that just screams for an interactive GUI that is much better provided by your favorite NLE.
|
|
|
|
|
|
#12 | Link |
|
Registered User
Join Date: Nov 2001
Posts: 291
|
Maybe this can help, function ZoomInOut by Didée
http://forum.doom9.org/showthread.ph...71#post1586571 |
|
|
|
|
|
#13 | Link |
|
Retried Guesser
Join Date: Jun 2012
Posts: 1,371
|
johnmeyer, you are right of course
KenBurnsEffect() looks like it would fill the need perfectly anyway.EDIT for basic zooms, I found it easier to call ZoomBox (support function for KenBurnsEffect) Last edited by raffriff42; 19th July 2013 at 13:40. Reason: script |
|
|
|
|
|
#14 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,392
|
Raffriff42,
Just a tip (Gavino originated) Code:
factor = Float(Default(factor, 1.0)) # use this instead of
factor = Default(factor, 1.0) # this
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
|
|
|
|
|
#15 | Link |
|
Retried Guesser
Join Date: Jun 2012
Posts: 1,371
|
> ensures that factor is a float if passed as int
Ah, of course. Thank you StainlessS. I'll go ahead and post a working (if hackish) script with examples Code:
C=C.ConvertToRGB32() ## RGB32 required
/*
*/
## zoom 1x to 2x
return Animate(C, 1, 280, "SimpleZoomBox",
\ 1.0, 0, 0,
\ 2.0, 0, 0)
/*
## zoom in, panning up and to the right
endzoom = 2.0 ## try different values here
return Animate(C, 1, 280, "SimpleZoomBox",
\ 1.0, 0, 0,
\ endzoom, (endzoom * 0.25), (endzoom * -0.6))
*/
/*
## (random BG video)
B = C.Levels(0, 0.7, 255, 32, 96)
\ .Subtitle("SIMPLE ZOOM", size=156, align=2, text_color=$00ffff)
## zoom out, ending up in top right corner over BG video
C = Animate(C,
\ 1, 280, "SimpleZoomBox",
\ 1.0, 0, 0,
\ 0.25, -0.5, 0.6)
return B.Overlay(C, Mask=C.ShowAlpha)
*/
/*
## pan and tilt at constant zoom factor
endzoom = 2.2 ## try different values here
offsetX = 0.98 * endzoom * (1.0 - (1.0 / endZoom)) ## 0.98 = large movement (1.00 = full)
offsetY = 0.33 * endzoom * (1.0 - (1.0 / endZoom)) ## 0.33 = small movement
return Animate(C,
\ 1, 280, "SimpleZoomBox",
\ endzoom, -offsetX, offsetY,
\ endzoom, offsetX, -offsetY)
*/
###############################
### zoom an image with pan & tilt;
### wraps call to ZoomBox with fewer arguments for easier animation
#
#@param factor - range = 0.01 to 100 [default = 1.0]
#@param pan - location in source which will be centered in target:
# < 0.0=left, 0.0=center, > 0.0=right [default = 0.0]
#@param tilt - location in source which will be centered in target:
# < 0.0=up, 0.0=center, > 0.0=down [default = 0.0]
#
function SimpleZoomBox(clip C, float factor, float "pan", float "tilt")
{
Assert(C.IsRGB32, "SimpleZoomBox: clip must be RGB32")
factor = Min(Max(0.01, Float(Default(factor, 1.0))), 100.0)
pan = Float(Default(pan, 0.0))
tilt = Float(Default(tilt, 0.0))
offsetX = -(0.5 * pan * Float(C.Width))
offsetY = -(0.5 * tilt * Float(C.Height))
C = C.ZoomBox(
\ zoomFactor=(factor * 100.0),
\ ResizeMethod="Spline16Resize",
\ panX=offsetX, panY=offsetY)
return C
}
Last edited by raffriff42; 20th July 2013 at 17:23. |
|
|
|
|
|
#17 | Link |
|
Retried Guesser
Join Date: Jun 2012
Posts: 1,371
|
XBlade, this was your question:
>Let's say I have a 1280x720 image. How would I be able to zoom in smoothly to let's say about 100 pixels down from directly in the center? Code:
C=Avisource(<path>).ConvertToRGB32() return Animate(C, 1, 280, "SimpleZoomBox", \ 1.0, 0, 0, \ 5.0, 0, 0) "1.0" means start at normal size (1x). "5.0" means zoom to 5x. "0, 0" means zoom in to the center of the image. See example above ("zoom in, panning up and to the right") for zooming in to a particular spot. For this to work, you need to copy the code for SimpleZoomBox from my post above; copy Zoombox and its helpers from here; then save as plain text to your Avisynth Plugins folder as Zoombox.avsi. Last edited by raffriff42; 21st July 2013 at 15:45. |
|
|
|
|
|
#18 | Link | |
|
Registered User
Join Date: Jul 2013
Posts: 7
|
Quote:
Now, I should paste your code, and the code for Zoombox into a single text file and save that as .avsi? And that code you just posted will suffice for calling the effect? |
|
|
|
|
|
|
#19 | Link |
|
Retried Guesser
Join Date: Jun 2012
Posts: 1,371
|
Yep! Functions *can* be placed directly in the .avs script, but functions that you want to call from many .avs scripts should be put into .avsi files in the Plugins folder.
Plugin autoload and name precedence (Avisynth wiki) |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|