Overview
RTMP (Real-Time Messaging Protocol) is a widely-supported protocol for live streaming. It’s the de facto standard for streaming from encoders like OBS, vMix, and Wirecast to media servers.
Key Benefits
Wide compatibility : Supported by virtually all streaming software
Stable : Mature protocol with proven reliability
Simple setup : Easy to configure in most encoders
Low CPU usage : Efficient encoding and transmission
Codec support : H.264 video, AAC/MP3 audio
Publishing Streams
OBS Studio
OBS Settings
FFmpeg Command
Python (OpenCV)
Node.js (node-media-server)
Settings → Stream :
Service : Custom
Server : rtmp://your-server.com/WebRTCAppEE
Stream Key : stream123
Settings → Output :
Output Mode : Advanced
Encoder : x264
Rate Control : CBR
Bitrate : 2500 Kbps
Keyframe Interval : 2
Preset : veryfast
Profile : main
Tune : zerolatency
Settings → Video :
Base Resolution : 1920x1080
Output Resolution : 1280x720
FPS : 30
Mobile Apps
iOS (HaishinKit)
Android (rtmp-rtsp-stream-client-java)
import HaishinKit
import AVFoundation
class RTMPPublisher {
let rtmpConnection = RTMPConnection ()
let rtmpStream: RTMPStream
init () {
rtmpStream = RTMPStream ( connection : rtmpConnection)
// Video settings
rtmpStream. videoSettings = [
. width : 1280 ,
. height : 720 ,
. bitrate : 2500 * 1000 ,
. profileLevel : kVTProfileLevel_H264_Main_AutoLevel,
. maxKeyFrameIntervalDuration : 2
]
// Audio settings
rtmpStream. audioSettings = [
. bitrate : 128 * 1000 ,
. sampleRate : 44100
]
}
func startPublishing () {
rtmpStream. attachAudio (AVCaptureDevice. default ( for : . audio ))
rtmpStream. attachCamera (DeviceUtil. device ( withPosition : . back ))
rtmpConnection. connect ( "rtmp://your-server.com/WebRTCAppEE" )
rtmpStream. publish ( "stream123" )
}
func stopPublishing () {
rtmpStream. close ()
rtmpConnection. close ()
}
}
Playing Streams
Direct RTMP Playback
FFplay
Video.js (RTMP)
VLC Python
Flash Player (Legacy)
# Play RTMP stream
ffplay rtmp://your-server.com/WebRTCAppEE/stream123
# Play with low latency
ffplay -fflags nobuffer -flags low_delay \
rtmp://your-server.com/WebRTCAppEE/stream123
RTMP playback in browsers requires Flash, which is deprecated. For browser playback, convert RTMP to HLS, DASH, or WebRTC using Ant Media Server’s transcoding capabilities.
Configuration Options
Server Configuration
# RTMP settings in application.properties
# Enable/disable RTMP
rtmp.enabled =true
# RTMP port (default: 1935)
rtmp.port =1935
# RTMP ingestion buffer time (ms)
settings.rtmpIngestBufferTimeMs =0
# Accept undefined streams
settings.acceptOnlyStreamsInDataStore =false
# Recording settings
settings.mp4MuxingEnabled =true
settings.hlsMuxingEnabled =true
# Adaptive bitrate
settings.adaptiveResolutionsEnabled =true
Encoder Settings Recommendations
For Low Latency (3-5 seconds):
Keyframe Interval : 1-2 seconds
Bitrate Mode : CBR
Profile : baseline or main
Tune : zerolatency
Buffer Size : 2x bitrate
For High Quality:
Keyframe Interval : 2-4 seconds
Bitrate Mode : VBR or CBR
Profile : high
Preset : medium or slow
Two-Pass Encoding : enabled
For Low Bandwidth:
Resolution : 854x480 or lower
Bitrate : 500-1000 Kbps
Keyframe Interval : 2 seconds
Preset : veryfast or ultrafast
Profile : baseline
Stream Authentication
// Enable token-based security
settings . acceptOnlyStreamsInDataStore = true
// Publish URL with token
rtmp : //your-server.com/WebRTCAppEE/stream123?token=YOUR_TOKEN
Generate publish tokens via REST API:
curl -X PUT "https://your-server.com:5443/WebRTCAppEE/rest/v2/broadcasts/stream123" \
-H "Content-Type: application/json" \
-d '{
"name": "My Stream",
"type": "liveStream",
"streamId": "stream123"
}'
Troubleshooting
Connection Issues
Cannot connect to RTMP server:
# Test RTMP port
telnet your-server.com 1935
# Check firewall
sudo ufw status
sudo ufw allow 1935/tcp
# Verify Ant Media Server is running
sudo systemctl status antmedia
Stream not appearing:
# List active streams
curl http://your-server.com:5080/WebRTCAppEE/rest/v2/broadcasts/list/0/10
# Check server logs
tail -f /usr/local/antmedia/log/antmedia-error.log
Quality Issues
Pixelation/artifacts:
Increase bitrate
Use slower encoding preset
Check network bandwidth
Reduce resolution
Buffering/stuttering:
Decrease bitrate
Use faster preset (ultrafast/veryfast)
Check upload bandwidth
Reduce keyframe interval
High latency:
Set keyframe interval to 1-2 seconds
Enable tune=zerolatency in encoder
Use CBR bitrate mode
Reduce server-side buffer: rtmpIngestBufferTimeMs=0
Debug Commands
# Monitor RTMP connections
netstat -an | grep 1935
# Check stream info with FFprobe
ffprobe -v quiet -print_format json -show_streams \
rtmp://your-server.com/WebRTCAppEE/stream123
# Test stream with FFmpeg
ffmpeg -v verbose -i rtmp://your-server.com/WebRTCAppEE/stream123 \
-t 10 -f null -
# Monitor bandwidth
iftop -i eth0
Best Practices
Production Recommendations
Use consistent keyframe intervals : Set to 2 seconds for optimal HLS/DASH compatibility
Enable CBR for live streaming : Provides predictable bandwidth usage
Set appropriate buffer sizes : bufsize = 2 * bitrate
Use authentication : Enable token-based security for production
Monitor stream health : Use webhooks or REST API for monitoring
Configure reconnection : Set up automatic reconnection in encoders
Quality Presets
1080p High Quality
720p Standard
480p Low Bandwidth
ffmpeg -i input.mp4 \
-c:v libx264 -preset medium -b:v 4500k -maxrate 4500k -bufsize 9000k \
-vf scale=1920:1080 -g 60 -keyint_min 60 \
-c:a aac -b:a 192k -ar 48000 \
-f flv rtmp://your-server.com/WebRTCAppEE/stream123
Ant Media Server automatically converts RTMP to HLS, DASH, and WebRTC. Enable in configuration:
settings.hlsMuxingEnabled =true
settings.dashMuxingEnabled =true
settings.webRTCEnabled =true
Access converted streams:
HLS : https://your-server.com:5443/WebRTCAppEE/streams/stream123.m3u8
DASH : https://your-server.com:5443/WebRTCAppEE/streams/stream123.mpd
WebRTC : Use WebRTC player with streamId: stream123