使用c++编写的, 基于TensorRT的多路视频流推理pipeline项目,支持RTSP和MP4输入输出。
Go to file
2024-12-24 17:33:34 +08:00
common feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
docs Remove deprecated config.yaml file and update README to reflect new configuration structure. Enhance input/output mapping functionality in InputManager and add validation for unique source and target names in YamlConfigParser. Update tests to cover new output target mapping features and ensure backward compatibility with previous configuration formats. 2024-12-24 17:33:34 +08:00
examples feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
models feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
pipeline Remove deprecated config.yaml file and update README to reflect new configuration structure. Enhance input/output mapping functionality in InputManager and add validation for unique source and target names in YamlConfigParser. Update tests to cover new output target mapping features and ensure backward compatibility with previous configuration formats. 2024-12-24 17:33:34 +08:00
ref feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
test_data/videos Initial commit of TensorRT Pipeline project, including core components for video stream inference. Added configuration files, build scripts, and basic structure for input, output, and processing modules. Implemented logging and error handling mechanisms. Included example usage and testing framework setup. 2024-12-24 16:26:41 +08:00
Testing/Temporary feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
tests Remove deprecated config.yaml file and update README to reflect new configuration structure. Enhance input/output mapping functionality in InputManager and add validation for unique source and target names in YamlConfigParser. Update tests to cover new output target mapping features and ensure backward compatibility with previous configuration formats. 2024-12-24 17:33:34 +08:00
.cursorrules feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
.gitignore Initial commit of TensorRT Pipeline project, including core components for video stream inference. Added configuration files, build scripts, and basic structure for input, output, and processing modules. Implemented logging and error handling mechanisms. Included example usage and testing framework setup. 2024-12-24 16:26:41 +08:00
assistant_snippet_Hs+Hs+Hs+.txt Initial commit of TensorRT Pipeline project, including core components for video stream inference. Added configuration files, build scripts, and basic structure for input, output, and processing modules. Implemented logging and error handling mechanisms. Included example usage and testing framework setup. 2024-12-24 16:26:41 +08:00
assistant_snippet_Hs+Hs+Hs+H.txt Initial commit of TensorRT Pipeline project, including core components for video stream inference. Added configuration files, build scripts, and basic structure for input, output, and processing modules. Implemented logging and error handling mechanisms. Included example usage and testing framework setup. 2024-12-24 16:26:41 +08:00
assistant_snippet_Hs+Hy+Iqm.txt feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
assistant_snippet_Hy+Hs2Iqxm.txt Initial commit of TensorRT Pipeline project, including core components for video stream inference. Added configuration files, build scripts, and basic structure for input, output, and processing modules. Implemented logging and error handling mechanisms. Included example usage and testing framework setup. 2024-12-24 16:26:41 +08:00
assistant_snippet_Yx2Hs2Iqxm.txt feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
build.sh feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
CMakeLists.txt feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
context feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
main.cpp feat: 初始化项目结构 2024-12-24 16:25:03 +08:00
README.md Remove deprecated config.yaml file and update README to reflect new configuration structure. Enhance input/output mapping functionality in InputManager and add validation for unique source and target names in YamlConfigParser. Update tests to cover new output target mapping features and ensure backward compatibility with previous configuration formats. 2024-12-24 17:33:34 +08:00
当前模块进度 feat: 初始化项目结构 2024-12-24 16:25:03 +08:00

TensorRT Pipeline 推理项目

基于TensorRT的多路视频流推理pipeline项目支持RTSP和MP4输入输出。

功能特点

  • 多路输入源支持RTSP/MP4

    • 输入源状态监控
    • 可配置缓冲区
    • 自动重连机制
  • TensorRT推理引擎

    • FP32/FP16/INT8精度
    • 动态批处理
    • CUDA内存优化
    • ONNX模型导入
  • 可视化系统

    • 实时检测结果显示
    • 自定义渲染参数
    • 性能指标监控
  • 多路输出支持

    • RTSP推流
    • MP4本地存储
    • 可配置编码参数

项目结构

.
├── CMakeLists.txt          # 主构建配置
├── README.md              # 项目说明文档
├── build.sh              # 构建脚本
├── common/              # 通用组件
│   └── logger.hpp      # 日志组件
├── config.yaml         # 主配置文件
├── docs/              # 文档
│   ├── api_reference.md
│   ├── architecture.md
│   ├── build_guide.md
│   └── performance_tuning.md
├── examples/          # 示例代码
│   ├── CMakeLists.txt
│   ├── rtsp_demo.cpp
│   └── video_demo.cpp
├── logs/             # 日志目录
├── main.cpp          # 主程序入口
├── models/           # 模型文件
│   ├── model.engine
│   ├── yolov8n.engine
│   └── yolov8n.onnx
├── output/           # 输出目录
│   └── videos/      # 视频输出目录
├── pipeline/         # 核心pipeline实现
│   ├── CMakeLists.txt
│   ├── common/      # 通用组件
│   │   ├── config_parser.*
│   │   ├── logger.hpp
│   │   ├── pipeline.*
│   │   └── yaml_config_parser.*
│   ├── configs/     # 配置文件
│   │   └── pipeline.yaml
│   ├── inference/   # 推理相关实现
│   │   ├── cuda_helper.*
│   │   ├── preprocess.*
│   │   ├── trt_inference.*
│   │   └── types.hpp
│   ├── input/       # 输入模块
│   │   ├── frame_queue.*
│   │   ├── input_manager.*
│   │   ├── rtsp_reader.*
│   │   └── video_reader.*
│   ├── output/      # 输出模块
│   │   ├── output_manager.*
│   │   ├── rtsp_writer.*
│   │   ├── video_writer.*
│   │   └── writer_interface.hpp
│   ├── render/      # 渲染模块
│   │   ├── frame_drawer.*
│   │   └── renderer.*
│   ├── types.hpp    # 类型定义
│   └── utils/       # 工具类
│       ├── cuda_helper.*
│       ├── logger.*
│       └── timer.*
├── ref/             # 参考实现
│   └── tensorrt_engine.cpp
├── test_data/       # 测试数据
│   └── videos/
│       └── raw.mp4
└── tests/           # 测试代码
    ├── CMakeLists.txt
    ├── test_base.hpp
    ├── test_config_parser.cpp
    ├── test_cuda_helper.cpp
    ├── test_frame_drawer.cpp
    ├── test_frame_queue.cpp
    ├── test_input_manager.cpp
    ├── test_output_manager.cpp
    ├── test_pipeline.cpp
    ├── test_preprocess.cpp
    ├── test_renderer.cpp
    ├── test_rtsp_reader.cpp
    ├── test_rtsp_writer.cpp
    ├── test_trt_inference.cpp
    ├── test_video_reader.cpp
    ├── test_video_writer.cpp
    └── test_yaml_config.cpp

配置文件说明

项目使用 YAML 格式的配置文件来管理所有设置。主配置文件位于:

/pipeline/configs/pipeline.yaml

配置文件结构说明

  1. 输入源配置 (input.sources)

    • type: 输入类型 (video/rtsp)
    • name: 输入源名称,用于标识和映射
    • url: 输入源地址
    • buffer_size: 缓冲区大小
    • output_targets: 输出目标列表,指定该输入源对应的输出目标名称
      • 可以指定一个或多个输出目标
      • 如果不指定,默认使用所有可用的输出目标
      • 示例:output_targets: ["output1", "output2"]
  2. 输出目标配置 (output.targets)

    • type: 输出类型 (video/rtsp)
    • name: 输出目标名称,用于与输入源映射
    • path: 输出路径
    • fps: 输出帧率
    • codec: 编码器类型
    • bitrate: 码率设置
  3. 输入输出映射关系

    • 每个输入源可以指定一个或多个输出目标
    • 通过 output_targets 字段指定目标名称列表
    • 如果未指定 output_targets,默认使用所有输出目标
    • 映射规则:
      • 一对一映射:一个输入源映射到一个输出目标
      • 一对多映射:一个输入源可以同时映射到多个输出目标
      • 多对一映射:多个输入源可以映射到同一个输出目标
      • 默认映射:未指定映射时使用所有可用输出目标

配置示例

# Pipeline配置文件

input:
  sources:
    - type: rtsp
      name: "camera1"
      url: "rtsp://10.0.0.17:8554/camera1"
      buffer_size: 30
      output_targets: ["output1", "stream1"]  # 一个输入映射到多个输出
    
    - type: video
      name: "video1"
      url: "/data/test.mp4"
      buffer_size: 30
      output_targets: ["output2"]  # 一个输入映射到一个输出
    
    - type: rtsp
      name: "camera2"
      url: "rtsp://10.0.0.17:8554/camera2"
      buffer_size: 30
      # 未指定 output_targets将使用所有可用的输出目标

output:
  targets:
    - type: video
      name: "output1"
      path: "/output/camera1.mp4"
      fps: 30
      codec: "h264"
      bitrate: 4000000
    
    - type: rtsp
      name: "stream1"
      path: "rtsp://localhost:8554/live/camera1"
      fps: 30
      codec: "h264"
      bitrate: 4000000
    
    - type: video
      name: "output2"
      path: "/output/video1.mp4"
      fps: 30
      codec: "h264"
      bitrate: 4000000

# 日志配置
log:
  level: "info"            # debug/info/warn/error
  save_path: "logs/"       # 日志保存路径

输入输出映射功能说明

功能特点

  1. 灵活的映射关系

    • 支持一对一、一对多、多对一的映射关系
    • 可以动态配置每个输入源的输出目标
    • 提供默认映射机制,简化配置
  2. 资源优化

    • 根据映射关系优化资源分配
    • 避免不必要的输出处理
    • 支持输出目标的复用
  3. 错误处理

    • 配置验证确保映射关系有效
    • 运行时错误检测和恢复
    • 详细的错误日志和状态报告

使用方法

  1. 配置文件设置

    input:
      sources:
        - name: "camera1"
          output_targets: ["output1", "stream1"]  # 指定多个输出目标
        - name: "video1"
          output_targets: ["output2"]            # 指定单个输出目标
        - name: "camera2"                        # 使用默认映射
    
  2. 运行时管理

    • 可以通过API动态更新映射关系
    • 支持添加或移除输出目标
    • 提供映射状态查询接口
  3. 性能考虑

    • 合理配置映射关系避免资源浪费
    • 注意输出目标数量对性能的影响
    • 可以通过监控接口观察资源使用情况

最佳实践

  1. 映射配置

    • 根据实际需求配置映射关系
    • 避免不必要的多重映射
    • 使用有意义的名称便于管理
  2. 资源管理

    • 及时清理不再使用的输出目标
    • 监控资源使用情况
    • 在配置大量映射时注意性能影响
  3. 错误处理

    • 实现错误回调处理机制
    • 定期检查映射状态
    • 保存详细的错误日志

配置文件使用说明

  1. 测试程序

    • 测试程序固定使用 /pipeline/configs/pipeline.yaml
    • 配置文件路径在 tests/test_base.hpp 中定义
    • 运行测试时无需指定配置文件
  2. 主程序

    • 主程序通过命令行参数指定配置文件
    • 运行格式:./build/trt_pipeline_demo <config_file>
    • 推荐使用默认配置文件:
      ./build/trt_pipeline_demo pipeline/configs/pipeline.yaml
      
  3. 配置文件修改

    • 建议复制 pipeline.yaml 进行修改,而不是直接修改原文件
    • 修改时需要特别注意路径配置
    • 保持配置文件结构不变,只修改相应的值

环境依赖

  • CUDA = 12.1
  • TensorRT = 8.6
  • OpenCV = 4.10.0
  • FFmpeg (RTSP支持)

配置示例


## 架构设计

### 核心模块

- Input: 输入源管理、RTSP/视频读取、帧缓存队列
- Inference: TensorRT引擎、预处理、批处理管理
- Render: 结果可视化、性能指标显示
- Output: 输出管理、RTSP推流、视频保存

### 数据流

[输入源] -> [预处理] -> [推理] -> [后处理] -> [渲染] -> [输出]