YOLOv8 Real-time Inference CPP Project with reComputer RK3576
A multi-source input, multi-stream output, YOLOv8 real-time inference project based on RK3576, RKNN, MPP, RGA, and ZLMediaKit.
A multi-source input, multi-stream output YOLOv8 real-time inference project based on RK3576 / RKNN / MPP / RGA / ZLMediaKit.
Current project supports:
V4L2camera inputRTSPnetwork video inputlocalvideolocal video file looping input- Three RTSP output streams: main stream / sub stream / AI debug stream
YOLOv8 RKNNinference, bounding box overlay, class labels, time and FPS OSDlibavformatprioritized for RTSP/local compressed stream input, withffmpeg pipeas a fallback
Feature Overview
-
Input Sources
-
v4l2: Suitable for USB cameras, local capture -
rtsp: Suitable for IPC/NVR/network video streams -
localvideo: Suitable for local video playback, offline validation, loop inference -
Output Streams
-
Main stream:
rtsp://<board-ip>:8554/live/camera -
Sub stream:
rtsp://<board-ip>:8554/live/camera_sub -
AI debug stream:
rtsp://<board-ip>:8554/live/camera_ai -
Use
--streams main,sub,aito output any single, dual, or all three streams simultaneously -
Resolution Strategies
-
cameramain stream: Proportional scaling + padding (no stretching) -
camera_subsub stream: Proportional scaling + center cropping (no stretching) -
camera_aiAI debug stream: Proportional scaling + padding (no stretching) -
AI Inference
-
Fixed input of
640x640 -
Prioritizes
RGA letterboxfor preprocessing -
Supports detection cache, PTS matching, AI overlay
Deployment Guide
Dependencies
- RK3576 board runtime environment
- RKNN Runtime
- Rockchip MPP
- RGA /
librga - ZLMediaKit runtime library
- FFmpeg runtime library or command-line tools
Build Steps
cd /home/parker/Projects/rk3576_yolov8tortsp_demo
chmod +x scripts/build-linux.sh
./scripts/build-linux.shBuild outputs:
- Executable:
install/bin/rk3576_yolov8tortsp_demo - Runtime libraries:
install/lib - Documentation:
install/docs - Models directory:
install/model
Pre-run Setup
cd install
export LD_LIBRARY_PATH="$(pwd)/lib:${LD_LIBRARY_PATH}"Model Placement
Place the RKNN models into:
model/
yolov8n_rk3576.rknn
yolov8s_rk3576.rknn
yolov8m_rk3576.rknnIf --model is not explicitly provided, the program will automatically select existing models in the following order:
model/yolov8n_rk3576.rknnmodel/yolov8s_rk3576.rknnmodel/yolov8m_rk3576.rknn
Usage
V4L2 Camera Input
sudo ./bin/rk3576_yolov8tortsp_demo \
--source v4l2 \
--device /dev/video0 \
--model model/yolov8n_rk3576.rknn \
--camera-width 1920 \
--camera-height 1080 \
--output-width 1280 \
--output-height 720 \
--fps 30 \
--bitrate 4000000 \
--perf-interval-ms 1000 \
--rtsp-port 8554 \
--rtsp-app live \
--rtsp-stream cameraRTSP Input
sudo ./bin/rk3576_yolov8tortsp_demo \
--source rtsp \
--rtsp-input-url "rtsp://192.168.100.101:554/live" \
--rtsp-username "admin" \
--rtsp-password "c32bdc3e" \
--model model/yolov8n_rk3576.rknn \
--camera-width 1920 \
--camera-height 1080 \
--output-width 1280 \
--output-height 720 \
--fps 30 \
--bitrate 4000000 \
--perf-interval-ms 1000 \
--rtsp-timeout-ms 5000 \
--rtsp-reconnect-ms 1000 \
--rtsp-port 8554 \
--rtsp-app live \
--rtsp-stream cameraLocal Video Looping Input
sudo ./bin/rk3576_yolov8tortsp_demo \
--source localvideo \
--localvideo ./videos/demo.mp4 \
--model model/yolov8n_rk3576.rknn \
--camera-width 1920 \
--camera-height 1080 \
--output-width 1280 \
--output-height 720 \
--fps 30 \
--bitrate 4000000 \
--perf-interval-ms 1000 \
--rtsp-port 8554 \
--rtsp-app live \
--rtsp-stream cameraDetailed Logs
Only a startup summary is printed by default; to print detailed runtime logs, add:
--detail-infoExport NPU Input Frames
sudo ./bin/rk3576_yolov8tortsp_demo \
--source localvideo \
--localvideo ./videos/demo.mp4 \
--model model/yolov8n_rk3576.rknn \
--streams ai \
--dump-ai-input-dir ./debug_ai_input \
--dump-ai-input-every 30 \
--detail-infoEnable Specific Output Streams
--streams ai
--streams main,ai
--streams main,sub
--streams main,sub,aiExplanation:
--streams ai: Perform AI inference only and outputcamera_ai--streams main,ai: Output main stream and AI debug stream--streams main,sub: Standard dual-stream only, does not load RKNN model- When omitted, defaults to
--streams main,sub,ai
View Help
./bin/rk3576_yolov8tortsp_demo --helpAPI Reference
Core Command Line Arguments
--source <v4l2|rtsp|localvideo>: Input source type--device <path>: V4L2 device node--rtsp-input-url <url>: RTSP address--rtsp-username <value>: RTSP username--rtsp-password <value>: RTSP password--localvideo <path>: Local video file path--model <path>: RKNN model path--camera-width <value>/--camera-height <value>: Input resolution--output-width <value>/--output-height <value>: Main stream output resolution--sub-width <value>/--sub-height <value>: Sub stream output resolution--fps <value>: Target encoding framerate--bitrate <value>: Main stream target bitrate--rtsp-port <value>: Local RTSP server port--rtsp-app <value>: RTSP app name--rtsp-stream <value>: Main stream name--sub-stream <value>: Sub stream name--ai-stream <value>: AI debug stream name--streams <items>: Enable which output streams, supports comma-separated combinations ofmain,sub,ai--rtsp-timeout-ms <value>: RTSP read timeout--rtsp-reconnect-ms <value>: RTSP reconnect interval--perf-interval-ms <value>: PERF output cycle--detail-info: Enable detailed logs--help: Print help
PERF Meanings
process: Image processing time within the branchencode: MPP encoding timepush: RTSP pushing timee2e: Total time from start of processing to push completion within the branchfps: Actual branch throughput calculated by wall-clock statistical window
Project Structure Overview
rk3576_yolov8tortsp_demo
├── CMakeLists.txt
├── README.md
├── docs
├── include
│ ├── rk3576_demo
│ └── rk3576_yolo_demo
├── model
├── scripts
├── src
│ ├── ai # RKNN inference and pre/post-processing
│ ├── app # Application entry and orchestration
│ ├── branch # 3-branch output, OSD, PERF
│ ├── camera # V4L2 capture
│ ├── codec # MPP encode/decode
│ ├── common # Common types, logger, thread queues
│ ├── pipeline # V2 distribution and processing pipeline
│ ├── rga # Image scaling and conversion
│ ├── rtsp # Local RTSP publishing
│ ├── source # Input source abstraction and implementation
│ ├── utils
│ └── watermark # Time/FPS/Label rendering
└── third_partyDevelopment Guide
1. Extending Input Sources
- Unified interface at
include/rk3576_yolo_demo/source/i_source.hpp - Factory entry at
src/source/source_factory.cpp - New input sources should implement:
Open()Close()ReadPacket()Describe()
2. Extending Branch Outputs
- Branch implementation located at
src/branch/branch_output.cpp - Currently supports three geometry strategies:
stretchletterboxcenter_crop
- Geometric relations are calculated uniformly in
ComputeFrameTransform(), facilitating reuse for output scaling and AI box mapping
3. Extending AI Inference
- RKNN entry at
src/ai/yolov8_engine.cpp - Preprocessing prioritizes
RGA - Detection results enter the
DetectionFramecache, then are overlaid by the AI branch based onPTSmatching
4. Logging and Debugging
- Prints only startup summary by default
- Detailed runtime logs are enabled via
--detail-info - Logger is at
include/rk3576_yolo_demo/common/logger.hpp
Deployment Recommendations
- For production deployment, ensure proper permissions are set for
/dev/rga, video devices, and relevant runtime libraries - It is recommended to package models, runtime libraries, and configurations together with
install/ - RTSP input prioritizes
libavformat, automatically falling back toffmpeg pipein older environments - For long-term stable operation, it is recommended to use systemd or supervisor for daemon and restart management
Known Limitations
- Box drawing and watermark overlay for
camera_aistill consume some CPU overhead e2eis not the complete full-link latency; it only represents the time spent within the branchlocalvideois currently based on the compressed stream reading link, mainly used for offline validation and loop inference
Future Development Suggestions
- Continue to reduce OSD CPU overhead for
camera_ai, potentially introducing tile caching or more efficient blending paths - Add a true full-link
pipeline_e2emetric, distinct from the current branche2e - Improve playback pacing control in
localvideoscenarios to make it closer to real-time sources - Add more independent encoding parameter configuration capabilities for main/sub streams
- If more complex input types are needed, continue to extend the
sourceabstraction layer