# unconv/captacity architecture

> Architecture diagram of the GitHub repository unconv/captacity, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unconv/captacity
- Repository: https://github.com/unconv/captacity

## Overview

##### Main Components

a. Input/Output Layer:
- Video Input Handler
- Captioned Video Output Handler

b. Core Processing Components:
- Transcription Engine (Whisper - both local and API options)
- Text Processing Pipeline
- Caption Rendering Engine

c. Supporting Components:
- Asset Management (fonts)
- CLI Interface
- Configuration Handler

##### Component Relationships

1. Input Video → 2. Transcription → 3. Text Processing → 4. Caption Rendering → 5. Output Video

##### Detailed Component Breakdown

For each major component, include these elements:

Input Handler:
- Video file acceptance
- Format validation

Transcription Engine:
- Local Whisper Integration
- OpenAI API Integration
- Transcription output formatting

Text Processing:
- Segment Parser (segment_parser.py)
- Word timing management
- Text segmentation

Caption Rendering:
- Text Drawer (text_drawer.py)
- Font management

##### Implementation Details to Highlight

- Dual-path for Whisper transcription (local vs. API)
- Asset management system for fonts
- CLI and programmatic entry points

##### Specific Elements

**[Video Input] → [Transcription Engine]**
- [Local Whisper]
- [OpenAI API]
- ↓
**[Configuration] → [Text Processing]**
**[Font Assets] ─┘      ↓**
- [Caption Renderer]
- ↓
- [Video Output]

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        VI[Video Input]:::input
    end

    subgraph "Core Processing"
        TE[Transcription Engine]:::core
        click TE "https://github.com/unconv/captacity/blob/master/captacity/transcriber.py"
        
        subgraph "Transcription Options"
            LW[Local Whisper]:::processing
            OA[OpenAI API]:::external
        end
        
        TP[Text Processing Pipeline]:::core
        click TP "https://github.com/unconv/captacity/blob/master/captacity/segment_parser.py"
        
        CR[Caption Rendering Engine]:::core
        click CR "https://github.com/unconv/captacity/blob/master/captacity/text_drawer.py"
    end

    subgraph "Supporting Systems"
        CLI[CLI Interface]:::interface
        click CLI "https://github.com/unconv/captacity/blob/master/captacity/cli.py"
        
        CONF[Configuration Handler]:::config
        
        subgraph "Asset Management"
            FA[Font Assets]:::assets
            click FA "https://github.com/unconv/captacity/tree/master/captacity/assets/fonts/"
        end
    end

    subgraph Output
        VO[Video Output]:::output
    end

    %% Main Flow
    VI --> TE
    TE --> |Choose| LW
    TE --> |Choose| OA
    LW --> TP
    OA --> TP
    TP --> CR
    CR --> VO

    %% Supporting Connections
    CONF --> TP
    CONF --> CR
    FA --> CR
    CLI --> TE
    CLI --> CONF

    %% Styles
    classDef core fill:#2b6cb0,stroke:#1a4971,color:white
    classDef input fill:#48bb78,stroke:#2f855a,color:white
    classDef output fill:#48bb78,stroke:#2f855a,color:white
    classDef processing fill:#4299e1,stroke:#2b6cb0,color:white
    classDef external fill:#9f7aea,stroke:#805ad5,color:white
    classDef config fill:#ecc94b,stroke:#d69e2e,color:black
    classDef interface fill:#ed8936,stroke:#dd6b20,color:white
    classDef assets fill:#4fd1c5,stroke:#38b2ac,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Input/Output]:::input
        L3[Processing]:::processing
        L4[External Services]:::external
        L5[Configuration]:::config
        L6[Interface]:::interface
        L7[Assets]:::assets
    end
```
