guide_subtitles_73.txt•14.7 kB
# Guide: Subtitles [Source Link](https://docs.videodb.io/guide-subtitles-73)
VideoDB Documentation
Pages
[Welcome to VideoDB Docs](https://docs.videodb.io/)
[Quick Start Guide](https://docs.videodb.io/quick-start-guide-38)
[How Accurate is Your Search?](https://docs.videodb.io/how-accurate-is-your-search-88)
[Video Indexing Guide](https://docs.videodb.io/video-indexing-guide-101)
[Semantic Search](https://docs.videodb.io/semantic-search-89)
[Collections](https://docs.videodb.io/collections-68)
[Public Collections](https://docs.videodb.io/public-collections-102)
[Callback Details](https://docs.videodb.io/callback-details-66)
[Ref: Subtitle Styles](https://docs.videodb.io/ref-subtitle-styles-57)
[Language Support](https://docs.videodb.io/language-support-79)
[Guide: Subtitles](https://docs.videodb.io/guide-subtitles-73)
[Visual Search and Indexing](https://docs.videodb.io/visual-search-and-indexing-80)
[Scene Extraction Algorithms](https://docs.videodb.io/scene-extraction-algorithms-84)
[Custom Annotations](https://docs.videodb.io/custom-annotations-81)
[Scene-Level Metadata: Smarter Video Search & Retrieval](https://docs.videodb.io/scene-level-metadata-smarter-video-search-retrieval-107)
[Advanced Visual Search Pipelines](https://docs.videodb.io/advanced-visual-search-pipelines-82)
[Playground for Scene Extractions](https://docs.videodb.io/playground-for-scene-extractions-83)
[Deep Dive into Prompt Engineering : Mastering Video Scene Indexing](https://docs.videodb.io/deep-dive-into-prompt-engineering-mastering-video-scene-indexing-93)
[Multimodal Search](https://docs.videodb.io/multimodal-search-90)
[Multimodal Search: Quickstart](https://docs.videodb.io/multimodal-search-quickstart-91)
[Conference Slide Scraper with VideoDB](https://docs.videodb.io/conference-slide-scraper-with-videodb-92)
[Dynamic Video Streams](https://docs.videodb.io/dynamic-video-streams-44)
[Ref: TextAsset](https://docs.videodb.io/ref-textasset-74)
[Guide : TextAsset](https://docs.videodb.io/guide-textasset-75)
[Director - Video Agent Framework](https://docs.videodb.io/director-video-agent-framework-98)
[Agent Creation Playbook](https://docs.videodb.io/agent-creation-playbook-103)
[How I Built a CRM-integrated Sales Assistant Agent in 1 Hour](https://docs.videodb.io/how-i-built-a-crm-integrated-sales-assistant-agent-in-1-hour-106)
[Make Your Video Sound Studio Quality with Voice Cloning](https://docs.videodb.io/make-your-video-sound-studio-quality-with-voice-cloning-105)
[Setup Director Locally](https://docs.videodb.io/setup-director-locally-104)
[Open Source Tools](https://docs.videodb.io/open-source-tools-94)
[LlamaIndex VideoDB Retriever](https://docs.videodb.io/llamaindex-videodb-retriever-58)
[PromptClip: Use Power of LLM to Create Clips](https://docs.videodb.io/promptclip-use-power-of-llm-to-create-clips-52)
[StreamRAG: Connect ChatGPT to VideoDB](https://docs.videodb.io/streamrag-connect-chatgpt-to-videodb-43)
[Examples and Tutorials](https://docs.videodb.io/examples-and-tutorials-35)
[Dubbing - Replace Soundtrack with New Audio](https://docs.videodb.io/dubbing-replace-soundtrack-with-new-audio-49)
[Beep curse words in real-time](https://docs.videodb.io/beep-curse-words-in-real-time-53)
[Remove Unwanted Content from videos](https://docs.videodb.io/remove-unwanted-content-from-videos-5)
[Instant Clips of Your Favorite Characters](https://docs.videodb.io/instant-clips-of-your-favorite-characters-3)
[Insert Dynamic Ads in real-time](https://docs.videodb.io/insert-dynamic-ads-in-real-time-7)
[Adding Brand Elements with VideoDB](https://docs.videodb.io/adding-brand-elements-with-videodb-76)
[Revolutionize Video Editing with VideoDb: Effortless Ad Placement and Seamless Video Integration](https://docs.videodb.io/revolutionize-video-editing-with-videodb-effortless-ad-placement-8)
[Eleven Labs x VideoDB: Adding AI Generated voiceovers to silent footage](https://docs.videodb.io/eleven-labs-x-videodb-adding-ai-generated-voiceovers-to-silent-f-59)
[Elevating Trailers with Automated Narration](https://docs.videodb.io/elevating-trailers-with-automated-narration-60)
[Add Intro/Outro to Videos](https://docs.videodb.io/add-intro-outro-to-videos-61)
[Enhancing Video Captions with VideoDB Subtitle Styling](https://docs.videodb.io/enhancing-video-captions-with-videodb-subtitle-styling-62)
[Audio overlay + Video + Timeline](https://docs.videodb.io/audio-overlay-video-timeline-63)
[Building Dynamic Video Streams with VideoDB: Integrating Custom Data and APIs](https://docs.videodb.io/building-dynamic-video-streams-with-videodb-integrating-custom-d-85)
[Adding AI Generated Voiceovers with VideoDB and LOVO](https://docs.videodb.io/adding-ai-generated-voiceovers-with-videodb-and-lovo-70)
[AI Generated Ad Films for Product Videography: Wellsaid, Open AI & VideoDB](https://docs.videodb.io/ai-generated-ad-films-for-product-videography-wellsaid-open-ai-v-71)
[Fun with Keyword Search](https://docs.videodb.io/fun-with-keyword-search-77)
[AWS Rekognition and VideoDB - Intelligent Video Clips](https://docs.videodb.io/aws-rekognition-and-videodb-intelligent-video-clips-4)
[AWS Rekognition and VideoDB - Effortlessly Remove Inappropriate Content from Video](https://docs.videodb.io/aws-rekognition-and-videodb-effortlessly-remove-inappropriate-co-6)
[Overlay a Word-Counter on Video Stream](https://docs.videodb.io/overlay-a-word-counter-on-video-stream-86)
[Generate Automated Video Outputs with Text Prompts \| DALL-E + ElevenLabs + OpenAI + VideoDB](https://docs.videodb.io/generate-automated-video-outputs-with-text-prompts-dall-e-eleven-87)
[Edge of Knowledge](https://docs.videodb.io/edge-of-knowledge-10)
[Building Intelligent Machines](https://docs.videodb.io/building-intelligent-machines-16)
[Part 1 - Define Intelligence](https://docs.videodb.io/part-1-define-intelligence-17)
[Part 2 - Observe and Respond](https://docs.videodb.io/part-2-observe-and-respond-18)
[Part 3 - Training a Model](https://docs.videodb.io/part-3-training-a-model-19)
[Society of Machines](https://docs.videodb.io/society-of-machines-20)
[Society of Machines](https://docs.videodb.io/society-of-machines-23)
[Autonomy - Do we have the choice?](https://docs.videodb.io/autonomy-do-we-have-the-choice-21)
[Emergence - An Intelligence of the collective](https://docs.videodb.io/emergence-an-intelligence-of-the-collective-22)
[Drafts](https://docs.videodb.io/drafts-24)
[From Language Models to World Models: The Next Frontier in AI](https://docs.videodb.io/from-language-models-to-world-models-the-next-frontier-in-ai-65)
[The Future Series](https://docs.videodb.io/the-future-series-78)
[Building World's First Video Database](https://docs.videodb.io/building-worlds-first-video-database-25)
[Multimedia: From MP3/MP4 to the Future with VideoDB](https://docs.videodb.io/multimedia-from-mp3-mp4-to-the-future-with-videodb-26)
[Introducing VideoDB: The Pinnacle of Synchronized Video Streaming for the Modern Web](https://docs.videodb.io/introducing-videodb-the-pinnacle-of-synchronized-video-streaming-27)
[Dynamic Video Streams](https://docs.videodb.io/dynamic-video-streams-50)
[Why do we need a Video Database Now?](https://docs.videodb.io/why-do-we-need-a-video-database-now-41)
[What's a Video Database ?](https://docs.videodb.io/whats-a-video-database-36)
[Enhancing AI-Driven Multimedia Applications](https://docs.videodb.io/enhancing-ai-driven-multimedia-applications-37)
[Misalignment of Today's Web](https://docs.videodb.io/misalignment-of-todays-web-67)
[Beyond Traditional Video Infrastructure](https://docs.videodb.io/beyond-traditional-video-infrastructure-28)
[Research Grants](https://docs.videodb.io/research-grants-96)
[Team](https://docs.videodb.io/team-46)
[Internship: Build the Future of AI-Powered Video Infrastructure](https://docs.videodb.io/internship-build-the-future-of-ai-powered-video-infrastructure-97)
[Ashutosh Trivedi](https://docs.videodb.io/ashutosh-trivedi-32)
[Playlists](https://docs.videodb.io/playlists-33)
[Talks - Solving Logical Puzzles with Natural Language Processing - PyCon India 2015](https://docs.videodb.io/talks-solving-logical-puzzles-with-natural-language-processing-p-34)
[Ashish](https://docs.videodb.io/ashish-45)
[Shivani Desai](https://docs.videodb.io/shivani-desai-48)
[Gaurav Tyagi](https://docs.videodb.io/gaurav-tyagi-51)
[Rohit Garg](https://docs.videodb.io/rohit-garg-64)
[Customer Love](https://docs.videodb.io/customer-love-42)
[Temp Doc](https://docs.videodb.io/temp-doc-54)
Quick Start Guide
# Guide: Subtitles
[](https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/guides/Subtitle.ipynb)
## 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
[VideoDB](https://videodb.io/)
Get your API key from
[VideoDB Console](https://console.videodb.io/)
. ( 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()
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
[streaming link](https://docs.videodb.io/unraveling-multimedia-from-mp3-mp4-to-the-future-with-videodb-26#_luGNZ)
, 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, passSubtitleStytle()with configured styles tovideo.add\_subtitle()
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 toTrue 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)
### 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.
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)
### 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
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)
### 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)
### 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 typeSubtitleBorderStyle
outline: The width(px) of the outline around the text.
shadow : The depth(px) of the shadow behind the text
View API Reference to know more about SubtitleBorderStyle
from videodb import SubtitleStyle, SubtitleBorderStyle
stream\_url = video.add\_subtitle(
style=SubtitleStyle(
shadow=2,
back\_colour="&H00000000",
border\_style=SubtitleBorderStyle.no\_border,
)
)
play\_stream(stream\_url)
## 👨💻 Next Steps
Check out the other resources and tutorials using Subtitle and Subtitle Styling 💅.
[Enhancing Video Captions with VideoDB Subtitle Styling](https://docs.videodb.io/enhancing-video-captions-with-videodb-subtitle-styling-62)
If you have any questions or feedback. Feel free to reach out to us 🙌🏼
[Discord](https://discord.gg/py9P639jGz)
[GitHub](https://github.com/video-db)
[Email](mailto:ashu@videodb.io)
Adding Subtitles
🛠️ Setup
📦 Installing packages
🔑 API Keys
🌐 Connect to VideoDB
🎥 Upload Video
🔊 Index Spoken Words
📝 Default Subtitles
💅 Custom Styled Subtitles
1\. Typography and Style
2\. Color and Effects
3\. Position and Margins
4\. Text Transformation
5\. Borders and Shadow
👨💻 Next Steps
---