Python: captionbob.effects
captionbob.effects.glitch
The glitch effect: heavy white capitals whose spoken word splits.
Each caption shows up to two words in one line, in capitals and with no end marks. A caption also ends at each end mark, such as a comma or a full stop. The words are narrow white capitals with a white stroke, which makes them heavy and keeps the room inside the letters open. While a word is spoken, it has no stroke, and a pink copy of it to the right and a light cyan copy to the left show at its edges and in the room inside its letters. The keywords of a caption are in a color, with a thin white rim, and they do not split. The keywords of a video take the keyword colors in turn. A caption shows at once with its first word, and it leaves at once when it ends.
Each caption is a pink copy on the bottom layer, a light cyan copy on the layer above it, a white rim of its keywords on the next layer when it has a keyword, and its words on the top layer. All events of a caption hold all its words in the same runs, so each word has the same place in each event.
The caption groups that end at each end mark, the words in capitals with no end marks, the spoken time of each word and its look in that time, the keywords and their colors in turn, the color and border tags, the size tags and the text of a line with a word gap come from caption_groups_at_marks, shown_group, spoken_times, spoken_look_tags, keyword_places, keywords_in_turn, keyword_word_tags, fill_and_outline_tags, look_tags, border_tag, size_tags and word_gap_line_text of effect_common.
Source file: captionbob/effects/glitch.py
Settings
The command line and the HTTP API call this effect the style glitch. Its settings class is GlitchSettings. Each setting has the default below.
| Setting | Type | Default | Description |
|---|---|---|---|
most_words |
integer | 2 |
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" |
Name of the font of the text. |
font_size |
integer | 134 |
Height of the font in pixels. |
bold |
boolean | true |
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 | 2.5 |
Width of the outline in pixels. 0 gives no outline. |
bottom_position |
number | 0.7208 |
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.57 |
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. |
word_gap |
number | 10.0 |
Room in pixels that is added after each space, at the letter width. A value below 0 puts the words closer. |
capitals |
boolean | true |
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. |
spoken_stroke_width |
number | 0.0 |
Width in pixels of the stroke of a spoken word and of its copies, 0 or above. 0 gives them no stroke. |
split_width |
number | 3.0 |
How far the right copy and the left copy of a spoken word stand to the right and to the left of its letters, in pixels, 0 or above. 0 gives no split. |
split_right_color |
string | "#E5A4AF" |
Color of the copy to the right, as "#RRGGBB". |
split_left_color |
string | "#92ECE5" |
Color of the copy to the left, as "#RRGGBB". |
keyword_colors |
list | ["#F9FF2A", "#2DF9F9", "#ED333D"] |
The colors of the keywords, as "#RRGGBB". The keywords of a video take them in turn. |
keyword_rim |
number | 2.0 |
Width in pixels of the rim around a keyword in the stroke color, 0 or above. The keyword has the stroke width less the rim in its own color, and 0 at least. 0 gives no rim. |
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. |
GlitchSettings
@dataclass(frozen=True)
class GlitchSettings(CaptionSettings)
The look and the timing of the glitch effect.
The settings of CaptionSettings come first: the word counts, the font, the colors, the stroke, the bottom position and the side margin. The letter width, the word gap, the switches of the words, the stroke of the spoken word, the settings of the split, the keyword colors, the keyword rim and the hold time follow them. The effect changes the defaults of some of them. The stroke is the outline of the words that are not spoken, in the color of their letters, which makes them heavy. The bottom position is the bottom of the 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.word_gap: Room in pixels that is added after each space, at the letter width. A value below 0 puts the words 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.spoken_stroke_width: Width in pixels of the stroke of a spoken word and of its copies, 0 or above. 0 gives them no stroke.split_width: How far the right copy and the left copy of a spoken word stand to the right and to the left of its letters, in pixels, 0 or above. 0 gives no split.split_right_color: Color of the copy to the right, as "#RRGGBB".split_left_color: Color of the copy to the left, as "#RRGGBB".keyword_colors: The colors of the keywords, as "#RRGGBB". The keywords of a video take them in turn.keyword_rim: Width in pixels of the rim around a keyword in the stroke color, 0 or above. The keyword has the stroke width less the rim in its own color, and 0 at least. 0 gives no rim.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 is not a whole number.ValueError: When a value is outside its range, or when a color is not in the form "#RRGGBB".
GlitchSettings.keyword_border
def keyword_border(self) -> float
Give the stroke of a keyword in its color: the stroke width less the keyword rim, and 0 at least.
GlitchEffect
class GlitchEffect
def __init__(
self, settings: GlitchSettings,
keyword_picker: KeywordPicker = DEFAULT_KEYWORD_PICKER) -> None
Builds the ASS script of heavy white capitals whose spoken word splits into a pink edge and a light cyan edge, with keywords in color.
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.
GlitchEffect.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 caption has a right copy, a left copy, a rim when it has a keyword, 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.
GlitchEffect.caption_events
def caption_events(
self, caption: ShownCaption, keyword_colors: Mapping[int, str],
middle_x: float, caption_bottom: int) -> list[str]
Write the events of one caption.
Args:
caption: The caption with the times of its events and its words as spoken.keyword_colors: The color of each keyword place in the words of the caption.middle_x: The column of the middle of the video.caption_bottom: The row of the bottom of the line.
Returns:
The right copy, the left copy, the rim when the caption has a keyword, and the text event, in this order.