Skip to content

rnshim/RapidRTMP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RapidRTMP

A high-performance RTMP-to-HLS streaming server written in Go, designed for low-latency live streaming with OBS Studio and other RTMP sources.

πŸš€ Features

  • RTMP Ingest: Accepts RTMP streams from OBS Studio, FFmpeg, and other sources
  • HLS Output: Converts streams to HLS (HTTP Live Streaming) for web playback
  • MPEG-TS Segments: Uses MPEG-TS format for maximum compatibility
  • Low Latency: Optimized for live streaming with minimal delay
  • Token Authentication: Secure stream publishing with token-based auth
  • Auto-Segmentation: Automatic HLS segment creation and playlist management
  • H.264 Support: Full H.264 video codec support with SPS/PPS handling
  • Web Player: Built-in test player for immediate stream testing

πŸ“‹ Requirements

  • Go 1.21+
  • FFmpeg (for segment muxing)
  • OBS Studio (for testing)

πŸ› οΈ Installation

1. Clone and Build

git clone https://github.com/yourusername/RapidRTMP.git
cd RapidRTMP
go mod tidy
go build -o rapidrtmp .

2. Install FFmpeg

macOS (Homebrew):

brew install ffmpeg

Ubuntu/Debian:

sudo apt update
sudo apt install ffmpeg

Windows: Download from FFmpeg.org

3. Run the Server

./rapidrtmp

The server will start on localhost:8080 by default.

🎬 Quick Start

1. Start the Server

./rapidrtmp

2. Get a Stream Token

curl -X POST http://localhost:8080/api/v1/publish \
  -H "Content-Type: application/json" \
  -d '{"streamKey":"mystream"}'

Response:

{
  "token": "abc123...",
  "streamKey": "mystream"
}

3. Configure OBS Studio

  1. Open OBS Studio
  2. Go to Settings β†’ Stream
  3. Set Service to "Custom"
  4. Set Server to: rtmp://localhost:1935/live
  5. Set Stream Key to: mystream?token=abc123...
  6. Click "Start Streaming"

4. Watch the Stream

Open test-player.html in your browser or visit:

http://localhost:8080/live/mystream/index.m3u8

πŸ”§ Configuration

Environment Variables

  • RTMP_PORT: RTMP server port (default: 1935)
  • HTTP_PORT: HTTP server port (default: 8080)
  • SEGMENT_DURATION: HLS segment duration in seconds (default: 1)
  • MAX_SEGMENTS: Maximum segments to keep (default: 10)

Stream Settings

The server automatically handles:

  • H.264 video codec with SPS/PPS extraction
  • MPEG-TS segment generation
  • HLS playlist management
  • Token-based authentication

πŸ“‘ API Endpoints

Authentication

POST /api/v1/publish

{
  "streamKey": "mystream"
}

Response:

{
  "token": "abc123...",
  "streamKey": "mystream"
}

HLS Playback

GET /live/{streamKey}/index.m3u8

  • Returns HLS playlist

GET /live/{streamKey}/segment_{n}.ts

  • Returns MPEG-TS segment

Health Check

GET /api/ping

  • Returns server status

πŸŽ₯ Supported Sources

OBS Studio

  • Encoder: x264 (recommended)
  • Rate Control: CBR or VBR
  • Keyframe Interval: 1-2 seconds
  • Profile: High
  • Tune: zerolatency (optional)

FFmpeg

ffmpeg -i input.mp4 -c:v libx264 -preset fast -f flv rtmp://localhost:1935/live/mystream?token=abc123...

Other RTMP Sources

Any RTMP-compatible streaming software that supports:

  • H.264 video codec
  • AAC audio codec (optional)
  • RTMP protocol

πŸ—οΈ Architecture

RTMP Source (OBS) β†’ RTMP Server β†’ H.264 Parser β†’ FFmpeg Muxer β†’ HLS Segments β†’ Web Player

Components

  • RTMP Server: Handles incoming RTMP connections
  • H.264 Parser: Extracts SPS/PPS and converts AVCC to Annex-B
  • FFmpeg Muxer: Creates MPEG-TS segments from video frames
  • HLS Segmenter: Manages segment lifecycle and playlist generation
  • HTTP Server: Serves HLS playlists and segments

πŸ” Troubleshooting

Common Issues

1. "Stream not found" error

  • Verify the stream key and token are correct
  • Check that OBS is actually streaming (not just connected)
  • Ensure the server is running

2. Video plays but no audio

  • Audio support is currently video-only
  • Audio frames are received but not muxed into segments
  • This is a known limitation

3. Time bar doesn't work

  • This is normal for live streams
  • Live content doesn't support seeking/scrubbing
  • The time bar shows current position only

4. Buffering issues

  • Check network connection
  • Verify FFmpeg is installed and working
  • Try reducing video quality in OBS

Debug Mode

Enable debug logging:

RUST_LOG=debug ./rapidrtmp

Check server logs:

tail -f /tmp/rapidrtmp.log

πŸš€ Performance

  • Latency: ~2-3 seconds end-to-end
  • CPU Usage: Low (thanks to FFmpeg's copy codec)
  • Memory: ~50MB base + ~10MB per active stream
  • Concurrent Streams: Tested up to 10 simultaneous streams

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

  • go-rtmp - RTMP protocol implementation
  • FFmpeg - Media processing
  • livego - Inspiration for MPEG-TS approach
  • HLS.js - Client-side HLS playback

πŸ“ž Support


Happy Streaming! 🎬

About

High-performance RTMP streaming server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •