Deploying SRS
Introduction
SRS (Simple Realtime Server) is an open-source, high-performance real-time video streaming server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, and MPEG-DASH. Designed for live streaming applications, SRS handles everything from low-latency interactive streaming to large-scale content delivery.
Built with C++ for performance and reliability, SRS has been battle-tested by major streaming platforms handling millions of concurrent viewers. The server provides a comprehensive solution for live video infrastructure, from ingesting streams to delivering them to viewers across any platform.
Key highlights of SRS:
- Multiple Protocols: RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH
- Ultra-Low Latency: Sub-second latency with WebRTC
- High Concurrency: Handle thousands of simultaneous streams
- Cluster Support: Scale horizontally with edge clusters
- Stream Recording: DVR functionality for live streams
- Transcoding: FFmpeg integration for codec conversion
- HTTP Callbacks: Webhooks for stream events
- Authentication: Token-based stream authentication
- Statistics API: Real-time metrics and monitoring
- Console UI: Built-in web management interface
- Docker Native: First-class container support
This guide walks through deploying SRS on Klutch.sh using Docker, configuring streaming protocols, and setting up live video infrastructure.
Why Deploy SRS on Klutch.sh
Deploying SRS on Klutch.sh provides several advantages for live streaming:
Simplified Deployment: Klutch.sh automatically builds your SRS configuration without complex server setup.
Persistent Storage: Attach persistent volumes for stream recordings and configuration.
HTTPS by Default: Secure access to the management console and HTTP-based protocols.
Scalable Resources: Allocate CPU and memory based on stream count and viewer load.
GitHub Integration: Store configuration in version control for reproducible deployments.
Always-On Streaming: 24/7 availability ensures your streaming infrastructure is always ready.
Prerequisites
Before deploying SRS on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your SRS configuration
- Basic familiarity with Docker and streaming concepts
- Understanding of RTMP/HLS/WebRTC protocols
- (Optional) A custom domain for your streaming server
Deploying SRS on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 8080
Create Your Repository
Create a new GitHub repository for your SRS deployment. Add a Dockerfile:
FROM ossrs/srs:5
COPY srs.conf /usr/local/srs/conf/docker.conf
EXPOSE 1935 8080 1985 8000/udp
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD curl -f http://localhost:1985/api/v1/versions || exit 1
CMD ["./objs/srs", "-c", "conf/docker.conf"]Create srs.conf:
listen 1935;max_connections 1000;daemon off;srs_log_tank console;
http_api { enabled on; listen 1985;}
http_server { enabled on; listen 8080; dir ./objs/nginx/html;}
rtc_server { enabled on; listen 8000; candidate *;}
vhost __defaultVhost__ { hls { enabled on; hls_fragment 10; hls_window 60; hls_path ./objs/nginx/html; hls_m3u8_file [app]/[stream].m3u8; hls_ts_file [app]/[stream]-[seq].ts; }
http_remux { enabled on; mount [vhost]/[app]/[stream].flv; }
rtc { enabled on; rtmp_to_rtc on; rtc_to_rtmp on; }}Push to GitHub
Commit and push your files to your GitHub repository.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project.
Create a New App
Within your project, create a new app. Connect your GitHub account and select your repository.
Configure HTTP Traffic
For the web console and HLS streaming:
Note: RTMP (1935) and WebRTC (8000/udp) may require additional configuration or separate deployments.
Attach Persistent Volumes
Add volumes for recordings and HLS segments:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/usr/local/srs/objs/nginx/html | 50 GB | HLS segments and recordings |
/usr/local/srs/conf | 100 MB | Configuration files |
Deploy Your Application
Click Deploy to start the build process.
Access SRS Console
Once deployed, access the SRS console at https://your-app.klutch.sh/console/.
Streaming Protocols
RTMP Ingest
Push streams using RTMP:
rtmp://your-server:1935/live/stream_keyCompatible encoders:
- OBS Studio
- FFmpeg
- Wirecast
- vMix
HLS Playback
Access HLS streams:
https://your-app.klutch.sh/live/stream_key.m3u8HTTP-FLV
Low-latency HTTP streaming:
https://your-app.klutch.sh/live/stream_key.flvWebRTC
Ultra-low latency playback:
// WebRTC player connectionconst pc = new RTCPeerConnection();// Connect to SRS WebRTC endpointConfiguration Options
Stream Authentication
Add token-based authentication:
vhost __defaultVhost__ { http_hooks { enabled on; on_publish http://your-auth-server/api/auth; on_unpublish http://your-auth-server/api/disconnect; }}DVR Recording
Enable stream recording:
vhost __defaultVhost__ { dvr { enabled on; dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].flv; dvr_plan session; dvr_duration 30; dvr_wait_keyframe on; }}Transcoding
Configure FFmpeg transcoding:
vhost __defaultVhost__ { transcode { enabled on; ffmpeg ./objs/ffmpeg/bin/ffmpeg; engine sd { enabled on; vcodec libx264; vbitrate 800; vfps 25; vwidth 640; vheight 360; acodec libfdk_aac; abitrate 64; output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_sd; } }}Multi-Bitrate Streaming
Adaptive Bitrate
Configure multiple quality levels:
vhost __defaultVhost__ { hls { enabled on; hls_fragment 2; hls_window 10; }}Stream Variants
Create multiple encodings:
- Original: 1080p @ 4000kbps
- High: 720p @ 2000kbps
- Medium: 480p @ 1000kbps
- Low: 360p @ 500kbps
API Usage
Statistics API
Query stream statistics:
GET https://your-app.klutch.sh:1985/api/v1/streams/Response includes:
- Active streams
- Viewer counts
- Bitrate information
- Connection details
Stream Control
Manage streams via API:
# Disconnect a streamDELETE /api/v1/clients/{id}
# Get stream infoGET /api/v1/streams/{id}Cluster Deployment
Edge Servers
Scale with edge distribution:
vhost edge.example.com { cluster { mode remote; origin origin.example.com; }}Origin Protection
Protect origin servers:
- Edge servers handle viewer connections
- Origin handles ingest only
- Reduces origin load
Monitoring
Built-in Console
Access metrics at /console/:
- Stream list
- Client connections
- Server resources
- Real-time graphs
Prometheus Metrics
Export metrics for monitoring:
http_api { enabled on; listen 1985;}Webhook Notifications
Receive stream events:
http_hooks { enabled on; on_connect http://your-server/hooks/connect; on_close http://your-server/hooks/close; on_publish http://your-server/hooks/publish; on_unpublish http://your-server/hooks/unpublish; on_play http://your-server/hooks/play; on_stop http://your-server/hooks/stop;}Security
Stream Keys
Require authentication:
- Generate unique stream keys
- Validate on publish hooks
- Expire after use (optional)
HTTPS Playback
Secure stream delivery:
- HLS over HTTPS
- HTTP-FLV over HTTPS
- WebRTC with DTLS
IP Restrictions
Limit access by IP:
security { enabled on; deny publish all; allow publish 192.168.0.0/16;}Best Practices
Performance Optimization
- Tune GOP size for latency vs quality
- Use appropriate HLS segment lengths
- Enable kernel optimizations
- Monitor resource usage
Reliability
- Configure reconnection handling
- Implement health checks
- Use redundant origins
- Plan for failover
Troubleshooting
Stream Not Publishing
- Check RTMP port accessibility
- Verify stream key
- Review authentication hooks
- Check encoder settings
Playback Issues
- Confirm HLS segments generating
- Check CORS configuration
- Verify player compatibility
- Review network connectivity
High Latency
- Reduce HLS segment length
- Consider HTTP-FLV or WebRTC
- Check transcoding delays
- Optimize network path
Additional Resources
- SRS Official Website
- SRS Documentation
- SRS GitHub Repository
- SRS Wiki
- Klutch.sh Persistent Volumes
- Klutch.sh Deployments
Conclusion
Deploying SRS on Klutch.sh provides a powerful foundation for live video streaming. With support for multiple protocols, low-latency options, and extensive configuration capabilities, SRS handles everything from small personal streams to large-scale broadcasting. Combined with Klutch.sh’s reliable hosting and persistent storage, you get a professional streaming infrastructure that’s ready for production use.