我在一家小型政府机构工作,该机构希望为公众提供董事会会议的直播。我们使用 OBS 进行编码,它从未给我们带来任何问题,但最近我们收到很多投诉,称我们的直播流断开连接或根本无法在我们的网络端加载。
我们正在使用 5 年前构建的 NGINX RTMP/HLS 流媒体服务器来提供此流媒体,最近我将其更新为最新版本的 Ubuntu Server,为了使其尽可能保持最新状态,我甚至重新安装了 NGINX 并更新了一些内容,但总体上保留了我们的旧配置。现在我已经进行了测试,但是,我注意到可能基于浏览器的性能问题,但我想先在这里问一下,以确保我们的服务器遵守规则。
我们的nginx.conf如下:
load_module "modules/ngx_rtmp_module.so";
user www-data;
worker_processes auto;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#If you want to enable gzip, uncomment the following:
#gzip on;
#gzip_disable "msie6";
server{
listen 80;
server_name localhost;
add_header Access-Control-Allow-Origin *;
#rtmp stat
location /stat{
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
#This moves stat.xsl to a different location
root /usr/src/nginx-rtmp-module;
}
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#client (VLC, etc) can access HLS here.
location /hls {
root /tmp;
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
if ($request_method = 'OPTIONS'){
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
}
}
rtmp {
server{
listen 8081;
chunk_size 8192;
ping 30s;
notify_method get;
allow play all;
#allow publish all;
application live {
# We're going to split the stream into different bitrates here for adaptive streaming.
live on;
exec ffmpeg -i rtmp://localhost:8081/live/$name -async 1 -vsync -1 -c:v libx264 -c:a libfdk_aac -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:8081/hls/$name_low -c:v libx264 -c:a libfdk_aac -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:8081/hls/$name_mid -c:v libx264 -c:a libfdk_aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:8081/hls/$name_high -c:v libx264 -c:a libfdk_aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:8081/hls/$name_hd720 -c copy -f flv rtmp://localhost:8081/hls/$name_src;
}
#You should be sending x.264/aac RTMP stream via ffmpeg to this application
application hls {
allow play all;
#allow publish all;
live on;
hls on;
hls_path /tmp/hls;
hls_playlist_length 60s;
hls_fragment 1s;
hls_variant _low BANDWIDTH=288000,RESOLUTION=426x240;
hls_variant _mid BANDWIDTH=448000,RESOLUTION=640x360;
hls_variant _high BANDWIDTH=1152000,RESOLUTION=854x480;
hls_variant _hd720 BANDWIDTH=2048000,RESOLUTION=1280x720;
hls_variant _src BANDWIDTH=4096000,RESOLUTION=1920x1080;
}
}
}
如上所述,我们使用 Video.js 在我们的网站上为用户提供流。有关该配置可能超出了本论坛的范围,但为了提供完整的信息,此流在 Firefox 和 Chrome(均在桌面上)以及 Brave Browser(移动版)上播放没有问题,但在 Brave Browser(桌面版)或 Chrome(移动版)上无法播放
这个 nginx.conf 中是否存在可能导致此类功能(或缺乏功能?)的问题,或者这是否完全与 Web 部分有关?