captionbob docs

Version 1.0.0
Contents ↓

Python: captionbob.effects

captionbob.effects.cobalt

Cobalt effect: white words in one line, with a larger blue keyword.

The effect clones the look of the source video Theo:

  • A caption holds up to three words, and it also ends at each end mark, such as a comma. It shows its words as spoken, with their end marks, in one line in the middle of the video.
  • The letters are white, medium weight and set close together, with a thin spread in their own color. They have no outline and no shadow.
  • The keyword of a caption is larger and blue, on the line of the other words. A caption with a keyword stands a little lower.
  • The captions take five entrances in turn: a rise from a little below its place, no entrance, a short dim of the whole caption, the words fading in one by one as they are spoken, and a slow growth for the whole time of the caption.

Each caption is one event. A caption with more letters than the widest line letters is made smaller in step, so that it stays in one line.

Source file: captionbob/effects/cobalt.py

Settings

The command line and the HTTP API call this effect the style cobalt. Its settings class is CobaltSettings. 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 82 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 0.3 Width of the outline in pixels. 0 gives no outline.
bottom_position number 0.6703 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_spacing number -4.5 Room in pixels after each letter of a word at its full size. A value below 0 puts the letters closer.
word_gap number 3.7 Room in pixels that is added to each space. A value below 0 puts the words closer.
end_at_marks boolean true True to end a caption also at each end mark, such as a comma.
widest_line_letters integer 27 The most letters, with the spaces, of a caption at its full size, 1 or above. A keyword letter counts as large as the keyword scale. A caption with more letters is made smaller in step. A caption that grows counts its letters at its size at its end.
keyword_color string "#29B3F6" The color of a keyword, as "#RRGGBB".
keyword_scale number 1.38 The size of a keyword as a part of the size of the other words, above 0.
keyword_drop number 29.0 How far a caption with a keyword stands below a caption with none, in pixels at the full size. A value below 0 puts it higher.
turns list ["rise", "still", "dim", "words", "grow"] The entrances that the captions take in order, each one of "rise", "still", "dim", "words" and "grow".
rise_distance number 19.0 How far below its place a caption that rises shows at its start, in pixels. A value below 0 shows it above.
rise_seconds number 0.12 The time in which a caption rises to its place, 0 or above.
rise_delay number 0.5 The part of the rise time in which the caption waits below its place before it moves, from 0 to 1.
dim_start_seconds number 0.06 The time after its start at which a caption that dims gets the dim opacity, 0 or above.
dim_end_seconds number 0.2 The time after its start at which it gets its full strength again, not before the dim start.
dim_opacity number 0.28 The strength of a caption while it is dim, from 0 for not seen to 1.
word_fade_seconds number 0.12 The time in which a word of a caption that shows its words one by one fades in, 0 or above.
grow_scale number 1.085 The size at its end of a caption that grows, as a part of its size at its start, above 0.
hold_seconds number 0.0 The longest time that a caption stays after its last word ends.

CobaltSettings

@dataclass(frozen=True)
class CobaltSettings(CaptionSettings)

The look and the timing of the cobalt effect.

The settings of CaptionSettings come first: the word counts, the font, the colors, the stroke, the bottom position and the side margin. The stroke is a spread of the letters. A word with no keyword has the stroke color, and a keyword has a spread in its own color. The bottom position is the bottom of the line box of a caption with no keyword. These settings follow them.

Args:

  • letter_spacing: Room in pixels after each letter of a word at its full size. A value below 0 puts the letters closer.
  • word_gap: Room in pixels that is added to each space. A value below 0 puts the words closer.
  • end_at_marks: True to end a caption also at each end mark, such as a comma.
  • widest_line_letters: The most letters, with the spaces, of a caption at its full size, 1 or above. A keyword letter counts as large as the keyword scale. A caption with more letters is made smaller in step. A caption that grows counts its letters at its size at its end.
  • keyword_color: The color of a keyword, as "#RRGGBB".
  • keyword_scale: The size of a keyword as a part of the size of the other words, above 0.
  • keyword_drop: How far a caption with a keyword stands below a caption with none, in pixels at the full size. A value below 0 puts it higher.
  • turns: The entrances that the captions take in order, each one of "rise", "still", "dim", "words" and "grow".
  • rise_distance: How far below its place a caption that rises shows at its start, in pixels. A value below 0 shows it above.
  • rise_seconds: The time in which a caption rises to its place, 0 or above.
  • rise_delay: The part of the rise time in which the caption waits below its place before it moves, from 0 to 1.
  • dim_start_seconds: The time after its start at which a caption that dims gets the dim opacity, 0 or above.
  • dim_end_seconds: The time after its start at which it gets its full strength again, not before the dim start.
  • dim_opacity: The strength of a caption while it is dim, from 0 for not seen to 1.
  • word_fade_seconds: The time in which a word of a caption that shows its words one by one fades in, 0 or above.
  • grow_scale: The size at its end of a caption that grows, as a part of its size at its start, above 0.
  • hold_seconds: The longest time that a caption stays after its last word ends.

Raises:

  • TypeError: When a word count or the widest 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 turn is not known.

CobaltSettings.turn_of

def turn_of(self, caption_index: int) -> str

Give the turn of a caption.

Args:

  • caption_index: The place of the caption in the captions of the video, 0 for the first.

Returns:

The turns in order from the first caption, again and again.

CobaltEffect

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

Builds the ASS script of white words in one line with a larger blue keyword, whose captions take five entrances in turn.

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.

CobaltEffect.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 starts with its first word. It ends when the next caption starts, and at the latest the hold time after its last word and at the end of the video. Each caption is one event.

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.