Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
pub:http-live-streaming [2020/04/10 21:20] – Marco Kragepub:http-live-streaming [2020/04/10 22:21] (aktuell) – Marco Krage
Zeile 1: Zeile 1:
-====== Http Live Streaming (HLS) mit nginx ======+====== HTTP Live Streaming (HLS) mit nginx ======
  
-Stream URL: ''rtmp://NGINX-SERVER/livestream'' kkk +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. 
-Stream Key: frei wählbar z.B.: stream+Optional stellt er dieses auch direkt als Webserver bereit. Das Verzeichnis könnte aber von einem bestehenden Webservers ausgeliefert werden.
  
 ===== Installation ===== ===== Installation =====
  
   apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev   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   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   wget http://nginx.org/download/nginx-1.16.1.tar.gz
   tar -xf nginx-1.16.1.tar.gz   tar -xf nginx-1.16.1.tar.gz
   cd nginx-1.16.1   cd nginx-1.16.1
  
-nginx am besten in eigenes Verzeichnis kompilierern (über ''--prefix'')+nginx am besten in eigenes Verzeichnis kompilierern (über ''<nowiki>--prefix</nowiki>'')
   ./configure --prefix=/usr/local/nginx-rtmp --with-http_ssl_module --add-module=../nginx-rtmp-module   ./configure --prefix=/usr/local/nginx-rtmp --with-http_ssl_module --add-module=../nginx-rtmp-module
   make   make
   make install   make install
  
-Ordner erstellen in dem der Stream zur Auslieferung gespeichert wird. Konnte auch in einem bestehende documentroot eines anderen Webservers liegen. +Ordner erstellen in dem der Stream zur Auslieferung gespeichert wird.  
-Dann entfällt der http Teil der nginx Konfiguration  + 
-  mkdir -p /stream/hls/+  mkdir -p /var/www/hls/live 
 +  mkdir -p /var/www/videos 
 +  mkdir -p /var/www/html
  
  
 ===== nginx Konfiguration ===== ===== nginx Konfiguration =====
 <code> <code>
-worker_processes  auto;+#user nginx; 
 +worker_processes auto;
 events { events {
- worker_connections  1024;+  worker_connections 1024;
 } }
  
-# RTMP configuration+# RTMP Konfiguration
 rtmp { rtmp {
- server { +  server { 
- listen 1935; # Listen on standard RTMP port +  listen 1935; 
- chunk_size 4000;+  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 livestream { +    application vod { 
- live on; +      play /var/www/videos; 
- # Turn on HLS +    } 
- hls on; + }
- hls_path /stream/hls/; +
- hls_fragment 3; +
- hls_playlist_length 120; +
- # disable consuming the stream from nginx as rtmp +
- deny play all; +
- } +
- }+
 } }
  
-# HTTP configuration+# HTTP Konfiguration
 http { http {
- sendfile off; +  include   mime.types; 
- tcp_nopush on; +  default_type  application/octet-stream; 
- aio on; +  sendfile on; 
- directio 512; +  tcp_nopush on; 
- default_type application/octet-stream; +  keepalive_timeout 65; 
-  +  gzip on; 
- server { +  server { 
- listen 80; +    listen 80; 
- server_name localhost; +    server_name _;
-  +
- root /stream/; +
-  +
- location / { +
- #index  index.html index.htm; +
- autoindex on; +
- } +
-  +
- location /hls/ { +
- default_type application/octet-stream; +
-  +
- # Disable cache +
- add_header 'Cache-Control' 'no-cache';+
  
- # CORS setup +    autoindex on;
- add_header 'Access-Control-Allow-Origin' '*' always; +
- add_header 'Access-Control-Expose-Headers' 'Content-Length';+
  
- # allow CORS preflight requests +    location / { 
- if ($request_method = 'OPTIONS') { +      root /var/www/html; 
- add_header 'Access-Control-Allow-Origin' '*'; +      index index.html index.htm; 
- add_header 'Access-Control-Max-Age' 1728000; +    } 
- add_header 'Content-Type' 'text/plain charset=UTF-8'; +    # the http end point our web based users connect to see the live stream 
- add_header 'Content-Length' 0; +    location /live { 
- return 204; +      types { 
- } +        application/vnd.apple.mpegurl m3u8; 
- +      } 
- types { +      alias /var/www/hls/live; 
- application/dash+xml mpd; +      add_header Cache-Control no-cache; 
- application/vnd.apple.mpegurl m3u8; +    } 
- video/mp2t ts; +  }
- } +
- } +
- }+
 } }
 </code> </code>
 +
 +
 +===== Web Player =====
 +''/var/www/html/player.html''
 +<code>
 +<!DOCTYPE html>
 +<html>
 +<head>
 +<meta charset=utf-8 />
 +<title>videojs-contrib-hls embed</title>
 +<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
 +</head>
 +<body>
 +  <h1>Video.js Example Embed</h1>
 +
 +  <video-js id="my_video_1" class="vjs-default-skin" controls preload="auto" width="640" height="480">
 +    <source src="http://localhost/live/STREAM-KEY/index.m3u8" type="application/x-mpegURL">
 +  </video-js>
 +
 +  <script src="https://unpkg.com/video.js/dist/video.js"></script>
 +  <script src="https://unpkg.com/@videojs/http-streaming/dist/videojs-http-streaming.js"></script>
 +
 +  <script>
 +var player = videojs('my_video_1',{
 + liveui: true
 +});
 +  </script>
 +</body>
 +</html>
 +
 +</code>
 +
 +===== Streamen =====
 +STREAM-KEY ist ein freiwählbarer Name
 +
 +Stream Ziel ist: ''<nowiki>rtmp://server_ip:1935/live/STREAM-KEY</nowiki>''
 +
 +Die Playlist des Stream dann unter ''<nowiki>http://server_ip/live/STREAM-KEY/index.m3u8</nowiki>'' 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 ===== ===== OBS Studio =====
-Stream URL: <pre>rtmp://NGINX-SERVER/livestream</pre> kkk +Stream-URL: ''<nowiki>rtmp://server_ip:1935/live</nowiki>'' 
-Stream Key: frei wählbar z.B.: stream +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.+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
pub/http-live-streaming.1586546418.txt.gz · Zuletzt geändert: (Externe Bearbeitung)