RTMP Streaming Guide
Learn how to push RTMP streams to Lunar Stream using various encoders.
RTMP Flow Overview
RTMP URL Format
rtmp://{host}/live/{streamKey}?pushToken={pushToken}Example:
rtmp://ingest.lunarstream.kozow.com/live/ee04affe2a669854052102fe762bd715?pushToken=eyJhbGciOiJSUzI1NiIs...OBS Studio Configuration
Step 1: Open Stream Settings
- Open OBS Studio
- Go to Settings → Stream
Step 2: Configure Custom Server
| Setting | Value |
|---|---|
| Service | Custom... |
| Server | rtmp://ingest.lunarstream.kozow.com/live |
| Stream Key | {streamKey}?pushToken={pushToken} |
TIP
Use the streamKeyWithToken value from the Create Livestream API response directly.
Step 3: Recommended Output Settings
Go to Settings → Output → Streaming:
| Setting | Recommended Value |
|---|---|
| Video Bitrate | 2500-6000 Kbps |
| Encoder | x264 or NVENC |
| Audio Bitrate | 128-320 Kbps |
| Keyframe Interval | 2 seconds |
Step 4: Video Settings
Go to Settings → Video:
| Setting | Recommended Value |
|---|---|
| Base Resolution | 1920x1080 |
| Output Resolution | 1920x1080 or 1280x720 |
| FPS | 30 or 60 |
Supported Input Formats
Lunar Stream accepts the following input specifications:
| Parameter | Supported Values |
|---|---|
| Video Codec | H.264 (AVC) |
| Audio Codec | AAC |
| Resolution | Up to 1920x1080 |
| Frame Rate | Up to 60 fps |
| Video Bitrate | Up to 8 Mbps |
| Audio Bitrate | Up to 320 Kbps |
Important
Always use H.264 video codec and AAC audio codec for best compatibility.
FFmpeg Command
For automated streaming or testing:
bash
ffmpeg -re -i input.mp4 \
-c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
-c:a aac -b:a 128k -ar 44100 \
-f flv "rtmp://ingest.lunarstream.kozow.com/live/YOUR_STREAM_KEY?pushToken=YOUR_PUSH_TOKEN"FFmpeg Options Explained
| Option | Description |
|---|---|
-re | Read input at native frame rate |
-c:v libx264 | Use H.264 video codec |
-preset veryfast | Encoding speed/quality tradeoff |
-b:v 3000k | Video bitrate |
-c:a aac | Use AAC audio codec |
-f flv | Output format for RTMP |
Mobile SDK Integration
React Native Example
javascript
import { LiveStreamView } from 'react-native-live-stream';
const BroadcasterScreen = ({ streamConfig }) => {
const rtmpUrl = `${streamConfig.rtmpServer}/${streamConfig.streamKeyWithToken}`;
return (
<LiveStreamView
style={{ flex: 1 }}
rtmpUrl={rtmpUrl}
videoSettings={{
width: 1280,
height: 720,
bitrate: 3000000,
fps: 30
}}
audioSettings={{
bitrate: 128000,
sampleRate: 44100
}}
onStreamStateChanged={(state) => console.log('State:', state)}
onError={(error) => console.error('Error:', error)}
/>
);
};Push Token Management
Token Lifecycle
Token Expiration
Push tokens expire after 1 hour by default. When expired:
- Stream status changes to
TOKEN_EXPIRED - Broadcaster is disconnected
- You need to generate a new token
Best Practice
Monitor token expiration and refresh tokens before they expire to ensure uninterrupted streaming.
Generate New Push Token
bash
curl -X POST https://api.xxxxxx.xxx/api/v1/livestream/generate-push-token \
-H "ls-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"projectId": "YOUR_PROJECT_ID",
"streamKey": "ee04affe2a669854052102fe762bd715",
"expiresIn": 7200
}'Response:
json
{
"data": {
"livestreamId": "d926da37-56ae-4212-83bc-f20d9de64d6b",
"pushToken": "eyJhbGciOiJSUzI1NiIs...",
"streamKey": "ee04affe2a669854052102fe762bd715",
"expiresAt": "2026-01-12T20:12:59.000Z",
"rtmpUrl": "rtmp://ingest.lunarstream.kozow.com/live/ee04affe2a669854052102fe762bd715?pushToken=eyJhbGci...",
"streamKeyWithToken": "ee04affe2a669854052102fe762bd715?pushToken=eyJhbGci..."
}
}Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| Connection refused | Invalid RTMP URL | Verify URL format and server address |
| Authentication failed | Invalid or expired token | Generate a new push token |
| Stream drops frequently | Network instability | Reduce bitrate, check connection |
| Poor video quality | Low bitrate setting | Increase video bitrate |
| Audio out of sync | Incorrect encoder settings | Set keyframe interval to 2 seconds |
Next Steps
- HLS Playback - Integrate video player for viewers
- Multi-CDN Setup - Configure CDN failover
- API Reference - Complete livestream API docs