Skip to content

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multimodal Video Graph System

A system that transforms YouTube videos into queryable multimodal semantic graphs. Built for research in video understanding, featuring transcript-first graph construction, visual enrichment, and cross-video semantic search.


How It Works

1. Video Ingestion

When you provide a YouTube URL, the system:

  1. Downloads the video using yt-dlp
  2. Extracts audio as 16kHz mono WAV (optimal for speech recognition)
  3. Detects scenes using ffmpeg's built-in scene detection filter
  4. Extracts frames at configurable FPS (default: 1 fps)
  5. Segments clips based on scene boundaries

All heavy processing uses ffmpeg directly—no OpenCV or PySceneDetect dependencies.

2. Transcription

Audio is sent to OpenAI Whisper API for transcription:

  • Segment-level timestamps for precise alignment
  • Automatic audio compression for files exceeding 24MB
  • Outputs both raw segments and sentence-level groupings

3. Visual Understanding

Each video clip is analyzed using OpenAI GPT-4o Vision:

  • Visual Captioning: Describes what's happening in the scene
  • Entity Detection: Identifies objects, people, UI elements
  • Scene Classification: talking_head, presentation_slide, screencast, etc.
  • OCR Extraction: Reads on-screen text via Vision API

Processing runs in parallel (5 concurrent calls by default) for speed.

4. Graph Construction (Transcript-First)

The system builds a semantic graph with this structure:

Nodes:

Type Description
TranscriptNode Sentence with text, timestamps, topic assignment
VisualNode Clip with description, entities, OCR, scene type
TopicNode Topic segment with title, keywords, time range
EntityNode Canonical entity (person, product, concept) with aliases

Edges:

Type Description
TEMPORAL_NEXT Sequential ordering between segments
ALIGNED_TO Transcript ↔ Visual temporal overlap
DISCOURSE_RELATION EXPLAINS, SUPPORT, COUNTER, EXAMPLE_OF, etc.
BELONGS_TO_TOPIC Segment → Topic membership
CONTAINS_ENTITY Node mentions entity

The construction is transcript-first: the semantic structure comes from analyzing the transcript, then visual nodes are attached via temporal alignment.

📖 For detailed explanation of the graph building methodology, see GRAPH_BUILDING.md

5. Embedding Pre-computation

After graph construction, embeddings are computed for all nodes using text-embedding-3-small:

  • Runs in parallel (10 concurrent calls by default)
  • Saved to embeddings.json for instant retrieval
  • Enables semantic search without query-time embedding computation

6. Query & Retrieval

When you ask a question:

  1. Hybrid Search: Combines embedding similarity + keyword matching
  2. k-hop Expansion: Retrieves related nodes through graph edges
  3. Context Assembly: Collects relevant transcript and visual evidence
  4. Answer Generation: LLM synthesizes answer with timestamp citations

Responses include:

  • Direct answer to the question
  • Evidence items with node IDs and timestamps
  • Relevant subgraph for visualization

7. Cross-Video Search

The system supports searching across all processed videos:

  • Semantic search using pre-computed embeddings
  • Keyword fallback for videos without embeddings
  • LLM synthesizes answers citing multiple videos
  • Reports which videos contain relevant information

Architecture

Architecture diagram

Graph Schema

Discourse Relations

The system identifies these semantic relationships between transcript segments:

Relation Meaning
EXPLAINS A clarifies or elaborates on B
EXAMPLE_OF A is a concrete instance of B
SUPPORT A provides evidence for B
COUNTER A contradicts or opposes B
CAUSES A leads to or results in B
STEP_BEFORE A precedes B in a sequence
ELABORATES A adds detail to B
DEFINES A provides definition of term in B

Schema Classification

Each topic segment is classified by its discourse type:

  • Narrative: Story-telling, chronological events
  • Descriptive: Explaining what something is
  • Informative: Presenting facts or information
  • Instructional: Teaching how to do something
  • Argumentative: Making a case or persuading

Performance Optimizations

Parallel Processing

  • Visual captioning: 5 concurrent API calls
  • OCR extraction: 5 concurrent API calls
  • Embedding computation: 10 concurrent API calls
  • Reduces processing time by 60-70% for LLM-heavy stages

UI Performance

  • Graph Viewer: Limits to 200 nodes with Topics/Sampled view toggle
  • Transcript Panel: Virtual scrolling, renders only visible segments
  • Time Updates: Throttled to 2/second to prevent re-render storms

Caching

  • All OpenAI API calls are cached
  • Embeddings pre-computed and stored
  • Graph exported to JSON and GraphML formats

Data Flow

For a 10-minute video:

Stage Output
Download video.mp4 (50-200 MB)
Audio audio.wav (16kHz mono)
Frames ~600 JPGs at 1 fps
Clips ~15-20 scene-based clips
Transcript ~80-120 segments
Visual 15-20 clip analyses
Graph 100-200 nodes, 200-400 edges
Embeddings 100-200 vectors (1536-dim each)

Key Design Decisions

Why Transcript-First?

Videos are primarily experienced through spoken content. Building the semantic structure from transcript ensures the graph reflects the narrative flow, with visual content enriching rather than driving the structure.

Why OpenAI for Everything?

Using a single provider (OpenAI) for transcription, vision, OCR, embeddings, and generation:

  • Minimizes dependencies (no Tesseract, OpenCV, local models)
  • Smaller Docker images
  • Consistent quality across modalities
  • Simpler deployment

Why Pre-computed Embeddings?

Computing embeddings at query time for 100+ nodes adds 10-30 seconds of latency. Pre-computing during ingestion makes queries instant.

Why Hybrid Search?

Pure semantic search can miss exact keyword matches (e.g., "Cisco" might not be semantically similar to query). Combining embedding similarity + keyword matching ensures both conceptual and lexical matches are found.


Technology Stack

Backend:

  • Python 3.12
  • FastAPI + Uvicorn
  • OpenAI API (Whisper, GPT-4o, embeddings)
  • ffmpeg for video processing
  • yt-dlp for YouTube downloads

Frontend:

  • React 18
  • Cytoscape.js for graph visualization
  • TanStack Query for data fetching
  • Framer Motion for animations

Infrastructure:

  • Docker + Docker Compose
  • Alpine Linux base (minimal image size)

Output Files

After processing a video, the system creates:

data/videos/{video_id}/
├── video.mp4           # Downloaded video
├── audio.wav           # Extracted audio
├── metadata.json       # Video metadata
├── transcript.json     # Timestamped transcript
├── visual.json         # Visual analysis results
├── graph.json          # Full graph structure
├── graph.graphml       # GraphML export
├── embeddings.json     # Pre-computed embeddings
├── frames/             # Extracted frames
└── clips/              # Scene-based clips

Research Applications

This system is designed for research in:

  • Video Understanding: Semantic analysis of video content
  • Multimodal Learning: Integrating text, speech, and vision
  • Knowledge Graphs: Temporal, discourse-aware graph construction
  • Explainable AI: Evidence-based answers with citations
  • Video Search: Semantic retrieval across video corpora

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages