Python: captionbob.effects
captionbob.effects.swipe_from_left
Swipe from left effect: a caption comes in from the left and fades out.
A caption shows a few words. It starts at the time at which its first word is spoken, outside the left edge of the video. In the first part of its time it moves to the middle of the video, fast at the start and slow at the end. Then it stays in the middle. In the last part of its time it fades out.
The swipe of a caption is a row of events of the script that follow one another, and each event is one straight move. One more event holds the caption in the middle and fades it out. The effect draws nothing itself. It builds the text of an ASS script, and the ffmpeg filter ass draws the script on the video. The swipe of the four swipe effects and the common part of the effects are in effect_common.py.
Source file: captionbob/effects/swipe_from_left.py
Settings
The command line and the HTTP API call this effect the style swipe_from_left. Its settings class is SwipeFromLeftSettings. 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 | "DejaVu Sans" |
Name of the font of the text. |
font_size |
integer | 80 |
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 | 6.0 |
Width of the outline in pixels. 0 gives no outline. |
bottom_position |
number | 0.75 |
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. |
swipe_in_part |
number | 0.3 |
The part of the time of a caption, at its start, in which it moves from the edge of the video to the middle, from 0 to 1. 0 shows the caption in the middle at once. |
fade_out_part |
number | 0.3 |
The part of the time of a caption, at its end, in which it fades out, from 0 to 1. 0 gives a caption that leaves with no fade. The two parts together are at most 1. |
hold_seconds |
number | 0.6 |
The longest time that a caption stays after its last word ends. The caption goes earlier when the next caption starts. |
SwipeFromLeftSettings
@dataclass(frozen=True)
class SwipeFromLeftSettings(SwipeSettings)
The look and the timing of the swipe from left effect.
The settings of SwipeSettings come first: the word counts, the font, the colors, the stroke, the bottom position, the side margin, the swipe in part and the fade out part. The hold time follows them. In this effect the side margins are those of a caption that sits in the middle. One word that is wider than the room between them has its end in the video when its caption starts. The swipe in part is the time in which a caption moves from the left edge to the middle.
Args:
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 the two parts together are above 1, when a color is not in the form "#RRGGBB", or when the font name is empty or holds a comma.
SwipeFromLeftEffect
class SwipeFromLeftEffect
def __init__(self, settings: SwipeFromLeftSettings) -> None
Builds the ASS script that brings each caption in from the left.
Args:
settings: The look and the timing of the effect.
SwipeFromLeftEffect.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 shows from the start of 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. The swipe in part of this time, in whole centiseconds, is cut into events that follow one another, and each event is one straight move of the caption. One more event holds the caption in the middle for the rest of the time and fades it out.
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.