fooser 7 anni fa
parent
commit
7be07d934f
5 ha cambiato i file con 121 aggiunte e 0 eliminazioni
  1. 29 0
      Dockerfile
  2. 1 0
      conf/clear.sh
  3. 2 0
      conf/crontab
  4. 1 0
      conf/hls.sh
  5. 88 0
      conf/nginx.conf

+ 29 - 0
Dockerfile

@@ -0,0 +1,29 @@
+FROM debian:stretch
+RUN apt update
+RUN apt install -y git autoconf automake build-essential libgpac-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev wget yasm libdvdnav4 libdvdread4 libvpx. libx264. libpcre3 libpcre3-dev libssl-dev unzip nano htop cron
+ENV TZ=Europe/Madrid
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
+RUN mkdir -p /builder/ffmpeg /hls /save /var/log/nginx/ && chmod -R 777 /hls
+COPY ./conf/clear.sh /hls
+RUN chmod +x /hls/clear.sh
+COPY ./conf/crontab /etc/cron.d/clear-task
+RUN chmod 0644 /etc/cron.d/clear-task
+RUN crontab /etc/cron.d/clear-task
+RUN wget https://ffmpeg.org/releases/ffmpeg-4.1.3.tar.bz2 -O /builder/ffmpeg.tar.bz2
+RUN wget https://nginx.org/download/nginx-1.14.2.tar.gz -O /builder/nginx.tar.gz
+RUN wget https://github.com/arut/nginx-rtmp-module/archive/master.zip -O /builder/rtmp_nginx.zip
+RUN cd /builder && tar -zxvf nginx.tar.gz && unzip rtmp_nginx.zip && ls
+RUN cd /builder/nginx-1.14.2/ && ./configure --add-module=../nginx-rtmp-module-master
+RUN cd /builder/nginx-1.14.2/ && make -j12
+RUN cd /builder/nginx-1.14.2/ && make install
+RUN tar xjf /builder/ffmpeg.tar.bz2 -C /builder/ffmpeg --strip-components=1
+WORKDIR /builder/ffmpeg
+RUN ./configure --enable-nonfree --enable-libx264 --enable-gpl
+RUN make -j12; make install
+COPY ./conf/nginx.conf /usr/local/nginx/conf
+COPY ./conf/hls.sh /opt/
+RUN chmod +x /opt/hls.sh
+WORKDIR /usr/local/nginx/sbin
+CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
+RUN cron
+RUN crontab -l

+ 1 - 0
conf/clear.sh

@@ -0,0 +1 @@
+cd "$(dirname "$0")" && find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c 'cd "$0" && rm $(find . -name "*.ts" -printf "%T+\t%p\n" | sort -d | head -n-13 | awk "{ print $2 }") 2> /dev/null' {} \;

+ 2 - 0
conf/crontab

@@ -0,0 +1,2 @@
+*/2 * * * * sh /hls/clear.sh
+

+ 1 - 0
conf/hls.sh

@@ -0,0 +1 @@
+ffmpeg -i rtmp://localhost/live/$1 -async 1 -vsync -1 -c:v libx264 -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/low/$1_low -c copy -f flv rtmp://localhost/src/$1_nuevakey_src;

+ 88 - 0
conf/nginx.conf

@@ -0,0 +1,88 @@
+user root;
+worker_processes  auto;
+events {
+    # Allows up to 1024 connections, can be adjusted
+    worker_connections  1024;
+}
+
+# RTMP configuration
+rtmp {
+    server {
+        listen 1935; # Listen on standard RTMP port
+        chunk_size 8192;
+
+        # This application is to accept incoming stream
+        application live {
+            live on; # Allows live input
+            wait_key on;
+            # Once receive stream, transcode for adaptive streaming
+            # This single ffmpeg command takes the input and transforms
+            # the source into 4 different streams with different bitrate
+            # and quality. P.S. The scaling done here respects the aspect
+            # ratio of the input.
+            exec /opt/hls.sh $name;
+        }
+
+        # This application is for splitting the stream into HLS fragments
+        application low {
+            live on; # Allows live input from above
+            hls on; # Enable HTTP Live Streaming
+            wait_key on;
+            wait_video on;
+            hls_cleanup off;
+            hls_nested on;
+            hls_playlist_length 2100ms;
+            hls_fragment 700ms;
+            hls_fragment_naming system;
+
+            # Pointing this to an SSD is better as this involves lots of IO
+            hls_path /hls;
+
+            # Instruct clients to adjust resolution according to bandwidth
+            hls_variant _low BANDWIDTH=288000,RESOLUTION=640x480;
+        }
+
+        application src {
+            live on; # Allows live input from above
+            hls on; # Enable HTTP Live Streaming
+            wait_key on;
+            wait_video on;
+            hls_cleanup off;
+            hls_nested on;
+            hls_playlist_length 2100ms;
+            hls_fragment 700ms;
+            hls_fragment_naming system;
+
+            # Pointing this to an SSD is better as this involves lots of IO
+            hls_path /hls;
+
+            # Instruct clients to adjust resolution according to bandwidth
+            hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
+        }
+    }
+}
+
+http {
+    # See http://licson.net/post/optimizing-nginx-for-large-file-delivery/ for more detail
+    # This optimizes the server for HLS fragment delivery
+    sendfile off;
+    tcp_nopush on;
+    #aio on;
+    directio 512;
+
+    # HTTP server required to serve the player and HLS fragments
+    server {
+        listen 8080;
+        error_log /var/log/nginx/rtmp-error.log;
+
+        location /show {
+            types {
+                application/vnd.apple.mpegurl m3u8;
+            }
+
+            alias /hls;
+            add_header Cache-Control no-cache; # Prevent caching of HLS fragments
+            add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
+        }
+    }
+}