Adaptive bitrate in an RTMP-to-HLS pipeline helps a stream stay stable as network conditions change. When a viewer’s bandwidth drops, the playback can switch to a lower-quality rendition without stopping the video.

When the connection improves, it can shift back to a higher-quality version just as smoothly. This balance matters because live streams often move across unpredictable networks. Without an adaptive bitrate, even a small fluctuation can cause buffering, delays, or complete interruptions.

Prerequisites

A properly configured streaming environment with RTMP input and tools to convert and package the stream into HLS is essential to enable adaptive bitrate delivery.

1. Prepare an RTMP-compatible encoder or camera, such as OBS Studio, hardware encoders, or IP cameras.

code
# Example: Start streaming from OBS or a hardware encoder supporting RTMP
code
rtmp://your_streaming_server/live/stream_key

2. Choose a streaming server or software that can transcode RTMP input and output HLS streams. Popular options include FFmpeg, NGINX with RTMP module, and cloud services.

code
# FFmpeg installation example for Ubuntu
code
sudo apt-get install ffmpeg
code
# NGINX with RTMP module installation example
code
sudo apt-get install nginx libnginx-mod-rtmp

3. Configure the server to accept RTMP input and handle HLS segment generation and playlist creation.

code
# Example NGINX RTMP configuration snippet for HLS
code
rtmp {
code
server {
code
listen 1935;
code
chunk_size 4096;
code
application live {
code
live on;
code
record off;
code
hls on;
code
hls_path /tmp/hls;
code
hls_fragment 4s;
code
hls_playlist_length 30s;
code
}
code
}
code
}
code
http {
code
server {
code
listen 8080;
code
location /hls {
code
types {
code
application/vnd.apple.mpegurl m3u8;
code
video/mp2t ts;
code
}
code
root /tmp;
code
add_header Cache-Control no-cache;
code
}
code
}
code
}

4. Ensure a reliable network connection for smooth live streaming.

Why Convert RTMP to HLS for Adaptive Bitrate?

RTMP handles live video input well, but cannot adjust quality during playback, whereas HLS supports multiple quality levels, so viewers always get the best possible stream for their network.

Step 1: Start with RTMP as the ingest protocol from encoders since it is widely supported.

Step 2: Recognize that RTMP does not support adaptive bitrate natively.

Step 3: Convert RTMP stream to HLS, which supports multiple bitrates.

Step 4: Use HLS’s chunked streaming and playlist system to enable players to switch stream quality dynamically based on network conditions.

How Adaptive Bitrate Works in RTMP-to-HLS Conversion

The original RTMP stream is processed into several video qualities, and the player switches between them smoothly depending on the viewer’s bandwidth and device capability.

Step 1: Transcode the single RTMP stream into multiple renditions at different bitrates and resolutions.

Step 2: Segment each rendition into small chunks (commonly 6 to 10 seconds).

Step 3: Generate playlists for each rendition and a master playlist indexing all bitrates.

Step 4: During playback, the player selects the best bitrate for the current bandwidth and switches streams seamlessly if conditions change.

Setting Up ABR Streams from RTMP

To enable adaptive streaming, the RTMP feed must be transcoded into multiple bitrates, segmented into small chunks, and organized into playlists that guide the player’s quality selection.

Step 1: Ingest RTMP stream into a media server or transcoding tool.

Step 2: Configure transcoding for multiple simultaneous output streams with varying bitrates.

Step 3: Segment each output into HLS-compliant chunks and generate individual playlists.

Step 4: Create a master HLS playlist referencing all renditions.

Step 5: Deliver HLS segments and playlists via HTTP web server or CDN for scalable distribution.

code
# Example FFmpeg command for basic RTMP to HLS
code
ffmpeg -i rtmp://localhost/live/stream \
code
-c:v libx264 -c:a aac -f hls \
code
-hls_time 6 -hls_list_size 6 -hls_flags delete_segments \
code
/var/www/html/hls/output.m3u8
code
code
# Example FFmpeg command for Adaptive Bitrate HLS
code
ffmpeg -re -i rtmp://localhost/live/stream \
code
-map v:0 -map a:0 -c:v:0 libx264 -b:v:0 5000k -s:v:0 1920x1080 \
code
-map v:0 -map a:0 -c:v:1 libx264 -b:v:1 2500k -s:v:1 1280x720 \
code
-map v:0 -map a:0 -c:v:2 libx264 -b:v:2 1200k -s:v:2 854x480 \
code
-c:a aac -f hls -hls_time 6 -hls_list_size 6 -hls_flags independent_segments \
code
-var_stream_map "v:0,a:0 v:1,a:0 v:2,a:0" \
code
-master_pl_name master.m3u8 \
code
/var/www/html/hls/stream_%v.m3u8

Best Practices for Bitrate Ladder and Encoding

Selecting a range of video bitrates spaced effectively and using compatible codecs ensures smooth switching, consistent visual quality, and reliable playback across devices and networks.

Step 1: Choose bitrate steps spaced 1.5x to 2x apart (e.g., 1500k, 3000k, 6000k) to allow smooth quality switching.

Step 2: Match resolution to bitrate to maintain consistent visual quality.

Step 3: Use widely supported codecs like H.264 for video, AAC for audio.

Step 4: Pick segment lengths that balance latency and overhead (e.g., 6-10 seconds).

Step 5: Test playback across devices and network conditions.

code
# Example bitrate ladder settings
code
# 5000 kbps at 1080p
code
# 2500 kbps at 720p
code
# 1200 kbps at 480p