Overlaying Text elements on a video is very useful in multiple scenarios. VideoDB’s Asset class let’s you define a text asset with rich style with many fonts, colors and positions to add into your stream in real time.
This document provides an API Reference to interface with the TextStyleclass.
Here's how you might typically use the TextStyleclass in your application:
from videodb import connect
from videodb.asset import TextAsset, TextStyle
conn =connect()
coll = conn.get_collection()
video = coll.get_video("MY_VIDEO_ID")
text_asset =TextAsset(
text="THIS IS A TEXT Asset",
duration=5,
style=TextStyle(
font="Inter",
fontsize=50,
fontcolor="#FFCFA5",
)
)
TextStyle
font
The font family used for the text.
Default: "Sans"
Type:str
Checkout List of Supported Fonts
fontsize
The size of the text
Default: 24
Type:int
fontcolor
The color of the font.
Default: black
Type:str
See also Color Format & recognized colors
alpha
Transparency level of the text.
The value can be a number between 0.0 and 1.0
Default: 1.0 (fully opaque)
Type:float
borderw
The width of the border around the text.
Default: 0
Type:float
bordercolor
The color of the text border.
Default: black
Type:str
x
The horizontal position of the text, can be a expression(str) or fixed value(float)
They are relative to the left border of Video
Default: "(w -tw )/2"
Type: int or str
To learn more about expressions, checkout Using Expression in Position
y
The horizontal position of the text, can be a expression(str) or fixed value(float)
They are relative to the left border of Video
Default: "(h -th )/2"
Type: int or str
To learn more about expressions, checkout Using Expression in Position
box
Whether to draw a background box around the text.
Default: True
Type: bool
boxw
The width of the background box.
Default:0
Type:float
boxh
The height of the background box.
Default:0
Type:float
boxcolor
The color of the background box.
Default: white
Type:str
See also Color Format & recognized colors
boxborderw
The width of the border to be drawn around the box using boxcolor
Default: 10
Type:float
text_align
The alignment of the text within its box.
Default: T+L
Type:str
This accepts a parameter which can be Horizonatal Flag , Vertical flag or Combination of both:
Horizontal-Flag :L , CorM
Vertical-Flag : T , M or B
Vertical-Flag + Horizontal-Flag
y_align
Specify what the y value is referred to.
Default: text
Type:str
Possible values are:
text
baseline
font
shadowx
Horizontal shadow offset.
Default:0
Type:float
shadowy
Vertical shadow offset.
Default: 0
Type:float
shadowcolor
The color of the shadow behind the text.
Default: black
Type: str
tabsize
The size of a tab character in spaces.
Default: 4
Type:int
line_spacing
Set the line spacing in pixel
Default: 0
Type:int
Using Expression in Position
Expressions can be used to set positions of TextAsset .
To Create a expression, you need to use variables and bind them using mathematical expression
See List of available variables
Example:
Consider this expression : (w - tw ) /2
Above expression uses variables w & twand bind them using a simple mathematical expression.
Variable Available in Position Expressions
w : Width of Video
h : Height of Video
tw: Width of TextAsset
th : Height of TextAsset
sar : Video’s aspect ratio.
rand(min, max) : Returns a random number included between min and max
Color Format
TextStyle accepts colors in various formats, detailed in the ffmpeg-utils "Color" section. This includes support for both named colors and RGB(A) hex codes.
Recognized colors
The following names of colors are recognized along with their hexadecimal values: