VideoHelp Forum
+ Reply to Thread
Results 1 to 15 of 15
Thread
  1. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    I'm trying to create an AviSynth script that replaces one shot in a video using one image.

    How do I start zoomed in on the image, then gradually zoom out?
    Does anyone have a script example or tutorial I could take a look at?
    Quote Quote  
  2. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Originally Posted by El Heggunte View Post
    Is it the "Zoom overlay 1" example? My image shows up, but there is no zoom happening--the image is motionless.

    Here's my script:

    Code:
    LoadPlugin("C:\DVD\DGDecode.dll")
    Function myfunc(clip clip1, clip ovl4, int x, int y, int w, int h)
    {
      w = w - w%2
      h = h - h%2
      my_ovl4 = BicubicResize(ovl4,w,h)
      Overlay(clip1,my_ovl4,x,y)
    }
    clip1 = MPEG2Source("C:\DVD\02\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\DVD\24\VTS_01_1.d2v")
    ovl4 = ImageSource("C:\Images\02.png").BicubicResize(720,480)
    Animate(0,158,"myfunc",
    \  clip1,ovl4, 10, 10, 10, 10,
    \  clip1,ovl4,300,300,360,288)
    ovl4 = ovl4.ConvertToYV12()
    clip2.Trim(25,2720)FadeOut(19) + clip1.Trim(2697,25188) + clip1.Trim(25189,25347).Overlay(ovl4) + clip1.Trim(25348,0)
    Quote Quote  
  3. Same issue as in your other thread, Overlay() is not using the proper arguments

    Break it down to simpler script, before adding other things


    Code:
    LoadPlugin("C:\DVD\DGDecode.dll")
    Function myfunc(clip clip1, clip ovl4, int x, int y, int w, int h)
    {
      w = w - w%2
      h = h - h%2
      my_ovl4 = BicubicResize(ovl4,w,h)
      Overlay(clip1,my_ovl4,x,y)
    }
    
    clip1 = MPEG2Source("C:\DVD\02\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\DVD\24\VTS_01_1.d2v")
    ovl4 = ImageSource("C:\Images\02.png").BicubicResize(720,480).ConvertToYV12()
    
    Animate(0,158,"myfunc",
    \  clip1,ovl4, 10, 10, 10, 10,
    \  clip1,ovl4,300,300,360,288)
    You should see something happening between 0-158
    Quote Quote  
  4. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Thank you! It's working now, but the zoom is pretty jumpy (it looks like it's alternating between resizing on the x-axis and resizing on the y-axis). Am I not specifying the framerate correctly?

    Code:
    LoadPlugin("C:\DVD\DGDecode.dll")
    Function myfunc(clip clip1, clip ovl4, int x, int y, int w, int h)
    {
      w = w - w%2
      h = h - h%2
      my_ovl4 = BicubicResize(ovl4,w,h)
      Overlay(clip1,my_ovl4,x,y)
    }
    clip1 = MPEG2Source("C:\DVD\02\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\DVD\24\VTS_01_1.d2v")
    ovl4 = ImageSource("C:\Images\02.png", fps=clip1.framerate).BicubicResize(720,480).ConvertToYV12()
    ovl4 = Animate(0,158,"myfunc",
    \  clip1,ovl4,-55,-36,838,559,
    \  clip1,ovl4,0,0,720,480)
    clip2.Trim(25,2720)FadeOut(19) + clip1.Trim(2697,25188) + clip1.Trim(25189,25347).Overlay(ovl4) + clip1.Trim(25348,0)
    Quote Quote  
  5. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Is the reason I can't get a smooth zoom because the resize animation is moving in increments smaller than 1 pixel per frame? Or because I'm not implementing subpixel resampling? Or because I'm not using floating points?

    Current script:
    Code:
    LoadPlugin("C:\DGDecode.dll")
    clip1 = MPEG2Source("C:\1\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\2\VTS_01_1.d2v")
    ovl1 = ImageSource("C:\Images\1.png", fps=clip1.framerate).BicubicResize(720,480).ConvertToYV12
    Function myfunc(clip clip1, clip ovl1, int x, int y, int w, int h)
    {
      w = w - w%2
      h = h - h%2
      my_ovl1 = BicubicResize(ovl1,w,h)
      Overlay(clip1,my_ovl1,x,y)
    }
    ovl1 = Animate(2,158,"myfunc",
    \  clip1,ovl1,-55,-36,838,559,
    \  clip1,ovl1,0,0,720,480)
    clip2.Trim(25,2720).FadeOut0(19) + \
    clip1.Trim(2696,25188) + \
    clip1.Trim(25189,25346).Overlay(ovl1) + \
    clip1.Trim(25347,0)
    Recap of the problem I'm having:
    I'm trying to replace a shot in a video with an image, and apply a zoom effect to it that mimics a camera zooming out. My current script uses resizing animation to simulate the motion of the zoom. The problem I'm having is that the animation of the resize isn't smooth. The image constantly jitters as it changes size.

    Software:
    AviSynth 2.6
    VirtualDub-1.10.4

    Specs:
    Windows 7 Professional, 64-bit
    AMD Phenom(tm) II X6 1090T Processor 3.21 GHz
    AMD 6870
    AMD 6850
    8.00 GB RAM
    Quote Quote  
  6. You need to adjust src_left, src_top, src_width and src_height to get a smooth zoom. The math is a little tricky,
    but the excellent ZoomBox script handles it for you.
    It adds black borders as needed to maintain the same dimensions as the source clip.
    It also does panning at the same time - some examples here.
    Minimum practical size is 8x8. Contrary to the docs, Zoom.dll is not needed for simple zoom/pan without rotation.
    Compatible with AVS and AVS+, 32/64bit. Note, if using AVS+, r2664 or later is needed for resizing in an Animate call.
    Code:
    Import("<path>\ZoomBox.avsi")
    
    <Last = RGB32>
    
    ## zoom in from 0.01x to 1.0x
    Animate(0, 120, "myfunc", 0.01, 1.0)
    return Last
    
    function myfunc(clip C, float f)
    {
        f    = Pow(f, 2.0) ## speed up as size gets larger
        return C.SimpleZoomBox(f)
    }
    
    ###############################
    ### zoom an image with pan & tilt
    ## wraps call to ZoomBox with fewer arguments for easier animation
    ##
    ## @ factor - range ~ 0.01 to 100 [default = 1.0]
    ## @ pan    - location in source which will be centered in target:
    ##               < 0.0=left, 0.0=center, > 0.0=right [default = 0.0]
    ## @ 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(8.0/C.Height, 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; 31st Mar 2018 at 09:37.
    Quote Quote  
  7. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Thank you, the Zoombox zoom looks really smooth!

    There are two things though that I'm having trouble with using Zoombox:
    1. How do I apply the zoom to just the ovl1 portion of my clip?
    2. How do I offset the x and y axes before zooming out? (I see how to do it after zooming out.)

    My current script:
    Code:
    LoadPlugin("C:\DGDecode.dll")
    clip1 = MPEG2Source("C:\1\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\2\VTS_01_1.d2v")
    clip1 = clip1.ConvertToRGB
    clip2 = clip2.ConvertToRGB
    ovl1 = ImageSource("C:\Images\1.png")
    ovl1 = ovl1.ConvertToRGB
    clip2.Trim(25,2720).FadeOut0(19) + \
    clip1.Trim(2696,25188) + \
    clip1.Trim(25189,25346).Overlay(ovl1) + \
    clip1.Trim(25347,0)
    Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    return Last
    function myfunc(clip C, float f)
    {
        f    = Pow(f, 2.0)
        return C.SimpleZoomBox(f)
    }
    function SimpleZoomBox(clip C, float factor, float "pan", float "tilt")
    {
        Assert(C.IsRGB32, "SimpleZoomBox: clip must be RGB32")
        factor = Min(Max(8.0/C.Height, 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
    }
    Quote Quote  
  8. >1. How do I apply the zoom to just the ovl1 portion of my clip?
    Not sure what you mean, but I'm guessing you want the image to start small and zoom in over a non-zooming background.
    You create a mask clip so the black borders on ovl1 are transparent. Something like this (not tested!)
    Code:
    clip1 = MPEG2Source("C:\1\VTS_01_1.d2v")
    clip2 = MPEG2Source("C:\2\VTS_01_1.d2v")
    clip1 = clip1.ConvertToRGB
    clip2 = clip2.ConvertToRGB
    ovl1 = ImageSource("C:\Images\1.png")
    ovl1 = ovl1.ConvertToRGB
    
    ovl1Z = ovl1.Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    
    ovl1M = BlankClip(ovl1, color=$ffffff)
    \	    .Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    
    clip2.Trim(25,2720).FadeOut0(19) + \
    clip1.Trim(2696,25188) + \
    clip1.Trim(25189,25346).Overlay(ovl1Z, mask=ovl1M) + \
    clip1.Trim(25347,0)
    #Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    return Last
    (EDIT reading comprehension fail, you want to start big and zoom back to fill the screen; the script should still work)

    >2. How do I offset the x and y axes before zooming out? (I see how to do it after zooming out.)
    You can animate the pan and tilt arguments as well as zoom. Since you're doing that, you might as well animate
    SimpleZoomBox directly instead of wrapping it in myfunc.
    Something like this (not tested!)
    Code:
    ovl1Z = ovl1.Animate(2, 158, "SimpleZoomBox", 
    \    1.3554456019, -1.0, -1.0, [* start zoom, pan, tilt *]
    \       1.0,        0.0,  0.0  [*  end  zoom, pan, tilt *]
    \ )
    Quote Quote  
  9. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Thanks for your help, but unfortunately, I'm getting the following error message with each of your two examples:
    VirtualDub Error
    Avisynth open failure:
    Script error: Invalid arguments to function "Animate"
    The errors are coming from the following lines:
    Code:
    ovl1Z = ovl1.Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    Code:
    \ )
    Originally Posted by raffriff42 View Post
    >1. How do I apply the zoom to just the ovl1 portion of my clip?
    Not sure what you mean
    What I meant was that I want to have the zoom start and end on the specific shot which ovl1 replaces, rather than the beginning of the video.
    Quote Quote  
  10. OK this script "works" in that it does not raise an error.
    Diagnostic & temporary code left in, in case it helps you.
    EDIT - I exaggerated the zoom & pan for testing purposes.
    Code:
    clip1 = ColorBarsHD(width=640, height=400)
    clip2 = clip1.Invert.FlipVertical
    
    ovl1 = clip1.ColorYUV(showyuv=true)
    ovl1 = ovl1.BilinearResize(clip1.Width, clip1.Height)
    \          .Subtitle("O", size=0.9*ovl1.Height, align=2)
    \          .Letterbox(8, 8, 8, 8)
    
    clip1 = clip1.ConvertToRGB
    clip2 = clip2.ConvertToRGB
    ovl1  = ovl1.ConvertToRGB
    #return ovl1
    
    clip1 = clip1.ConvertToRGB.ShowFrameNumber(x=16, y=24)
    clip2 = clip2.ConvertToRGB.ShowFrameNumber(x=16, y=80)
    ovl1  = ovl1.ConvertToRGB.ShowFrameNumber(x=16, y=160)
    
    #ovl1Z = ovl1.Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    #
    #ovl1M = BlankClip(ovl1, color=$ffffff)
    #\       .Animate(2, 158, "myfunc", 1.3554456019, 1.0)
    
    ovl1Z = ovl1.Animate(2, 158, "SimpleZoomBox", 
    \    2.0, -3.0,  0.0, [* start zoom, pan, tilt *]
    \    0.5,  0.5,  0.0  [*  end  zoom, pan, tilt *]
    \ ) #.Trim(0, length=160)
    
    ovl1M = BlankClip(ovl1, color=$ffffff)
    \           .Animate(2, 158, "SimpleZoomBox", 
    \    2.0, -3.0,  0.0, [* start zoom, pan, tilt *]
    \    0.5,  0.5,  0.0  [*  end  zoom, pan, tilt *]
    \ ) #.Trim(0, length=160)
    #return ovl1M
    
    clip1.Trim(25189,25346).Overlay(ovl1Z, mask=ovl1M)
    ovl1clip = Last
    #return Last
    
    clip2.Trim(25,2720).FadeOut0(19) + \
    clip1.Trim(2696,25188) + \
    ovl1clip + \
    clip1.Trim(25347,0)
    return Last
    Image
    [Attachment 45073 - Click to enlarge]


    Image
    [Attachment 45074 - Click to enlarge]
    Last edited by raffriff42; 1st Apr 2018 at 18:19.
    Quote Quote  
  11. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Thanks again, but I'm still getting the same error with this:
    Code:
    \ )
    Quote Quote  
  12. Complete script please? Are you using the script I posted above? It does not have that line...

    The line closes parentheses from a function call above it when arguments are placed on separate lines. For example:
    Code:
    a = x(
    \   y, 
    \   z
    \ )
    you can also write
    Code:
    a = x(
    \   y, 
    \   z)
    or
    Code:
    a = x(y, z)
    if you want. but
    Code:
    a = x(y, z)
    \ )
    is an error; it is equivalent to
    Code:
    a = x(y, z) )
    Last edited by raffriff42; 1st Apr 2018 at 22:53.
    Quote Quote  
  13. Member
    Join Date
    Sep 2008
    Location
    United States
    Search Comp PM
    Originally Posted by raffriff42 View Post
    Complete script please? Are you using the script I posted above? It does not have that line...
    Yeah, I was using the script you posted above in post #11. This is the complete line giving me the error:
    Code:
    \ ) #.Trim(0, length=160)
    Quote Quote  
  14. This
    Code:
    \ ) #.Trim(0, length=160)
    ...is not a complete "line" in AviSynth. The backslash is a line continuation character, so what follows is part of the line above it. (link)

    The "Invalid arguments to function X" error is very annoying. You need to check all arguments and make sure they are the right type (clip, string, float or int) as per the function declaration. (link)

    For example, to check the first argument to Animate, you need to verify that the first argument, ovl1 , contains a valid clip at that point in the script:
    Code:
    return ovl1
    ovl1Z = ovl1.Animate(2, 158, "SimpleZoomBox", 
    \    2.0, -3.0,  0.0, [* start zoom, pan, tilt *]
    \    0.5,  0.5,  0.0  [*  end  zoom, pan, tilt *]
    \ ) #.Trim(0, length=160)
    If it is confirmed to be a valid clip, then you need to check each of the other arguments.
    Last edited by raffriff42; 2nd Apr 2018 at 16:31.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!