videodb
VideoDB Documentation
videodb
VideoDB Documentation
Quick Start Guide

icon picker
Guide: Subtitles

Adding Subtitles

This guide gives you an introduction to adding Subtitle Styles by showing you visual outputs of the configurations available for the SubtitleStyle class, such as
Typography and Style
Color and Effects
Positioning and Margins
Text Transformation
Borders and Shadow

🛠️ Setup

📦 Installing packages

%pip install videodb

🔑 API Keys

Before proceeding, ensure access to
light
Get your API key from . ( Free for first 50 uploads, No credit card required ) 🎉
import os

os.environ["VIDEO_DB_API_KEY"] = ""

🌐 Connect to VideoDB

from videodb import connect

conn = connect()
coll = conn.get_collection()

🎥 Upload Video

Upload a base video to add subtitle. For this guide, we’ll use following video
video = coll.upload(url="https://www.youtube.com/watch?v=il39Ks4mV9g")
video.play()
info
You can upload from your local file system too by passing file_path in upload()

🔊 Index Spoken Words

First, we need to index the video using video.index_spoken_words() function.This ensures the availability of the transcript. Without this step VideoDB wouldn’t be able to add captions to any video.
video.index_spoken_words()

📝 Default Subtitles

To add subtitles to your video you can use video.add_subtitle() .
This method returns a , that you can play using play_stream() method
from videodb import play_stream
# Add Subtitle to Video
stream_url = video.add_subtitle()

# Play stream
play_stream(stream_url)

💅 Custom Styled Subtitles

To customise the style of subtitle, pass SubtitleStytle() with configured styles to video.add_subtitle()
info
View API Reference for SubtitleStyle class 💅

1. Typography and Style

Configure Typography of the Subtitle by passing following parameters to SubtitleStyle() class
font_name : The name of the font to use for the subtitles.
font_size : The size(px) of the font
spacing : Spacing(px) between characters
bold : Set to True for bold text
italic : Set to True for italic text
underline : Set to True for underlined text
strike_out : Set to True for strike-through text
from videodb import SubtitleStyle, play_stream

stream_url = video.add_subtitle(
SubtitleStyle(
font_name = "Roboto",
font_size = 12,
spacing = 0,
bold = False,
italic = False,
underline = False,
strike_out = False
)
)
play_stream(stream_url)

1 (1).png

2. Color and Effects

Configure color of Subtitle by passing following parameters to SubtitleStyle() class
primary_colour : The color of the main subtitle text.
secondary_colour : The color used for karaoke or secondary effects.
outline_colour : The color of the outline of the text.
back_colour : The color of the subtitle background.
info
Format of Color
SubtitleStyle accepts colors in the &HBBGGRR hexadecimal format, where the sequence represents the blue, green, and red components,
&H prefix is required in this color format.
And when transparency is needed, an alpha value is placed at the beginning, yielding &HAABBGGRR.
from videodb import SubtitleStyle

stream_url = video.add_subtitle(
SubtitleStyle(
primary_colour = "&H00A5CFFF",
secondary_colour = "&H00FFFF00",
outline_colour = "&H000341C1",
back_colour = "&H803B3B3B",
)
)
play_stream(stream_url)


2.png


3. Position and Margins

Configure alignment and position of Subtitle by passing following parameters to SubtitleStyle() class
alignment : Alignment of subtitle. Accepts a value a type SubtitleAlignment
margin_l : Sets margin area on left side of Subtitle box
margin_r : Sets margin area on right side of Subtitle box
margin_v : Sets margin area of top and bottom of Subtitle box
info
View API Reference to know more about SubtitleAlignment

from videodb import SubtitleStyle, SubtitleAlignment

stream_url = video.add_subtitle(
SubtitleStyle(
alignment = SubtitleAlignment.middle_center,
margin_l = 10,
margin_r = 10,
margin_v = 20,
)
)
play_stream(stream_url)

3.png


4. Text Transformation

Transform the text size and spacing by passing following parameters to SubtitleStyle() class
scale_x : Factor for scaling of the font horizontally
scale_y : Factor for scaling of the font vertically
angle : Rotation angle(degress) of the text
from videodb import SubtitleStyle

stream_url = video.add_subtitle(
SubtitleStyle(
scale_x = 1.5,
scale_y = 3,
angle = 0,
)
)

play_stream(stream_url)

4 (1).png

5. Borders and Shadow

Add border style, outline and shadow by passing following parameters to SubtitleStyle() class
border_style : Border style of subtitle. Accepts a value a type SubtitleBorderStyle
outline : The width(px) of the outline around the text.
shadow : The depth(px) of the shadow behind the text
info
View API Reference to know more about SubtitleBorderStyle

from videodb import SubtitleStyle, SubtitleBorderStyle

5.png

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.