# adi4771/ai-video-editor-semantic-clip-search architecture

> Architecture diagram of the GitHub repository adi4771/ai-video-editor-semantic-clip-search, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adi4771/ai-video-editor-semantic-clip-search
- Repository: https://github.com/adi4771/ai-video-editor-semantic-clip-search

## Overview

AI Video Editor is a Streamlit application for finding and exporting video moments from natural-language queries. Users upload a video, which is inspected, sampled into frames, and indexed with CLIP embeddings and detected objects. A query may be simplified by Claude; the app searches indexed frames, groups matches into ranked segments, previews them, then cuts individual clips and optionally merges a highlight reel for download. The graph follows documented and excerpted calls; storage is session-local files and an NPZ cache, not a database.

Main entry points: [`app.py`](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py) (Streamlit workflow), [`pipeline/embeddings.py`](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/embeddings.py) (Frame embeddings), [`pipeline/search.py`](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/search.py) (Frame search), [`pipeline/clip_generator.py`](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/clip_generator.py) (Clip cutting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_app["Streamlit workflow<br/>[app.py]"]
  node_preview["Segment previews<br/>[app.py]"]
  node_downloads["Clip downloads<br/>[app.py]"]
end

subgraph group_indexing["Video indexing"]
  node_metadata["Video metadata<br/>[video_utils.py]"]
  node_frames["Frame extraction<br/>[extract_frames.py]"]
  node_embeddings["Frame embeddings<br/>[embeddings.py]"]
  node_object_detection["Object detection"]
  node_model["CLIP model loader"]
  node_cache[("Embedding cache<br/>[embeddings.py]")]
end

subgraph group_retrieval["Semantic retrieval"]
  node_simplifier["Query optimizer"]
  node_search["Frame search<br/>[search.py]"]
  node_similarity["Cosine scoring<br/>[similarity.py]"]
  node_grouping["Segment grouping<br/>[search.py]"]
end

subgraph group_export["Clip export"]
  node_clip_generation["Clip cutting<br/>[clip_generator.py]"]
  node_merging["Highlight reel merge<br/>[clip_generator.py]"]
end

node_user(("Video editor user"))
node_claude{{"Claude API"}}
node_ffmpeg{{"ffmpeg"}}

node_user -->|"uploads and searches"| node_app
node_app -->|"reads metadata"| node_metadata
node_app -->|"extracts frames"| node_frames
node_app -->|"indexes frames"| node_embeddings
node_embeddings -->|"encodes images"| node_model
node_embeddings -->|"detects objects"| node_object_detection
node_embeddings -->|"reads and writes"| node_cache
node_app -->|"optimizes query"| node_simplifier
node_simplifier -.->|"requests simplification"| node_claude
node_app -->|"searches frames"| node_search
node_search -->|"encodes text"| node_model
node_search -->|"scores frames"| node_similarity
node_search -->|"groups matches"| node_grouping
node_app -->|"renders segments"| node_preview
node_app -->|"cuts segments"| node_clip_generation
node_clip_generation -->|"gets duration"| node_metadata
node_clip_generation -->|"cuts video"| node_ffmpeg
node_app -->|"requests merge"| node_merging
node_merging -->|"merges clips"| node_ffmpeg
node_app -->|"offers downloads"| node_downloads
node_downloads -->|"returns clips"| node_user

click node_app "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py"
click node_metadata "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/video_utils.py"
click node_frames "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/extract_frames.py"
click node_embeddings "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/embeddings.py"
click node_object_detection "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/object_detection.py"
click node_model "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/models/clip_model_loader.py"
click node_cache "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/embeddings.py"
click node_simplifier "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/query_simplifier.py"
click node_search "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/search.py"
click node_similarity "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/similarity.py"
click node_grouping "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/search.py"
click node_preview "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py"
click node_clip_generation "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/clip_generator.py"
click node_merging "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/clip_generator.py"
click node_downloads "https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_preview,node_downloads,node_user toneBlue
class node_metadata,node_frames,node_embeddings,node_object_detection,node_model,node_cache toneAmber
class node_simplifier,node_search,node_similarity,node_grouping,node_claude toneMint
class node_clip_generation,node_merging toneRose
class node_ffmpeg toneIndigo
```

## Components

### User interaction

- [Streamlit workflow](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py): `app.py`
- [Segment previews](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py): `app.py`
- [Clip downloads](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/app.py): `app.py`

### Video indexing

- [Video metadata](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/video_utils.py): `utils/video_utils.py`
- [Frame extraction](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/extract_frames.py): `pipeline/extract_frames.py`
- [Frame embeddings](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/embeddings.py): `pipeline/embeddings.py`
- [Object detection](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/object_detection.py): `pipeline/object_detection.py`
- [CLIP model loader](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/models/clip_model_loader.py): `models/clip_model_loader.py`
- [Embedding cache](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/embeddings.py): `pipeline/embeddings.py`

### Semantic retrieval

- [Query optimizer](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/query_simplifier.py): `utils/query_simplifier.py`
- [Frame search](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/search.py): `pipeline/search.py`
- [Cosine scoring](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/utils/similarity.py): `utils/similarity.py`
- [Segment grouping](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/search.py): `pipeline/search.py`

### Clip export

- [Clip cutting](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/clip_generator.py): `pipeline/clip_generator.py`
- [Highlight reel merge](https://github.com/adi4771/ai-video-editor-semantic-clip-search/blob/main/pipeline/clip_generator.py): `pipeline/clip_generator.py`

### Other components

- **Video editor user**
- **Claude API**
- **ffmpeg**

## Connections

- Video editor user → Streamlit workflow: uploads and searches (evidence: `app.py`)
- Streamlit workflow → Video metadata: reads metadata (evidence: `app.py`)
- Streamlit workflow → Frame extraction: extracts frames (evidence: `app.py`)
- Streamlit workflow → Frame embeddings: indexes frames (evidence: `app.py`)
- Frame embeddings → CLIP model loader: encodes images (evidence: `pipeline/embeddings.py`)
- Frame embeddings → Object detection: detects objects (evidence: `pipeline/embeddings.py`)
- Frame embeddings → Embedding cache: reads and writes (evidence: `pipeline/embeddings.py`)
- Streamlit workflow → Query optimizer: optimizes query (evidence: `app.py`)
- Query optimizer → Claude API: requests simplification (evidence: `utils/query_simplifier.py`)
- Streamlit workflow → Frame search: searches frames (evidence: `app.py`)
- Frame search → CLIP model loader: encodes text (evidence: `pipeline/search.py`)
- Frame search → Cosine scoring: scores frames (evidence: `pipeline/search.py`)
- Frame search → Segment grouping: groups matches (evidence: `app.py`)
- Streamlit workflow → Segment previews: renders segments (evidence: `app.py`)
- Streamlit workflow → Clip cutting: cuts segments (evidence: `app.py`)
- Clip cutting → Video metadata: gets duration (evidence: `pipeline/clip_generator.py`)
- Clip cutting → ffmpeg: cuts video (evidence: `pipeline/clip_generator.py`)
- Streamlit workflow → Highlight reel merge: requests merge (evidence: `app.py`)
- Highlight reel merge → ffmpeg: merges clips (evidence: `pipeline/clip_generator.py`)
- Streamlit workflow → Clip downloads: offers downloads (evidence: `app.py`)
- Clip downloads → Video editor user: returns clips (evidence: `app.py`)
