# tdollar15/opusclip-clone architecture

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

- Interactive diagram: https://gitdiagram.com/tdollar15/opusclip-clone
- Repository: https://github.com/tdollar15/opusclip-clone

## Overview

##### Main Components
- Input/Output:
- Input video source (via a provided YouTube URL).
- Output short video (Final.mp4).
- Download Module:
- YoutubeDownloader (Components/YoutubeDownloader.py) handles video fetching.
- Preprocessing:
- The main.py script orchestrates the whole process.
- Transcription:
- Transcription module (Components/Transcription.py) utilizes Whisper to transcribe the video.
- Extraction:
- LanguageTasks (Components/LanguageTasks.py) communicates with GPT-4 to extract the most engaging segments.
- Speaker and Face Detection:
- SpeakerDetection (Components/SpeakerDetection.py) to detect speakers.
- Speaker (Components/Speaker.py) and FaceCrop (Components/FaceCrop.py) to detect and crop the faces.
- Models in the models/ directory (deploy.prototxt and the caffemodel) support face detection tasks.
- Video Editing:
- Edit (Components/Edit.py) handles the editing/cropping operations (vertical cropping for short format).
- Environment/Configuration:
- A .env file for managing sensitive API keys.
- requirements.txt defines dependencies.

##### Relationships and Data Flow
- The process begins when main.py prompts for a YouTube URL.
- The YoutubeDownloader downloads the long-form video.
- Once downloaded, the Transcription module processes the video to convert audio to text.
- Using the transcript, the LanguageTasks component calls GPT-4 (via the OpenAI API) to determine which parts are the “highlights.”
- SpeakerDetection and Speaker modules are utilized to identify and verify speakers during these segments.
- The FaceCrop module, leveraging OpenCV and the provided Haar Cascade model files (haarcascade_frontalface_default.xml and models’ files), ensures that the frames are cropped properly (vertically) for optimal display in shorts.
- The Edit module then puts together the final short video output.
- Finally, the processed video (Final.mp4) is saved.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input/Output Layer
    A["Input: YouTube URL<br/>(via main.py)"]:::external
    B["Output: Final.mp4"]:::external

    %% Main Controller
    C["Main Controller (main.py)"]:::controller

    %% Download Module
    D["YoutubeDownloader<br/>(Components/YoutubeDownloader.py)"]:::videoProcessing

    %% Transcription Module
    E["Transcription (Whisper)<br/>(Components/Transcription.py)"]:::transcription

    %% Highlight Extraction Module
    F["LanguageTasks (GPT-4)<br/>(Components/LanguageTasks.py)"]:::language

    %% Speaker Detection Modules
    G["SpeakerDetection<br/>(Components/SpeakerDetection.py)"]:::videoProcessing
    H["Speaker Identification<br/>(Components/Speaker.py)"]:::videoProcessing

    %% Face Detection and Cropping Modules
    I["FaceCrop<br/>(Components/FaceCrop.py)"]:::videoProcessing
    J["Face Detection Model<br/>(models/deploy.prototxt)"]:::external
    K["Face Detection Weights<br/>(models/res10_300x300_ssd_iter_140000_fp16.caffemodel)"]:::external
    L["Haar Cascade Model<br/>(haarcascade_frontalface_default.xml)"]:::external

    %% Video Editing Module
    M["Edit Module<br/>(Components/Edit.py)"]:::editing

    %% Environment and Dependencies
    N["Environment Variables<br/>(.env)"]:::external
    O["Dependencies<br/>(requirements.txt)"]:::external

    %% External Tools
    P["FFmpeg"]:::external
    Q["OpenCV"]:::external
    R["OpenAI API"]:::external

    %% Data Flow
    A -->|"provides URL"| C
    C -->|"orchestrates"| D
    D -->|"downloads video"| E
    D -->|"sends video to"| G
    D -->|"sends video to"| I
    E -->|"generates transcript"| F
    F -->|"identifies highlights"| M
    G -->|"detects speakers"| H
    H -->|"verifies speakers"| M
    I -->|"crops faces"| M
    P --- D
    Q --- I
    R --- F
    N --- F
    N --- E
    O --- C

    %% Final Output
    M -->|"produces"| B

    %% Click Events
    click C "https://github.com/tdollar15/opusclip-clone/blob/main/main.py"
    click D "https://github.com/tdollar15/opusclip-clone/blob/main/Components/YoutubeDownloader.py"
    click E "https://github.com/tdollar15/opusclip-clone/blob/main/Components/Transcription.py"
    click F "https://github.com/tdollar15/opusclip-clone/blob/main/Components/LanguageTasks.py"
    click G "https://github.com/tdollar15/opusclip-clone/blob/main/Components/SpeakerDetection.py"
    click H "https://github.com/tdollar15/opusclip-clone/blob/main/Components/Speaker.py"
    click I "https://github.com/tdollar15/opusclip-clone/blob/main/Components/FaceCrop.py"
    click M "https://github.com/tdollar15/opusclip-clone/blob/main/Components/Edit.py"
    click N "https://github.com/tdollar15/opusclip-clone/blob/main/.env"
    click O "https://github.com/tdollar15/opusclip-clone/blob/main/requirements.txt"
    click J "https://github.com/tdollar15/opusclip-clone/blob/main/models/deploy.prototxt"
    click K "https://github.com/tdollar15/opusclip-clone/blob/main/models/res10_300x300_ssd_iter_140000_fp16.caffemodel"
    click L "https://github.com/tdollar15/opusclip-clone/blob/main/haarcascade_frontalface_default.xml"

    %% Class definitions for colors
    classDef controller fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef videoProcessing fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef transcription fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef language fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef editing fill:#F1948A,stroke:#922B21,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
