Understanding RTSP Video Streaming
Real Time Streaming Protocol (RTSP) is the industry standard for IP camera video delivery. This application note covers optimization techniques for achieving sub-200ms end-to-end latency in demanding surveillance applications.
Latency Components
Total streaming latency comprises multiple components:
| Component | Typical Range | Optimization Potential |
|---|---|---|
| Sensor Readout | 16-33ms | Limited (frame rate dependent) |
| ISP Processing | 5-20ms | Medium (pipeline tuning) |
| Encoding | 30-100ms | High (GOP, bitrate) |
| Network | 1-50ms | Medium (protocol, QoS) |
| Decoding | 20-50ms | High (player configuration) |
| Display | 8-16ms | Limited (display hardware) |
Encoder Optimization
GOP Structure
Group of Pictures (GOP) configuration significantly impacts latency:
Low-latency GOP configuration:
- GOP Size: 30-60 frames (1-2 seconds)
- B-frames: Disabled (removes reordering delay)
- Reference frames: 1-2 maximum
- Intra-refresh: Enable for smoother bitrate
Standard settings:
- I-frame interval: 30 (1 second at 30fps)
- P-frame only mode: Enabled
- Bitrate mode: CBR for consistent latencyRate Control
Bitrate configuration affects both latency and quality:
- CBR (Constant Bitrate): Consistent latency, predictable bandwidth
- VBR (Variable Bitrate): Better quality, variable latency
- CVBR: Balanced approach with bitrate ceiling
- CRF: Quality-focused, not recommended for low-latency
For lowest latency, use CBR with a bitrate ceiling of 4-8 Mbps for 1080p. Higher bitrates increase encoding time without proportional quality improvement.
Network Configuration
Transport Selection
RTSP supports multiple transport modes:
| Transport | Latency | Reliability | Use Case |
|---|---|---|---|
| RTP/UDP | Lowest | Lower | Local network, real-time |
| RTP/TCP (interleaved) | Medium | Higher | Firewall traversal |
| HTTP tunneling | Highest | Highest | Restrictive networks |
Buffer Management
Proper buffer sizing balances latency against packet loss resilience:
Recommended buffer settings:
- Jitter buffer: 50-100ms (adaptive)
- Socket receive buffer: 256KB-1MB
- Reordering window: 50ms maximum
- Timeout: 5 seconds for stream recovery
VLC low-latency configuration:
--network-caching=100
--live-caching=100
--clock-jitter=0Server-Side Optimization
Camera-side configurations for low-latency streaming:
- Enable zero-copy video pipelines
- Use hardware timestamping
- Minimize pre-roll delay
- Configure RTP packetization: MTU-sized packets
- Enable RTCP for synchronization feedback
Client-Side Optimization
Decoder and player configuration:
FFmpeg low-latency receive:
ffmpeg -fflags nobuffer -flags low_delay \
-rtsp_transport udp \
-i rtsp://camera/stream \
-vcodec copy -an output.mp4
GStreamer pipeline:
gst-launch-1.0 rtspsrc location=rtsp://camera/stream \
latency=0 buffer-mode=auto \
! rtph264depay ! h264parse \
! avdec_h264 ! autovideosink sync=falseMeasuring Latency
Accurate latency measurement requires proper methodology:
- Use synchronized clocks (NTP or PTP) on camera and display
- Display real-time clock in camera field of view
- Photograph display showing both times
- Calculate glass-to-glass latency
- Repeat measurements for statistical significance
Troubleshooting Common Issues
| Symptom | Likely Cause | Solution |
|---|---|---|
| High jitter | Network congestion | QoS prioritization |
| Increasing delay | Buffer accumulation | Reduce buffer sizes |
| Frame drops | Insufficient bandwidth | Reduce bitrate/resolution |
| Artifacts | Packet loss | Switch to TCP or add FEC |
Conclusion
Achieving low-latency RTSP streaming requires optimization across the entire pipeline. By carefully configuring encoder, network, and player parameters, latencies under 200ms are achievable for most surveillance applications.