Log in

View Full Version : Subtitle() - Alpha channel?


NoX1911
13th April 2011, 02:18
Hallo,
why don't i get an alpha channel from Subtitle()? I want to do some effects with Overlay(). How is it meant to be done?

src = ColorBars(320, 240)

text1 = Blankclip(src, length=1, color=$00ff0000, pixel_type="RGB32").Subtitle("-= Text1 =-", y=src.height()-60, size=24, text_color=$00ffff00, align=2)

O1=text1.Loop(200).FadeIO0(50).FadeIO0(50).FadeIO(50)

#text1.loop(50)
ShowAlpha(text1).loop(50)
#Overlay(src, O1, mask=ShowAlpha(text1))

Avisynth 2.5.8
Windows7 32Bit

IanB
13th April 2011, 03:37
Subtitle uses the top 8 bits, 0xFF000000, of the colour values to specify transparency for the text painting process. It never paints the Alpha channel in RGB32 format. You need to manually build your alpha mask clip from painted colour channels. In the example above you probably do not want any ShowAlpha() calls.

0xFF000000 specifies a fully transparent colour. 0x00rrggbb specifies a fully opaque rgb value.

Examples of use :- Text_color=0xFF000000 , Halo_color=0x40FFFF00 => Transparent text with a 25% transparent (75% opaque) yellow halo (1 pixel border).

NoX1911
13th April 2011, 18:41
Thanks, works. Its a simple video titler (fade in/out, 3 lines).
I'm wondering if there is already a collection/library of simple text effects for video titling.

src = colorbars(640,480).ShowSMPTE(y=30)

FPS=25 # for correct subs timing
line1="Line1 *** Line1 *** Line1"
line2="Line2 ***** Line2 ***** Line2 ***** Line2"
line3="Line3 * Line3 * Line3 * Line3 * Line3 * Line3"

l1col=$ffffff # Line1 color $RGB
l2col=$ffffff # Line2 color $RGB
l3col=$ffff00 # Line3 color $RGB

fsize=24 # Font size
fspace=25 # Font line space
offset=0 # Subs start time offset (frames)
dura=5 # Subs duration (seconds)
Tfade=1.0 # Subs fading time (1*x speed)

####################################################################################

text1 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line1, y=src.height()-(10+fspace*2), size=fsize, text_color=l1col, align=2)
text2 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line2, y=src.height()-(10+fspace), size=fsize, text_color=l2col, align=2)
text3 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line3, y=src.height()-10, size=fsize, text_color=l3col, align=2)

alpha1 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line1, y=src.height()-(10+fspace*2), size=fsize, halo_color=$ffffff, text_color=$ffffff, align=2)
alpha2 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line2, y=src.height()-(10+fspace), size=fsize, halo_color=$ffffff, text_color=$ffffff, align=2)
alpha3 = Blankclip(src, length=1, color=$00000000, pixel_type="RGB32").Subtitle(line3, y=src.height()-10, size=fsize, halo_color=$ffffff, text_color=$ffffff, align=2)

# non-linear fades (smoother in/out)
O1=Blankclip(alpha1,1+offset)+alpha1.Loop(fps*dura).FadeIO0(round(fps/Tfade)).FadeIO0(round(fps/Tfade)).FadeIO(round(fps/Tfade))
O2=Blankclip(alpha1,3+offset)+alpha2.Loop(fps*dura).FadeIO0(round(fps/Tfade)).FadeIO0(round(fps/Tfade)).FadeIO(round(fps/Tfade))
O3=Blankclip(alpha1,5+offset)+alpha3.Loop(fps*dura).FadeIO0(round(fps/Tfade)).FadeIO0(round(fps/Tfade)).FadeIO(round(fps/Tfade))

Overlay(src, text1, mask=O1)
Overlay(last, text2, mask=O2)
Overlay(last, text3, mask=O3)

Gavino
13th April 2011, 18:59
I'm wondering if there is already a collection/library of simple text effects for video titling.
There is the SubtitleEx plugin:
http://avisynth.org/warpenterprises/files/subtitleex_25_dll_20040819.zip
Documentation:
http://avisynth.org/warpenterprises/files/dvutilities_20050717.zip

NoX1911
13th April 2011, 20:21
Nice, even with dynamic fading effects. Thanks.

IanB
13th April 2011, 23:16
NoX1911,

Overlay() is a pretty heavy function, in your original script it would be much more efficient to build a total text overlay and alpha mask first then use a single Overlay() call to apply it in a single call.

The Fade*() functions are canned examples of Dissolve() with a blank/silent clip.

You can use Dissolve() between a clip and a texted version of that clip to have the text fade in and/or out.

Like stacking Fade's you can stack Dissolve's to effect the transition curve.

Thus a more efficient implementation could be (math errors excepted) :-...

Ffade = round(fps/Tfade)
Fdura = round(fps*dura)

Src1 = src.Trim(0, -offset-Ffade) # Src from start to end of fade in
Src3 = src.Trim(offset+Ffade+Fdura, 0) # Src from start of fade out to end

src # Source to paint text onto

Subtitle(line1, y=src.height()-(10+fspace*2), size=fsize, text_color=l1col, align=2)
Subtitle(line2, y=src.height()-(10+fspace), size=fsize, text_color=l2col, align=2)
Subtitle(line3, y=src.height()-10, size=fsize, text_color=l3col, align=2)

# non-linear fades (smoother in/out)

TextA = Trim(offset, -Ffade-Fdura-Ffade) # Texted src from start of fade in to end of fade out
Dissolve(Src1, TextA, Src3, Ffade)

TextB = Trim(offset, -Ffade-Fdura-Ffade) # Faded texted src from start of fade in to end of fade out
Dissolve(Src1, TextB, Src3, Ffade)

TextC = Trim(offset, -Ffade-Fdura-Ffade) # Double faded texted src from start of fade in to end of fade out
Dissolve(Src1, TextC, Src3, Ffade)

AudioDub(Src) # Put back unfaded audio track

NoX1911
14th April 2011, 21:55
Indeed, much faster. Runs in realtime now. Will use this.

Thanks! :)