TextAsset API Reference
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 TextStyle class.
Checkout to dive deep into the outputs of these parameters
Import
Import TextStyle from videodb.asset
from videodb import connect
from videodb.asset import TextAsset, TextStyle
Usage
Here's how you might typically use the TextStyle class 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.
Checkout List of Supported Fonts
fontsize
The size of the text
fontcolor
The color of the font.
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)
borderw
The width of the border around the text.
bordercolor
The color of the text border.
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
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
To learn more about expressions, checkout Using Expression in Position
box
Whether to draw a background box around the text.
boxw
The width of the background box.
boxh
The height of the background box.
boxcolor
The color of the background box.
See also Color Format & recognized colors
boxborderw
The width of the border to be drawn around the box using boxcolor
text_align
The alignment of the text within its box.
This accepts a parameter which can be Horizonatal Flag , Vertical flag or Combination of both:
Horizontal-Flag : L , C or M Vertical-Flag : T , M or B Vertical-Flag + Horizontal-Flag
y_align
Specify what the y value is referred to.
Possible values are:
shadowx
Horizontal shadow offset.
shadowy
Vertical shadow offset.
shadowcolor
The color of the shadow behind the text.
tabsize
The size of a tab character in spaces.
line_spacing
Set the line spacing in pixel
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 & tw and bind them using a simple mathematical expression.
Variable Available in Position Expressions
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: