Python: captionbob.effects
captionbob.effects.bolt
The bolt effect: heavy capitals whose spoken line has a strong color.
Each caption shows its words in heavy white capitals with a black edge, with no end marks. A caption ends at each end mark, such as a comma. A short caption stays on one line. A longer caption is cut into two lines, and the top line takes the larger half of the words. The line whose words are spoken has the line color of the caption, and the other line is white. The captions take the line colors yellow, green and red in turn. A caption with a keyword has an emoji above it or below it, in the middle of the video. The emoji pops in from a small size.
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 text event draws the letters over it, with an outline in the color of the letters that makes them heavier. The top line stands on the caption bottom, and the second line hangs from the line gap below it. libass breaks a line that is too wide for the room between the side margins: the rows of the top line grow up and the rows of the second line grow down, so the two lines never cover each other. An emoji is not drawn by ASS: the effect gives one emoji layer for each caption with a keyword, and the ffmpeg filters draw it. The settings of the lines and of the shadow, the captions with their lines and line colors, the places of the lines and the edge of an emoji come from SpokenLineSettings and spoken_line_captions of effect_common, and the tags of the spoken line come from line_look_tags of effect_common.
Source file: captionbob/effects/bolt.py
Settings
The command line and the HTTP API call this effect the style bolt. Its settings class is BoltSettings. 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" |
Name of the font of the text. |
font_size |
integer | 66 |
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 | 3.0 |
Width of the outline in pixels. 0 gives no outline. |
bottom_position |
number | 0.661 |
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 | 1.28 |
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 | 11.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 | 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. |
line_letters |
integer | 13 |
The most letters, with the spaces, of a caption that stays on one line, 1 or above. |
line_colors |
list | ["#FAFF31", "#4AFF41", "#DE1B2F"] |
The colors of the line that is spoken, as "#RRGGBB". The captions take them in turn. |
shadow_color |
string | "#000000" |
The color of the shadow, as "#RRGGBB". |
shadow_spread |
number | 11.0 |
How far the shadow reaches past the outline, in pixels. |
shadow_blur |
number | 6.0 |
How far the edge of the shadow fades out, in pixels. |
shadow_opacity |
number | 1.0 |
The strength of the shadow, from 0 for no shadow to 1. |
shadow_drop |
number | 0.0 |
How far the shadow is below the letters, in pixels. A value below 0 puts the shadow above them. |
emoji_size |
number | 122.0 |
The side of the emoji in pixels, above 0. |
emoji_gap |
number | 30.0 |
Room in pixels between the caption and the emoji. |
emoji_places |
list | ["below", "below", "above", "above"] |
The places of the emojis, one or more of "above" and "below". The captions with an emoji take them in turn. |
emoji_pop_scale |
number | 0.4 |
The size of an emoji at the start of its caption, as a part of its full size, above 0. |
emoji_pop_seconds |
number | 0.2 |
The time in which an emoji grows to its full size. 0 shows it at its full size at once. |
hold_seconds |
number | 0.1 |
The longest time that a caption stays after its last word ends. The caption goes earlier when the next caption starts. |
BoltLayers
class BoltLayers(NamedTuple)
What the effect gives for the words of one video.
Args:
ass_text: The text of the ASS script.emojis: One emoji layer for each caption with a keyword, in time order.
BoltSettings
@dataclass(frozen=True)
class BoltSettings(SpokenLineSettings)
The look and the timing of the bolt 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 SpokenLineSettings follow them, from the letter width to the shadow drop, and then the settings of the emoji and the hold time. The effect changes the defaults of some of them. The primary color is the color of the white lines. The stroke is the outline of the letters, which makes them heavier in the color of their line. 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.line_colors: The colors of the line that is spoken, as "#RRGGBB". The captions take them in turn.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.emoji_size: The side of the emoji in pixels, above 0.emoji_gap: Room in pixels between the caption and the emoji.emoji_places: The places of the emojis, one or more of "above" and "below". The captions with an emoji take them in turn.emoji_pop_scale: The size of an emoji at the start of its caption, as a part of its full size, above 0.emoji_pop_seconds: The time in which an emoji 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", when an emoji place is not known, or when the font name is empty or holds a comma.
BoltEffect
class BoltEffect
def __init__(
self, settings: BoltSettings,
keyword_picker: KeywordPicker = DEFAULT_KEYWORD_PICKER) -> None
Builds the ASS script and the emoji layers of heavy capitals with a black edge, whose spoken line is yellow, green or red, with an emoji above or below.
Args:
settings: The look and the timing of the effect.keyword_picker: Names the keywords of each caption. A caption with a keyword has an emoji. With no value, the keyword of a caption is its longest word when that word has seven letters or more.
BoltEffect.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 group has a shadow event 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.
BoltEffect.build_layers
def build_layers(
self, words: Sequence[Word], video: VideoInfo,
emoji_path: Path) -> BoltLayers
Build the ASS script and the emoji layers for one video.
The script is the script of build_ass_text. Each caption with a keyword has one emoji layer with the times of the caption.
Args:
words: The words of the video in time order, each with its times.video: The frame size and the duration of the video.emoji_path: The emoji image, such as an animated GIF or a PNG with a see-through background. The effect does not read the image. ffmpeg reads it when it draws the layers.
Returns:
The script and the emoji layers.
Raises:
TypeError: When the emoji path is not a Path.FileNotFoundError: When the emoji image is not a file.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.