diff --git a/Dockerfile b/Dockerfile index 15495be..d722f9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM registry.sindominio.net/nginx RUN apt-get update -y && \ - apt-get install -y libnginx-mod-rtmp cron + apt-get install -y libnginx-mod-rtmp cron \ + ffmpeg wget RUN rm -rf /var/www/html/* @@ -21,6 +22,9 @@ RUN mkdir -p /var/www/html/hls && \ # poner el index.html css y js COPY index.html /var/www/html/ +RUN mkdir /var/www/html/rtmp/ && \ + wget https://raw.githubusercontent.com/arut/nginx-rtmp-module/master/stat.xsl -O /var/www/html/rtmp/stat.xsl + RUN mkdir -p /var/www/html/assets/ COPY assets/styles-sintoniza.css /var/www/html/assets/ COPY assets/video-js.min.css /var/www/html/assets/video-js.min.css @@ -28,5 +32,5 @@ COPY assets/video.min.js /var/www/html/assets/video-js.min.js COPY assets/jquery-3.6.1.slim.min.js /var/www/html/assets/jquery-slim.min.js # copiar la configuración por defecto de nginx con nuestros cambios incluidos -COPY nginx-site-default.conf /etc/nginx/sites-available/default +COPY nginx-site-default.conf /etc/nginx/sites-enabled/default diff --git a/docker-compose.yml b/docker-compose.yml index aa16c18..ee95de2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,10 @@ -sintoniza: - container_name: sintoniza - hostname: sintoniza +version: "3" +services: + sintoniza: + build: . restart: always image: registry.sindominio.net/sintoniza user: 111:65534 ports: - "0.0.0.0:8080:8080" + - "0.0.0.0:1935:1935" diff --git a/nginx-rtmp.conf b/nginx-rtmp.conf index b36ca01..3cdb977 100644 --- a/nginx-rtmp.conf +++ b/nginx-rtmp.conf @@ -18,6 +18,33 @@ rtmp { # para bloquear el directo # quita el comentario de la línea siguiente # deny play all; + + # TODO: Podemos usarlo para validar los accesos + #on_publish http://docker.for.mac.host.internal:5000/api/stream/start; + #on_publish_done http://docker.for.mac.host.internal:5000/api/stream/end; + + ## Transcode video for low latencies + exec ffmpeg -i rtmp://localhost/entrada/$name -c:v libx264 -x264opts keyint=60:no-scenecut -b:v 450k -c:a copy -s 854x480 -r 30 -sws_flags bilinear -tune zerolatency -preset veryfast -f flv rtmp://localhost/show/$name_sd; } + + application show { + live on; # Allows live input from above + hls on; # Enable HTTP Live Streaming + hls_type live; # Either 'event' or 'live' (live means played from current live position) + deny play all; # Disable consuming the stream from nginx as rtmp + + hls_fragment 2s; + hls_playlist_length 10s; + + # Pointing this to an SSD is better as this involves lots of IO + # hls_path /tmp/hls/; + hls_path /var/www/html/canal/variant/; + + # Instruct clients to adjust resolution according to bandwidth + #hls_variant _subsd BANDWIDTH=400000; + hls_variant _sd BANDWIDTH=1000000; + #hls_variant _hd BANDWIDTH=5000000; + } + } } diff --git a/nginx-site-default.conf b/nginx-site-default.conf index 8081f1d..a638137 100644 --- a/nginx-site-default.conf +++ b/nginx-site-default.conf @@ -12,17 +12,35 @@ server { location / { try_files $uri $uri/ =404; } + + location /control { + rtmp_control all; + } + + # rtmp stat + location /stat { + rtmp_stat all; + rtmp_stat_stylesheet stat.xsl; + } + + location /stat.xsl { + root /var/www/html/rtmp; + } + location /canal { # Disable cache add_header Cache-Control no-cache; # CORS setup - add_header 'Access-Control-Allow-Origin' '*' always; - add_header 'Access-Control-Expose-Headers' 'Content-Length'; - + add_header 'Cache-Control' 'no-cache'; + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; + add_header 'Access-Control-Allow-Headers' 'Range'; + # allow CORS preflight requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Range'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0;