Overview
MediaMTX provides the streaming infrastructure for the Joystick IoT platform, supporting multiple input and output protocols with low latency and high performance.Configuration
Docker Compose
Network mode
MediaMTX useshost network mode to access all network interfaces:
- Direct access to device streams
- Support for UDP protocols
- Simplified port management
- Lower network overhead
Configuration file
MediaMTX is configured viamediamtx.yml:
Supported protocols
Input protocols
MediaMTX can receive streams via:- RTSP - Real-Time Streaming Protocol
- RTMP - Real-Time Messaging Protocol
- WebRTC - Web Real-Time Communication
- SRT - Secure Reliable Transport
- UDP - User Datagram Protocol
- MPEG-TS - MPEG Transport Stream
Output protocols
Clients can consume streams via:- RTSP - For VLC and other media players
- WebRTC - For web browsers
- HLS - HTTP Live Streaming for browsers
- Low-Latency HLS - Reduced latency HLS
Stream paths
Streams are organized by path:Dynamic path creation
Switcher service creates paths via API:Path deletion
API endpoints
MediaMTX exposes a REST API on port 9997:List paths
Get path
Add path
Edit path
Delete path
Port usage
MediaMTX uses multiple ports:| Port | Protocol | Purpose |
|---|---|---|
| 8554 | RTSP | RTSP streaming |
| 1935 | RTMP | RTMP streaming |
| 8888 | HTTP | HLS streaming |
| 8889 | WebSocket | WebRTC signaling |
| 8189 | UDP | WebRTC data |
| 9997 | HTTP | API server |
Streaming examples
RTSP client
View stream in VLC:WebRTC in browser
HLS in browser
Device configuration
Devices stream to MediaMTX using various methods:RTSP push
Device pushes RTSP stream:RTSP pull
MediaMTX pulls from device:WebRTC
Device streams via WebRTC:Performance tuning
Buffer settings
Adjust buffer sizes for latency vs stability:Protocol selection
Choose protocol based on requirements:- WebRTC - Lowest latency (< 1s)
- Low-Latency HLS - Low latency (2-4s), wide compatibility
- HLS - Higher latency (6-10s), maximum compatibility
- RTSP - Low latency, requires player
Resource limits
Monitoring
Logs
MediaMTX provides detailed logs:Metrics
API provides metrics:Integration with Switcher
Switcher manages MediaMTX paths:- Device mode set to “live”
- Switcher calls MediaMTX API to add path
- Path configured with device stream source
- Clients can access stream
Slot switching
When slot switches:- PocketBase updates device
activeSlot - Hook detects change
- Stream source updated to new slot host
- MediaMTX reconnects to new source
Troubleshooting
Stream not available
- Verify path exists in MediaMTX
- Check device is streaming to correct URL
- Test device stream directly
- Review MediaMTX logs
High latency
- Use WebRTC or Low-Latency HLS
- Reduce buffer sizes
- Check network bandwidth
- Optimize device encoding settings
Connection errors
- Verify network connectivity
- Check firewall rules
- Ensure ports are not blocked
- Test with different protocol
Performance issues
- Reduce concurrent streams
- Lower resolution/bitrate
- Increase resource limits
- Use hardware encoding on device
Security considerations
Authentication
Enable authentication for streams:Encryption
Use encrypted protocols:- RTSPS (RTSP over TLS)
- RTMPS (RTMP over TLS)
- WebRTC (built-in encryption)
Network isolation
Restrict access via firewall:Advanced features
Recording
Record streams to disk:Multiple sources
Failover between sources:Transcoding
Transcode streams (requires FFmpeg):Best practices
Use appropriate protocol
Match protocol to use case:- Live monitoring: WebRTC
- Recording: RTSP
- Web playback: HLS
- Low bandwidth: SRT
Monitor resources
Track CPU, memory, and bandwidth:Plan for scale
Consider stream count and quality:- 1080p: ~4-8 Mbps per stream
- 720p: ~2-4 Mbps per stream
- 480p: ~1-2 Mbps per stream