Log in

View Full Version : Scroll in and fade in a subtitle at the same time?


pinkshiro
1st May 2010, 00:22
I have looked through the documentation for Subtitle and have nutted my way through SubtitleEx (although I can't find any documentation on this one).

Subtitle + Animate will allow me to scroll text in from the left or right of the screen, like so:

title=bg.Animate(0,10,"Subtitle", \
"Hello World!",100,100,0,15,"Comic Sans MS",40,$00FF00,$000000,5,0,0,\
"Hello World!",100,400,0,15,"Comic Sans MS",40,$00FF00,$000000,5,0,0)


SubtitleEx will let me fade in the text...

Is there an way to combine the effects?

Gavino
1st May 2010, 00:46
SubtitleEx can do both fading and moving at the same time using
SubtitleEx(..., effects="f(...)m(...)")

For details, see documentation which can be found here (http://avisynth.org/warpenterprises/files/dvutilities_20050717.zip).

pinkshiro
1st May 2010, 00:48
Excellent! Thanks so much for that documentation, couldn't find it anywhere.

pinkshiro
1st May 2010, 02:11
Instead of making an additional thread I will just add this related question:

SubtitleEx is great, works really well.

My subtitles are going to have backgrounds, which are also going to fade in the same way that my subtitle is going to fade in.

E.g. if my subtitle is scrolling in from off screen left to right, then the background will do the same thing.

What is the best method for this? I have been playing around with the following code, which imports a PNG (with some transparency) and overlays it onto the main video:

Logo=ImageSource("stjohn/footer.png", end = 104, use_DevIL=false).ConvertToRGB32()

LogoMask = ImageReader("stjohn/footer.png",pixel_type="RGB32").ShowAlpha(pixel_type="RGB32")

Mask = Mask.KenBurnsEffect(startFrame=0, endFrame=10, KeepState=false, startPanX=-640, endPanX=0)

Mask = Mask.KenBurnsEffect(startFrame=70, endFrame=80, KeepState=false, startPanX=0, endPanX=-640)

Logoheight = Height(Logo)

FinalVideo = Overlay(FinalVideo, Logo, 0, (H-Logoheight), mask=Mask)

There are some obvious problems with the code above. As soon as the mask has does it's final scroll OUT of view, the overlayed PNG pops back to it's original position instead of staying hidden.

What I essentially want is to have a background to my subtitle which only appears when I need it. Don't want it overlayed for the entire length of the original video. Any thoughts?

pinkshiro
1st May 2010, 07:04
I've done some further changes to the above script to handle background images for my subtitles:


#Cut up Final video into three chunks.

TransLength = 10 #Transition Length
StartPoint = 30 #Starting point for subtitle
EndPoint = 100 #Ending point for subtitle

Cut1 = Trim(FinalVideo, 0, (StartPoint))
Cut2 = Trim(FinalVideo, StartPoint+1, EndPoint)
Cut3 = Trim(FinalVideo, EndPoint+1, 0)

Logo=ImageSource("stjohn/footer.png", end = 104, use_DevIL=false).ConvertToRGB32()

#Create a mask for the logo
LogoMask = ImageReader("stjohn/footer.png",pixel_type="RGB32").ShowAlpha(pixel_type="RGB32")

LogoMask = LogoMask.KenBurnsEffect(startFrame=0, endFrame=10, KeepState=false, startPanX=-640, endPanX=0)

LogoMask = LogoMask.KenBurnsEffect(startFrame=60, endFrame=70, KeepState=false, startPanX=0, endPanX=-640)


#Logo width and height
Logowidth = Width(Logo)
Logoheight = Height(Logo)


Cut2 = Overlay(Cut2, Logo, 0, (H-Logoheight), mask=LogoMask)

FinalVideo = Cut1 + Cut2 + Cut3

FinalVideo = FinalVideo.SubtitleEx("Life Begins at 60 at St Johns Road", x=50, y=340, firstframe=30, lastframe=100, effects = "b,f(10,10), m(10,-590, 340, 10, -590, 340)", textcolor = $00FFFFFF, halocolor = $FF000000, size=20, font="Myriad Pro" )


If there is a better way to doing this, I am all ears.

Gavino
1st May 2010, 08:05
There are some obvious problems with the code above. As soon as the mask has does it's final scroll OUT of view, the overlayed PNG pops back to it's original position instead of staying hidden.
I think you can cure that by removing KeepState=false from the KenBurnsEffect, so the mask remains scrolled off.

However, it is more efficient anyway to restrict the Overlay to just the frames in question, as you have done with the Trim approach in your follow-up post.

Jenyok
15th February 2012, 15:27
Didee
Gavino

Questions.

How to determinate in pix font width if I know font height in pix, for example, font_height = 100 pix, which is font_width = pix ?
Has any font ratio between font height and font width in pix ? Which is this ratio ?

See working result of script.
For you usage, if needed.


LoadPlugin("C:\PROGRAM FILES (X86)\AVISYNTH 2.5\PLUGINS\GSCRIPT_11\gscript.dll")
LoadPlugin("C:\PROGRAM FILES (X86)\AVISYNTH 2.5\PLUGINS\SUBTITLEEX_25_DLL_20040819\subtitleex.dll")

#Import("utils2.avs")



AnimateString1 = "JenyokC" # 7
AnimateString2 = "Jenyok" # 6
#AnimateString3 = "ЦЕНТРНАУЧФИЛЬМ" # 14

AnimateString3 = "ANTIMILITARISTIC" # 16 characters long
#AnimateString4 = "ANTHROPOLOGICAL" # 15 characters long

MinHeight = 30
MaxHeight = 115

xx = 50
yy = 500

ef = "cb"
SH = 1.80

WorkString = AnimateString3
#WorkString = AnimateString4

LengthString = StrLen(WorkString)
OddString = LengthString % 2

WrkStr = ""
Step = Ceil(LengthString / 2.0)
StepHeight = Int((MaxHeight - MinHeight) / Step)


BlankClip(length=250, width=768, height=576)



GScript("""
WrkSize = MaxHeight
WrkSize1 = 0
for (i=1, LengthString, 1) {
WrkStr = MidStr(WorkString, i, 1)
if (i == 1) {
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
else {
if (i == LengthString) {
WrkSize = MaxHeight
xx = xx + Int(WrkSize/SH)
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
else {
if (OddString > 0) {
if (i == Step) {
WrkSize1 = WrkSize - StepHeight
WrkSize = MinHeight
xx = xx + Int(WrkSize1/SH)
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
WrkSize = WrkSize1
}
if (i < Step) {
xx = xx + Int(WrkSize/SH)
WrkSize = WrkSize - StepHeight
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
if (i > Step) {
WrkSize = WrkSize + StepHeight
xx = xx + Int(WrkSize/SH)
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
}
if (OddString == 0) {
if ((i == Step) || (i == Step + 1)) {
WrkSize1 = WrkSize
WrkSize = MinHeight
if (i == Step + 1) {
WrkSize1 = WrkSize1 - StepHeight
xx = xx + Int(WrkSize/SH)
}
else {
xx = xx + Int(WrkSize1/SH)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
WrkSize = WrkSize1
}
if (i < Step) {
xx = xx + Int(WrkSize/SH)
WrkSize = WrkSize - StepHeight
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
if (i > Step + 1) {
WrkSize = WrkSize + StepHeight
xx = xx + Int(WrkSize/SH)
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=ef, size=WrkSize, textcolor=$00FFFFFF, halocolor=$00000000)
}
}
}
}
WrkStr = ""
WrkSize1 = 0
}
""")

ConvertToYUY2()

Gavino
15th February 2012, 18:29
How to determinate in pix font width if I know font height in pix, for example, font_height = 100 pix, which is font_width = pix ?
Has any font ratio between font height and font width in pix ? Which is this ratio ?
There is no fixed ratio - it depends entirely on the font used.
Moreover, most fonts are variable width, so width is not the same for all characters ('m' is wider than 'i', for example).

Jenyok
15th February 2012, 19:09
Gavino

Thanks.

StainlessS
16th February 2012, 03:59
"Courier New" is a monospaced font.

Jenyok
16th February 2012, 11:45
New version.
See working result of script (very interesting).
For you usage, if needed.


LoadPlugin("C:\PROGRAM FILES (x86)\AVISYNTH 2.5\PLUGINS\GSCRIPT_11\gscript.dll")
LoadPlugin("C:\PROGRAM FILES (x86)\AVISYNTH 2.5\PLUGINS\SUBTITLEEX_25_DLL_20040819\subtitleex.dll")


function MessageClipEx2(clip clp, string text, int "xx", int "yy", float "hy", \
int "first_frame", int "last_frame", string "font", \
string "effects", int "size_min", int "size_max", \
int "text_color", int "halo_color")
{
# SubtitleEx(
# clip clp
# string text,
# int "x",
# int "y",
# int "firstframe",
# int "lastframe",
# string "font",
# string "effects",
# int "size",
# int "textcolor",
# int "halocolor")

size_max = Default(size_max, 80)
size_min = Default(size_min, 40)
hy = Default(hy, 1.70)
xx = Default(xx, 50)
yy = Default(yy, 100)
text_color = Default(text_color, $00FFFFFF) # White color text by default...
halo_color = Default(halo_color, $00000000) # Halo color background by default...

last = clp

size_max = (size_max == size_min) ? size_max + size_min : size_max
LengthString = StrLen(text)
Step = Ceil(LengthString / 2.0)
StepHeight = Int((size_max - size_min) / (Step - 1))
WrkSize = size_max
WrkStr = ""

GScript("""
for (i = 1, LengthString, 1) {
WrkStr = MidStr(text, i, 1)
if (i == 1) {
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=size_max, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
else {
if (i == LengthString) {
if (size_max > size_min) {
xx = xx + Int(size_max / hy)
}
if (size_max < size_min) {
xx = xx + Int(WrkSize / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=size_max, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
else {
if ((LengthString % 2) > 0) {
if (i == Step) {
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
WrkSize = WrkSize - StepHeight
if (size_max < size_min) {
xx = xx + Int(size_min / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=size_min, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
if (i < Step) {
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
WrkSize = WrkSize - StepHeight
if (size_max < size_min) {
xx = xx + Int(WrkSize / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=WrkSize, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
if (i > Step) {
if (size_max < size_min) {
xx = xx + Int(WrkSize / hy)
}
WrkSize = WrkSize + StepHeight
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=WrkSize, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
}
if ((LengthString % 2) == 0) {
if ((i == Step) || (i == Step + 1)) {
if (i == Step) {
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
if (size_max < size_min) {
xx = xx + Int(size_min / hy)
}
}
else {
WrkSize = WrkSize - StepHeight
xx = xx + Int(size_min / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=size_min, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
if (i < Step) {
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
WrkSize = WrkSize - StepHeight
if (size_max < size_min) {
xx = xx + Int(WrkSize / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=WrkSize, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
if (i > Step + 1) {
if (size_max < size_min) {
xx = xx + Int(WrkSize / hy)
}
WrkSize = WrkSize + StepHeight
if (size_max > size_min) {
xx = xx + Int(WrkSize / hy)
}
SubTitleEx(last, WrkStr, x=xx, y=yy, effects=effects, size=WrkSize, textcolor=text_color, halocolor=halo_color, \
firstframe=first_frame, lastframe=last_frame, font=font)
}
}
}
}
WrkStr = ""
}
""")

clp = last

return clp
}


AnimateString1 = "JenyokC" # 7
AnimateString2 = "Jenyok" # 6
AnimateString3 = "ЦЕНТРНАУЧФИЛЬМ" # 14

AnimateString4 = "ANTIMILITARISTIC" # 16 characters long
AnimateString5 = "ANTHROPOLOGICAL" # 15 characters long


xx = 52
hy = 1.88

xx1 = 25
hy1 = 1.88

sm = 124 # 143
sn = 40

sm1 = 30
sn1 = 134 # 150

BlankClip(length=250, width=768, height=576)


MessageClipEx2(AnimateString4, xx=xx, yy=146, size_min=sn, size_max=sm, hy=hy, effects="cb")
MessageClipEx2(AnimateString4, xx=xx1, yy=323, size_min=sn1, size_max=sm1, hy=hy1, effects="cb")
MessageClipEx2(AnimateString4, xx=xx, yy=496, size_min=sn, size_max=sm, hy=hy, effects="cb")