# rtsp-server **Repository Path**: xhoobin/rtsp-server ## Basic Information - **Project Name**: rtsp-server - **Description**: 海康摄像头AI推理后,零延迟的 AI 视频流 RTSP 服务器 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 60 - **Created**: 2026-04-25 - **Last Updated**: 2026-04-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RTSP Server - Ultra-Low Latency AI Video Streaming [中文](README.md) | **English** > **Say goodbye to lag!** Stream your AI detection results with near-zero latency! ![Demo](docs/rtsp服务器0延迟效果.gif) A standalone RTSP server module based on live555, supporting NVENC hardware encoding for ultra-low latency video streaming. **Supports auto-registration to ZLMediaKit for WebRTC playback.** ## Features - **NVENC Hardware Encoding**: Uses NVIDIA GPU for H.264 encoding with <5ms latency - **Ultra-Low Latency**: Single frame buffer queue for minimal delay - **Auto ZLM Registration**: Automatically registers to ZLMediaKit on startup - **Command Line Arguments**: Flexible configuration for video source, port, ZLM settings - **Auto Reconnect**: Automatically reconnects when video source disconnects - **Standalone Module**: Can be used independently from the main project ## Requirements - Windows 10/11 - Visual Studio 2022 (Build Tools) - CMake 3.15+ - vcpkg with packages: `opencv4`, `glog`, `ffmpeg` - NVIDIA GPU with NVENC support (optional, falls back to software encoding) - ZLMediaKit (for WebRTC forwarding) ## Quick Start ### 1. Build ```batch cd rtsp_server build.bat ``` ### 2. Run ```batch cd build\Release RTSPServer.exe rtsp://admin:password@192.168.1.64:554/stream --zlm-secret YOUR_ZLM_SECRET ``` ### 3. Play Open WebRTC player in browser, or use VLC to play `rtsp://localhost:8554/ai_stream` ## Command Line Arguments ``` RTSPServer.exe [options] Options: --port RTSP server port (default: 8554) --stream Stream name (default: ai_stream) --zlm-host ZLM host (default: localhost) --zlm-port ZLM HTTP port (default: 8088) --zlm-secret ZLM API secret (required for auto-register) --no-zlm Disable auto-register to ZLM --no-display Disable OpenCV window display --help Show help message ``` ## Usage Examples ### Basic Usage (Auto-register to ZLM) ```batch RTSPServer.exe rtsp://admin:password@192.168.1.64:554/Streaming/Channels/102 --zlm-secret hXSs7WNDSONHwG7vdhWL2qmZMgnDL2D6 ``` ### Custom Port and Stream Name ```batch RTSPServer.exe rtsp://admin:password@192.168.1.64:554/stream --port 8555 --stream camera1 --zlm-secret abc123 ``` ### Connect to Remote ZLM Server ```batch RTSPServer.exe rtsp://admin:password@192.168.1.64:554/stream --zlm-host 192.168.1.100 --zlm-port 8088 --zlm-secret abc123 ``` ### RTSP Server Only (No ZLM) ```batch RTSPServer.exe rtsp://admin:password@192.168.1.64:554/stream --no-zlm ``` ### Background Mode (No Display) ```batch RTSPServer.exe rtsp://admin:password@192.168.1.64:554/stream --zlm-secret abc123 --no-display ``` ## Workflow ``` ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ Camera/Source │────>│ RTSPServer.exe │────>│ ZLMediaKit │────>│ Browser/Player │ │ (RTSP/File) │ │ (NVENC Encode) │ │ (WebRTC Relay) │ │ (WebRTC Play) │ └─────────────────┘ └──────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ Auto Register │ WebRTC │ addStreamProxy │ ▼ ▼ rtsp://localhost:8554 http://localhost:8088 ``` ### 📸 Demo: Original Stream vs AI Stream ![Zero Latency Demo](docs/rtsp服务器0延迟效果.gif) ![Original vs AI Stream](docs/原始视频流与AI视频流对比.png) > Left: Original camera feed. Right: AI detection output. Nearly synchronized! ## Playback ### WebRTC (Recommended, Lowest Latency) After startup, the program outputs the WebRTC URL: ``` [INFO] WebRTC URL: http://localhost:8088/index/api/webrtc?app=live&stream=ai_stream ``` ### VLC Player ``` Media -> Open Network Stream -> rtsp://localhost:8554/ai_stream ``` ### FFplay (Low Latency Mode) ```batch ffplay -fflags nobuffer -flags low_delay rtsp://localhost:8554/ai_stream ``` ## Performance | Metric | Value | |--------|-------| | Encoding Latency | <5ms (NVENC) | | End-to-End Latency | 50-100ms (WebRTC) | | Max Resolution | 4K | | Default Bitrate | 4Mbps | | GOP Size | 30 frames | ## Troubleshooting ### ZLM Registration Failed 1. Ensure ZLMediaKit is running 2. Check `--zlm-secret` is correct 3. Check `--zlm-port` is correct (default 8088) ### Video Source Not Found 1. Verify RTSP URL is correct 2. Ensure camera is online and accessible 3. Test RTSP URL with VLC first ### NVENC Not Available The program automatically falls back to x264 software encoding. ### CMake Build Failed Use English-only paths. CMake 4.x has issues with non-ASCII paths. ## Directory Structure ``` rtsp_server/ ├── RTSPServer.h # Header file ├── RTSPServer.cpp # Implementation ├── example_main.cpp # Main program with CLI support ├── CMakeLists.txt # CMake build file ├── build.bat # Build script ├── README.md # Chinese documentation (default) ├── README_EN.md # English documentation ├── 3rdparty/ │ └── live555/ # live555 library source └── build/ └── Release/ ├── RTSPServer.exe # Executable └── *.dll # Required DLLs ``` ## API Reference (For Development) ```cpp class RTSPServerWrapper { public: bool init(int port, const std::string& streamName, int width, int height, int fps); bool start(); void stop(); bool pushFrame(const cv::Mat& frame); std::string getRtspUrl() const; bool isRunning() const; }; ``` ## License - **live555** - LGPL - **FFmpeg** - LGPL/GPL - **OpenCV** - Apache 2.0 --- **If this project helps you, please give it a ⭐ Star!**