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
      • VideoDB x TwelveLabs: Real-Time Video Understanding
      • 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
    • 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
      • 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
os.environ["VIDEO_DB_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 (optional): Prepare Data for Integration

No additional data transformation is required in this example since we are using the data directly from the API. However, in more complex scenarios, you may need to format the data to be suitable for VideoDB.

🧱 Step 5: Create VideoDB Assets

We create VideoDB assets for the base video, the user's name (text), and their picture (image). The `TextStyle` object allows us to customize the appearance of the text elements.
from videodb import play_stream, TextStyle, MediaType
from videodb.asset import VideoAsset, TextAsset, ImageAsset
from videodb.timeline import Timeline

# Video Asset
video_asset = VideoAsset(asset_id=video.id, start=0)

# Text Asset with First Name
name_asset = TextAsset(
text=f'Hi {first_name} !',
duration=4,
style=TextStyle(
fontsize=32,
font="montserrat",
borderw=1,
boxcolor="#D2C11D",
boxborderw="20",
x="((w-tw)/2)",
y="(h-th)/4"
)
)

# Image Asset with Medium Picture
image = coll.upload(url=medium_picture, media_type=MediaType.image)
image_asset = ImageAsset(
asset_id=image.id,
width=80,
height=80,
x="275",
y="230",
duration=4
)

# Fixed Text Asset
cmon_asset = TextAsset(
text="Here are your favorite moments",
duration=4,
style=TextStyle(
fontsize=24,
fontcolor="#D2C11D",
font="montserrat",
borderw=1,
bordercolor="#D2C11D",
boxborderw="20",
x="((w-tw)/2)",
y="(h-200)"
)
)


↔️ Step 6: Create the VideoDB Timeline

The VideoDB timeline allows you to arrange and layer your assets to create a dynamic video stream. In this example, we add the name and picture overlays at a specific time (5 seconds) within the base video.
# Create the timeline
timeline = Timeline(conn)

# Add the base video to the timeline
timeline.add_inline(video_asset)

# Add overlays to the timeline
timeline.add_overlay(5, name_asset)
timeline.add_overlay(5, cmon_asset)
timeline.add_overlay(5, image_asset)

▶️ Step 7: Generate and Play the Personalized Stream

The generate_stream() method creates a streamable URL for your personalized video stream. You can then use play_stream() to preview it in your browser.
from videodb import play_stream

stream_url = timeline.generate_stream()
print(stream_url)
play_stream(stream_url)

Conclusion

This tutorial showcased how to create personalized video streams using VideoDB. By integrating data from external APIs and custom databases, you can enhance your video content, personalize user experiences, and unlock new possibilities for engagement. Explore various data sources, experiment with different integrations, and customize your video streams to suit your specific needs.
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.