Python: captionbob.effects
captionbob.effects.dash
The dash effect: narrow white words in sentence case.
Each caption shows its words in narrow white letters of a medium weight, in the case in which they are spoken and with no end marks. A caption ends at each end mark, such as a comma. A caption stays on one line up to the line letters, and a longer caption is cut into two lines. A keyword is in a heavier font, with a wider outline in its own color, for the whole caption. A soft dark shadow lies under the letters, a little below them. A caption pops in: it shows a little smaller and grows to its full size in the pop time.
Each line of a caption has two events with the times of the caption. The shadow event draws the letters in the shadow color, with a border that fades out, the shadow drop below the line. The text event draws the letters over it, with an outline in the color of the letters that makes them heavier. Both events of a line pop in, and each space of a line gets the word gap. The settings of the lines, the captions with their lines and keywords, the places of the lines and the check that the shadow is seen come from LineSettings, line_captions and shadow_is_seen of effect_common.
Source file: captionbob/effects/dash.py
Settings
The command line and the HTTP API call this effect the style dash. Its settings class is DashSettings. Each setting has the default below.
| Setting | Type | Default | Description |
|---|---|---|---|
most_words |
integer | 3 |
The most words that one caption shows. |
fewest_words |
integer | 1 |
The fewest words that one caption shows, when its sentence is long enough for that. |
font_name |
string | "Ubuntu Medium" |
Name of the font of the text. |
font_size |
integer | 94 |
Height of the font in pixels. |
bold |
boolean | false |
True for bold text. |
primary_color |
string | "#FFFFFF" |
Color of the text, as "#RRGGBB". |
stroke_color |
string | "#FFFFFF" |
Color of the outline of the text, as "#RRGGBB". |
stroke_width |
number | 1.3 |
Width of the outline in pixels. 0 gives no outline. |
bottom_position |
number | 0.6776 |
Where the bottom of the caption sits, as a part of the video height from the top. 0.75 is three quarters of the way down. |
side_margin |
integer | 54 |
Room in pixels that stays free on the left and on the right of the caption. A caption that is too wide for the room between the margins breaks into lines. |
letter_width |
number | 0.845 |
The width of the letters as a part of the width that the font gives them, above 0. 1 keeps the width of the font. |
line_gap |
number | 0.0 |
Room in pixels between the bottom of the top line and the top of the second line. A value below 0 puts the lines closer. |
capitals |
boolean | false |
True to write the words in capitals. |
end_at_marks |
boolean | true |
True to end a caption at each end mark, such as a comma. |
line_letters |
integer | 28 |
The most letters, with the spaces, of a caption that stays on one line, 1 or above. |
word_gap |
number | -2.9 |
Room in pixels that is added to each space between two words, at the letter width. A value below 0 puts the words closer. 0 keeps the space of the font. |
keyword_font_name |
string | "Ubuntu" |
Name of the font of a keyword. |
keyword_bold |
boolean | true |
True for a bold keyword. |
keyword_stroke_width |
number | 3.0 |
Width in pixels of the outline of a keyword, in the stroke color. |
shadow_color |
string | "#000000" |
The color of the shadow, as "#RRGGBB". |
shadow_spread |
number | 5.0 |
How far the shadow reaches past the outline, in pixels. |
shadow_blur |
number | 10.0 |
How far the edge of the shadow fades out, in pixels. |
shadow_opacity |
number | 0.46 |
The strength of the shadow, from 0 for no shadow to 1. |
shadow_drop |
number | 6.0 |
How far the shadow is below the letters, in pixels. A value below 0 puts the shadow above them. |
pop_scale |
number | 0.91 |
The size of a caption at its start, as a part of its full size, above 0. 1 shows it at its full size at once. |
pop_seconds |
number | 0.04 |
The time in which a caption grows to its full size. 0 shows it at its full size at once. |
hold_seconds |
number | 0.0 |
The longest time that a caption stays after its last word ends. The caption goes earlier when the next caption starts. |
DashSettings
@dataclass(frozen=True)
class DashSettings(LineSettings)
The look and the timing of the dash effect.
The settings of CaptionSettings come first: the word counts, the font, the colors, the stroke, the bottom position and the side margin. The settings of LineSettings follow them, from the letter width to the line letters, and then the word gap, the settings of the keywords, of the shadow and of the pop, and the hold time. The effect changes the defaults of some of them. The font, the bold and the primary color are those of the words that are not keywords. The stroke is the outline of the letters, which makes them heavier. The bottom position is the bottom of the top line.
Args:
letter_width: The width of the letters as a part of the width that the font gives them, above 0. 1 keeps the width of the font.line_gap: Room in pixels between the bottom of the top line and the top of the second line. A value below 0 puts the lines closer.capitals: True to write the words in capitals.end_at_marks: True to end a caption at each end mark, such as a comma.line_letters: The most letters, with the spaces, of a caption that stays on one line, 1 or above.word_gap: Room in pixels that is added to each space between two words, at the letter width. A value below 0 puts the words closer. 0 keeps the space of the font.keyword_font_name: Name of the font of a keyword.keyword_bold: True for a bold keyword.keyword_stroke_width: Width in pixels of the outline of a keyword, in the stroke color.shadow_color: The color of the shadow, as "#RRGGBB".shadow_spread: How far the shadow reaches past the outline, in pixels.shadow_blur: How far the edge of the shadow fades out, in pixels.shadow_opacity: The strength of the shadow, from 0 for no shadow to 1.shadow_drop: How far the shadow is below the letters, in pixels. A value below 0 puts the shadow above them.pop_scale: The size of a caption at its start, as a part of its full size, above 0. 1 shows it at its full size at once.pop_seconds: The time in which a caption grows to its full size. 0 shows it at its full size at once.hold_seconds: The longest time that a caption stays after its last word ends. The caption goes earlier when the next caption starts.
Raises:
TypeError: When a word count or the line letters is not a whole number.ValueError: When a value is outside its range, when a color is not in the form "#RRGGBB", or when a font name is empty or holds a backslash, a curly bracket or a comma.
DashSettings.has_shadow
def has_shadow(self) -> bool
True when the shadow has strength and reaches past the letters: it spreads, it is blurred or it is below them.
DashEffect
class DashEffect
def __init__(
self, settings: DashSettings,
keyword_picker: KeywordPicker = DEFAULT_KEYWORD_PICKER) -> None
Builds the ASS script of narrow white words in sentence case with a soft shadow and a heavier keyword, which pop in.
Args:
settings: The look and the timing of the effect.keyword_picker: Names the keywords of each caption. With no value, the keyword of a caption is its longest word when that word has seven letters or more.
DashEffect.build_ass_text
def build_ass_text(self, words: Sequence[Word], video: VideoInfo) -> str
Build the ASS script of the effect for the words of one video.
Each line of each caption has a shadow event, when the shadow can be seen, and a text event. The events start with the first word of their caption. They end when the next caption starts, and at the latest the hold time after its last word and at the end of the video.
Args:
words: The words of the video in time order, each with its times.video: The frame size and the duration of the video.
Returns:
The text of the ASS script. It has no event when there are no words.
Raises:
ValueError: When the side margins leave no room for the caption in the width of the video, or when the keyword picker gives a place that is not a word of its caption.