load_module modules/ngx_stream_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
# disable consuming the stream from nginx as rtmp
deny play all;
# Turn on HLS
hls on;
hls_path /data/hls/;
hls_fragment 3;
hls_playlist_length 60;
hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
}
}
}
docker run --detach --name nginx-hls-stream \
--volume "${PWD}/hls-stream.conf:/etc/nginx/nginx.conf" \
--publish "1935:1935" \
--workdir "/usr/share/nginx/" \
nginx
telnet localhost 1935
docker stop nginx-hls-stream
docker rm nginx-hls-stream
KEY='stream1'
streamlink --stdout --url "${VIDEO_URL}" --default-stream '720p,480p' | \
ffmpeg -re -i 'pipe:' -async 1 -vsync 1 \
-c:v libx264 -c:a aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -strict -2 -f flv "rtmp://localhost/show/${KEY}_high" \
-c:v libx264 -c:a aac -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -strict -2 -f flv "rtmp://localhost/show/${KEY}_mid" \
-c:v libx264 -c:a aac -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -strict -2 -f flv "rtmp://localhost/show/${KEY}_low" \
-c:v libx264 -c:a aac -strict -2 -f flv "rtmp://localhost/show/${KEY}_src"