VideoHelp Forum
+ Reply to Thread
Results 1 to 3 of 3
Thread
  1. Member
    Join Date
    May 2012
    Location
    Argentina
    Search PM
    Hi, I am trying to do this in AviSynth: static background + title zooming in.

    I tried using "animate()" (as the wiki says) but the result of this is a really choppy zoom (I guess it is because of font sizes getting "snapped" to some values).

    Code:
    BlankClip(width=320, height=240)
    return Animate(0,48,"Subtitle", "Hello, World!",160,120,0,99999,"Arial",0,
      \  "Hello, World!",25,130,0,99999,"Arial",48)
    So then I searched and found a script called "KenBurnsEffect", which works nice. The problem is that I need to render the subtitle into a temporary surface (otherwise I get the effect in the background too), and subtitle() doesn't modify the alpha value of the pixels, so to blend it into the background, I need to create a mask.

    Code:
    bg = ImageSource("test.png", end=100, fps=30).convertToRGB32()
    
    blank = BlankClip(length=100, width=640, height=360, pixel_type="RGB32", color=$000000, fps=30)
    white = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$00FF00, halo_color=$000000, align=5)
    alpha = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$FFFFFF, halo_color=$000000, align=5)
    return Overlay(bg, white, mask=alpha)
    The problem is that Overlay does "non pre-multiplied alpha" (aka Flat matte) blending, so the subtitles appear with a black outline (undesired):



    My solution is to manually do the premultiplied alpha blending (using a multiply of the background with the inverse of the alpha and then an addition to the foreground):

    Code:
    bg = ImageSource("test.png", end=100, fps=30).convertToRGB32()
    
    blank = BlankClip(length=100, width=640, height=360, pixel_type="RGB32", color=$000000, fps=30)
    white = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$00FF00, halo_color=$000000, align=5)
    alpha = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$FFFFFF, halo_color=$000000, align=5).invert("RGB")
    return Overlay(Overlay(bg,alpha,mode="multiply"), white, mode="add")


    This works perfectly, but I'm guessing there has to be a simpler way to perform that...

    Thanks,
    Gzaloprgm
    Quote Quote  
  2. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    A workaround for jerkiness/positioning might be to uprez+uprateconvert the footage prior to adding the text/subs being animated, then downrezzing+downrateconverting after. Yes it is a quality compromise, but it will get you smooth sub-pixel positioning.

    There are probably other workarounds as well...Gavino? jagabo?...

    Scott
    Quote Quote  
  3. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by gzaloprgm View Post
    This works perfectly, but I'm guessing there has to be a simpler way to perform that...
    The problem is actually due to the way the halo_color interacts with the anti-aliasing performed by Subtitle().
    The solution is to set the halo_color to the same as the text_color in the first Subtitle call.
    Code:
    bg = ImageSource("test.png", end=100, fps=30).convertToRGB32()
    blank = BlankClip(length=100, width=640, height=360, pixel_type="RGB32", color=$000000, fps=30)
    white = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$00FF00, halo_color=$00FF00, align=5)
    alpha = blank.Subtitle("Test Subtitle", x=320, y=180, size=40, text_color=$FFFFFF, halo_color=$000000, align=5)
    return Overlay(bg, white, mask=alpha)
    Since you are using RGB, you could also replace the last line by (faster and better quality):
    return Layer(bg, white.Mask(alpha))

    Regarding the jerky zooming, use floating point instead of integer for the positions to allow the animation to perform a smooth interpolation and allow Subtitle to use sub-pixel positioning.
    Code:
    BlankClip(width=320, height=240)
    return Animate(0,48,"Subtitle", "Hello, World!",160.0,120.0,0,99999,"Arial",0,
     \  "Hello, World!",25.0,130.0,0,99999,"Arial",48)
    although there may still be jerkiness (in size) if fonts are not available for all point sizes.
    Quote Quote  



Similar Threads

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