Python: captionbob.effects
captionbob.effects.rosie
The rosie effect: large bold white words with a red keyword.
Each caption shows one or two words in bold white letters, in the case of the transcript and with no end marks, such as commas. A caption ends at each end mark. The letters are a little wider than the font gives them, and an outline of their own color makes them heavier. The keyword of a caption, its longest word when that word is long enough, has the keyword color. A caption with no such word has no keyword.
A caption shows whole from the start of its first word, with no move and no fade. It stays on one line up to the line letters, and a longer caption has two lines: the top line stands on the bottom position, and the second line hangs the line gap below it. Each line is centred in the video and is one event.
The settings of the lines and their places, the captions with their lines, their times and their keywords, the tags of each word with a keyword, the tags of the colors of the letters and of their outline, the text of a line and the size tags of the letter width come from effect_common.
The effect draws nothing itself. It builds the text of an ASS script, and ffmpeg draws it on the video. The defaults are the look of the source video of the effect, measured on its frames and scaled to a video of 1080x1920.
Source file: captionbob/effects/rosie.py
Settings
The command line and the HTTP API call this effect the style rosie. Its settings class is RosieSettings. 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 | 120 |
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 | 1.0 |
Width of the outline in pixels. 0 gives no outline. |
bottom_position |
number | 0.6063 |
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.03 |
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 | 18 |
The most letters, with the spaces, of a caption that stays on one line, 1 or above. |
keyword_color |
string | "#EA0122" |
The color of the letters of a keyword, as "#RRGGBB". |
keyword_stroke_color |
string | "#EA0122" |
The color of the outline of a keyword, as "#RRGGBB". |
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. |
RosieSettings
@dataclass(frozen=True)
class RosieSettings(LineSettings)
The look and the timing of the rosie 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 colors of the keyword and the hold time. The effect changes the defaults of some of them. The stroke is an outline of the letters, in their color by default, 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.keyword_color: The color of the letters of a keyword, as "#RRGGBB".keyword_stroke_color: The color of the outline of a keyword, as "#RRGGBB".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, or when a color is not in the form "#RRGGBB".
RosieEffect
class RosieEffect
def __init__(
self, settings: RosieSettings,
keyword_picker: KeywordPicker = DEFAULT_KEYWORD_PICKER) -> None
Builds the ASS script of one or two words in large bold white letters, with the keyword of a caption in red.
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.
RosieEffect.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 one 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.