View Full Version : Subtitle - Align Middle?
zerowalker
16th May 2013, 17:49
I was wondering if itīs possible to align subtitle text to the middle of the screen.
I know that align 5 seems to do it, But, it doesnīt work if i use more rows than 1, the other rows just keep going down.
So i wonder if there is a way to keep it all aligned no matter lines?
creaothceann
16th May 2013, 18:55
global LineHeight = 16
BlankClip(240, 640, 480, "YV12", 30000, 1001)
Sub(5, 1, "1")
Sub(5, 2, "2")
Sub(5, 3, "3")
Sub(5, 4, "4")
Sub(5, 5, "5")
function Sub(clip c, int LineCount, int curLine, string Text) {
c
Subtitle(Text, -1, ((Height - (LineCount * LineHeight)) / 2) + ((curLine - 1) * LineHeight), align=8)
}
Or you could just use AegiSub and .ass subtitles.
zerowalker
16th May 2013, 19:01
Interesting thanks.
How does it work with Aegisub?
creaothceann
16th May 2013, 19:54
You start the program, select "Video | Use Dummy Video..." or load an external video (actual file or .avs script), enter the text in the box to the right of the video display ("\N" is a linebreak), set start and ending times/frames and save to a .ass file when you're done entering lines. (You can also set the font with the "S" button in the toolbar; that's where the option to align the text is.)
Then create a new script (or edit the current one), and add a call to TextSub (either via VSFilter.dll (http://avisynth.org.ru/docs/english/externalfilters/vsfilter.htm) or the fork (http://code.google.com/p/xy-vsfilter/)).
Overdrive80
16th May 2013, 20:19
Interesting thanks.
How does it work with Aegisub?
For aegisub you have use tags as {\a10}middlle x, middle y
StainlessS
17th May 2013, 12:35
An easy way to automatically count newlines in Subtitle text is to use the RT_Stats RT_StrReplace to delete "\n" flags
and measure the difference in string length.
EDIT: but you would need to ensure that each and every line had
a "\n" flag.
StainlessS
17th May 2013, 15:40
Try this as a line counter.
Function CountSubtitleLines(String s) {
s=RT_StrReplace(s,"\n",Chr(10),Sig=false) # replace String case Insignificant
Return RT_TxtQueryLines(s) # Line count with/without final newline
}
ColorBars()
# Test
s="The\ncat\nsat\non\Nthe\Nmat"
s2=s+"\n"
x=CountSubtitleLines(s)
y=CountSubtitleLines(s2)
RT_Debug("S="+S,String(x))
RT_Debug("S2="+S2,String(y))
Subtitle("X="+String(x)+" Y="+String(y))
return Last
DebugView
00000011 38.76157379 [2272] RT_Debug: S=The\ncat\nsat\non\Nthe\Nmat 6
00000012 38.76282501 [2272] RT_Debug: S2=The\ncat\nsat\non\Nthe\Nmat\n 6
zerowalker
17th May 2013, 16:08
I am not sure if it works, i get the colorbars, but thatīs it.
StainlessS
17th May 2013, 17:08
It's writing output to DebugView window, you need debugview from SysInternals (MicroSoft).
EDIT: Added a subtitle line to show return values. Debugview is very handy to have though.
EDIT: Here DebugView
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
zerowalker
17th May 2013, 17:24
Ah okay.
But how do i use it on Subtitle()?
AS itīs just returning values from the s variable.
Thanks
StainlessS
17th May 2013, 17:30
It was really intended for creaothceann's Sub() function, to do away with having to provide line count as an argument.
Or, it could be implemented to default to auto calc mode if not user supplied (so it would not break existing scripts).
zerowalker
17th May 2013, 19:13
Canīt it be implemented into Subtitle(), and ad an argument "Always in middle=true" or something?
StainlessS
17th May 2013, 21:10
Give this a whirl
#Avisource("D:\avs\test.avi")
ColorBars()
Function SubV(clip c, string text, float "x", float "y", int "first_frame", int "last_frame", string "font", float "size", \
int "text_color", int "halo_color", int "align", int "spc", int "lsp", float "font_width", float "font_angle", bool "interlaced", \
bool "vcenter") { # http://forum.doom9.org/showthread.php?p=1628899#post1628899
c
# GScript("""
size=Default(size,18)
vcenter=Default(vcenter,false)
if(Defined(align) && Defined(lsp)) {
if((align>=4 && align<=6) && vcenter) { # vertical central justification.
s=RT_StrReplace(text,"\n",Chr(10),Sig=false)
Lines = RT_TxtQueryLines(s) # Line count with/without final newline
y=(Height/2) - ((Lines-1) * (size + lsp/8.0) / 2.0)
} else if(align>=1 && align<=3) { # vertical bottom justification.
s=RT_StrReplace(text,"\n",Chr(10),Sig=false)
Lines = RT_TxtQueryLines(s) # Line count with/without final newline
y=Height - ((Lines-1) * (size + lsp/8.0))
}
}
# """)
Subtitle(text,x,y,first_frame,last_frame,font,size,text_color,halo_color,align,spc,lsp,font_width,font_angle,interlaced)
}
VC=True
#VC=False
S="The\nQuick\nBrown\nfox\njumped\nover\nthe\nlazy\ndog.\nThe\nQuick\nBrown\nfox\njumped\nover\nthe\nlazy\ndog.\n"
TEST_BOT = True
#TEST_BOT = False
if(!TEST_BOT) { # vcenter relative
SubV(S,lsp=0,align=4,vcenter=VC)
SubV(S,lsp=0,align=5,vcenter=VC)
SubV(S,lsp=0,align=6,vcenter=VC)
} Else { # bottom relative
SubV(S,lsp=0,align=1)
SubV(S,lsp=0,align=2)
SubV(S,lsp=0,align=3)
}
[EDIT: Above updated to add TEST_BOT in client stuff.]
EDIT: Fixed as per Gavino post. NOTE, vcenter is additional arg to switch on vertical central justification.
Gavino
17th May 2013, 23:58
y=(Height/2) - ((Lines-1) * size / 2.0)
To be strictly accurate allowing for the line spacing, size should be replaced here by (size + lsp/8.0), although the difference is small unless lsp is quite large.
StainlessS
18th May 2013, 00:02
Fixed, thanx. :)
EDIT: By the way I'll say it again, We Love GScript. :thanks:
PS, are/were you a school teacher ?
fvisagie
20th May 2013, 12:29
PS, are/were you a school teacher ?
Also wondered about the possibility of some teaching vocation... :)
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.