captionbob docs

Version 1.0.0
Contents ↓

Python: captionbob.effects

captionbob.effects.hush

The hush effect: small white capitals whose words rise into place.

Each caption shows its words in small white capitals with no end marks. A caption holds up to six words, and it ends at each end mark, such as a comma. A caption stays on one line up to the line letters. 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.

The words of a caption show one by one at their places in the caption. A word shows at the start of its word: it fades in and rises from the rise height below its place into its place in the fade time. The caption leaves at once when it ends.

Each line of a caption has one text event with the times of the caption. In it each word is hidden until its rise is over, and then it shows. Each word has one rise event from the start of its word to the end of its rise. The rise event writes the whole line of the word with the other words hidden, so the word has its place in the line, and it moves the line up into its place while the word fades in. The rise events are on a layer of their own.

The settings of the lines, the places of the lines, the caption groups that end at each end mark, the words in capitals with no end marks, the rise of each word with the time at which it shows and the tags of its fade, the tags that show a word at a time and the text of a line with a word gap come from LineSettings, rise_place_tags, word_rises, rise_appear_centiseconds, power_fade_tags, caption_groups_at_marks, shown_group, appear_tags and word_gap_line_text of effect_common.

Source file: captionbob/effects/hush.py

Settings

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

Setting Type Default Description
most_words integer 6 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 42 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.612 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.0 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 6.7 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 26 The most letters, with the spaces, of a caption that stays on one line, 1 or above.
top_line_words integer 4 The words of the top line of a caption of two lines, 1 or above. The second line holds at least one word.
word_gap number 1.2 Room in pixels that is added after each space, at the letter width. A value below 0 puts the words closer.
rise_height number 30.0 How far below its place a word shows at the start of its rise, in pixels. 0 gives no rise, and a value below 0 shows the word above its place.
fade_seconds number 0.125 The time in which a word fades in and rises into its place. 0 shows each word in full at its place at once.
fade_power number 1.6 The power of the part of the fade time that gives the strength of a word, above 0. 1 gives a fade at one speed, and a power above 1 a fade that is slow at the start.
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.

HushSettings

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

The look and the timing of the hush 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 word gap, the settings of the rise and the fade, 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 caption that stays on one line, 1 or above.
  • top_line_words: The words of the top line of a caption of two lines, 1 or above. The second line holds at least one word.
  • word_gap: Room in pixels that is added after each space, at the letter width. A value below 0 puts the words closer.
  • rise_height: How far below its place a word shows at the start of its rise, in pixels. 0 gives no rise, and a value below 0 shows the word above its place.
  • fade_seconds: The time in which a word fades in and rises into its place. 0 shows each word in full at its place at once.
  • fade_power: The power of the part of the fade time that gives the strength of a word, above 0. 1 gives a fade at one speed, and a power above 1 a fade that is slow at the start.
  • 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".

HushSettings.line_words

def line_words(self, words: Sequence[Word]) -> list[list[Word]]

Cut the words of a caption into one line or two lines.

Args:

  • words: The words of the caption, as the effect shows them.

Returns:

One line when the caption has the line letters or fewer, with its spaces, or when it has one word. Else two lines: the top line with the top line words, and the second line with the rest. The second line holds at least one word.

HushSettings.fade_tags

def fade_tags(self) -> str

Write the tags of a word that fades in from the start of its rise event.

Returns:

The tags with no curly brackets. The word is hidden at the start, and its strength grows with the fade power of the part of the fade time that is over.

HushEffect

class HushEffect
    def __init__(self, settings: HushSettings) -> None

Builds the ASS script of small white capitals whose words fade in one by one and rise into their places.

Args:

  • settings: The look and the timing of the effect.

HushEffect.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 text event. The text 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. Each word whose rise has time has one rise 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.