RTMP Streaming Guide
Learn how to push RTMP streams to Lunar Stream using various encoders.
RTMP URL Format
rtmp://{host}/live/{streamKey}?pushToken={pushToken}Example:
rtmp://stream.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://stream.lunarstream.kozow.com/live |
| Stream Key | {streamKey}?pushToken={pushToken} |
Use the streamKeyWithParams value from the Create Livestream API response.
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 |
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://stream.lunarstream.kozow.com/live/ee04affe2a669854052102fe762bd715?pushToken=eyJhbGci..."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.rmtpServer}/${streamConfig.streamKeyWithParams}`;
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 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
Generate New Push Token
bash
curl -X POST https://api.lunarstream.kozow.com/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://stream.lunarstream.kozow.com/live/ee04affe2a669854052102fe762bd715?pushToken=eyJhbGci...",
"streamKeyWithToken": "ee04affe2a669854052102fe762bd715?pushToken=eyJhbGci..."
}
}Troubleshooting
| Issue | Solution |
|---|---|
| Connection refused | Check RTMP URL and port (1935) |
| Authentication failed | Verify push token is valid and not expired |
| Stream drops | Check network stability, reduce bitrate |
| Poor quality | Increase bitrate, check encoder settings |