Add RTSP deployment infrastructure and documentation

- Add .gitignore to exclude build artifacts and mediamtx binary
- Add deploy-rtsp.sh script for automated MediaMTX setup
- Add mediamtx.yml configuration with detailed comments
- Update README with RTSP usage instructions and architecture
- Document ISP processing pipeline and performance metrics
This commit is contained in:
yuquanjun 2026-04-19 17:25:37 +08:00
parent c32fd1b233
commit 96cf5579bd
4 changed files with 256 additions and 0 deletions

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# Kernel module artifacts
*.o
*.ko
*.mod.c
*.mod.o
*.cmd
modules.order
Module.symvers
# Build artifacts
build/
.*.tmp_versions/
*.symtypes
# RTSP server binary (too large, downloaded at deploy time)
mediamtx
mediamtx.tar.gz
# Temporary files
*.swp
*.swo
*~
.DS_Store

View File

@ -153,8 +153,106 @@ ffmpeg -f rawvideo -pix_fmt bayer_bggr16le -s 1920x1080 -r 30 \
GPL v2
## RTSP 网络流服务器
本驱动集成 libcamera 支持,可通过 MediaMTX 实现 RTSP 网络直播。
### 快速启动
```bash
# SSH 连接到 Zero 2W
ssh root@<board-ip>
# 下载并启动 RTSP 服务器
cd /root
./deploy-rtsp.sh start
# 查看日志
cat /var/log/mediamtx.log
# 停止服务
./deploy-rtsp.sh stop
```
### 在 Windows/macOS/Linux 上播放
#### VLC 方式
```bash
vlc "rtsp://<board-ip>:8554/cam"
```
#### ffplay 方式
```bash
ffplay "rtsp://<board-ip>:8554/cam"
```
#### Python + OpenCV 方式
```python
import cv2
cap = cv2.VideoCapture("rtsp://<board-ip>:8554/cam")
while True:
ret, frame = cap.read()
if ret:
cv2.imshow("SC235HAI", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
```
### 配置说明
编辑 `mediamtx.yml` 调整以下参数:
| 参数 | 默认值 | 说明 |
|------|--------|------|
| rpiCameraWidth | 1920 | 分辨率宽 |
| rpiCameraHeight | 1080 | 分辨率高 |
| rpiCameraFPS | 30 | 帧率 |
| rpiCameraCodec | hardwareH264 | 编码器硬件H264 |
| rpiCameraIDRPeriod | 60 | I 帧间隔 |
| rtspAddress | :8554 | RTSP 监听端口 |
### 架构
```
SC235HAI 传感器
↓ MIPI CSI-2 (2-lane)
Unicam (CSI 接收器) → ISP (Raspberry Pi V3D ISP)
↓ YUV420
libcamera (0.6.0) → rpicam-apps
↓ H.264 编码(硬件)
MediaMTX → RTSP/HLS/WebRTC/SRT
VLC / ffplay / 流媒体播放器
```
### ISP 处理流程
驱动通过 libcamera 实现的 ISP 处理:
1. **Raw Bayer** (1920x1080-SBGGR10) 从传感器捕获
2. **Demosaicing** - Bayer to RGB 转换
3. **Color Space** - RGB to YUV420 转换
4. **ISP Pipeline** - 曝光、增益、白平衡、去噪等
5. **H.264 编码** - 硬件编码器压缩
6. **网络传输** - RTSP 协议发送
### 性能指标
- **帧率**: 30 fps
- **分辨率**: 1920x1080
- **编码**: H.264 (硬件加速)
- **码率**: 自适应 (~2-4 Mbps)
- **延迟**: ~500ms
## 更新日志
### 2026-04-19
- 添加 V4L2 完整 control 接口EXPOSURE/GAIN/VBLANK/HBLANK/PIXEL_RATE/LINK_FREQ
- 支持 libcamera v0.6.0 ISP 处理
- 集成 MediaMTX RTSP 服务器
- 实现网络视频直播
### 2026-04-14
- 初始版本发布
- 支持 1920x1080@30fps RAW10 输出

84
deploy-rtsp.sh Normal file
View File

@ -0,0 +1,84 @@
#!/bin/bash
# deploy-rtsp.sh - SC235HAI RTSP Streaming Server Deployment
# Usage: ./deploy-rtsp.sh [start|stop|restart]
set -e
RTSP_DIR="/root"
MEDIAMTX_VERSION="v1.9.3"
MEDIAMTX_URL="https://github.com/bluenviron/mediamtx/releases/download/${MEDIAMTX_VERSION}/mediamtx_${MEDIAMTX_VERSION}_linux_arm64v8.tar.gz"
MEDIAMTX_BIN="${RTSP_DIR}/mediamtx"
MEDIAMTX_CONFIG="${RTSP_DIR}/mediamtx.yml"
RTSP_PORT=8554
download_mediamtx() {
if [ ! -f "$MEDIAMTX_BIN" ]; then
echo "[INFO] Downloading mediamtx ${MEDIAMTX_VERSION}..."
cd "$RTSP_DIR"
curl -L -o mediamtx.tar.gz "$MEDIAMTX_URL"
tar -xzf mediamtx.tar.gz mediamtx mediamtx.yml
rm -f mediamtx.tar.gz
chmod +x "$MEDIAMTX_BIN"
echo "[OK] mediamtx installed at $MEDIAMTX_BIN"
else
echo "[OK] mediamtx already installed"
fi
}
start_rtsp() {
download_mediamtx
# Kill any existing instance
pkill -f "mediamtx" 2>/dev/null || true
sleep 1
# Copy config from script directory if present
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "${SCRIPT_DIR}/mediamtx.yml" ]; then
cp "${SCRIPT_DIR}/mediamtx.yml" "$MEDIAMTX_CONFIG"
echo "[OK] Using mediamtx.yml from script directory"
fi
# Start mediamtx
cd "$RTSP_DIR"
nohup "$MEDIAMTX_BIN" "$MEDIAMTX_CONFIG" > /var/log/mediamtx.log 2>&1 &
PID=$!
sleep 3
# Verify it's running
if kill -0 $PID 2>/dev/null; then
echo "[OK] MediaMTX started (PID: $PID)"
echo "[OK] RTSP stream available at: rtsp://$(hostname -I | awk '{print $1}'):${RTSP_PORT}/cam"
else
echo "[ERROR] Failed to start MediaMTX"
cat /var/log/mediamtx.log
return 1
fi
}
stop_rtsp() {
pkill -f "mediamtx" 2>/dev/null || true
echo "[OK] MediaMTX stopped"
}
restart_rtsp() {
stop_rtsp
sleep 1
start_rtsp
}
case "${1:-start}" in
start)
start_rtsp
;;
stop)
stop_rtsp
;;
restart)
restart_rtsp
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

51
mediamtx.yml Normal file
View File

@ -0,0 +1,51 @@
# MediaMTX configuration for SC235HAI RTSP streaming
# https://github.com/bluenviron/mediamtx
logLevel: info
# RTSP server settings
rtspAddress: :8554
rtspReadTimeout: 10s
rtspWriteTimeout: 10s
# UDP/RTP settings
rtpAddress: :8000
rtcpAddress: :8001
# HLS (HTTP Live Streaming) - for web browsers
hlsAddress: :8888
hlsVariant: main
hlsSegmentCount: 3
hlsSegmentDuration: 1s
# WebRTC settings
webRTCAddress: :8889
webRTCICEUDPMuxAddress: :8189
# SRT (Secure Reliable Transport)
srtAddress: :8890
# Paths configuration
paths:
# Main camera stream: rtsp://[host]:8554/cam
cam:
source: rpiCamera
# Camera settings (must match SC235HAI resolution)
rpiCameraWidth: 1920
rpiCameraHeight: 1080
rpiCameraFPS: 30
# Video codec and encoding
rpiCameraCodec: hardwareH264 # Use hardware H.264 encoder
rpiCameraIDRPeriod: 60 # IDR frame interval (keyframe every 60 frames)
# Camera tuning and processing
rpiCameraTuningFile: "/usr/share/libcamera/ipa/rpi/vc4/ov5647.json"
rpiCameraExposure: normal
rpiCameraAWB: auto
rpiCameraDenoise: "off"
rpiCameraMetering: centre
# Output bitrate (0 = auto)
# rpiCameraBitrate: 2500000 # Uncomment to limit bitrate to 2.5 Mbps