我有一个 nginx 的工作设置,其中 rtmp 模块运行良好,可以使用 dash 和 hsl 创建直播流。到目前为止没有问题。
当我尝试为自适应流启用 ffmpeg 转码时,它会成功创建 hls 版本、视频块、每个视频版本的 m3pu8 以及我从网络播放器调用的主 m3u8。
但是在 dash 版本中,我获得了块、每个版本的 mpd 清单,但没有主清单。
我是否遗漏了什么?任何帮助都将不胜感激。
nginx.conf:
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
application live {
live on;
exec ffmpeg -i rtmp://stream.server.net/live/$name -threads 1
-c:v libx264 -profile:v baseline -b:v 768K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 96k
rtmp://stream.server.net/liveout/$name_360
-c:v libx264 -profile:v baseline -b:v 1024K -s 852x480 -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://stream.server.net/liveout/$name_480;
}
application liveout {
live on;
hls on;
hls_path /home/stream/hls/;
hls_fragment 4s;
hls_playlist_length 60s;
dash on;
dash_path /home/stream/dash;
dash_fragment 10s;
dash_playlist_length 30s;
dash_nested off;
hls_variant _360 BANDWIDTH=448000;
hls_variant _480 BANDWIDTH=1152000;
}
}
}
http {
server {
server_name stream.server.net;
root /home/stream/;
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/stream/;
add_header Cache-Control no-cache;
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# Allow CORS preflight requests
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;
}
}
location /dash {
root /home/stream/;
# Serve DASH fragments
types {
application/dash+xml mpd;
video/mp4 mp4;
}
add_header Cache-Control no-cache;
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# Allow CORS preflight requests
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;
}
}
location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page
# in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /home/stream/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/stream.server.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/stream.server.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
types {
text/html html;
application/dash+xml mpd;
}
server {
if ($host = stream.server.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name stream.server.net;
return 404; # managed by Certbot
}}
答案1
这似乎是 dash_variant 中缺少的功能nginx-rtmp-模块。 这好像是ut0mt8已添加此功能但可能不稳定。