====== HTTP Live Streaming (HLS) mit nginx ====== Wir bauen hier einen speziellen nginx, mit einem rtmp Modul, welcher einen rtmp Stream empangen kann und daraus eine HLS Playlist und die Videos Chunks in einem Web Root ablegt. Optional stellt er dieses auch direkt als Webserver bereit. Das Verzeichnis könnte aber von einem bestehenden Webservers ausgeliefert werden. ===== Installation ===== apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev RTMP Modul clonen git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git Aktuellen Build von nginx laden und entpacken wget http://nginx.org/download/nginx-1.16.1.tar.gz tar -xf nginx-1.16.1.tar.gz cd nginx-1.16.1 nginx am besten in eigenes Verzeichnis kompilierern (über ''--prefix'') ./configure --prefix=/usr/local/nginx-rtmp --with-http_ssl_module --add-module=../nginx-rtmp-module make make install Ordner erstellen in dem der Stream zur Auslieferung gespeichert wird. mkdir -p /var/www/hls/live mkdir -p /var/www/videos mkdir -p /var/www/html ===== nginx Konfiguration ===== #user nginx; worker_processes auto; events { worker_connections 1024; } # RTMP Konfiguration rtmp { server { listen 1935; chunk_size 4096; ping 30s; notify_method get; allow play all; # rmtp handler our clients connect to for live streaming, it runs on port 1935. It converts the stream to HLS and stores it on our server application live { live on; hls on; hls_path /var/www/hls/live; hls_nested on; # create a new folder for each stream record_notify on; record_path /var/www/videos; record all; record_unique on; } application vod { play /var/www/videos; } } } # HTTP Konfiguration http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; server { listen 80; server_name _; autoindex on; location / { root /var/www/html; index index.html index.htm; } # the http end point our web based users connect to see the live stream location /live { types { application/vnd.apple.mpegurl m3u8; } alias /var/www/hls/live; add_header Cache-Control no-cache; } } } ===== Web Player ===== ''/var/www/html/player.html'' videojs-contrib-hls embed

Video.js Example Embed

===== Streamen ===== STREAM-KEY ist ein freiwählbarer Name Stream Ziel ist: ''rtmp://server_ip:1935/live/STREAM-KEY'' Die Playlist des Stream dann unter ''http://server_ip/live/STREAM-KEY/index.m3u8'' aufzurufen. Entweder über z.B. über VLC oder den Webplayer ==== ffmpeg ==== ffmpeg -i /path/to/video -c:v h264 -c:a aac -strict -2 -f flv rtmp://server_ip:1935/live/STREAM-KEY ===== OBS Studio ===== Stream-URL: ''rtmp://server_ip:1935/live'' Stream-Key: frei wählbar z.B.: stream Nach dem Stream Key richtet sich auch die playlist und clip Namen welche dann über den Webserver aufrufbar sind. Quellen: https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/ https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/ https://dev.to/samuyi/how-to-setup-nginx-for-hls-video-streaming-on-centos-7-3jb8