VideoHelp Forum




+ Reply to Thread
Results 1 to 9 of 9
  1. Hi,

    First, sorry for my bad english.

    I'm trying to do an avisynth function and i have a crash when i use it (no error log ).

    Here is the code :

    Code:
    function Incruster(clip film, string "image", int "abs", int "ord", int "start", int "end", float "fade")
    {
    
    fps=film.FrameRate
    fade=Default(fade, 0)
    fade=Round(fps*fade)
    
    incrust=ImageSource(image, pixel_type="RGB32")
    film1=film.Trim(0, start-1)
    film2=film.Trim(start, end)
    film3=film.Trim(end+1, film.FrameCount-1)
    
    film2b=Overlay(film2,incrust,mask=incrust.ShowAlpha().Trim(start,end).FadeIO0(fade),x=abs,y=ord)
    
    v=film1++film2b++film3
    
    return(v)
    }
    This function should make an overlay on a video with a transparent PNG file and make this overlay appears only after "start" and before "end" with fading in and out.


    And this is the script i use for avsproxy :

    Code:
    film=AVISource("C:\01.avi")
    film=film.Incruster(image="C:\01.png", abs=0, ord=0, start=1000, end=3000, fade=1.5)
    Can anyone tell me what's wrong ?
    Quote Quote  
  2. Does it work if you open it in a media player or VirtualDub?

    Add "return(film)". Otherwise AviSynth will attempt to return last (the default video name).

    film=AVISource("C:\01.avi")
    film=film.Incruster(image="C:\01.png", abs=0, ord=0, start=1000, end=3000, fade=1.5)
    return(film)
    Can AviDemux open AVS scripts? Not all programs can.
    Last edited by jagabo; 2nd Jun 2011 at 19:38.
    Quote Quote  
  3. AVIDemux use a small program called AVSProxy to read AVS scripts.

    Oh, adding return(film) to the AVS script solved this issue, thanks !

    Now, just something to change in this function and it'll be ok
    Quote Quote  
  4. Hum, now there is still one problem. Here it is :

    I want to display an overlay from frame 1000 to frame 3000 so here is my AVS script :

    Code:
    film=AVISource("C:\01.avi")
    film=film.Incruster(image="C:\01.png", abs=0, ord=0, start=1000, end=3000, fade=1.5, verbose=true)
    return(film)
    And here is my function :

    Code:
    function Incruster(clip film, string "image", int "abs", int "ord", int "start", int "end", float "fade", bool "verbose")
    {
    
    fps=film.FrameRate
    fade=Default(fade, 0)
    fade=Round(fps*fade)
    
    incrust=ImageSource(image, pixel_type="RGB32")
    film1=film.Trim(0, start-1)
    film2=film.Trim(start, end)
    film3=film.Trim(end+1, film.FrameCount-1)
    
    film2b=Overlay(film2,incrust,mask=incrust.ShowAlpha().FadeIO0(fade),x=abs,y=ord)
    
    v=film1++film2b++film3
    
    verbose = Default(verbose, false)
    v = verbose ? v.Show(start, end, abs, ord, fade) : v
    
    return(v)
    }
    
    function Show (clip v, int "start", int "end", int "abs", int "ord", int "fade")
    {
    i = 10
    v= v.subtitle("Overlay from "+start.string +" to "+end.string, 10,i)
    i = i+20
    v = v.subtitle("Display (x,y) = ("+abs.string +","+ord.string+")", 10,i)
    i = i+20
    v = v.subtitle("Fading = "+fade.string+" frame(s)", 10,i)
    
    return(v)
    }
    Verbose mode returns :

    Overlay from 1000 to 3000
    Display (x,y) = (0,0)
    Fading = 36 frame(s)
    36 frames because my movie is 23.976fps.

    Now, in fact, overlay really appears from frames 1000 to 2000 and i don't know why...
    Last edited by Khyinn; 3rd Jun 2011 at 03:30. Reason: remove useless code
    Quote Quote  
  5. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by Khyinn View Post
    Hum, now there is still one problem.
    overlay really appears from frames 1000 to 2000 and i don't know why...
    That's because ImageSource by default gives you a clip of 1001 frames.
    Change the definition of incrust to:
    incrust=ImageSource(image, pixel_type="RGB32", start=start, end=end)

    Incidentally, your function suffers from a common problem when using Trim with variable arguments - it will not work if called with start=1 (can you see why?).
    Replace
    film1=film.Trim(0, start-1)
    by
    film1=film.Trim(0, -start)

    Actually, it won't work for start=0 either, or ending at the last frame.
    If those cases may be required, you need to add extra logic to handle them.

    Originally Posted by jagabo View Post
    Add "return(film)". Otherwise AviSynth will attempt to return last (the default video name).
    The solution is correct, but the explanation is not.
    It's a common myth that 'last' is returned by default. If the last statement is an assignment, a void value (equivalent to a defaulted parameter) is returned, even if 'last' was previously set.
    Quote Quote  
  6. Thank you so much Gavino for all your explanations, now it works as intended.

    Don't need to start at 0 or ending on the last frame but if you have time to modify this function for those who need this, please do it.

    Here is my final function :

    Code:
    function Incruster(clip film, string "image", int "abs", int "ord", int "start", int "end", float "fade", bool "verbose")
    {
    
    fps=film.FrameRate
    fade=Default(fade, 0)
    fade=Round(fps*fade)
    
    incrust=ImageSource(image, pixel_type="RGB32", start=start, end=end)
    film1=film.Trim(0, -start)
    film2=film.Trim(start, end)
    film3=film.Trim(end+1, 0)
    
    film2b=Overlay(film2,incrust,mask=incrust.ShowAlpha().FadeIO0(fade),x=abs,y=ord)
    
    v=film1++film2b++film3
    
    verbose = Default(verbose, false)
    v = verbose ? v.Show(start, end, abs, ord, fade) : v
    
    return(v)
    }
    
    function Show (clip v, int "start", int "end", int "abs", int "ord", int "fade")
    {
    i = 10
    v= v.subtitle("Overlay from "+start.string +" to "+end.string, 10,i)
    i = i+20
    v = v.subtitle("Display (x,y) = ("+abs.string +","+ord.string+")", 10,i)
    i = i+20
    v = v.subtitle("Fading = "+fade.string+" frame(s)", 10,i)
    
    return(v)
    }
    Quote Quote  
  7. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by Khyinn View Post
    Don't need to start at 0 or ending on the last frame but if you have time to modify this function for those who need this, please do it.
    The simplest way to do it is to replace the line
    v=film1++film2b++film3
    by
    v = start > 0 ? film1++film2b : film2b
    v = end+1 < film.Framecount ? v++film3 : v
    Quote Quote  
  8. Thanks, so the really really final function :

    Code:
    function Incruster(clip film, string "image", int "abs", int "ord", int "start", int "end", float "fade", bool "verbose")
    {
    fps=film.FrameRate
    fade=Default(fade, 0)
    fade=Round(fps*fade)
    
    incrust=ImageSource(image, pixel_type="RGB32", start=start, end=end)
    film1=film.Trim(0, -start)
    film2=film.Trim(start, end)
    film3=film.Trim(end+1, 0)
    
    film2b=Overlay(film2,incrust,mask=incrust.ShowAlpha().FadeIO0(fade),x=abs,y=ord)
    
    v = start > 0 ? film1++film2b : film2b
    v = end+1 < film.Framecount ? v++film3 : v
    
    verbose = Default(verbose, false)
    v = verbose ? v.Show(start, end, abs, ord, fade) : v
    
    return(v)
    }
    
    function Show (clip v, int "start", int "end", int "abs", int "ord", int "fade")
    {
    i = 10
    v = v.subtitle("Overlay from "+start.string +" to "+end.string, 10,i)
    i = i+20
    v = v.subtitle("Display (x,y) = ("+abs.string +","+ord.string+")", 10,i)
    i = i+20
    v = v.subtitle("Fading = "+fade.string+" frame(s)", 10,i)
    
    return(v)
    }
    Quote Quote  
  9. Originally Posted by Gavino View Post
    Originally Posted by jagabo View Post
    Add "return(film)". Otherwise AviSynth will attempt to return last (the default video name).
    The solution is correct, but the explanation is not.
    It's a common myth that 'last' is returned by default. If the last statement is an assignment, a void value (equivalent to a defaulted parameter) is returned, even if 'last' was previously set.
    Thanks for that clarification. That explains something I saw the other day when debugging a script.
    Quote Quote  



Similar Threads

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