Skip to content

Instantly share code, notes, and snippets.

@caffeinum
Last active November 24, 2020 13:56
Show Gist options
  • Save caffeinum/6edf80e3c7820f66c269cfa4c4a0982e to your computer and use it in GitHub Desktop.
Save caffeinum/6edf80e3c7820f66c269cfa4c4a0982e to your computer and use it in GitHub Desktop.
RTMP Server Basic setup

Setup restream with NGINX

  1. Install FFMPEG
  2. Setup rtmp application for restream
  3. Test
rtmp {
server {
listen 1935;
chunk_size 4096;
application studio107 {
live on;
}
application mirror {
live on;
}
application live {
live on;
record off;
}
# TODO: other applications: restream, repack
# Dynamic Youtube
application a-youtube {
live on;
exec_push ffmpeg \
-i rtmp://localhost/$app/$name \
-c copy \
-f flv rtmp://a.rtmp.youtube.com/live2/$name;
}
application x-youtube {
live on;
exec_push ffmpeg \
-i rtmp://localhost/$app/$name \
-c copy \
-f flv rtmp://x.rtmp.youtube.com/live2/$name;
}
}
}
  1. После создания нового сервера установить nginx и пакет для rtmp
# from https://askubuntu.com/questions/1031953/nginx-rtmp-module-on-ubuntu-18-04#1034600
sudo apt update
sudo apt install nginx-core nginx-common libnginx-mod-rtmp
sudo service nginx restart
  1. Добавить в конец /etc/nginx/nginx.conf:
include /etc/nginx/rtmp.conf;
  1. Создать файл /etc/nginx/rtmp.conf
sudo vim /etc/nginx/rtmp.conf

с содержимым из rtmp.conf (ниже на странице)

  1. Настроить HTTPS
# update snap (optional)
sudo snap install core; sudo snap refresh core

# install certbot
sudo snap install --beta --classic certbot
sudo snap set certbot trust-plugin-with-root=ok

# issue certs
sudo certbot --nginx

Как настроить статистику по стримам на /stat

  1. Настроить папку в сайте default

  2. Настроить rtmp_stylesheet директиву

  3. Test at /stat location

  4. Скачать stat.xsl из репозитория: https://raw.githubusercontent.com/arut/nginx-rtmp-module/master/stat.xsl

  5. Положить в корень сайта, например:

# sites/default
      root /var/www/static;
      
      # RTMP
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root /var/www/static;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment