Log in

View Full Version : Subtitle, Aspect ratio?


zerowalker
20th December 2013, 02:03
If i want to have a subtitle on a video with non square pixels, how am i supposed to do it?

The only thing i can think of is Resizing the Video to make in 1:1 then add it and save the video.

But not sure if that is the optimal way to go.

TheFluff
20th December 2013, 02:42
Stretch the subtitles appropriately before applying them. If you're using VSFilter this is trivial, just change the vertical or horizontal scaling factor in the text style in the subtitles file.

zerowalker
20th December 2013, 10:40
I am talking about "Hard Subs" or rather the Filter in Avisynth called "Subtitle".
Not really using it for Subtitles, but more for displaying certain info.

raffriff42
20th December 2013, 19:04
You can fake it pretty well...http://avisynth.nl/index.php/Subtitle

The spc parameter allows you to modify the character spacing (0=unchanged). The value can be positive or negative to widen or narrow the text...

The font_width parameter allows you to modify, in 0.125 units, the aspect ratio of character glyphs...


ColorBars.KillAudio
Subtitle("ROYGBIV", x=-1, y=100, spc=-10, font_width=6)
Subtitle("ROYGBIV", x=-1, y=150, spc=0, font_width=0) ## width=default
Subtitle("ROYGBIV", x=-1, y=200, spc=10, font_width=10)
Subtitle("ROYGBIV", x=-1, y=250, spc=20, font_width=20)
https://www.dropbox.com/s/zaq9jyl3v0up4rf/subtitle_width.jpg?raw=1

zerowalker
22nd December 2013, 13:20
Is there a way to calculate it?
For example from 720x480 (1:1) to 16:9?

zero9999
22nd December 2013, 18:33
function SubtitleEx(clip c, string "text", int "x", int "y", int "first_frame", int "last_frame", string "font",
\ int "size", int "text_color", int "halo_color", int "align", int "spc", int "lsp",
\ float "font_base_width", float "font_angle", bool "interlaced", val "par")
{
font = Default(font, "Arial")
size = Default(size, 18)

fbws = font.LUIsEq("Arial||Calibri||Verdana", true)
font_base_width = Select(fbws+1, Default(font_base_width,0), 0.42, 0.44, 0.47 )

Assert(IsString(par) || IsFloat(par) || !Defined(par), "SubTitleEx: par must be either a float or a prest")
if (IsString(par))
{
par_p = LuIsEq(par, "ntsc_wide||ntsc_full||pal_wide||pal_full", true)
Assert(par_p>=0, "SubtitleEx: unknown preset")
par = Select(par_p, 155200./127953, 38800./42651, 4600./3159, 1150./1053)
}

font_width = Defined(par) ? font_base_width * size / par : Undefined
return c.Subtitle(text, x, y, first_frame, last_frame, font, size, text_color, halo_color, align, spc,
\ lsp, font_width, font_angle, interlaced)
}


start with this. however, i don't think there's any easy way to automatically retrieve the base width for any font in avisynth

AzraelNewtype
22nd December 2013, 21:16
I am talking about "Hard Subs" or rather the Filter in Avisynth called "Subtitle".
Not really using it for Subtitles, but more for displaying certain info.

So was he, though he wasn't suggesting use of the Subtitle filter as it's kind of crap.

Download aegisub to edit your subtitles, set the style x width to 84% (based on your later post DVD 16:9 anamorphic expansion; yes there is a way to calculate it: 720/853 [the final width of a 16:9 expansion of 480p content... ish, it's slightly messy]), load its vsfilter.dll, use textsub(). Problem solved.

zero9999
23rd December 2013, 01:48
Download aegisub to edit your subtitles, set the style x width to 84%
should be 82.5%

raffriff42
23rd December 2013, 01:53
Definitely, VSFilter sounds like a better way to do it ...except I think zerowalker is generating timestamp titles on the fly, based on a previous thread of his (http://forum.doom9.org/showthread.php?t=169863).

zerowalker
4th January 2014, 04:08
I am willin to try Aegissubs, i can add it in the MKV, will save image information (compared to Hardsubs which canīt be removed) and it will be in the MKV and not take upp "space".

How can i make new lines in it?
If i want for example to write.

Date: xxxx
Time: xxx

And want it to look, just like that?

For me it just getīs together, even if i make line jumps.

EDIT:

Okay found it out, i tried \n as itīs usually "new line", but you hade to write \N , not sure what \n does then, but i solved it.
Thanks for mentioning it, this is probably a lot better solution for this kind, as i donīt have a timestamp on-the-fly here, and just write the dates on the file for archiving.

hlrsnd
9th February 2014, 22:31
I'm using Avisynth and Virtualdub to convert some old NTSC MiniDV tapes to mp4 format. I am manually adding date and time information using Avisynth's Subtitle filter and using x264 to encode. In my command line I have specified a sample aspect ratio of 8:9 to match the original NTSC format (correct me if I should use something else). This makes the subtitle text narrow. Text is Arial, size 34. What value should I use for spc or font_width to compensate for the 8:9 SAR? I have been playing around with different values but would like to know an exact value, without researching Visual C++ documentation as the Wiki mentions.

wonkey_monkey
9th February 2014, 23:47
I think the aspect ratio is actually 10:11 (though someone may correct me shortly).

As for what value you should use for font_width, I have no idea. I did a test, and determined that the default value for font_width is about 12.9 when the size is 30, which is meaningless to me. As the documentation says:

It is related to the size parameter by the default GDI aspect ratio and the natural aspect ratio of the chosen font.

Why it couldn't just be a simple ratio is beyond me.

On the other hand, there's nothing actually wrong about displaying a font at a slightly different aspect ratio. I'd just experiment until it looks good to you. If I had to determine it experimentally, I'd create a clip and resize it by 8:9 horizontally, then stack it with an unresized subtitled clip and change the values until they matched.

David

hlrsnd
10th February 2014, 03:16
Thanks. I did some more testing and discovered spc is not what I want since it only increases space between characters but does not make them wider. I used font_width. Based on your info of font size 30 having a width of 12.9, for my size of 34 and aspect ratio of 9:8, I used (34/30)*12.9*(9/8) = 16.45. Rounding to the nearest 0.125, font_width=16.5. It looks about right, but is there a way to calculate the value without experimenting?

hlrsnd
13th February 2014, 04:26
I couldn't find any information on the default value for font_width to be able to calculate a new one, so I did some tests using the following simple script:

ColorBars.KillAudio
Subtitle("TEXT SIZE 34 FONT_WIDTH=14",x=50,y=125,size=34,font_width=14)
Subtitle("TEXT SIZE 34 FONT_WIDTH=14.125",x=50,y=150,size=34,font_width=14.125)
Subtitle("TEXT SIZE 34 FONT_WIDTH=14.5",x=50,y=175,size=34,font_width=14.5)
Subtitle("TEXT SIZE 34 FONT_WIDTH=0",x=50,y=200,size=34,font_width=0)
Subtitle("TEXT SIZE 34 FONT_WIDTH=14.625",x=50,y=225,size=34,font_width=14.625)
Subtitle("TEXT SIZE 34 FONT_WIDTH=14.75",x=50,y=250,size=34,font_width=14.75)
Subtitle("TEXT SIZE 34 FONT_WIDTH=14.875",x=50,y=275,size=34,font_width=14.875)

Result is attached. The default font_width for Arial text size 34 is slightly more than 14.5. Hope this helps someone.

hello_hello
13th February 2014, 06:18
I found this thread due to having the opposite question. When using vsfilter to add subtitles, how does it (appear to) determine the aspect ratio of the video for idx subtitles?

When encoding video with a script such as this, the end result seems to be exactly the same whether the video is resized to square pixels (as per the script) or the resizing is removed and an aspect ratio set instead. ie For the anamorphic version the hardcoded subtitles have the same dimensions once the video is resized to the correct aspect ratio on playback.

LoadPlugin("C:\Program Files\MeGUI\tools\dgindex\DGDecode.dll")
DGDecode_mpeg2source("D:\VTS_01_1.d2v")
Spline36Resize(852,480)
LoadPlugin("C:\Program Files\MeGUI\tools\avisynth_plugin\VSFilter.dll")
VobSub("E:\subs.idx")

raffriff42
13th February 2014, 14:31
I assume font_width adjusts arguments to Windows TextOut and related API routines. I messed about with these a long time ago, and all I can remember is, it's complicated :) For example: How To Fit Text in a Rectangle ('http://support.microsoft.com/kb/200262') (support.microsoft.com)
...
Generally, the smaller the font, the relatively wider the font's glyphs become. This occurs because as a font becomes smaller, you must have a relatively larger amount of horizontal space to make each glyph readable.

To make this issue even more difficult, TrueType hinting may adjust the width of an individual glyph in the font at a certain size to maintain the readability of the glyph. Consider the sum of widths of several glyphs in a string that have been adjusted by hinting. In this scenario, the width of the string is unpredictable.

EDIT here's a visual illustration of this particular problem (http://damieng.com/blog/2007/06/13/font-rendering-philosophies-of-windows-and-mac-os-x).

wonkey_monkey
13th February 2014, 17:25
In my day we had 8x8 binary pixels for each of 224 characters and were glad of it. Pah!

raffriff42
15th September 2014, 07:06
This is kind of interesting:
Subtitle: Animated parameter demonstration (http://avisynth.nl/index.php/Subtitle#Animated_parameter_demonstration) (avisynth wiki)
(alignment; inter-character spacing; character width; inter-line spacing; angle)

StainlessS
15th September 2014, 12:34
Perhaps this of use to somebody:

Subtitle Character set.

Function RT_SubTitleCharSet() {
GSCript("""
S=""
for(y=0,15) {
s=s+"$"+RT_Hex(y*16,2)+ " "
for(x=0,15) {
n=y*16+x
c=(n<32 || n > 223) ? "." : Chr(n)
s=s+c
}
s=s+Chr(10)
}
""")
S
}
Function RT_DebugCharSet() {
GSCript("""
S=""
for(y=0,15) {
s=s+"$"+RT_Hex(y*16,2)+ " "
for(x=0,15) {
n=y*16+x
c=(n<32) ? "." : Chr(n)
s=s+c
}
s=s+Chr(10)
}
""")
S
}
Function SubtitleCharSet() {
GSCript("""
S=""
for(y=0,15) {
s=s+"$"+RT_Hex(y*16,2)+ " "
for(x=0,15) {
n=y*16+x
c=(n<32) ? "." : Chr(n)
s=s+c
}
s=s+"\n"
}
""")
S
}

colorbars

colorbars(width=360,height=512).Trim(0,-1)
s=RT_StrReplace(SubtitleCharSet,Chr(10),"\n")
Subtitle(s,font="Courier New",size=32,lsp=0)
return Last


EDIT:
https://s20.postimg.cc/lmj7hycfx/Subtitle_Charset_zps8d6c05ed.jpg (https://postimg.cc/image/j57gaosjd/)

raffriff42
15th September 2014, 13:44
Interesting, if tangential to the topic.
BTW what does Chr(2000) give you, can you guess? How about Chr(-2000) ?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
(answer: input % 256 in unsigned 32 bit math)