Skip to main content
Open In Colab

The Idea

Ever wished you could create fun, educational videos for kids with just a single topic? Tell the system “explain the solar system” and get back a complete animated video with:
  • Kid-friendly voiceover narration
  • Fun background music
  • Loopable animated backgrounds
  • Timed subject videos (cartoons of planets, stars, etc.)
  • Animated captions that kids can follow along
This workflow takes a topic and magically transforms it into a complete learning video. All powered by VideoDB’s Editor SDK — pure automation magic.

Setup

Install Dependencies

pip install videodb

Connect to VideoDB

import os
import math
import videodb

# Connect to VideoDB
api_key = "your_api_key"
conn = videodb.connect(api_key=api_key)
coll = conn.get_collection()

Implementation

Step 1: Generate Script and Title

import json

# Define the learning topic
topic = "Explain the solar system"

script_prompt = f"""You are a friendly children's educational content writer.

Write a fun, simple explanation about: "{topic}"

Requirements:
- Target audience: 5-year-old children
- Length: 250 words
- Use simple words and short sentences
- Make it fun and engaging

Return a JSON with:
- "title": A fun, catchy title for the video (max 5 words)
- "script": The complete narration script

Example format:
{{"title": "The Amazing Sun!", "script": "Hey friends! Today we're going to learn about..."}}
"""

script_response = coll.generate_text(
    prompt=script_prompt,
    model_name="pro",
    response_type="json"
)

# Handle nested output structure
if 'output' in script_response and isinstance(script_response['output'], dict):
    video_title = script_response["output"]["title"]
    video_script = script_response["output"]["script"]
else:
    video_title = script_response["title"]
    video_script = script_response["script"]

Step 2: Generate Background Prompts

bg_prompt = f"""Based on this children's educational video topic: "{topic}"

Create prompts for background media.

Return JSON with:
- "background_video_prompt": Detailed prompt for generating background video
- "music_prompt": Prompt for generating background music

Example: {{"background_video_prompt": "...", "music_prompt": "..."}}
"""

bg_response = coll.generate_text(
    prompt=bg_prompt,
    model_name="pro",
    response_type="json"
)

# Handle nested output structure
if isinstance(bg_response, dict) and "output" in bg_response:
    background_video_prompt = bg_response["output"]["background_video_prompt"]
    music_prompt = bg_response["output"]["music_prompt"]
else:
    background_video_prompt = bg_response["background_video_prompt"]
    music_prompt = bg_response["music_prompt"]

Step 3: Generate All Assets

# Generate voiceover from script
voiceover = coll.generate_voice(
    text=video_script,
    voice_name="Default"
)

# Generate background music (loopable)
bg_music = coll.generate_music(
    prompt=music_prompt,
    duration=10
)

# Generate background video (loopable)
bg_video = coll.generate_video(
    prompt=background_video_prompt,
    duration=5
)

Step 4: Generate Word-Level Transcript

# Generate and fetch timestamped transcript
voiceover.generate_transcript()
transcript = voiceover.get_transcript()

Step 5: Generate Custom Captions File

# Create ASS (Advanced SubStation Alpha) captions with styling
def create_ass_captions(transcript, voiceover_duration):
    ass_header = """[Script Info]
Title: Kids Educational Video
ScriptType: v4.00+

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour
Style: Default,Arial,48,&H00FFFF00,&H000000FF,&H00000000,&H00000000

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
"""
    events = []

    for word_info in transcript:
        start_ms = int(word_info["start"] * 100)  # Convert to centiseconds
        end_ms = int(word_info["end"] * 100)
        word = word_info["text"]

        # Format: Hh:Mm:Ss.Cc
        start_time = f"0:{start_ms//6000:02d}:{(start_ms%6000)//100:02d}.{start_ms%100:02d}"
        end_time = f"0:{end_ms//6000:02d}:{(end_ms%6000)//100:02d}.{end_ms%100:02d}"

        event = f"Dialogue: 0,{start_time},{end_time},Default,,0,0,0,,{{\\c&HFF00FF&}}{word}"
        events.append(event)

    return ass_header + "\n".join(events)

ass_captions = create_ass_captions(transcript, voiceover.length)

Step 6: Build Multi-Layer Timeline

from videodb.editor import (
    Timeline, Track, Clip, VideoAsset, AudioAsset, TextAsset,
    Font, Background, Alignment, HorizontalAlignment, VerticalAlignment
)

# Create timeline
timeline = Timeline(conn)

# Intro title card (5 seconds)
intro_track = Track()
intro_text = TextAsset(
    text=video_title,
    font=Font(size=56, color="#FFFFFF"),
    background=Background(color="rgba(100, 50, 200, 0.8)"),
    alignment=Alignment(horizontal=HorizontalAlignment.center, vertical=VerticalAlignment.center)
)
intro_track.add_clip(0, Clip(asset=intro_text, duration=5))
timeline.add_track(intro_track)

# Background video track (looped)
bg_track = Track()
bg_asset = VideoAsset(id=bg_video.id, start=0)
bg_clip = Clip(
    asset=bg_asset,
    duration=float(voiceover.length),
    opacity=0.7,
    scale=1.1  # Slight zoom for visual interest
)
bg_track.add_clip(5, bg_clip)  # Start after intro
timeline.add_track(bg_track)

# Voiceover track
voice_track = Track()
voice_asset = AudioAsset(id=voiceover.id)
voice_clip = Clip(asset=voice_asset, duration=float(voiceover.length), volume=1.0)
voice_track.add_clip(5, voice_clip)
timeline.add_track(voice_track)

# Background music track (looped)
music_track = Track()
music_asset = AudioAsset(id=bg_music.id)
music_clip = Clip(
    asset=music_asset,
    duration=float(voiceover.length),
    volume=0.3  # Low volume - voiceover is primary
)
music_track.add_clip(5, music_clip)
timeline.add_track(music_track)

# Captions track (rendered as overlay)
caption_track = Track()
# Apply ASS captions to timeline
# (Implementation depends on VideoDB's caption support)

Step 7: Add Outro Card

# Outro "Happy Learning!" card (5 seconds)
# Calculate outro start time (after intro + voiceover)
outro_start = 5 + float(voiceover.length)

outro_track = Track()
outro_text = TextAsset(
    text="Happy Learning! 🎉",
    font=Font(size=52, color="#FFFFFF"),
    background=Background(color="rgba(50, 200, 100, 0.8)"),
    alignment=Alignment(horizontal=HorizontalAlignment.center, vertical=VerticalAlignment.center)
)
outro_track.add_clip(outro_start, Clip(asset=outro_text, duration=5))
timeline.add_track(outro_track)

Step 8: Render Final Video

# Generate the complete educational video
stream_url = timeline.generate_stream()

# Calculate total duration
total_duration = 5 + float(voiceover.length) + 5  # intro + voiceover + outro

print(f"Video created successfully!")
print(f"Title: {video_title}")
print(f"Duration: {total_duration} seconds")
print(f"Stream: {stream_url}")

What You Get

A complete 70-80 second educational video with:
  • Kid-friendly AI-written script
  • Natural voiceover narration (kids’ voice)
  • Loopable animated background
  • Timed subject videos (cartoon illustrations)
  • Synchronized animated captions
  • Upbeat background music
  • Professional intro and outro cards
Here’s the final educational video:

Perfect For

  • Home Learning - Parents teaching kids at home
  • Educational Channels - YouTube Kids content creators
  • School Supplements - Teachers augmenting classroom lessons
  • Language Learning - Kids’ language learning videos
  • Skill Development - Tutorial videos for children

What Topics Can You Cover?

  • The Solar System
  • Ocean Animals
  • Ancient Civilizations
  • How Photosynthesis Works
  • The Water Cycle
  • Math Basics
  • History Stories
  • Science Experiments
  • Geography
  • And anything else!

The Result

What used to take weeks of scriptwriting, voiceover recording, animation, and editing now takes minutes. Teachers and parents can create engaging, professional educational content instantly. Kids get to learn with animated characters, fun music, and engaging visuals. Everyone wins. Pure learning magic — powered by VideoDB.

Explore the Full Notebook

Open the complete implementation with advanced subject video generation, caption styling, and content customization.