Gernot Walzl


Nginx is a web server with interesting modules to extend its functionality.
The Real Time Messaging Protocol (RTMP) is used to send video (& audio) streams
over the internet. Nginx offers a RTMP media streaming module.

Many action cams and drones support sending their video streams via RTMP.

This page is focused on the configuration of RTMP on Nginx.



sudo apt install nginx libnginx-mod-rtmp

RTMP configuration example

# For rtmp, worker_processes needs to be 1, which is the default.
#worker_processes auto;

rtmp {
    server {
        listen 1935;

        # Who is allowed to connect can be handled with
        # HTTP response status codes.

        application live {
            live on;

            hls on;
            hls_path /tmp/hls;

            dash on;
            dash_path /tmp/dash;

http {

    server {
        listen 8080;

        location /hls {
            types {
                application/ m3u8;
            root /tmp;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;

        location /dash {
            types {
                application/dash+xml mpd;
            root /tmp;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;


Reload the configuration:

sudo systemctl reload nginx

Publishing a stream with FFmpeg

The following command creates a stream named stream in
the configured application live:

ffmpeg -re -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f flv rtmp://

Receive the stream from the RTMP server and show it on screen:

ffplay -fflags nobuffer rtmp://

HTTP Live Streaming (HLS)

<!DOCTYPE html>
<html lang="en">
<title>HTTP Live Streaming</title>
<script src=""></script>
<video id="video" controls></video>
  var video = document.getElementById('video');
  var videoSrc = '';
  if (Hls.isSupported()) {
    var hls = new Hls();
    hls.on(Hls.Events.MEDIA_ATTACHED, function () {
      video.muted = true;;
  } else if (video.canPlayType('application/')) {
    video.src = videoSrc;

HTTP Live Streaming (HLS) adds a delay / latency of approx. 10 to 60 seconds
to the live input stream.

CONTENT.html source 2023-09-16 4.4 KB