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
      • icon picker
        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
      • 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

Insert Dynamic Ads in real-time

Video files are not very flexible if we want to change the flow and insert another video at a certain place. Imagine putting a video advertisement on your video stream for your customers. You don't need to edit the video file and create another one.
VideoDB simplifies it for you. It gives you power to build contextualize Ad insertion and personalized Ad insertion on your videos.
image.png

Setup

🔧 Installing VideoDB in your environment

VideoDB is available as a
!pip install videodb

🔗 Setting Up a connection to VideoDB

To connect to VideoDB, simply create a Connection object, and connect to the collection.
This can be done by either providing your VideoDB API key directly to the constructor or by setting the VIDEO_DB_API_KEY environment variable with your API key.
light
Get your API key from . ( Free for first 50 uploads, No credit card required ) 🎉
import videodb
import os
from getpass import getpass

# Prompt user for API key securely
api_key = getpass("Please enter your VideoDB API Key: ")
os.environ["VIDEO_DB_API_KEY"] = api_key

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

Uploading the videos to VideoDB

Let's have a base video as Sam Altman's conversation on OpenAI and AGI. We'll choose another video to insert in this 👉 ( let's get IBM's Advertisement) . We are going to insert the Ad video into the base video at a specific timestamp.
For this, we will need to first upload both the videos to VideoDB.
base_video_url = "https://www.youtube.com/watch?v=e1cf58VWzt8"
ad_video_url = "https://www.youtube.com/watch?v=jtwduf2lh08"

base_video = coll.upload(url=base_video_url)
ad_video = coll.upload(url=ad_video_url)

Inserting Ad in our Base Video

Now that we have both videos uploaded, we’ll use VideoDB’s Editor SDK to create a timeline with multiple clips. We’ll break the base video into segments and insert the ad at the 10-second mark:
Clip 1: Base video from 0 to 10 seconds
Clip 2: Full ad video
Clip 3: Base video continues from 10 seconds to end
from videodb.editor import Timeline, Track, Clip, VideoAsset
from videodb import play_stream

# Define timing
insert_time = 10 # Insert ad at 10 seconds
base_duration = int(base_video.length)
ad_duration = int(ad_video.length)

# Create timeline and track
timeline = Timeline(conn)
track = Track()

# Clip 1: Base video from 0 to insert_time
clip1 = Clip(
asset=VideoAsset(id=base_video.id),
duration=insert_time
)
track.add_clip(0, clip1)

# Clip 2: Full ad video
clip2 = Clip(
asset=VideoAsset(id=ad_video.id),
duration=ad_duration
)
track.add_clip(insert_time, clip2)

# Clip 3: Base video continues from insert_time to end
clip3 = Clip(
asset=VideoAsset(id=base_video.id, start=insert_time),
duration=base_duration - insert_time
)
track.add_clip(insert_time + ad_duration, clip3)

# Generate stream
timeline.add_track(track)
stream_link = timeline.generate_stream()
stream_link is a streaming link that offers instant playback capability – no rendering necessary. ⚡️

Play Modified Video

Let’s check the results:
from videodb import play_stream
play_stream(stream_link)
You can generate as many streaming links as needed for your use-case. This gives you power to personalize your video content for each user.

No Limitations

The inserted video doesn’t have to be solely for advertisements; it can be a disclaimer or announcement for the person watching the video. Furthermore, your stream is dynamic, enabling you to adjust the timestamp and insertion video based on your business logic.
This is an incredible power to have for any product hosting videos. Let’s master video content manipulation like a pro!
Godspeed ✨ We can’t wait to see all the awesome stuff you can build with VideoDB Would love to know your thoughts at 👉 contact@vidoedb.io.


 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.