# pushkrjain/video_forge architecture

> Architecture diagram of the GitHub repository pushkrjain/video_forge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pushkrjain/video_forge
- Repository: https://github.com/pushkrjain/video_forge

## Overview

#### Purpose and Entry Points
Video Forge V2 is a Python/Streamlit system that converts a user-guided topic or article into a deterministic vertical 1080×1920 MP4. The interactive entry point is `app.py`; it manages chat state, script approval, pipeline status, and invokes the renderer. The non-UI orchestration entry point is `video/pipeline.py`, with standalone diagnostic runners in `debug_full_pipeline.py` and `debug_pipeline.py`.

#### Conversation-to-Script Layer
The application first turns user input into an article, analysis, selected creative intent, combinations, and a structured short-video script. `app.py` owns the session-driven state machine and chat interaction; `prompts.py` contains the prompt contracts; `llm.py` provides the Anthropic Foundry/Azure Claude client. This is a hard boundary: rendering starts only after a script is generated and the user explicitly triggers video generation.

Paths: `app.py`, `prompts.py`, `llm.py`, `utils.py`.

#### Pipeline Orchestration and Working-State Boundary
`video/pipeline.py` coordinates five sequential dependency waves in a per-run `temp/` workspace: parse first; audio and images concurrently; storyboard after both; frame extraction; then compilation. It cleans transient inputs, preserves the final output under `temp/output/`, and fail-fast prevents later render stages after audio failure. Logging is shared with the UI and concurrent producer stages.

Paths: `video/pipeline.py`, `video/__init__.py`, `temp/output/final_reel.mp4`.

#### V1: Script Parsing, Speech, and Clock Authority
V1 converts the formatted script to section JSON and produces the authoritative audio timeline. It calls Claude to parse sections, generates Edge TTS chunks concurrently, stitches them with pydub, and derives cumulative millisecond timing from actual audio. The resulting sections, `master.mp3`, and timings are the contract consumed by storyboard generation and frame extraction.

Paths: `video/v1_tts.py`, `prompts.py`, `llm.py`.

#### V2: Visual Asset Acquisition
V2 independently resolves a visual asset per section using a five-worker thread pool. It searches SerpAPI Google Images, asks Azure OpenAI GPT-5-nano vision to rank candidates, downloads/crops selected images to portrait JPEGs, and substitutes typed color cards for pauses or failures. This isolates nondeterministic external retrieval before deterministic rendering begins.

Paths: `video/v2_images.py`, `copyright_free.py`, `video/pipeline.py`.

#### V3: Generated Storyboard as Rendering Program
V3 uses Claude Sonnet Skills and Code Execution to generate a self-contained GSAP storyboard HTML file from sections, timings, and image assets. Skill definitions impose design, vertical layout, GSAP, and virtual-clock rules; MD5 state avoids unnecessary skill synchronization. Validation enforces the seekable global-timeline contract and retries once with targeted repairs. The HTML is the boundary between generative design and frame rendering.

Paths: `video/v3_storyboard.py`, `skills/gsap-animation/SKILL.md`, `skills/video-clock-contract/SKILL.md`, `skills/.hashes.json`.

#### V4–V5: Deterministic Offline Rendering and Encoding
V4 splits the 30fps timeline across four independent Playwright/Chromium workers. Each loads the storyboard, waits for assets, seeks the GSAP virtual clock for assigned timestamps, and writes indexed JPEG frames. V5 invokes FFmpeg to combine `%05d.jpg` frames with master audio into H.264/AAC MP4, optionally mixing background music. These stages do not depend on real-time browser animation.

Paths: `video/v4_frames.py`, `video/v5_compile.py`, `packages.txt`.

#### Material Runtime and External Dependencies
The primary runtime is Python with Streamlit, asyncio/thread pools, Playwright Chromium, and FFmpeg. External services are Anthropic Foundry on Azure for chat, parse, and storyboard generation; Azure OpenAI for image ranking; SerpAPI for image search; and Edge TTS for speech. Required secrets are represented in `.env.example`; system browser dependencies are declared in `packages.txt`.

Paths: `.env.example`, `requirements.txt`, `packages.txt`.

Main entry points: [`video/v1_tts.py`](https://github.com/pushkrjain/video_forge/blob/main/video/v1_tts.py) (Parse & speech timeline), [`video/v2_images.py`](https://github.com/pushkrjain/video_forge/blob/main/video/v2_images.py) (Visual asset acquisition), [`video/v3_storyboard.py`](https://github.com/pushkrjain/video_forge/blob/main/video/v3_storyboard.py) (GSAP storyboard), [`video/v5_compile.py`](https://github.com/pushkrjain/video_forge/blob/main/video/v5_compile.py) (MP4 compilation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversation["Conversation &amp; Script"]
  node_ui["Streamlit app<br/>interactive entry point<br/>[app.py]"]
  node_prompts["Prompt contracts<br/>prompt definitions<br/>[prompts.py]"]
  node_claude["Claude client<br/>LLM adapter<br/>[llm.py]"]
  node_script["Approved video script<br/>structured script"]
end

subgraph group_pipeline["Render Pipeline"]
  node_orchestrator["Pipeline orchestrator<br/>run coordinator<br/>[pipeline.py]"]
  node_workspace[("Run workspace<br/>transient artifacts")]
  node_tts["Parse &amp; speech timeline<br/>V1 audio stage<br/>[v1_tts.py]"]
  node_visuals["Visual asset acquisition<br/>V2 image stage<br/>[v2_images.py]"]
  node_storyboard["GSAP storyboard<br/>V3 rendering program<br/>[v3_storyboard.py]"]
  node_skills["Storyboard skills<br/>generation constraints<br/>[SKILL.md]"]
end

subgraph group_rendering["Offline Rendering"]
  node_frames["Frame extraction<br/>V4 renderer<br/>[v4_frames.py]"]
  node_compile["MP4 compilation<br/>V5 encoder<br/>[v5_compile.py]"]
  node_chromium{{"Playwright Chromium<br/>browser runtime"}}
  node_ffmpeg{{"FFmpeg<br/>media encoder"}}
end

subgraph group_external["External Services"]
  node_anthropic{{"Anthropic Foundry<br/>chat and generation API"}}
  node_azurevision{{"Azure OpenAI vision<br/>image ranking API"}}
  node_serpapi{{"SerpAPI Google Images<br/>image search API"}}
  node_edgetts{{"Edge TTS<br/>speech API"}}
end

node_ui -->|"uses"| node_prompts
node_ui -->|"drives conversation"| node_claude
node_prompts -->|"defines requests"| node_claude
node_claude -->|"calls"| node_anthropic
node_ui -->|"approves"| node_script
node_script -->|"starts render"| node_orchestrator
node_orchestrator -->|"parse first"| node_tts
node_tts -->|"generates chunks"| node_edgetts
node_tts -->|"parses sections"| node_anthropic
node_tts -->|"sections and timings"| node_visuals
node_tts -->|"sections and timings"| node_storyboard
node_orchestrator -.->|"runs concurrently with audio"| node_visuals
node_visuals -->|"searches"| node_serpapi
node_visuals -->|"ranks candidates"| node_azurevision
node_visuals -->|"portrait assets"| node_storyboard
node_skills -->|"constrains generation"| node_storyboard
node_storyboard -->|"generates and repairs"| node_anthropic
node_storyboard -->|"seekable HTML"| node_frames
node_frames -->|"renders with"| node_chromium
node_frames -->|"indexed JPEGs"| node_compile
node_tts -->|"master audio"| node_compile
node_compile -->|"encodes with"| node_ffmpeg
node_compile -->|"writes final reel"| node_workspace

click node_ui "https://github.com/pushkrjain/video_forge/blob/main/app.py"
click node_prompts "https://github.com/pushkrjain/video_forge/blob/main/prompts.py"
click node_claude "https://github.com/pushkrjain/video_forge/blob/main/llm.py"
click node_orchestrator "https://github.com/pushkrjain/video_forge/blob/main/video/pipeline.py"
click node_tts "https://github.com/pushkrjain/video_forge/blob/main/video/v1_tts.py"
click node_visuals "https://github.com/pushkrjain/video_forge/blob/main/video/v2_images.py"
click node_storyboard "https://github.com/pushkrjain/video_forge/blob/main/video/v3_storyboard.py"
click node_skills "https://github.com/pushkrjain/video_forge/blob/main/skills/gsap-animation/SKILL.md"
click node_frames "https://github.com/pushkrjain/video_forge/blob/main/video/v4_frames.py"
click node_compile "https://github.com/pushkrjain/video_forge/blob/main/video/v5_compile.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_ui,node_prompts,node_claude,node_script toneBlue
class node_orchestrator,node_workspace,node_tts,node_visuals,node_storyboard,node_skills toneAmber
class node_frames,node_compile,node_chromium,node_ffmpeg toneMint
class node_anthropic,node_azurevision,node_serpapi,node_edgetts toneRose
```

## Components

### Conversation & Script

- [Streamlit app](https://github.com/pushkrjain/video_forge/blob/main/app.py): interactive entry point · Manages chat state, approval, and pipeline status. · `app.py`
- [Prompt contracts](https://github.com/pushkrjain/video_forge/blob/main/prompts.py): prompt definitions · `prompts.py`
- [Claude client](https://github.com/pushkrjain/video_forge/blob/main/llm.py): LLM adapter · `llm.py`
- **Approved video script**: structured script · Rendering begins only after explicit user approval.

### Render Pipeline

- [Pipeline orchestrator](https://github.com/pushkrjain/video_forge/blob/main/video/pipeline.py): run coordinator · Coordinates dependency waves in a per-run workspace. · `video/pipeline.py`
- **Run workspace**: transient artifacts · Preserves the final MP4 under temp/output/.
- [Parse & speech timeline](https://github.com/pushkrjain/video_forge/blob/main/video/v1_tts.py): V1 audio stage · Produces sections, master audio, and authoritative timings. · `video/v1_tts.py`
- [Visual asset acquisition](https://github.com/pushkrjain/video_forge/blob/main/video/v2_images.py): V2 image stage · Resolves portrait images or typed color-card fallbacks per section. · `video/v2_images.py`
- [GSAP storyboard](https://github.com/pushkrjain/video_forge/blob/main/video/v3_storyboard.py): V3 rendering program · Generates and validates seekable storyboard HTML. · `video/v3_storyboard.py`
- [Storyboard skills](https://github.com/pushkrjain/video_forge/blob/main/skills/gsap-animation/SKILL.md): generation constraints · Defines GSAP and virtual-clock requirements. · `skills/gsap-animation/SKILL.md`

### Offline Rendering

- [Frame extraction](https://github.com/pushkrjain/video_forge/blob/main/video/v4_frames.py): V4 renderer · Four Chromium workers seek the virtual clock and write JPEG frames. · `video/v4_frames.py`
- [MP4 compilation](https://github.com/pushkrjain/video_forge/blob/main/video/v5_compile.py): V5 encoder · Combines indexed frames, master audio, and optional music. · `video/v5_compile.py`
- **Playwright Chromium**: browser runtime
- **FFmpeg**: media encoder

### External Services

- **Anthropic Foundry**: chat and generation API · Supplies chat, parsing, and storyboard generation.
- **Azure OpenAI vision**: image ranking API
- **SerpAPI Google Images**: image search API
- **Edge TTS**: speech API

## Connections

- Streamlit app → Prompt contracts: uses
- Streamlit app → Claude client: drives conversation
- Prompt contracts → Claude client: defines requests
- Claude client → Anthropic Foundry: calls
- Streamlit app → Approved video script: approves
- Approved video script → Pipeline orchestrator: starts render
- Pipeline orchestrator → Parse & speech timeline: parse first
- Parse & speech timeline → Edge TTS: generates chunks
- Parse & speech timeline → Anthropic Foundry: parses sections
- Parse & speech timeline → Visual asset acquisition: sections and timings
- Parse & speech timeline → GSAP storyboard: sections and timings
- Pipeline orchestrator → Visual asset acquisition: runs concurrently with audio
- Visual asset acquisition → SerpAPI Google Images: searches
- Visual asset acquisition → Azure OpenAI vision: ranks candidates
- Visual asset acquisition → GSAP storyboard: portrait assets
- Storyboard skills → GSAP storyboard: constrains generation
- GSAP storyboard → Anthropic Foundry: generates and repairs
- GSAP storyboard → Frame extraction: seekable HTML
- Frame extraction → Playwright Chromium: renders with
- Frame extraction → MP4 compilation: indexed JPEGs
- Parse & speech timeline → MP4 compilation: master audio
- MP4 compilation → FFmpeg: encodes with
- MP4 compilation → Run workspace: writes final reel
