# sherlockchou86/videopipe architecture

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

- Interactive diagram: https://gitdiagram.com/sherlockchou86/videopipe
- Repository: https://github.com/sherlockchou86/videopipe

## Overview

##### Project Type and Purpose
- VideoPipe is a C++ video analysis framework that operates as a pipeline. It is designed for video structuring and analysis (face recognition, behavior analysis, object tracking, etc.) by combining independent plugin nodes.
- The README highlights its flexibility (supporting different inference backends, OSD, streaming outputs, recording, etc.) and stands as an alternative to frameworks like DeepStream and mxVision.

##### Analyzing the File Structure
- The file tree is organized around directories such as “nodes”, “objects”, “samples”, “utils”, and “third_party”.
- The “nodes” directory is further categorized into subdirectories such as “ba” (behavior analysis), “broker” (message and data proxy), “infers” (inference implementations), “osd” (on-screen display), “proc” (processing pipelines), “record” (record tasks), and “track” (tracking algorithms). This subdivision reveals a modular design where each node is a plugin in the pipeline.
- The “third_party” directory includes libraries (e.g., cereal for serialization, paddle_ocr, TRT-related, kissnet for networking) which are integral to the functioning of the system.
- Other folders include “samples” that demonstrate pipeline usage and “utils” for additional support functions (logging, analysis board).

##### Key Architectural Components
- Input Nodes: Represented by nodes such as vp_file_src_node, vp_rtsp_src_node, and vp_udp_src_node – they read video or image data.
- Inference Nodes: Found in nodes/infers. They provide various deep learning or classical algorithm-based processing (e.g., vp_yunet_face_detector_node, vp_trt_vehicle_detector, etc.).
- Broker Nodes: Present in nodes/broker, these handle data transmission using different protocols (Kafka, sockets, etc.) and data formats (JSON, XML).
- Processing and Control Nodes: In nodes like “proc” for frame-fusion or expression checks, and “track” for various tracking strategies.
- Output or Sink Nodes: Such as vp_screen_des_node, vp_rtmp_des_node, as well as record nodes for video/image recording.
- Utility Components: Include logging utilities (under utils/logger), the analysis board for pipeline visualization, and error handling classes (in excepts).

##### Relationships, Interactions, and Data Flow
- The overall design is like a directed acyclic graph (pipeline) where each node accepts data from one or multiple predecessor nodes, processes the video frames or data, and passes the result to its successors.

##### Architectural Patterns and Design Principles
- Plugin-Oriented Architecture: Each node is self-contained, supporting the independent configuration and extension.
- Separation of Concerns: Clear division between data acquisition, video decoding, algorithm inference, and output rendering.
- Flexibility and Extensibility: The design supports various backends (OpenCV, TensorRT, Paddle, etc.) while allowing custom business logic integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        FS["Video File Source (vp_file_src_node)"]:::input
        RTSP["RTSP Source (vp_rtsp_src_node)"]:::input
        UDP["UDP Source (vp_udp_src_node)"]:::input
    end

    %% Inference & Processing Layer
    subgraph "Inference & Processing Layer"
        subgraph "Inference Nodes"
            FA["Face Detector (vp_yunet_face_detector_node)"]:::inference
        end
        subgraph "Processing & Control Nodes"
            FF["Frame Fusion (vp_frame_fusion_node)"]:::processing
            EC["Expression Check (vp_expr_check_node)"]:::processing
            ST["Sort Tracking (vp_sort_track_node)"]:::processing
        end
        subgraph "Broker Nodes"
            MB["Message Broker (vp_msg_broker_node)"]:::broker
        end
    end

    %% Output Layer
    subgraph "Output Layer"
        SD["Screen Display (vp_screen_des_node)"]:::output
        RTMP["RTMP Display (vp_rtmp_des_node)"]:::output
        REC["Record Task"]:::output
    end

    %% Utility Components
    subgraph "Utility Components"
        LG["Logger"]:::utility
        AB["Analysis Board"]:::utility
    end

    %% Third Party Dependencies
    subgraph "Third Party Libraries"
        TP["Third Party Dependencies"]:::thirdparty
    end

    %% Connections - Pipeline Flow
    FS -->|"feeds"| FA
    RTSP -->|"feeds"| FA
    UDP -->|"feeds"| FA

    FA -->|"process"| FF
    FA -->|"sends"| MB

    FF -->|"fuse"| EC
    EC -->|"tracks"| ST

    ST -->|"output"| SD
    ST -->|"output"| RTMP
    ST -->|"output"| REC

    MB -->|"broadcast"| SD

    %% Utility Connections
    FS --- LG
    RTSP --- LG
    UDP --- LG
    FA --- LG
    FF --- LG
    EC --- LG
    ST --- LG
    MB --- LG

    FF --- AB
    EC --- AB
    ST --- AB

    %% Third Party Integration
    FA --- TP
    FF --- TP
    MB --- TP

    %% Click Events
    click FS "https://github.com/sherlockchou86/videopipe/blob/master/nodes/vp_file_src_node.cpp"
    click RTSP "https://github.com/sherlockchou86/videopipe/blob/master/nodes/vp_rtsp_src_node.cpp"
    click UDP "https://github.com/sherlockchou86/videopipe/blob/master/nodes/vp_udp_src_node.cpp"
    click FA "https://github.com/sherlockchou86/videopipe/blob/master/nodes/infers/vp_yunet_face_detector_node.cpp"
    click MB "https://github.com/sherlockchou86/videopipe/blob/master/nodes/broker/vp_msg_broker_node.cpp"
    click FF "https://github.com/sherlockchou86/videopipe/blob/master/nodes/proc/vp_frame_fusion_node.cpp"
    click EC "https://github.com/sherlockchou86/videopipe/blob/master/nodes/proc/vp_expr_check_node.cpp"
    click ST "https://github.com/sherlockchou86/videopipe/blob/master/nodes/track/vp_sort_track_node.cpp"
    click SD "https://github.com/sherlockchou86/videopipe/blob/master/nodes/vp_screen_des_node.cpp"
    click RTMP "https://github.com/sherlockchou86/videopipe/blob/master/nodes/vp_rtmp_des_node.cpp"
    click REC "https://github.com/sherlockchou86/videopipe/tree/master/nodes/record"
    click LG "https://github.com/sherlockchou86/videopipe/blob/master/utils/logger/vp_logger.cpp"
    click AB "https://github.com/sherlockchou86/videopipe/blob/master/utils/analysis_board/vp_analysis_board.cpp"
    click TP "https://github.com/sherlockchou86/videopipe/tree/master/third_party"

    %% Styles
    classDef input fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef inference fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef broker fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef processing fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef output fill:#FF7F7F,stroke:#000,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef thirdparty fill:#DA70D6,stroke:#000,stroke-width:2px;
```
