captionbob docs

Version 1.0.0
Contents ↓

Python: captionbob.effects

captionbob.effects.remy

The remy effect: narrow leaning white capitals with a hard black shadow.

Each caption shows its words in narrow white capitals that lean to the right, with their end marks, such as commas and full stops. A caption holds up to five words, and three words or more when its sentence is long enough. It ends at each end mark. A caption of the top line words or fewer stays on one line. A longer caption is cut into two lines: the top line holds the first top line words, and the second line holds the rest. The top line stands on the bottom position, and the second line hangs the line gap below it.

Each word has a hard black shadow below it and to its right. The keywords of a caption are in a color, and the keywords of a video take the keyword colors in turn. A caption pops in a little larger than its size, and after the pop time it has its size. It leaves at once when it ends.

Each line of a caption is one event with the times of the caption. The top line grows from its bottom in the pop, and the second line grows from its top, so the two lines do not touch.

The settings of the lines, the places of the lines, the caption groups that end at each end mark, the words in capitals, the cut of a caption into lines by the words of its top line, the keywords and their colors in turn, the lean, the size tags, the spacing tags and the text of a line with tags for each word and each gap come from LineSettings, caption_groups_at_marks, group_in_capitals, lines_by_top_words, keyword_places, keywords_in_turn, keyword_word_tags, lean_tags, size_tags, spacing_tag and word_lines_text of effect_common.

Source file: captionbob/effects/remy.py

Settings

The command line and the HTTP API call this effect the style remy. Its settings class is RemySettings. Each setting has the default below.

Setting Type Default Description
most_words integer 5 The most words that one caption shows.
fewest_words integer 3 The fewest words that one caption shows, when its sentence is long enough for that.
font_name string "Ubuntu Condensed" Name of the font of the text.
font_size integer 106 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.5974 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.8 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 -13.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 24 The most letters, with the spaces, of a top line, 1 or above. A line with one word holds that word.
top_line_words integer 3 The most words of a caption that stays on one line, and of the top line of a caption of two lines, 1 or above.
letter_gap number 2.0 Room in pixels that is added after each letter, at the letter width. A value below 0 puts the letters closer.
word_gap number 3.2 Room in pixels that is added after each space, in place of the letter gap, at the letter width. A value below 0 puts the words closer.
slant number 0.2462 How far libass leans the letters, as the shear before the letter width. The top of a letter is the slant times the letter width of its height to the right of its bottom. 0 gives upright letters, and a value below 0 leans them to the left.
keyword_colors list ["#E40420", "#65FF27", "#F8FF34"] The colors of the keywords, as "#RRGGBB". The keywords of a video take them in turn.
shadow_color string "#000000" The color of the shadow, as "#RRGGBB".
shadow_right number 7.0 How far the shadow is to the right of the letters, in pixels. A value below 0 puts it to the left.
shadow_drop number 8.0 How far the shadow is below the letters, in pixels. A value below 0 puts it above them.
pop_scale number 1.1 The size of a caption in its pop time, as a part of its size, above 0. 1 gives no pop.
pop_seconds number 0.083 The time from the start of a caption in which it has the pop scale. 0 gives no pop.
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.

RemySettings

@dataclass(frozen=True)
class RemySettings(LineSettings)

The look and the timing of the remy 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 top line words, the letter gap, the word gap, the slant, the keyword colors, the settings of the shadow and of the pop, and the hold time. The effect changes the defaults of some of them. The stroke is the outline of the letters in their own color, 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 top line, 1 or above. A line with one word holds that word.
  • top_line_words: The most words of a caption that stays on one line, and of the top line of a caption of two lines, 1 or above.
  • letter_gap: Room in pixels that is added after each letter, at the letter width. A value below 0 puts the letters closer.
  • word_gap: Room in pixels that is added after each space, in place of the letter gap, at the letter width. A value below 0 puts the words closer.
  • slant: How far libass leans the letters, as the shear before the letter width. The top of a letter is the slant times the letter width of its height to the right of its bottom. 0 gives upright letters, and a value below 0 leans them to the left.
  • keyword_colors: The colors of the keywords, as "#RRGGBB". The keywords of a video take them in turn.
  • shadow_color: The color of the shadow, as "#RRGGBB".
  • shadow_right: How far the shadow is to the right of the letters, in pixels. A value below 0 puts it to the left.
  • shadow_drop: How far the shadow is below the letters, in pixels. A value below 0 puts it above them.
  • pop_scale: The size of a caption in its pop time, as a part of its size, above 0. 1 gives no pop.
  • pop_seconds: The time from the start of a caption in which it has the pop scale. 0 gives no pop.
  • 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, the line letters or the top line words is not a whole number.
  • ValueError: When a value is outside its range, or when a color is not in the form "#RRGGBB".

RemyEffect

class RemyEffect
    def __init__(
            self, settings: RemySettings,
            keyword_picker: KeywordPicker = DEFAULT_KEYWORD_PICKER) -> None

Builds the ASS script of narrow leaning white capitals with a hard black shadow and keywords in color, 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.

RemyEffect.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.

RemyEffect.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 the lines 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 each line.
  • caption_bottom: The row of the bottom of the top line.

Returns:

The event of each line from the top.