Subtitle

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (more table formatting)
(add link to avs+ documentation)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:FuncDef|Subtitle(clip ''clip'', string ''text'', float ''x'', float ''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_width'', float ''font_angle'', bool ''interlaced'')|Subtitle(clip ''clip'', string ''text'')}}
+
<div style="max-width:62em" >
  
The Subtitle filter adds anti-aliased text to a range of frames. All parameters after ''text'' are optional and can be omitted or specified out of order using the ''name=value'' syntax.
+
<div {{BlueBox2|40|0|3px solid purple}} >
 +
{{AvsPlusFullname}}<br>
 +
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/subtitle.html https://avisynthplus.readthedocs.io]
 +
</div>
  
The short form (with all default parameters) is useful when you don't really care what the subtitle looks like as long as you can see it--for example, when you're using [[StackVertical]] and its ilk to display several versions of a frame at once, and you want to label them to remember which is which.  
+
The '''Subtitle''' filter adds anti-aliased text to a range of frames. All parameters after {{FuncArg|text}} are optional and can be omitted or specified out of order using the ''name=value'' syntax.
  
This filter is used internally by AviSynth for [[Version]], [[ShowFrameNumber]] and for reporting error messages.
+
The short form (with all default parameters) is useful when you don't really care what the subtitle looks like as long as you can see it&mdash;for example, when you're using [[StackVertical]] and its ilk to display several versions of a frame at once, and you want to label them to remember which is which.  
 +
</div>
  
===Parameters===
+
__TOC__
 +
==Syntax and Parameters==
 +
<div style="max-width:62em" >
 +
{{Template:FuncDef|Subtitle(clip ''clip'', string ''text'', float ''x'', float ''y'', int ''first_frame'', int ''last_frame'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ''font'', float ''size'', int ''text_color'', int ''halo_color'', int ''align'', int ''spc'', int ''lsp'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''font_width'', float ''font_angle'', bool ''interlaced'')|Subtitle(clip ''clip'', string ''text'')
 +
}}
  
:;text
+
{{AvsPluscon}}<br>
 +
{{Template:FuncDef|Subtitle(clip ''clip'', string ''text'', float ''x'', float ''y'', int ''first_frame'', int ''last_frame'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ''font'', float ''size'', int ''text_color'', int ''halo_color'', int ''align'', int ''spc'', int ''lsp'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''font_width'', float ''font_angle'', bool ''interlaced'', string ''font_filename'', bool ''utf8'')
 +
}}
 +
 
 +
:{{Par2|text|string|}}
 
:: The text to be displayed.  
 
:: The text to be displayed.  
  
:;x, y
+
:{{Par2|x|float|(auto)}}
 +
:{{Par2|y|float|(auto)}}
 
:: Text position. Can be set to -1 to automatically center the text horizontally or vertically, respectively. Negative values of ''x'' and ''y'' not equal to -1 can be used to move subtitles partially off the screen.
 
:: Text position. Can be set to -1 to automatically center the text horizontally or vertically, respectively. Negative values of ''x'' and ''y'' not equal to -1 can be used to move subtitles partially off the screen.
  
Line 19: Line 36:
 
::: y = ''size'' if align=4,5,6 or none; 0 if align=7,8,9; or height-1 if align=1,2,3
 
::: y = ''size'' if align=4,5,6 or none; 0 if align=7,8,9; or height-1 if align=1,2,3
  
::'''Caution:''' If your script uses Subtitle with [[Animate]] and negative ''x'' or ''y'' values, ''x'' or ''y'' might momentarily become -1, causing a glitch in the video. Starting from v2.60 they can be float.
+
::'''Caution:''' Using v2.58 or older, if your script uses Subtitle with [[Animate]] and negative ''x'' or ''y'' values, ''x'' or ''y'' might momentarily become -1, causing a glitch in the video.  
  
:;first_frame, last_frame
+
:{{Par2|first_frame|int|0}}
 +
:{{Par2|last_frame|int|(clip.Framecount-1)}}
 
::The text will be shown starting from frame ''first_frame'' and ending with frame ''last_frame''.  
 
::The text will be shown starting from frame ''first_frame'' and ending with frame ''last_frame''.  
  
::Default values: first_frame=0, last_frame=Framecount(''clip'')-1
+
:{{Par2|font|string|"Arial"}}
 +
::Font name; can be the name of any installed Windows font.
  
:;font
+
:{{Par2|size|float|18.0}}
::Font name; default "Arial".  
+
 
+
::All installed fonts on the current machine are available; they are located in your 'windows\fonts' folder.
+
 
+
:;size
+
 
::Height of the text in pixels, and is rounded to the nearest 0.125 pixel. Default 18.
 
::Height of the text in pixels, and is rounded to the nearest 0.125 pixel. Default 18.
  
:;text_color, halo_color
+
:{{Par2|text_color|int|[[Preset colors|color_yellow]]}}
 +
:{{Par2|halo_color|int|[[Preset colors|color_black]]}}
 
::Colors for font fill and outline respectively. Default yellow, black.  
 
::Colors for font fill and outline respectively. Default yellow, black.  
  
:::These may be any of the [[Preset colors]], or specified as hexadecimal $aarrggbb values, similar to HTML--except that they start with $ instead of # and the 4th octet specifies the alpha transparency. $00rrggbb is completely opaque, $FF000000 is fully transparent. You can disable the halo by selecting this color. See [[Colors]] for more information on specifying colors.
+
<div {{NotaBeneWidthIndent|54|4|4px solid blue}} >
 +
These may be any of the [[Preset colors]], or specified as hexadecimal $aarrggbb values, similar to HTML--except that they start with $ instead of # and the 4th octet specifies the alpha transparency. $00rrggbb is completely opaque, $FF000000 is fully transparent. You can disable the halo by selecting this color. See [[Colors]] for more information on specifying colors.
 +
</div>
  
:;align
+
:{{Par2|align|int|7}}
 
::Set where the text is placed, based on the numeric keypad layout, as follows:  
 
::Set where the text is placed, based on the numeric keypad layout, as follows:  
<div style="margin-left:8em"><div>
+
<div style="margin:1em 1em 1em 8em;"><div>
{| border="0" cellpadding="4" style="border:none; text-align:center;vertical-align:middle;"
+
[[File:Subtitle-align-chart.png|border]]
|
+
 
|style="width:5em;" | Left
+
[[File:Subtitle-align-demo.png]]
|style="width:5em;" | Center
+
</div> </div>
|style="width:5em;" | Right
+
|
+
|-
+
|style="height:2em;text-align:right;" | Top&nbsp;
+
|style="border:1px solid black;" | 7
+
|style="border:1px solid black;" | 8
+
|style="border:1px solid black;" | 9
+
|style="text-align:left;vertical-align:top;font-size:90%;margin:0;padding:0;" | &nbsp;''top'' at y.
+
|-
+
|style="height:2em;text-align:right;" | Middle&nbsp;
+
|style="border:1px solid black;" | 4
+
|style="border:1px solid black;" | 5
+
|style="border:1px solid black;" | 6
+
| style="text-align:left;vertical-align:middle;font-size:90%;margin:0;padding:0;" | &nbsp;''baseline'' at y.
+
|-
+
|style="height:2em;text-align:right;" | Bottom&nbsp;
+
|style="border:1px solid black;" | 1
+
|style="border:1px solid black;" | 2
+
|style="border:1px solid black;" | 3
+
|style="text-align:left;vertical-align:bottom;font-size:90%;margin:0;padding:0;" | &nbsp;''bottom'' at y.
+
|-
+
|
+
| style="text-align:left;font-size:90%;" | ''left'' at x.
+
| style="text-align:center;font-size:90%;" | ''center'' at x.
+
| style="text-align:right;font-size:90%;" | ''right'' at x.
+
|
+
|}</div></div>
+
  
 
::Default 7, or top-left. If ''x'' and/or ''y'' are given, text is positioned relative to the (x,y) location. Note there is no Y-center alignment setting.
 
::Default 7, or top-left. If ''x'' and/or ''y'' are given, text is positioned relative to the (x,y) location. Note there is no Y-center alignment setting.
  
:;spc
+
:{{Par2|spc|int|0}}
 
::Modify the inter-character spacing. If ''spc'' is less than zero, inter-character spacing is decreased; if greater, the spacing is increased. Default is 0: use Windows' default spacing.  
 
::Modify the inter-character spacing. If ''spc'' is less than zero, inter-character spacing is decreased; if greater, the spacing is increased. Default is 0: use Windows' default spacing.  
  
::This is helpful for trying to match typical fonts on the PC to fonts used in film and television credits which are usually wider for the same height or to just fit or fill in a space with a fixed per-character adjustment.  
+
::This is helpful for trying to match typical fonts on the PC to fonts used in film and television credits which are usually wider for the same height or to just fit or fill in a space with a fixed per-character adjustment. See example below.
  
:::For more information, see the Microsoft documentation of the function [http://msdn.microsoft.com/en-us/library/windows/desktop/dd145092%28v=vs.85%29.aspx SetTextCharacterExtra()].  
+
::For more information, see the Microsoft documentation of the function [http://msdn.microsoft.com/en-us/library/windows/desktop/dd145092%28v=vs.85%29.aspx SetTextCharacterExtra()].  
  
:;lsp
+
:{{Par2|lsp|int|}}
::Line Spacing Parameter; enables '''multi-line text''' (where "\n" enters a line break) and sets the additional inter-line spacing (if any) in 0.125 pixel units. Multi-line text was added in v2.57. Default undefined, which disables multi-line text.  
+
::'''L'''ine '''S'''pacing '''P'''arameter; enables ''multi-line text'' (where "\n" enters a line break). If ''lsp'' is less than zero, inter-line spacing is decreased; if greater, the spacing is increased, relative to Windows' default spacing. By default, multi-line text disabled.  
  
 
::In the unlikely event that you want to output the characters "\n" literally in a multi-line text, you can do this by using "\\n".
 
::In the unlikely event that you want to output the characters "\n" literally in a multi-line text, you can do this by using "\\n".
  
:;font_width
+
:{{Par2|font_width|float|0.0}}
::Set character width in logical units, to the nearest 0.125 unit. Default=0, use Windows' default width.
+
::Set character width in logical units, to the nearest 0.125 unit. Default=0, use Windows' default width. See example below.
  
::Character width varies, depending on the font face and size, but "Arial" at size=16 is about 7 units wide; if ''font_width'' is less than that, (but greater than zero), the text is squeezed, and if it is greater, the text is stretched. Negative numbers are converted to their absolute values.
+
::Character width varies, depending on the font face and size, but "Arial" at size=16 is about 7 units wide; if ''font_width'' is less than that, (but greater than zero), the text is squeezed, and if it is greater, the text is stretched. Negative numbers are converted to their absolute values.  
  
 
:::For more information, see the Microsoft documentation of the function [http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499%28v=vs.85%29.aspx CreateFont()].  
 
:::For more information, see the Microsoft documentation of the function [http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499%28v=vs.85%29.aspx CreateFont()].  
  
:;font_angle
+
:{{Par2|font_angle|float|0.0}}
 
::Adjust the baseline angle of text in degrees anti-clockwise to the nearest 0.1 degree. Default 0, no rotation.
 
::Adjust the baseline angle of text in degrees anti-clockwise to the nearest 0.1 degree. Default 0, no rotation.
  
:;interlaced
+
:{{Par2|interlaced|bool|false}}
 
::When enabled, reduces flicker from sharp fine vertical transitions on interlaced displays. It applies a mild vertical blur by increasing the anti-aliasing window to include 0.5 of the pixel weight from the lines above and below. Default=false.
 
::When enabled, reduces flicker from sharp fine vertical transitions on interlaced displays. It applies a mild vertical blur by increasing the anti-aliasing window to include 0.5 of the pixel weight from the lines above and below. Default=false.
  
===Examples===
+
:{{Par2|font_filename|string|}}
 +
::{{AvsPluscon}} allows using non-installed font, by giving the font file name. Once it is loaded, other Subtitle instances can use it.
  
# Some text in the center of the clip:
+
:{{Par2|utf8|bool|false}}
 +
::{{AvsPluscon}} allows drawing text encoded in UTF8. Can be a bit tricky, since Avisynth does not support utf8 scripts. But when a unicode script containing non-ansi characters is saved as UTF8 without BOM, the text itself can be passed as-is and providing the utf8=true setting.
 +
 
 +
</div>
 +
 
 +
==Examples==
 +
<div style="max-width:68em" >
 +
=====Center text=====
 
  AviSource("D:\clip.avi")
 
  AviSource("D:\clip.avi")
 
  Subtitle("Hello world!", align=5)
 
  Subtitle("Hello world!", align=5)
  
# Some text in the upper right corner of the clip with specified font, size and color:
+
=====Text in upper right corner with specified font, size and color=====
 
  AviSource("D:\clip.avi")
 
  AviSource("D:\clip.avi")
 
  Subtitle("Hello world!", font="georgia", size=24, text_color=$ff0000, align=9)
 
  Subtitle("Hello world!", font="georgia", size=24, text_color=$ff0000, align=9)
  
# Prints text on multiple lines
+
=====Print text on multiple lines with no halo border=====
# without any text halo border.
+
 
  BlankClip()
 
  BlankClip()
 
  Subtitle( \
 
  Subtitle( \
Line 119: Line 116:
 
           lsp=10, halo_color=$ff000000)
 
           lsp=10, halo_color=$ff000000)
 
   
 
   
# It results in:
+
It results in:
 
  Some text on line 1\nMore text on line 1
 
  Some text on line 1\nMore text on line 1
 
  Some text on line 2
 
  Some text on line 2
  
# Use String() to display values of functions.
+
=====Use String() to display values of functions=====
 
  AviSource("D:\clip.avi")
 
  AviSource("D:\clip.avi")
 
  Subtitle("Width=" + String(Width()))
 
  Subtitle("Width=" + String(Width()))
  
 +
=====Using ''spc'' and ''font_width'' arguments=====
 +
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)
 +
<div style="margin:1em 1em 1em 8em;"><div>
 +
[[File:Subtitle_width.jpg|360px]]
 +
</div></div>
  
Demonstrate extreme values of ''spc'', ''font_width'' and ''lsp'':
+
=====Animated parameter demonstration=====
  
 
  ColorbarsHD(width=640, height=360)
 
  ColorbarsHD(width=640, height=360)
Line 137: Line 143:
 
  s1 = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
 
  s1 = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
 
  s3 = "THE QUICK BROWN FOX \nJUMPS OVER \nTHE LAZY DOG."
 
  s3 = "THE QUICK BROWN FOX \nJUMPS OVER \nTHE LAZY DOG."
  minvalue = -64.0
+
  minvalue = -32.0
 
  maxvalue = +128.0
 
  maxvalue = +128.0
  return Animate(Last, 0, 255, "anim_spc", s1, minvalue , s1, maxvalue)
+
B = BlankClip(Last, length=15)
     \ + BlankClip(Last, length=10)
+
  return Animate(Last, 0, 255, "anim_aln", s3, 1.000000, s3, 9.999999)
     \ + Animate(Last, 0, 255, "anim_wid", s1, minvalue , s1, maxvalue)
+
    \ + B
     \ + BlankClip(Last, length=10)
+
    \ + Animate(Last, 0, 255, "anim_spc", s1, minvalue, s1, maxvalue)
     \ + Animate(Last, 0, 255, "anim_lsp", s3, minvalue , s3, maxvalue)
+
     \ + B
  function anim_spc(clip C, string s, float f){
+
     \ + Animate(Last, 0, 255, "anim_wid", s1, minvalue, s1, maxvalue)
     return C.Subtitle(s, align=8, size=16, font="Arial", spc=0)
+
     \ + B
     \      .Subtitle(s, align=5, size=16, font="Arial", spc=Round(f))
+
     \ + Animate(Last, 0, 255, "anim_lsp", s3, minvalue, s3, maxvalue)
     \       .Subtitle("spc = "+String(Round(f)), align=2, size=32)
+
    \ + B
 +
    \ + Animate(Last, 0, 255, "anim_ang", s1, -15.0000, s1, 375.0000).FadeOut(15)
 +
  function anim_aln(clip C, string s, float f) {
 +
     return C.Subtitle(s, align=Floor(f), lsp=0)
 +
     \      .Subtitle("align = "+String(Floor(f)),
 +
     \                 x=-1, y=C.Height-42, size=32, text_color=$c0c0c0)
 
  }
 
  }
  function anim_wid(clip C, string s, float f){
+
  function anim_spc(clip C, string s, float f) {
     return C.Subtitle(s, align=8, size=16, font="Arial", font_width=0)
+
     return C.Subtitle(s, align=8, spc=0, text_color=$c0c0c0)
     \      .Subtitle(s, align=5, size=16, font="Arial", font_width=f)
+
     \      .Subtitle(s, align=5, spc=Round(f))
     \      .Subtitle("font_width = "+String(Round(f)), align=2, size=32)
+
     \      .Subtitle("spc = "+String(Round(f)),  
 +
    \                align=2, size=32, text_color=$c0c0c0)
 
  }
 
  }
  function anim_lsp(clip C, string s, float f){
+
  function anim_wid(clip C, string s, float f) {
     return C.Subtitle(s, align=8, size=16, font="Arial", lsp=0)
+
     return C.Subtitle(s, align=8, font_width=0, text_color=$c0c0c0)
     \      .Subtitle(s, align=5, size=16, font="Arial", lsp=Round(f))
+
    \      .Subtitle(s, align=5, font_width=Round(f))
     \      .Subtitle("lsp = "+String(Round(f)), align=2, size=32)
+
    \      .Subtitle("font_width = "+String(Round(f)),
 +
    \                align=2, size=32, text_color=$c0c0c0)
 +
}
 +
function anim_lsp(clip C, string s, float f) {
 +
    return C.Subtitle(s, align=8, lsp=0, text_color=$c0c0c0)
 +
     \      .Subtitle(s, align=5, lsp=Round(f))
 +
     \      .Subtitle("lsp = "+String(Round(f)),  
 +
    \                align=2, size=32, text_color=$c0c0c0)
 +
}
 +
function anim_ang(clip C, string s, float f) {
 +
    return C.Subtitle(s, align=5, font_angle=f)
 +
    \      .Subtitle("font_angle = "+String(f, "%03.3f"),
 +
    \                align=2, size=32, text_color=$c0c0c0)
 
  }
 
  }
  
 +
=====UTF8 text indirectly =====
 +
{{AvsPluscon}}
 +
  Title="Cherry blossom "+CHR($E6)+CHR($A1)+CHR($9C)+CHR($E3)+CHR($81)+CHR($AE)+CHR($E8)+CHR($8A)+CHR($B1)
 +
  SubTitle(Title,utf8=true)
 +
</div>
  
===Changes===
+
==Changes==
 
+
<div style="max-width:62em" >
 
{| border="1"
 
{| border="1"
 +
|-
 +
| v2487
 +
| font_filename and utf8 parameter.{{AvsPluscon}}
 
|-
 
|-
 
| v2.60
 
| v2.60
Line 183: Line 215:
 
| Setting x=-1 uses horizontal center and center alignment (undocumented prior to v2.07).
 
| Setting x=-1 uses horizontal center and center alignment (undocumented prior to v2.07).
 
|}
 
|}
 +
</div>
  
 
+
==See also==
===See also===
+
<div style="max-width:62em" >
 
+
 
There are [[External_filters#Subtitling|external subtitling filters]] that display SRT, SSA, and other format subtitle files or offer more elaborate formatting.
 
There are [[External_filters#Subtitling|external subtitling filters]] that display SRT, SSA, and other format subtitle files or offer more elaborate formatting.
 
+
</div>
  
  
 
[[Category:Internal filters]]
 
[[Category:Internal filters]]
 +
[[Category:Debugging/Diagnostic filters]]
 +
[[Category:Subtitling]]

Latest revision as of 19:27, 16 September 2022

AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io

The Subtitle filter adds anti-aliased text to a range of frames. All parameters after text are optional and can be omitted or specified out of order using the name=value syntax.

The short form (with all default parameters) is useful when you don't really care what the subtitle looks like as long as you can see it—for example, when you're using StackVertical and its ilk to display several versions of a frame at once, and you want to label them to remember which is which.

Contents

[edit] Syntax and Parameters

Subtitle(clip clip, 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)

AVS+
Subtitle(clip clip, 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, string font_filename, bool utf8)

string  text =
The text to be displayed.
float  x = (auto)
float  y = (auto)
Text position. Can be set to -1 to automatically center the text horizontally or vertically, respectively. Negative values of x and y not equal to -1 can be used to move subtitles partially off the screen.
Default values:
x = 8 if align=1,4,7 or none; -1 if align=2,5,8; or width-8 if align=3,6,9
y = size if align=4,5,6 or none; 0 if align=7,8,9; or height-1 if align=1,2,3
Caution: Using v2.58 or older, if your script uses Subtitle with Animate and negative x or y values, x or y might momentarily become -1, causing a glitch in the video.
int  first_frame = 0
int  last_frame = (clip.Framecount-1)
The text will be shown starting from frame first_frame and ending with frame last_frame.
string  font = "Arial"
Font name; can be the name of any installed Windows font.
float  size = 18.0
Height of the text in pixels, and is rounded to the nearest 0.125 pixel. Default 18.
int  text_color = color_yellow
int  halo_color = color_black
Colors for font fill and outline respectively. Default yellow, black.

These may be any of the Preset colors, or specified as hexadecimal $aarrggbb values, similar to HTML--except that they start with $ instead of # and the 4th octet specifies the alpha transparency. $00rrggbb is completely opaque, $FF000000 is fully transparent. You can disable the halo by selecting this color. See Colors for more information on specifying colors.

int  align = 7
Set where the text is placed, based on the numeric keypad layout, as follows:

Subtitle-align-chart.png

Subtitle-align-demo.png

Default 7, or top-left. If x and/or y are given, text is positioned relative to the (x,y) location. Note there is no Y-center alignment setting.
int  spc = 0
Modify the inter-character spacing. If spc is less than zero, inter-character spacing is decreased; if greater, the spacing is increased. Default is 0: use Windows' default spacing.
This is helpful for trying to match typical fonts on the PC to fonts used in film and television credits which are usually wider for the same height or to just fit or fill in a space with a fixed per-character adjustment. See example below.
For more information, see the Microsoft documentation of the function SetTextCharacterExtra().
int  lsp =
Line Spacing Parameter; enables multi-line text (where "\n" enters a line break). If lsp is less than zero, inter-line spacing is decreased; if greater, the spacing is increased, relative to Windows' default spacing. By default, multi-line text disabled.
In the unlikely event that you want to output the characters "\n" literally in a multi-line text, you can do this by using "\\n".
float  font_width = 0.0
Set character width in logical units, to the nearest 0.125 unit. Default=0, use Windows' default width. See example below.
Character width varies, depending on the font face and size, but "Arial" at size=16 is about 7 units wide; if font_width is less than that, (but greater than zero), the text is squeezed, and if it is greater, the text is stretched. Negative numbers are converted to their absolute values.
For more information, see the Microsoft documentation of the function CreateFont().
float  font_angle = 0.0
Adjust the baseline angle of text in degrees anti-clockwise to the nearest 0.1 degree. Default 0, no rotation.
bool  interlaced = false
When enabled, reduces flicker from sharp fine vertical transitions on interlaced displays. It applies a mild vertical blur by increasing the anti-aliasing window to include 0.5 of the pixel weight from the lines above and below. Default=false.
string  font_filename =
AVS+ allows using non-installed font, by giving the font file name. Once it is loaded, other Subtitle instances can use it.
bool  utf8 = false
AVS+ allows drawing text encoded in UTF8. Can be a bit tricky, since Avisynth does not support utf8 scripts. But when a unicode script containing non-ansi characters is saved as UTF8 without BOM, the text itself can be passed as-is and providing the utf8=true setting.

[edit] Examples

[edit] Center text
AviSource("D:\clip.avi")
Subtitle("Hello world!", align=5)
[edit] Text in upper right corner with specified font, size and color
AviSource("D:\clip.avi")
Subtitle("Hello world!", font="georgia", size=24, text_color=$ff0000, align=9)
[edit] Print text on multiple lines with no halo border
BlankClip()
Subtitle( \
  "Some text on line 1\\nMore text on line 1\n" + \
  "Some text on line 2", \
         lsp=10, halo_color=$ff000000)

It results in:

Some text on line 1\nMore text on line 1
Some text on line 2
[edit] Use String() to display values of functions
AviSource("D:\clip.avi")
Subtitle("Width=" + String(Width()))
[edit] Using spc and font_width arguments
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)

Subtitle width.jpg

[edit] Animated parameter demonstration
ColorbarsHD(width=640, height=360)
AmplifyDB(-30)
Tweak(cont=0.5, sat=0.5)
ConvertToRGB32(matrix="PC.709")
Trim(0, 255)
s1 = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
s3 = "THE QUICK BROWN FOX \nJUMPS OVER \nTHE LAZY DOG."
minvalue = -32.0
maxvalue = +128.0
B = BlankClip(Last, length=15)
return Animate(Last, 0, 255, "anim_aln", s3, 1.000000, s3, 9.999999)
   \ + B
   \ + Animate(Last, 0, 255, "anim_spc", s1, minvalue, s1, maxvalue)
   \ + B
   \ + Animate(Last, 0, 255, "anim_wid", s1, minvalue, s1, maxvalue)
   \ + B
   \ + Animate(Last, 0, 255, "anim_lsp", s3, minvalue, s3, maxvalue)
   \ + B
   \ + Animate(Last, 0, 255, "anim_ang", s1, -15.0000, s1, 375.0000).FadeOut(15)
function anim_aln(clip C, string s, float f) {
    return C.Subtitle(s, align=Floor(f), lsp=0)
    \       .Subtitle("align = "+String(Floor(f)), 
    \                 x=-1, y=C.Height-42, size=32, text_color=$c0c0c0)
}
function anim_spc(clip C, string s, float f) {
    return C.Subtitle(s, align=8, spc=0, text_color=$c0c0c0)
    \       .Subtitle(s, align=5, spc=Round(f))
    \       .Subtitle("spc = "+String(Round(f)), 
    \                 align=2, size=32, text_color=$c0c0c0)
}
function anim_wid(clip C, string s, float f) {
    return C.Subtitle(s, align=8, font_width=0, text_color=$c0c0c0)
    \       .Subtitle(s, align=5, font_width=Round(f))
    \       .Subtitle("font_width = "+String(Round(f)), 
    \                 align=2, size=32, text_color=$c0c0c0)
} 
function anim_lsp(clip C, string s, float f) {
    return C.Subtitle(s, align=8, lsp=0, text_color=$c0c0c0)
    \       .Subtitle(s, align=5, lsp=Round(f))
    \       .Subtitle("lsp = "+String(Round(f)), 
    \                 align=2, size=32, text_color=$c0c0c0)
}
function anim_ang(clip C, string s, float f) {
    return C.Subtitle(s, align=5, font_angle=f)
    \       .Subtitle("font_angle = "+String(f, "%03.3f"), 
    \                 align=2, size=32, text_color=$c0c0c0)
}
[edit] UTF8 text indirectly

AVS+

 Title="Cherry blossom "+CHR($E6)+CHR($A1)+CHR($9C)+CHR($E3)+CHR($81)+CHR($AE)+CHR($E8)+CHR($8A)+CHR($B1)
 SubTitle(Title,utf8=true)

[edit] Changes

v2487 font_filename and utf8 parameter.AVS+
v2.60 position (x,y) can be float (previously int) (with 0.125 pixel granularity).
v2.58 Added font_width, font_angle, interlaced and alpha color blending.
v2.57 Added multi-line text and line spacing parameter.
v2.56 changed default align parameter: from "default = 4, if x == -1 then 5" to "default = 7, if x == -1 then 2"
v2.07 Added align and spc parameters. Setting y=-1 calculates vertical center (alignment unaffected). Default x and y values dependent on alignment (previously x=8, y=size).
v1.00 Setting x=-1 uses horizontal center and center alignment (undocumented prior to v2.07).

[edit] See also

There are external subtitling filters that display SRT, SSA, and other format subtitle files or offer more elaborate formatting.

Personal tools