# byjlw/video-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/byjlw/video-analyzer
- Repository: https://github.com/byjlw/video-analyzer

## Overview

##### Main Components

a) Input Processing Layer:
- Video Input Handler
- Frame Extraction Module (using OpenCV)
- Audio Extraction Module (using FFmpeg)

b) Core Processing Components:
- Frame Analysis Engine
- Audio Processing Engine (Whisper)
- LLM Client Interface Layer

c) Model Integration Layer:
- Vision Model Interface (Llama3.2/OpenAI)
- Audio Model Interface (Whisper)

d) Output Generation Layer:
- Analysis Aggregator
- JSON Output Generator

##### Component Relationships

**Input → Processing → Analysis → Output**

**Video Input ─┬→ Frame Extractor ──→ Vision Model ───┐**
- → Audio Extractor ──→ Whisper Model ──┤
- → Analysis Aggregator → JSON Output

**Configuration ────────────────────────────────────┘**

##### Key Technical Elements to Highlight

a) Client Architecture:
- Abstraction layer between different LLM clients (Ollama/OpenAI)
- Configuration-driven client selection

b) Processing Pipeline:
- Frame extraction with configurable parameters
- Audio processing with quality checks
- Parallel processing capabilities

##### Specific Implementation Details

**/video_analyzer/**
- analyzer.py (Core Orchestration)
- audio_processor.py (Audio Processing)
- frame.py (Frame Management)
- clients/ (LLM Client Layer)
- generic_openai_api.py
- ollama.py
- prompts/ (Analysis Templates)

##### Additional Elements

a) Configuration Flow:
- How config/default_config.json influences components
- Command-line override paths

b) Error Handling:
- Retry paths for API calls
- Fallback mechanisms

Create distinct sections for:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        VI[Video Input]:::input
        CF["Configuration"]:::config
        click CF "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/config/default_config.json"
        CLI["CLI Interface"]:::input
        click CLI "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/cli.py"
    end

    subgraph "Processing Layer"
        FE["Frame Extraction"]:::process
        click FE "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/frame.py"
        AE["Audio Extraction"]:::process
        click AE "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/audio_processor.py"
    end

    subgraph "Analysis Layer"
        FAE["Frame Analysis Engine"]:::analysis
        APE["Audio Processing Engine"]:::analysis
        click APE "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/audio_processor.py"
        
        subgraph "LLM Client Interface"
            LC["LLM Client Manager"]:::client
            click LC "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/clients/llm_client.py"
            OAI["OpenAI API Client"]:::client
            click OAI "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/clients/generic_openai_api.py"
            OL["Ollama Client"]:::client
            click OL "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/clients/ollama.py"
        end
        
        PT["Prompt Templates"]:::template
        click PT "https://github.com/byjlw/video-analyzer/tree/main/video_analyzer/prompts/frame_analysis/"
    end

    subgraph "Output Layer"
        AA["Analysis Aggregator"]:::output
        click AA "https://github.com/byjlw/video-analyzer/blob/main/video_analyzer/analyzer.py"
        JSON["JSON Output"]:::output
        click JSON "https://github.com/byjlw/video-analyzer/blob/main/docs/sample_analysis.json"
    end

    %% Relationships
    VI --> FE
    VI --> AE
    CLI --> CF
    CF --> LC
    CF --> FE
    CF --> AE

    FE --> FAE
    AE --> APE

    FAE --> LC
    APE --> LC
    PT --> LC

    LC --> OAI
    LC --> OL

    OAI --> AA
    OL --> AA
    APE --> AA
    AA --> JSON

    %% Styles
    classDef input fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef config fill:#c3b1e1,stroke:#333,stroke-width:2px
    classDef process fill:#90ee90,stroke:#333,stroke-width:2px
    classDef analysis fill:#ffe599,stroke:#333,stroke-width:2px
    classDef client fill:#ff9999,stroke:#333,stroke-width:2px
    classDef template fill:#ffd700,stroke:#333,stroke-width:2px
    classDef output fill:#87ceeb,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Input Components]:::input
        L2[Configuration]:::config
        L3[Processing]:::process
        L4[Analysis]:::analysis
        L5[Client Layer]:::client
        L6[Templates]:::template
        L7[Output]:::output
    end
```
