# styler00dollar/vsgan-tensorrt-docker architecture

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

- Interactive diagram: https://gitdiagram.com/styler00dollar/vsgan-tensorrt-docker
- Repository: https://github.com/styler00dollar/vsgan-tensorrt-docker

## Overview

##### Major Components
- Docker Environment & Deployment:
– Dockerfile, Docker-compose files (compose.yaml, compose_mpv.yaml, start_docker.sh)
– Different container configurations (latest, latest_no_avx512, minimal, etc.)
- Ingestion/Input Processing:
– Video reading via VapourSynth plugins (ffms2, lsmash, bestsource) as shown in the README examples.
– Custom scripts (e.g., inference.py, vfr_to_cfr.py) to load and possibly convert variable refresh rate (VFR) videos.
- Preprocessing & Analysis:
– Modules for scene change detection (see src/scene_detect.py and README examples) and deduplication (e.g., ddfi in custom_scripts/ddfi_rife_upscale_dedup_scene_change and src/dedup.py).
– Utility functions for manipulating frames (src/utils.py) such as FastLineDarkenMOD.
- Inference Engine:
– Core inference scripts (inference.py, inference_batch.py, main.py) that configure and call the TensorRT engine.
– Model-specific integration using modules such as vsrife (and its variations: vsrife, drba_rife) and others (cugan, ModernSpanimation, etc.) as referenced in the README.
– The engine conversion is handled via “trtexec” commands (documented in README) and references to ONNX-to-engine pipelines.
- Post-processing & Rendering:
– Conversion of processed frames back to a suitable video format using FFmpeg piped commands.
- Custom Scripts & Utilities:
– The “custom_scripts” folder houses a repository of individual examples and pipelines for different processing scenarios (batch inference, deduplicated inference, scene detection with interpolation, multi-GPU support, etc.)
– The “src” folder holds shared modules such as download.py and utilities common across different pipelines.

##### Relationships and Interactions
– Post-inference, processed frames are piped to FFmpeg (or similar tools) to encode and package the final output video.
– The entire process is containerized, meaning the Docker container encapsulating all dependencies (FFmpeg, TensorRT, VapourSynth, and custom scripts) acts as the runtime environment.
– Also include a multi-GPU support branch where a single input can be processed in parallel streams and interleaved back together.

##### Architectural Patterns and Design Principles
– Modular Design: The project splits functional concerns into separate directories (custom_scripts for example pipelines, src for shared libraries). Emphasize separation of concerns.
– Extensibility: The existence of many individual examples and model integration points reflect an extensible design where more pipelines (e.g., deduplicated inference, multi-GPU pipelines, etc.) can be added.

##### Relevant Technologies and Frameworks
– Docker (with Docker Compose)
– VapourSynth (and its various plugins: ffms2, lsmash, bestsource)
– TensorRT (and the associated vs-trt C++ library and Python wrappers)
– FFmpeg (for encoding/rendering video, piping input/output)
– Python (for scripting, inference orchestration, and utility modules)
– ONNX and trtexec for model conversion/building TensorRT engines

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Docker Container"
        %% Deployment Subgraph
        subgraph "Deployment"
            Dockerfile["Dockerfile"]:::config
            Dockerfile_minimal["Dockerfile_minimal"]:::config
            compose_yaml["compose.yaml"]:::config
            compose_mpv_yaml["compose_mpv.yaml"]:::config
            start_docker_sh["start_docker.sh"]:::config
        end

        %% Video Processing Pipeline Subgraph
        subgraph "Video Processing Pipeline"
            %% Input Processing Subgraph
            subgraph "Input Processing"
                vfr["vfr_to_cfr.py"]:::ingestion
                customIngest["Custom Ingest Scripts\n(custom_scripts)"]:::ingestion
            end

            %% Preprocessing & Analysis Subgraph
            subgraph "Preprocessing & Analysis"
                scene["Scene Detection\n(src/scene_detect.py)"]:::preprocessing
                dedup["Deduplication\n(src/dedup.py)"]:::preprocessing
                ddfi["DDFI Module\n(ddfi.py)"]:::preprocessing
                dedupVFI["Dedup VFI\n(deduped_vfi.py)"]:::preprocessing
                parser["Parse Module\n(parse.py)"]:::preprocessing
            end

            %% Inference Engine Subgraph
            subgraph "Inference Engine"
                inference["Inference\n(inference.py)"]:::inference
                batchInf["Batch Inference\n(inference_batch.py)"]:::inference
                infConfig["Inference Config\n(inference_config.py)"]:::inference
                mainCtrl["Main Controller\n(main.py)"]:::inference
                trtModule["TensorRT Module\n(src/rife_trt.py)"]:::inference
                multiGPU["Multi-GPU Processing"]:::inference
            end

            %% Post-processing Subgraph
            subgraph "Post-processing"
                colorTransfer["Color Transfer\n(color_transfer.py)"]:::postprocessing
            end

            %% Custom Scripts & Utilities Subgraph
            subgraph "Custom Scripts & Utilities"
                customScripts["Custom Scripts\n(custom_scripts)"]:::utilities
                downloadUtil["Download Utility\n(src/download.py)"]:::utilities
                utils["Utils\n(src/utils.py)"]:::utilities
            end
        end
    end

    %% Data Flow Connections
    %% From Deployment to Input Processing (docker startup triggers processing)
    start_docker_sh -->|"initiates"| vfr

    %% Input Processing to Preprocessing & Analysis
    vfr -->|"video frames"| scene
    vfr -->|"video frames"| dedup
    customIngest -->|"custom ingestion"| scene

    %% Preprocessing & Analysis to Inference Engine
    scene -->|"preprocessed frames"| inference
    dedup -->|"preprocessed frames"| inference
    ddfi -->|"processed frames"| inference
    dedupVFI -->|"processed frames"| inference
    parser -->|"metadata"| inference

    %% Inference Engine internal flow
    inference --> batchInf
    batchInf --> infConfig
    infConfig --> mainCtrl
    mainCtrl --> trtModule
    mainCtrl --> multiGPU
    multiGPU --> trtModule

    %% Inference Engine to Post-processing
    trtModule -->|"inferred frames"| colorTransfer

    %% Custom Scripts & Utilities support connections
    customScripts --- scene
    customScripts --- inference
    downloadUtil --> mainCtrl
    utils --> mainCtrl

    %% Styling Definitions
    classDef config fill:#ccf,stroke:#000,stroke-width:1px;
    classDef ingestion fill:#cfc,stroke:#000,stroke-width:1px;
    classDef preprocessing fill:#fc9,stroke:#000,stroke-width:1px;
    classDef inference fill:#99f,stroke:#000,stroke-width:1px;
    classDef postprocessing fill:#ff9,stroke:#000,stroke-width:1px;
    classDef utilities fill:#9f9,stroke:#000,stroke-width:1px;

    %% Click Events for Deployment
    click Dockerfile "https://github.com/styler00dollar/vsgan-tensorrt-docker/tree/main/Dockerfile"
    click Dockerfile_minimal "https://github.com/styler00dollar/vsgan-tensorrt-docker/tree/main/Dockerfile_minimal"
    click compose_yaml "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/compose.yaml"
    click compose_mpv_yaml "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/compose_mpv.yaml"
    click start_docker_sh "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/start_docker.sh"

    %% Click Events for Ingestion/Input Processing
    click vfr "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/vfr_to_cfr.py"
    click customIngest "https://github.com/styler00dollar/vsgan-tensorrt-docker/tree/main/custom_scripts"

    %% Click Events for Preprocessing & Analysis
    click scene "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/src/scene_detect.py"
    click dedup "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/src/dedup.py"
    click ddfi "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/custom_scripts/ddfi_rife_upscale_dedup_scene_change/ddfi.py"
    click dedupVFI "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/custom_scripts/ddfi_rife_upscale_dedup_scene_change/deduped_vfi.py"
    click parser "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/custom_scripts/ddfi_rife_upscale_dedup_scene_change/parse.py"

    %% Click Events for Inference Engine
    click inference "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/inference.py"
    click batchInf "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/inference_batch.py"
    click infConfig "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/inference_config.py"
    click mainCtrl "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/main.py"
    click trtModule "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/src/rife_trt.py"

    %% Click Event for Post-processing & Rendering
    click colorTransfer "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/color_transfer.py"

    %% Click Events for Custom Scripts & Utilities
    click customScripts "https://github.com/styler00dollar/vsgan-tensorrt-docker/tree/main/custom_scripts"
    click downloadUtil "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/src/download.py"
    click utils "https://github.com/styler00dollar/vsgan-tensorrt-docker/blob/main/src/utils.py"
```
