captionbob docs

Version 1.0.0
Contents ↓

Python: captionbob.effects

captionbob.effects.poppy

Poppy effect: bold rounded white words that pop in, with an emoji.

Each caption shows one or two words in bold rounded white letters with a black outline, in the case in which they are spoken and with no end marks. Each caption pops in: it starts a little smaller and grows to its full size in a short time, with its outline. A keyword has a cream fill and a dark olive outline. In the video, the colors of a thin outline spread a little into the letters, so the edge of a keyword shows a thin yellow green line.

A caption with a keyword has an emoji in the middle of the caption, above it or below it. The emoji captions of a video take the emoji places in turn. The emoji pops in with its caption and goes with it. The ffmpeg filters scale and overlay draw the emoji under the ASS script. The effect gives the place of the emoji as ffmpeg expressions on an emoji layer, and it reads no image.

The effect draws nothing itself. It builds the text of an ASS script and the emoji layers, and ffmpeg draws them on the video. The common part of the effects is in effect_common.py.

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/poppy.py

Settings

The command line and the HTTP API call this effect the style poppy. Its settings class is PoppySettings. 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 100 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 "#000000" Color of the outline of the text, as "#RRGGBB".
stroke_width number 9.0 Width of the outline in pixels. 0 gives no outline.
bottom_position number 0.697 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.08 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.
keyword_color string "#FFFFF7" Color of the letters of a keyword, as "#RRGGBB".
keyword_stroke_color string "#1E2000" Color of the outline of a keyword, as "#RRGGBB". The outline has the stroke width.
pop_scale number 0.91 The size of a caption and its emoji at their start, as a part of their full size, above 0.
pop_seconds number 0.1 The time in which a caption and its emoji grow to their full size. 0 shows them at their full size at once.
emoji_size number 168.0 The side of the emoji in pixels, above 0.
emoji_gap number 27.0 Room in pixels between the emoji and the caption. An emoji above the caption has its bottom the font size and the gap above the bottom of the caption. An emoji below the caption has its top the gap below the bottom of the caption.
emoji_places list ["above", "below"] The places of the emojis, one or more of "above" and "below". The emoji captions of a video take them in turn.
hold_seconds number 0.3 The longest time that a caption stays after its last word ends. The caption goes earlier when the next caption starts.

PoppyLayers

class PoppyLayers(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.

PoppySettings

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

The look and the timing of the poppy effect.

The settings of CaptionSettings come first: the word counts, the font, the colors, the stroke, the bottom position and the side margin. These settings follow them. The primary color is the color of the plain words, and the stroke is their outline.

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.
  • keyword_color: Color of the letters of a keyword, as "#RRGGBB".
  • keyword_stroke_color: Color of the outline of a keyword, as "#RRGGBB". The outline has the stroke width.
  • pop_scale: The size of a caption and its emoji at their start, as a part of their full size, above 0.
  • pop_seconds: The time in which a caption and its emoji grow to their full size. 0 shows them at their full size at once.
  • emoji_size: The side of the emoji in pixels, above 0.
  • emoji_gap: Room in pixels between the emoji and the caption. An emoji above the caption has its bottom the font size and the gap above the bottom of the caption. An emoji below the caption has its top the gap below the bottom of the caption.
  • emoji_places: The places of the emojis, one or more of "above" and "below". The emoji captions of a video take them in turn.
  • 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 is not a whole number.
  • ValueError: When a value is outside its range, when a color is not in the form "#RRGGBB", when the emoji places are not a tuple of known places, or when the font name is empty or holds a comma.

PoppyEffect

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

Builds the ASS script and the emoji layers of bold rounded white words that pop in, with keywords and an emoji above or below.

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.

PoppyEffect.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 group is one event. An event starts with the first word of its caption. 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.

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.

PoppyEffect.build_layers

def build_layers(
        self, words: Sequence[Word], video: VideoInfo,
        emoji_path: Path) -> PoppyLayers

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.