Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘οΈ YouTube Vision Skill

Empowering AI Agents to actually see and hear YouTube videos.
Adaptive Scene Extraction β€’ Audio-Visual Timeline Alignment β€’ Dual-Mode AI Engine β€’ MCP Server & Agent Skill

License: MIT Python 3.10+ Model Context Protocol yt-dlp Groq Whisper Gemini

YouTube Vision Skill Demo


πŸ›‘ The Problem: "The Blind AI Dilemma"

Almost every existing "YouTube AI" tool relies solely on scraping speech transcripts.

For coding tutorials, tech keynotes, architecture discussions, and product reviews, transcripts only contain half the story:

  • ❌ Presenters rarely read out their code line-by-line: "As you can see here, we change this line..." (An audio-only AI has no idea what changed).
  • ❌ Architecture diagrams & charts are invisible: High-level designs shown on slides are completely lost.
  • ❌ Terminal errors & UI interactions are ignored: Button clicks, console outputs, and debug logs are visual events.
  • ❌ Naive 1-FPS frame dumpers blow token budgets: A 10-minute video at 1 FPS yields 600 images (~600,000 vision tokens), overwhelming context windows and generating massive API bills.

YouTube Vision Skill solves this completely.


πŸ’‘ The Solution

YouTube Vision Skill treats YouTube videos as true multimodal streams:

  1. Smart Media Pipeline: Uses yt-dlp to download bandwidth-optimized streams (480p/720p) with native time-slice trimming (start_time, end_time) so you never download hours of video just to inspect a 2-minute section.
  2. Adaptive Scene Extraction: Zero dumb 1-FPS dumping. Uses visual difference algorithms (HSV histogram distance + FFmpeg scene filters) with temporal guardrails (min interval 1.5s, max interval 30s) to only capture frames when the screen actually changes (slide switch, IDE file change, terminal output). Compresses to WebP for 70-80% token savings over PNG.
  3. Zero-Cost Subtitle & Whisper Pipeline: Automatically checks for official human subtitles first (instant, free). If unavailable, falls back to sub-second timestamped transcription via Groq Whisper Large v3 or local faster-whisper.
  4. Timeline Alignment: Synchronizes extracted WebP frames with the exact spoken dialogue on a structured timeline.
  5. Dual-Mode AI Engine:
    • Mode 1 (Frame + Audio Pipeline): Feeds interleaved WebP frames and speech context into OpenAI (GPT-4o), Anthropic (Claude 3.5 Sonnet), or Local VLMs (Ollama Qwen2-VL / Llama 3.2-Vision).
    • Mode 2 (Native Video API): Leverages Google Gemini 2.5 Flash / Pro File API for end-to-end native video understanding.
  6. Built for Agents: Ready out-of-the-box as an MCP Server (Model Context Protocol), Agent Skill (SKILL.md), Python SDK, and interactive CLI.

πŸ—οΈ Architecture

flowchart TD
    User["AI Agent / User (Claude, Cursor, Antigravity, CLI)"] -->|MCP / SDK / CLI| Orch["YouTube Vision Orchestrator"]
    
    subgraph Pipeline["Smart Media Pipeline"]
        Orch -->|yt-dlp with Time Slice| Downloader["Smart Downloader (480p/720p)"]
        Downloader --> VideoStream["Video Stream (MP4)"]
        Downloader --> AudioStream["Audio Stream (MP3)"]
    end
    
    subgraph Visual["Adaptive Visual Processing"]
        VideoStream --> SceneDetector["Adaptive Scene Detector (OpenCV / FFmpeg)"]
        SceneDetector -->|Threshold gt 0.25 + Guardrails| WebPCompress["WebP Compression (Max 1280px, Q80)"]
        WebPCompress --> Frames["Key Scene Frames (.webp)"]
    end
    
    subgraph Audio["Audio & Speech Processing"]
        AudioStream --> Transcriber["Audio Transcriber"]
        Transcriber -->|Priority 1| OfficialSubs["Official Human Subtitles"]
        Transcriber -->|Priority 2 Fallback| GroqWhisper["Groq Whisper Large v3"]
        Transcriber -->|Priority 3 Fallback| LocalWhisper["faster-whisper / Auto Captions"]
        OfficialSubs --> Transcript["Timestamped Dialogue"]
        GroqWhisper --> Transcript
        LocalWhisper --> Transcript
    end
    
    Frames --> Aligner["Timeline Aligner (Context Engine)"]
    Transcript --> Aligner
    
    Aligner --> AlignedTimeline["Multimodal Timeline: [{ timestamp, frame_webp, speech_text }]"]
    
    subgraph Inference["Dual-Mode AI Engine"]
        AlignedTimeline -->|Mode 1: Interleaved Frames + Audio| VLM["Vision LLMs: OpenAI GPT-4o / Claude 3.5 / Ollama"]
        VideoStream -->|Mode 2: Native Video File API| Gemini["Google Gemini 2.5 Flash / Pro"]
    end
    
    VLM --> Output["Structured Multimodal Analysis (Code OCR, UI Insights, Verification)"]
    Gemini --> Output
Loading

πŸ“Š Benchmark: Naive Approach vs YouTube Vision Skill

Feature Naive Transcript Scraper Naive 1-FPS Frame Dumper YouTube Vision Skill
Reads On-Screen Code / IDE ❌ No βœ… Yes πŸš€ Yes (Crisp Monospace OCR)
Captures Architecture Slides ❌ No βœ… Yes πŸš€ Yes (Only when slide changes)
10-Min Video Vision Tokens 0 tokens ~600,000 tokens (Costly) ⚑ ~15,000 - 35,000 tokens (85% savings)
Time-Slice Trimming ❌ Full download ❌ Full download ⚑ Yes (yt-dlp download_ranges)
Speech-to-Visual Alignment ❌ None ❌ Manual πŸš€ Automatic Timeline Alignment
Model Context Protocol (MCP) ❌ No ❌ No πŸš€ Native MCP Server Included
Local Offline LLM Support ❌ No ⚠️ Difficult πŸš€ Yes (via Ollama Qwen2-VL)

πŸš€ Quickstart

1. Installation

# Clone the repository
git clone https://github.com/your-username/youtube-vision-skill.git
cd youtube-vision-skill

# Install dependencies (FFmpeg is automatically handled via imageio-ffmpeg!)
pip install -e ".[all]"

2. Configure Environment

Copy .env.example to .env and insert your desired API keys:

cp .env.example .env
# Optional: Mode 2 Native Gemini
GEMINI_API_KEY=your_gemini_key

# Optional: Mode 1 Whisper transcription fallback (Groq is ultra-fast & free tier available)
GROQ_API_KEY=your_groq_key

# Optional: Mode 1 Vision LLMs
OPENAI_API_KEY=your_openai_key
# or ANTHROPIC_API_KEY=your_anthropic_key
# or OLLAMA_BASE_URL=http://localhost:11434/v1

πŸ’» Usage

A. Command Line Interface (CLI)

# 1. Watch and analyze a video clip (with speech + visual understanding)
youtube-vision watch "https://www.youtube.com/watch?v=dQw4w9WgXcQ" --start "01:00" --end "03:30"

# 2. Focus on a specific technical question
youtube-vision watch "https://youtu.be/..." --focus "Extract the Docker Compose file shown"

# 3. Extract high-resolution frames around a specific timestamp for code reading
youtube-vision extract "https://youtu.be/..." --timestamp "04:12" --duration 10

# 4. Search for a specific topic or keyword across the video
youtube-vision search "https://youtu.be/..." --query "FastAPI dependency injection"

# 5. Start the MCP Server
youtube-vision mcp

B. Model Context Protocol (MCP) Server

Connect YouTube Vision Skill directly to Claude Desktop, Cursor, or Antigravity.

Claude Desktop Configuration

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "youtube-vision": {
      "command": "python",
      "args": ["-m", "youtube_vision.server.mcp_server"],
      "cwd": "/path/to/youtube-vision-skill",
      "env": {
        "GEMINI_API_KEY": "your_gemini_key",
        "GROQ_API_KEY": "your_groq_key",
        "OPENAI_API_KEY": "your_openai_key"
      }
    }
  }
}

Now you can prompt Claude:

"Claude, can you watch https://www.youtube.com/watch?v=... from minute 02:15 to 04:30 and tell me what code the instructor typed in the main.py file?"

Claude will invoke watch_video_overview and extract_visual_details autonomously!


C. Python SDK

from youtube_vision import YouTubeVisionOrchestrator

orchestrator = YouTubeVisionOrchestrator()

# Analyze a video segment
result = orchestrator.watch_video_overview(
    url="https://www.youtube.com/watch?v=your_video_id",
    start_time="02:00",
    end_time="04:30",
    mode="auto",
    focus_prompt="What database schema is shown on the whiteboard?"
)

print(result["summary"])

# Extract high-res WebP frame at exact second
details = orchestrator.extract_visual_details(
    url="https://www.youtube.com/watch?v=your_video_id",
    timestamp="03:45",
    high_res=True
)

print("Saved high-res frame to:", details["primary_frame"])

πŸ› οΈ The 3 Core Tools for Agents

Tool Name Purpose When the Agent Uses It
watch_video_overview Full or clipped multimodal analysis Getting the big picture, understanding slide decks, or watching a multi-minute tutorial section.
extract_visual_details High-res frame extraction (1080p WebP) Reading small monospace code in IDEs, terminal command outputs, or inspecting fine UI details.
search_in_video Semantic/keyword time anchor search Finding the exact minute a concept was mentioned before diving deeper with visual tools.

πŸ“ Repository Structure

youtube-vision-skill/
β”œβ”€β”€ .env.example                 # Configuration template with provider keys
β”œβ”€β”€ pyproject.toml               # Package dependencies & CLI entrypoints
β”œβ”€β”€ SKILL.md                     # Agent Skill specification file
β”œβ”€β”€ README.md                    # Project documentation
β”œβ”€β”€ src/
β”‚   └── youtube_vision/
β”‚       β”œβ”€β”€ __init__.py          # Public API exports
β”‚       β”œβ”€β”€ config.py            # Settings with env overrides
β”‚       β”œβ”€β”€ cli.py               # CLI commands (watch, extract, search, mcp)
β”‚       β”œβ”€β”€ core/
β”‚       β”‚   β”œβ”€β”€ models.py        # Pydantic data schemas
β”‚       β”‚   β”œβ”€β”€ ffmpeg_utils.py  # Cross-platform FFmpeg locator & runner
β”‚       β”‚   β”œβ”€β”€ downloader.py    # yt-dlp with time-slice trimming & 720p cap
β”‚       β”‚   β”œβ”€β”€ scene_detector.py# Adaptive Scene Extraction (OpenCV / FFmpeg)
β”‚       β”‚   β”œβ”€β”€ audio_transcriber.py # Official Subs -> Groq Whisper fallback
β”‚       β”‚   β”œβ”€β”€ timeline.py      # Audio-Visual timeline alignment
β”‚       β”‚   └── orchestrator.py  # Central workflow coordinator
β”‚       β”œβ”€β”€ engines/
β”‚       β”‚   β”œβ”€β”€ base.py          # Abstract Vision Engine
β”‚       β”‚   β”œβ”€β”€ frame_audio.py   # Mode 1: Interleaved Frames + Audio (GPT-4o/Claude/Ollama)
β”‚       β”‚   └── native_gemini.py # Mode 2: Native Gemini Video API
β”‚       └── server/
β”‚           β”œβ”€β”€ __init__.py
β”‚           └── mcp_server.py    # FastMCP Server implementation
└── tests/
    β”œβ”€β”€ test_models.py           # Timestamp parser and model tests
    β”œβ”€β”€ test_scene_detector.py   # Synthetic video adaptive scene test
    └── test_timeline.py         # Alignment & search tests

🀝 Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/awesome-feature)
  3. Commit your changes (git commit -m 'Add awesome feature')
  4. Run tests: pytest
  5. Push to the branch (git push origin feature/awesome-feature)
  6. Open a Pull Request

πŸ“„ License

Distributed under the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages