#daemon off; error_log /dev/stdout info; events { worker_connections 1024; } rtmp { server { listen ${RTMP_PORT}; chunk_size 4000; application stream { live on; exec ffmpeg -i rtmp://localhost:1935/stream/$name # 4K (2160p) - 比特率设置为 20Mbps -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 20000k -f flv -g 60 -r 60 -s 3840x2160 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_2160p20000kbs # 2K (1440p) - 比特率设置为 12Mbps -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 12000k -f flv -g 60 -r 60 -s 2560x1440 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1440p12000kbs # 1080p - 比特率设置为 6Mbps -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 6000k -f flv -g 60 -r 60 -s 1920x1080 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1080p6000kbs # 720p -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs # 480p -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs # 360p -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs; } application hls { live on; hls on; hls_fragment_naming system; hls_fragment 5; hls_playlist_length 10; hls_path /opt/data/hls; hls_nested on; # 添加新的分辨率变体 hls_variant _2160p20000kbs BANDWIDTH=20192000,RESOLUTION=3840x2160; hls_variant _1440p12000kbs BANDWIDTH=12192000,RESOLUTION=2560x1440; hls_variant _1080p6000kbs BANDWIDTH=6192000,RESOLUTION=1920x1080; hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720; hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480; hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360; } } } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /dev/stdout main; root /www/static; sendfile off; tcp_nopush on; server_tokens off; # 安全设置 add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; # 超时设置 client_body_timeout 12; client_header_timeout 12; keepalive_timeout 65; server { listen ${HTTP_PORT}; location /hls { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /opt/data; add_header Cache-Control no-cache; add_header Access-Control-Allow-Origin *; } location /live { alias /opt/data/hls; types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } add_header Cache-Control no-cache; add_header Access-Control-Allow-Origin *; } location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /www/static; } location = /healthcheck { access_log off; add_header Content-Type text/plain; return 200 'ok'; allow 127.0.0.1; deny all; } location /crossdomain.xml { default_type text/xml; expires 24h; } } }