Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th December 2013, 02:03   #1  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
Subtitle, Aspect ratio?

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.
zerowalker is offline   Reply With Quote
Old 20th December 2013, 02:42   #2  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
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.
TheFluff is offline   Reply With Quote
Old 20th December 2013, 10:40   #3  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
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.
zerowalker is offline   Reply With Quote
Old 20th December 2013, 19:04   #4  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
You can fake it pretty well...
Quote:
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...
Code:
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)

Last edited by raffriff42; 18th March 2017 at 01:18. Reason: (fixed image link)
raffriff42 is offline   Reply With Quote
Old 22nd December 2013, 13:20   #5  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
Is there a way to calculate it?
For example from 720x480 (1:1) to 16:9?
zerowalker is offline   Reply With Quote
Old 22nd December 2013, 18:33   #6  |  Link
zero9999
Registered User
 
Join Date: Oct 2011
Posts: 52
Code:
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

Last edited by zero9999; 23rd December 2013 at 01:40. Reason: i'm stupid
zero9999 is offline   Reply With Quote
Old 22nd December 2013, 21:16   #7  |  Link
AzraelNewtype
Registered User
 
AzraelNewtype's Avatar
 
Join Date: Oct 2007
Posts: 135
Quote:
Originally Posted by zerowalker View Post
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.
AzraelNewtype is offline   Reply With Quote
Old 23rd December 2013, 01:48   #8  |  Link
zero9999
Registered User
 
Join Date: Oct 2011
Posts: 52
Quote:
Originally Posted by AzraelNewtype View Post
Download aegisub to edit your subtitles, set the style x width to 84%
should be 82.5%
zero9999 is offline   Reply With Quote
Old 23rd December 2013, 01:53   #9  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
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.
raffriff42 is offline   Reply With Quote
Old 4th January 2014, 04:08   #10  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
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.

Last edited by zerowalker; 4th January 2014 at 05:01.
zerowalker is offline   Reply With Quote
Old 9th February 2014, 22:31   #11  |  Link
hlrsnd
Registered User
 
Join Date: Mar 2009
Posts: 32
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.
hlrsnd is offline   Reply With Quote
Old 9th February 2014, 23:47   #12  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
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:

Quote:
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
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 10th February 2014, 03:16   #13  |  Link
hlrsnd
Registered User
 
Join Date: Mar 2009
Posts: 32
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 is offline   Reply With Quote
Old 13th February 2014, 04:26   #14  |  Link
hlrsnd
Registered User
 
Join Date: Mar 2009
Posts: 32
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.
Attached Images
 
hlrsnd is offline   Reply With Quote
Old 13th February 2014, 06:18   #15  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
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")
hello_hello is offline   Reply With Quote
Old 13th February 2014, 14:31   #16  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
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:
Quote:
How To Fit Text in a Rectangle (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.

Last edited by raffriff42; 14th February 2014 at 06:49.
raffriff42 is offline   Reply With Quote
Old 13th February 2014, 17:25   #17  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
In my day we had 8x8 binary pixels for each of 224 characters and were glad of it. Pah!
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 15th September 2014, 07:06   #18  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
This is kind of interesting:
Subtitle: Animated parameter demonstration (avisynth wiki)
(alignment; inter-character spacing; character width; inter-line spacing; angle)
raffriff42 is offline   Reply With Quote
Old 15th September 2014, 12:34   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Perhaps this of use to somebody:

Subtitle Character set.
Code:
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:
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th February 2020 at 12:08.
StainlessS is offline   Reply With Quote
Old 15th September 2014, 13:44   #20  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
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)

Last edited by raffriff42; 15th September 2014 at 15:34.
raffriff42 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 18:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.