RTSP Streaming
Hardware-encode the camera feed on the RK3588 and push it out over RTSP. Supports local USB/MIPI cameras and test sources.
Overall block diagram
Camera (V4L2) → MPP hardware encode (H.264) → RTSP server → network → VLC/ffplay/client1. Install dependencies
sudo apt update
sudo apt install -y \
gstreamer1.0-rockchip1 \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-rtsp \
python3-gst-1.0 \
gir1.2-gst-rtsp-server-1.0 \
libgstrtspserver-1.0-0 \
ffmpegVerify after installation:
gst-inspect-1.0 mpph264enc 2>&1 | grep -E "Long-name|Version"
# Expected: Rockchip Mpp H264 Encoder / Version 1.14.4
python3 -c "import gi; gi.require_version('GstRtspServer','1.0'); \
from gi.repository import GstRtspServer; print('OK')"
# Expected: OK2. Quick test (test source)
2.1 Use the bundled example
The system ships with a complete RTSP streaming example:
cd /home/linaro/rtsp-push
python3 src_camera.py 8554 /live/srcOnce the service starts it prints:
[src_camera] ready at rtsp://127.0.0.1:8554/live/srcQuick test output:


2.2 Client connection test
Connect from a PC:
# Get the board IP
hostname -I | awk '{print $1}'
# Run on the PC (assuming the board IP is 192.168.49.138)
ffplay -rtsp_transport tcp rtsp://192.168.49.138:8554/live/src
# Or use VLC media player
# Ctrl+N → Network Stream → rtsp://192.168.49.138:8554/live/srcOn-board local test:
ffplay -rtsp_transport tcp rtsp://127.0.0.1:8554/live/src3. Camera configuration
3.1 Local camera (USB)
List available cameras:
ls -la /dev/video*Modify src_camera.py to use a local camera:
# Change videotestsrc to v4l2src
factory.set_launch(
'( v4l2src device=/dev/video11 io-mode=mmap ! '
' video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! '
' mpph264enc bps=2000000 gop=30 profile=high ! '
' h264parse ! rtph264pay name=pay0 pt=96 )'
)3.2 IP camera
RTSP streams from IP cameras can be ingested directly:
# Start IP-camera RTSP streaming
cd /home/linaro/rtsp-push
python3 src_camera.py 8554 /live/camera "rtsp://admin:password@192.168.49.38:554/Streaming/Channels/101"View from the PC:
ffplay -rtsp_transport tcp rtsp://192.168.49.138:8554/live/cameraIP-camera streaming output:

Common IP-camera RTSP URL formats:
# Hikvision
rtsp://admin:password@192.168.1.100:554/Streaming/Channels/101 # main stream
rtsp://admin:password@192.168.1.100:554/Streaming/Channels/102 # sub stream
# Dahua
rtsp://admin:password@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0
# Generic formats
rtsp://192.168.1.100:554/live/main
rtsp://192.168.1.100:554/stream14. Choosing a test pattern
Change the test pattern:
factory.set_launch(
'( videotestsrc is-live=true pattern=smpte ! ' # changed to smpte
' video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! '
' mpph264enc bps=2000000 gop=30 profile=high ! '
' h264parse ! rtph264pay name=pay0 pt=96 )'
)5. Encoder parameter tuning
5.1 Common mpph264enc parameters
| Parameter | Meaning | Recommended | Notes |
|---|---|---|---|
bps | Bitrate (bps) | 2000000~4000000 | 2-4 Mbps, balances quality and bandwidth |
gop | I-frame interval | 30/60 | Smaller values mean lower latency |
profile | H264 profile | high/main/baseline | high = best quality, baseline = lowest latency |
bps-max/bps-min | Bitrate bounds | 0 | 0 means auto-adjust |
5.2 Low-latency configuration
factory.set_launch(
'( videotestsrc is-live=true pattern=smpte ! '
' video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! '
' mpph264enc bps=2000000 gop=15 profile=baseline ! ' # lower latency
' h264parse ! rtph264pay config-interval=1 pt=96 )'
)
factory.set_latency(0) # minimum latency6. Complete RTSP service script
Recommended full script, based on real testing:
#!/usr/bin/env python3
"""RTSP 服务:支持测试源、本地摄像头
使用方法:
python3 src_camera.py [端口] [路径] [输入源]
示例:
python3 src_camera.py # 默认测试图案(SMPTE彩条)
python3 src_camera.py 8554 /live/src # 指定端口和路径
python3 src_camera.py 8554 /cam1 /dev/video11 # 本地摄像头
发布地址:rtsp://0.0.0.0:8554/live/src
"""
import sys
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GLib
Gst.init(None)
# 参数配置
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8554
path = sys.argv[2] if len(sys.argv) > 2 else '/live/src'
input_source = sys.argv[3] if len(sys.argv) > 3 else None
server = GstRtspServer.RTSPServer.new()
server.set_service(str(port))
factory = GstRtspServer.RTSPMediaFactory.new()
if input_source and input_source.startswith('/dev/video'):
# 本地摄像头模式
factory.set_launch(
f'( v4l2src device={input_source} io-mode=mmap ! '
f' video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! '
f' mpph264enc bps=2000000 gop=30 profile=high ! '
f' h264parse ! rtph264pay name=pay0 pt=96 )'
)
print(f'[本地摄像头模式] 设备: {input_source}')
else:
# 测试图案模式
pattern = input_source if input_source else 'smpte'
factory.set_launch(
f'( videotestsrc is-live=true pattern={pattern} ! '
f' video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! '
f' mpph264enc bps=2000000 gop=30 profile=high ! '
f' h264parse ! rtph264pay name=pay0 pt=96 )'
)
print(f'[测试图案模式] 图案: {pattern}')
factory.set_shared(True)
factory.set_latency(0)
server.get_mount_points().add_factory(path, factory)
server.attach(None)
print(f'📹 RTSP 服务启动中...')
print(f'📹 地址: rtsp://0.0.0.0:{port}{path}')
print(f'📹 按Ctrl+C停止服务')
GLib.MainLoop().run()7. Client connection methods
7.1 ffplay (recommended)
# Play in real time
ffplay -rtsp_transport tcp -fflags nobuffer -flags low_delay \
rtsp://<board_ip>:8554/live/src
# Inspect stream info
ffprobe -v error -show_streams rtsp://<board_ip>:8554/live/src7.2 VLC media player
- Open VLC media player
- Media → Open Network Stream (Ctrl+N)
- Enter:
rtsp://<board_ip>:8554/live/src - Click play
7.3 GStreamer
gst-launch-1.0 rtspsrc location=rtsp://<board_ip>:8554/live/src \
latency=0 protocols=tcp ! \
rtph264depay ! h264parse ! decodebin ! fakesink7.4 Mobile apps
- VLC mobile: supports RTSP playback
- iVMS: professional surveillance software
- ffplay mobile: mobile version of ffplay
8. Performance parameters
8.1 Resolution and frame-rate configurations
| Scenario | Resolution | FPS | Bitrate | Use case |
|---|---|---|---|---|
| HD surveillance | 1920×1080 | 25/30 | 4-6Mbps | Main surveillance areas |
| SD surveillance | 1280×720 | 25/30 | 2-3Mbps | General surveillance |
| Low latency | 640×480 | 30/60 | 1-2Mbps | Real-time-critical |
| Network-limited | 720×576 | 15/25 | 512K-1Mbps | Low-bandwidth environment |
8.2 Latency optimization
| Item | Default | Low-latency | Effect |
|---|---|---|---|
| GOP | 30 | 15/10 | Latency reduced by 30-50% |
| Profile | high | baseline | Better compatibility |
| Latency | default | 0 | Eliminates buffering latency |
| Protocol | TCP | UDP | Lower transport latency |
9. Troubleshooting
9.1 Connection problems
Symptom: the PC cannot connect to the RTSP stream
Checks:
# 1. Check service status
ps aux | grep src_camera
netstat -tuln | grep 8554
# 2. Check the board IP
hostname -I
# 3. Test local connectivity
ffprobe rtsp://127.0.0.1:8554/live/src
# 4. Test network connectivity
ping <board_ip>
telnet <board_ip> 85549.2 Picture-quality problems
Symptom: stuttering, blurring, or corruption in the picture
Solutions:
- Adjust the bitrate:
bps=3000000 - Adjust the GOP:
gop=15 - Adjust the profile:
profile=main - Check network bandwidth
9.3 Encoding problems
Symptom: streaming fails to start
Check dependencies:
gst-inspect-1.0 mpph264enc
gst-inspect-1.0 rtph264pay
gst-inspect-1.0 h264parse10. Advanced usage
10.1 Multiple streams
Streaming from multiple cameras simultaneously is supported:
# Start multiple service instances
python3 src_camera.py 8554 /cam1 /dev/video11 &
python3 src_camera.py 8555 /cam2 /dev/video12 &10.2 Recording to storage
Stream and record at the same time:
ffmpeg -rtsp_transport tcp -i rtsp://127.0.0.1:8554/live/src \
-c copy -f segment -segment_time 60 -segment_format mp4 \
-strftime 1 /tmp/recording_%Y%m%d_%H%M%S.mp411. Deployment recommendations
11.1 Production configuration
# 生产环境推荐参数
factory.set_launch(
'( videotestsrc is-live=true ! '
' video/x-raw,format=NV12,width=1920,height=1080,framerate=25/1 ! '
' mpph264enc bps=4000000 gop=25 profile=high ! '
' h264parse ! rtph264pay config-interval=1 pt=96 )'
)11.2 System service configuration
Create a systemd service:
# /etc/systemd/system/rtsp-push.service
[Unit]
Description=RTSP Push Service
After=network.target
[Service]
Type=simple
User=linaro
WorkingDirectory=/home/linaro/rtsp-push
ExecStart=/usr/bin/python3 src_camera.py 8554 /live/src
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable start on boot:
sudo systemctl enable rtsp-push
sudo systemctl start rtsp-push12. Performance benchmarks
Tested on the RK3588 + RK1828 platform:
| Resolution | FPS | Encoding | CPU usage | Memory | Bandwidth |
|---|---|---|---|---|---|
| 1920×1080 | 30fps | H.264 hardware encode | 15-20% | 150MB | 4-6Mbps |
| 1280×720 | 30fps | H.264 hardware encode | 8-12% | 100MB | 2-3Mbps |
| 640×480 | 30fps | H.264 hardware encode | 5-8% | 80MB | 1-2Mbps |
Related docs
- RTSP + AI Analysis — RTSP + RKNN inference + detection-box overlay
- YOLOv5 Object Detection — YOLOv5s detection example
- MPP Overview — multimedia framework
- VPU Codec — hardware encode/decode
