RTMP vs HLS is usually a false choice, because the two do different jobs. RTMP is an ingest protocol: it carries one stream over a persistent TCP connection from an encoder such as OBS or a hardware box to your server. HLS is a delivery protocol: it publishes short media segments and playlists over ordinary HTTP, so any web server or CDN can serve thousands of viewers. Most live setups use both. Choose RTMP for the first mile unless you have a reason to use SRT or WebRTC, and choose HLS for viewers unless you need less than a few seconds of delay.

A typical live delivery path
  1. 1EncoderOBS or a hardware box pushes RTMP
  2. 2Originnginx-rtmp receives the stream on port 1935
  3. 3PackagerWrites HLS segments and playlists
  4. 4HTTP deliveryA web server or CDN serves viewers

What RTMP and HLS each do well

RTMP keeps a single connection open and pushes audio and video as they are encoded. That suits an encoder because there is no segment to wait for and almost every encoder supports it. It suits viewers badly. Browser playback depended on Flash, and Adobe stopped supporting Flash Player on 31 December 2020. Each viewer would also hold a stateful connection to your server, and generic HTTP caches cannot help.

HLS turns the live stream into files. A player downloads a playlist, fetches the segments it lists, and moves between bitrate variants as the connection changes. Those files can be cached at every layer, which is why it scales. The price is latency, since the player has to stay behind the newest published segment.

RTMPHLS
Normal roleEncoder to serverServer or CDN to viewer
TransportPersistent TCP connectionHTTP requests
Browser playbackNot without extra softwareNative in some browsers, otherwise via a JavaScript player using Media Source Extensions
CDN cachingNoYes, segments are files
Adaptive bitrateNo, one stream per connectionYes
CodecsH.264 and AAC classically; HEVC and AV1 via Enhanced RTMP where both ends support itH.264 in TS or fMP4; HEVC and AV1 must use fMP4 on Apple devices

Latency: what the specifications actually imply

Marketing pages quote latency without saying how it was measured. It is easier to start from the rules that set the floor.

RFC 8216, section 6.3.3 says a client should not choose a segment that starts less than three target durations from the end of the playlist. Apple's authoring specification says the target duration should be 6 seconds. Three times 6 gives 18 seconds before you add encoding, packaging, network time and player buffer. Cut the segment to 2 seconds and the same rule gives 6 seconds.

Low-Latency HLS changes the unit. Segments are published in parts, and the player follows the newest parts instead of whole segments. Apple's spec recommends a Part Target Duration of one second and requires PART-HOLD-BACK to be at least three times that, so a compliant configuration holds back at least 3 seconds. The HLS second edition draft has a looser protocol minimum of twice the part target, and says it should be at least three times. Apple also ties the part duration to round-trip time: it must be at least the P95 RTT to your clients, and should be three times that.

DeliveryProtocol delay from the rulesBasis
HLS, 6 s segments18 s or more3 × 6 s target duration
HLS, 2 s segments6 s or more3 × 2 s target duration
LL-HLS, 1 s parts3 s or more3 × 1 s part target
RTMP playbackNo figure in any specDepends on encoder and player buffers

These are floors, so measure the real number on your own path. One vendor write-up puts plain HLS at about 20 to 30 seconds behind live in practice, and LL-HLS at about 2 to 5. Those figures fit the arithmetic, but they are deployment reports and your encoder settings will move them.

When LL-HLS is worth the trouble

LL-HLS asks more of your origin than classic HLS. The server has to publish parts as they are produced, advertise upcoming parts with EXT-X-PRELOAD-HINT, and support blocking playlist reload, where it holds a request open until the next part exists. A directory of static files behind nginx will not do any of that on its own, so you need a packager that implements it, and a CDN path that does not defeat it if you use one.

Live sport, auctions and anything with viewer interaction can justify it. A lecture or a linear channel usually cannot, and 2 second classic HLS gets you most of the way with far less to debug. If you need sub-second delay for real conversation, HLS of any kind is the wrong tool and WebRTC is the usual answer.

An nginx RTMP-to-HLS example

The nginx-rtmp module is packaged as libnginx-mod-rtmp in Debian 13 and in the universe component of Ubuntu 24.04, at upstream version 1.2.2. The directives below come from the module's directive reference.

Install, and put segments on a tmpfs
sudo apt install nginx libnginx-mod-rtmp
sudo mkdir -p /var/www/hls
sudo mount -t tmpfs -o size=512m,uid=33,gid=33 tmpfs /var/www/hls

UID and GID 33 are www-data on stock Debian and Ubuntu, which is the user nginx runs as there. Add the mount to /etc/fstab so it survives a reboot. Then add this to the end of /etc/nginx/nginx.conf, at the top level and outside the http block:

/etc/nginx/nginx.conf, top level
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;

            allow publish 198.51.100.10;
            deny publish all;
            deny play all;

            hls on;
            hls_path /var/www/hls;
            hls_fragment 2s;
            hls_playlist_length 12s;
        }
    }
}

Replace 198.51.100.10 with your encoder's address. If the encoder has no fixed address, the on_publish directive can call an HTTP endpoint that checks the stream key.

Serve the output from a site in the http context:

HLS site in the http context
server {
    listen 80;
    server_name stream.example.com;

    location /hls/ {
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        root /var/www;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }
}

Test with sudo nginx -t, reload, and publish something:

Publish a test stream with ffmpeg
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 6000k -maxrate 6000k -bufsize 12000k \
  -g 60 -keyint_min 60 -sc_threshold 0 \
  -c:a aac -b:a 160k -ar 48000 \
  -f flv rtmp://stream.example.com/live/test

The playlist appears at http://stream.example.com/hls/test.m3u8. Add TLS before real use.

A few things bite people here. HLS segments must start with an IDR frame, so hls_fragment 2s means little if the encoder sends a keyframe every 8 seconds: segments can only be cut on keyframes and will come out long. The -g 60 above sets a 2 second interval at 30 fps, which also matches Apple's keyframe recommendation. Next, Cache-Control: no-cache on segments is the module's documented example, and it is fine for a single origin. Behind a CDN, you want a short cache time on playlists and a long one on segments.

The module also does not transcode. For a bitrate ladder, run ffmpeg from an exec directive, push each rendition to a second application, and use hls_variant with hls_nested on to generate the multivariant playlist; the directive reference has a complete example. exec runs with nginx's cleaned environment, so use an absolute path to ffmpeg or keep env PATH; in the config. If you run several workers, the README points to rtmp_auto_push for multi-worker live streaming.

Know what you are giving up: the documentation describes H.264 and AAC with TS fragments and says nothing about fMP4, HEVC or LL-HLS. If you need those, look at a media server with a current packager. MediaMTX, for example, lists RTMP, SRT and WebRTC for publishing and HLS among its outputs. Check its current documentation for the low-latency mode you need.

Bandwidth arithmetic for an HLS origin

Ingest is the cheap side: one 6 Mbps stream in. Egress is what you size for. The rungs below come from Apple's example ladder, and audio is ignored for simplicity.

VariantVideo bitrateOne viewer, one hour
640 x 360365 kbit/s0.16 GB
960 x 5402,000 kbit/s0.9 GB
1280 x 7203,000 kbit/s1.35 GB
1920 x 10806,000 kbit/s2.7 GB

Suppose your audience averages 4.5 Mbps across those variants. Then:

  • Peak port use for 1,000 concurrent viewers is 1,000 × 4.5 Mbps = 4.5 Gbps.
  • A 2 hour event at that level transfers 4.5 Gbps × 7,200 s = 32,400 Gbit, or 4.05 TB.
  • A 1 Gbps port run at 80% carries 800 / 4.5, about 177 viewers. A 10 Gbps port at 80% carries about 1,777.
  • A channel running all month with an average of 300 viewers moves 1.35 Gbps × 2,592,000 s = 3,499,200 Gbit, or about 437 TB.

Concurrency at peak sets your port size. Average transfer sets your bill on metered hosting. Those are different numbers, so calculate both. Our streaming servers and 10 Gbps servers bill by port, with fair-use terms that protect the wider network, so peak is the figure that matters there. On metered hosting, run the monthly sum first and compare it with what an unmetered port would cost you.

Request rate is the other number people forget. Each viewer fetches about one segment and one playlist per segment duration. With 1,000 viewers on 2 second segments, that is about 500 segment and 500 playlist requests per second. With 6 second segments it is about 167 of each.

4.5 Gbpspeak egress for 1,000 viewersat a 4.5 Mbps average
500segment requests per second1,000 viewers, 2 s segments
167segment requests per second1,000 viewers, 6 s segments

nginx handles either easily when serving from memory, but disk-backed origins and small caches feel the difference. For the transcoding side, the same ladder written to disk is 365 + 2,000 + 3,000 + 6,000 = 11.365 Mbps, so a window of 24 seconds needs about 34 MB per stream. The 512 MB tmpfs above leaves plenty of room for several channels, and it keeps constant segment churn off your NVMe drives.

Which to use

Audience geography also matters more than protocol tuning at this level: an origin near your viewers takes real time off every request, and Amsterdam is a sensible default for European and North Atlantic audiences.