Skip to content
videodb
VideoDB Documentation
  • Pages
    • Welcome to VideoDB Docs
    • Quick Start Guide
      • Video Indexing Guide
      • Semantic Search
      • Collections
      • Public Collections
      • Callback Details
      • Ref: Subtitle Styles
      • Language Support
      • Guide: Subtitles
      • How Accurate is Your Search?
    • Visual Search and Indexing
      • Scene Extraction Algorithms
      • Custom Annotations
      • Scene-Level Metadata: Smarter Video Search & Retrieval
      • Advanced Visual Search Pipelines
      • Playground for Scene Extractions
      • Deep Dive into Prompt Engineering : Mastering Visual Indexing
      • How VideoDB Solves Complex Visual Analysis Tasks
      • Multimodal Search: Quickstart
      • Conference Slide Scraper with VideoDB
    • Examples and Tutorials
      • Dubbing - Replace Soundtrack with New Audio
      • VideoDB: Adding AI Generated voiceovers to silent footage
      • Beep curse words in real-time
      • Remove Unwanted Content from videos
      • Instant Clips of Your Favorite Characters
      • Insert Dynamic Ads in real-time
      • Adding Brand Elements with VideoDB
      • Elevating Trailers with Automated Narration
      • Add Intro/Outro to Videos
      • Audio overlay + Video + Timeline
      • icon picker
        Building Dynamic Video Streams with VideoDB: Integrating Custom Data and APIs
      • AI Generated Ad Films for Product Videography
      • Fun with Keyword Search
      • Overlay a Word-Counter on Video Stream
      • Generate Automated Video Outputs with Text Prompts | VideoDB
      • Multimodal Search
      • How I Built a CRM-integrated Sales Assistant Agent in 1 Hour
      • Make Your Video Sound Studio Quality with Voice Cloning
      • Automated Traffic Violation Reporter
      • VideoDB x TwelveLabs: Real-Time Video Understanding
    • Live Video→ Instant Action
    • Generative Media Quickstart
      • Generative Media Pricing
    • Video Editing Automation
      • Fit & Position: Aspect Ratio Control
      • Trimming vs Timing: Two Independent Timelines
      • Advanced Clip Control: The Composition Layer
      • Caption & Subtitles: Auto-Generated Speech Synchronization
      • Example Notebooks
    • Transcoding Quickstart
    • director-light
      Director - Video Agent Framework
      • Agent Creation Playbook
      • Setup Director Locally
    • Workflows and Integrations
      • zapier
        Zapier Integration
        • Auto-Dub Videos & Save to Google Drive
        • Create & Add Intelligent Video Highlights to Notion
        • Create GenAI Video Engine - Notion Ideas to Youtube
        • Automatically Detect Profanity in Videos with AI - Update on Slack
        • Generate and Store YouTube Video Summaries in Notion
        • Automate Subtitle Generation for Video Libraries
        • Solve customers queries with Video Answers
      • n8n
        N8N Workflows
        • AI-Powered Meeting Intelligence: Recording to Insights Automation
        • AI Powered Dubbing Workflow for Video Content
        • Automate Subtitle Generation for Video Libraries
        • Automate Interview Evaluations with AI
        • Turn Meeting Recordings into Actionable Summaries
        • Auto-Sync Sales Calls to HubSpot CRM with AI
        • Instant Notion Summaries for Your Youtube Playlist
    • Meeting Recording SDK
    • github
      Open Source
      • llama
        LlamaIndex VideoDB Retriever
      • PromptClip: Use Power of LLM to Create Clips
      • StreamRAG: Connect ChatGPT to VideoDB
    • mcp
      VideoDB MCP Server
    • videodb
      Give your AI, Eyes and Ears
      • Building Infrastructure that “Sees” and “Edits”
      • Agents with Video Experience
      • From MP3/MP4 to the Future with VideoDB
      • Dynamic Video Streams
      • Why do we need a Video Database Now?
      • What's a Video Database ?
      • Enhancing AI-Driven Multimedia Applications
      • Beyond Traditional Video Infrastructure
    • Customer Love
    • Join us
      • videodb
        Internship: Build the Future of AI-Powered Video Infrastructure
      • Ashutosh Trivedi
        • Playlists
        • Talks - Solving Logical Puzzles with Natural Language Processing - PyCon India 2015
      • Ashish
      • Shivani Desai
      • Gaurav Tyagi
      • Rohit Garg
      • Edge of Knowledge
        • Language Models to World Models: The Next Frontier in AI
        • Society of Machines
          • Society of Machines
          • Autonomy - Do we have the choice?
          • Emergence - An Intelligence of the collective
        • Building Intelligent Machines
          • Part 1 - Define Intelligence
          • Part 2 - Observe and Respond
          • Part 3 - Training a Model
      • Updates
        • VideoDB Acquires Devzery: Expanding Our AI Infra Stack with Developer-First Testing Automation

Building Dynamic Video Streams with VideoDB: Integrating Custom Data and APIs

Introduction

Imagine you're watching a captivating keynote session from your favorite conference, and you’re welcomed with a personalized stream just for you.
This tutorial demonstrates how to create dynamic video streams by integrating data from custom databases and external APIs. We'll use a practical example: a recording of a keynote session. By using VideoDB, we'll show how companies like can personalize the viewing experience for their audience, delivering a richer and more engaging experience.
We'll showcase how to:
Fetch data from a random user API to represent a hypothetical viewer.
Integrate this data into a custom VideoDB timeline.
Create a personalized stream that dynamically displays relevant information alongside the keynote video.
This tutorial is your guide to unlocking the potential of dynamic video streams and transforming your video content with personalized experiences.

Setup

📦 Installing packages

%pip install videodb

🔑 API Keys

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

# Secure way to enter your VideoDB API key
api_key = getpass("Please enter your VideoDB API Key: ")
os.environ["VIDEO_DB_API_KEY"] = api_key

Steps

🌐 Step 1: Connect to VideoDB

Establish a session for uploading videos. Import the necessary modules from VideoDB library to access functionalities.
import videodb
from videodb import connect

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

🗳️ Step 2: Upload Base Video

Upload and play the video to ensure it's correctly loaded. We’ll be using for the purpose of this tutorial.
# Upload and play a video from a URL
video = coll.upload(url="https://www.youtube.com/watch?v=Nmv8XdFiej0")
video.play()

# Alternatively, get a video from your VideoDB collection
video = coll.get_video('VIDEO_ID_HERE')
video.play()

📥 Step 3: Fetch Data from a Random User API

This code fetches a random user's data (name and picture) from the "randomuser.me" API. You can adapt this to retrieve data from any relevant API (e.g., product data, news articles) for your use case.
import requests

# Make a request to the Randomizer API
response = requests.get('https://randomuser.me/api/?results=1&nat=us,ca,gb,au')
data = response.json()

# Extract relevant information
first_name = data['results'][0]['name']['first']
medium_picture = data['results'][0]['picture']['medium']

🚥 Step 4 : Upload the image to VideoDB

First we download the image to local storage
Then we use the local path to upload it to VideoDB
import requests

# 1. Download the image locally
local_path = "my_local_image.jpg"

response = requests.get(medium_picture)
if response.status_code == 200:
with open(local_path, 'wb') as f:
f.write(response.content)
print(f"Image downloaded successfully to: {local_path}")
else:
print(f"Failed to download image. Status code: {response.status_code}")

# 2. Upload using the local file path

from videodb import play_stream, MediaType
image = coll.upload(file_path=local_path, media_type=MediaType.image)

print(f"Image uploaded to VideoDB: {image.id}")

🧱 Step 5: Create VideoDB Assets

We create VideoDB assets for the base video, the user's name (text), and their picture (image) using the new Editor SDK. The `Font` and `Background` objects allow us to customize the appearance of text elements.
from videodb.editor import (
Timeline, Track, Clip,
VideoAsset, TextAsset, ImageAsset,
Font, Background, Alignment, HorizontalAlignment, VerticalAlignment,
Position, Offset, Fit
)

# 1. Video Asset (Base background)
video_asset = VideoAsset(id=video.id, start=0)

# 2. Name Asset (Top)
name_asset = TextAsset(
text=f'Hi {first_name} !',
font=Font(family="Montserrat", size=60, color="#000000"),
background=Background(color="#D2C11D", border_width=20, opacity=1.0),
alignment=Alignment(horizontal=HorizontalAlignment.center, vertical=VerticalAlignment.top),
)

# 3. Message Asset (Middle)
cmon_asset = TextAsset(
text="Here are your favorite moments",
font=Font(family="Montserrat", size=60, color="#D2C11D"),
background=Background(color="#000000", border_width=20, opacity=1.0),
alignment=Alignment(horizontal=HorizontalAlignment.center, vertical=VerticalAlignment.center),
)

# 4. Image Asset (Bottom)
image_asset = ImageAsset(id=image.id)

↔️ Step 6: Create the VideoDB Timeline

Using the Track and Clip pattern, we arrange and layer assets to create a dynamic video stream. The main video goes on one track, while overlays (name, message, image) go on separate tracks with their start times.
# Create the timeline
timeline = Timeline(conn)

# --- Track 1: Main Video ---
video_track = Track()
video_clip = Clip(asset=video_asset, duration=float(video.length))
video_track.add_clip(0, video_clip)
timeline.add_track(video_track)

# --- Track 2: Overlays ---
overlay_track = Track()

# 1. Add Name Overlay (Top)
name_clip = Clip(
asset=name_asset,
duration=4,
position=Position.top,
offset=Offset(y=0.15)
)
overlay_track.add_clip(5, name_clip)

# 2. Add Message Overlay (Center)
cmon_clip = Clip(
asset=cmon_asset,
duration=4,
position=Position.center,
)
overlay_track.add_clip(5, cmon_clip)

# 3. Add Image Overlay (Bottom)
image_clip = Clip(
asset=image_asset,
duration=4,
position=Position.bottom,
scale=2,
fit=None,
offset=Offset(y=-0.15)
)
overlay_track.add_clip(5, image_clip)
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.