Python: captionbob.effects
captionbob.effects.swipe_from_right_with_trail
Swipe from right with trail effect: a caption comes in with a trail.
A caption shows a few words. It starts at the time at which its first word is spoken, outside the right 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. In this part a trail is behind it: each letter is smeared to the right in the color of the stroke. The trail is strongest next to a letter, and it gets weaker in a straight line to nothing at its end. When the caption is in the middle, the trail is gone. The caption stays there, and in the last part of its time it fades out. This is the mirror of the swipe from left with trail effect. The old effect drew its trail to the left of the caption, in front of it. This effect draws the trail behind the caption.
The old effect makes the trail half as long as its text. Here the length of the trail is a part of the width of the video.
The swipe of a caption is a row of events of the script that follow one another, and each event is one straight move. Under each of these events are the events of the trail, with the same times. 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 and the trail of the swipe effects and the common part of the effects are in effect_common.py.
Source file: captionbob/effects/swipe_from_right_with_trail.py
Settings
The command line and the HTTP API call this effect the style swipe_from_right_with_trail. Its settings class is SwipeFromRightWithTrailSettings. 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. |
trail_length |
number | 0.25 |
How far the trail reaches from a letter, as a part of the width of the video, from 0 to 1. 0 gives no trail. |
trail_opacity |
number | 0.5 |
How strong the trail is next to a letter, from 0 to 1. 0 gives no trail. |
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. |
SwipeFromRightWithTrailSettings
@dataclass(frozen=True)
class SwipeFromRightWithTrailSettings(TrailSettings)
The look and the timing of the swipe from right with trail effect.
The settings of TrailSettings come first: the word counts, the font, the colors, the stroke, the bottom position, the side margin, the swipe in part, the fade out part, the trail length and the trail opacity. The hold time follows them. In this effect the trail has the stroke color, and it reaches to the right of a letter. 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 start in the video when its caption starts. The swipe in part is the time in which a caption moves from the right edge to the middle, and 0 gives no trail.
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.
SwipeFromRightWithTrailEffect
class SwipeFromRightWithTrailEffect
def __init__(self, settings: SwipeFromRightWithTrailSettings) -> None
Builds the ASS script that brings each caption in with a trail.
Args:
settings: The look and the timing of the effect.
SwipeFromRightWithTrailEffect.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. The smears of the trail are in front of each of these events, with its times. 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.