一天中的好时光,
我正在尝试创建一个简单的RTMP / HLS服务器,以便能够流式传输和从中查看流,但是,我无法更改nginx-rtmp-module
(模块)将数据保存到的目录的名称。
一切正常,我能够流式传输到服务器,然后在浏览器中查看HLS流,但是,唯一的方法是输入 Stream Key 作为目标文件夹服务器获取m3u8文件。
当前我具有以下设置:
on_publish
到http://app.local/stream/start,首先,它检查数据库中是否存在密钥,如果存在,则为该数据库创建新的数据库条目。流(以UUID作为主键),接收通过条目创建获得的键,并将其返回到脚本有人知道如何:
我们非常感谢您的帮助!并感谢您的宝贵时间!
PsS 。这只是我现在拥有的以及我要实现的目标的一个小例子
流键: test_stream_key_user_1
散列键::73E179A6DB3796A3120319BFE80763427A2122253A5C1D347461268304B28CEB98CE3813DDF5FA8B7173937ED9386169FD3BF8E8C3765BC53BB151C7F5B1431E
当前目录命名:/tmp/hls/test_stream_key_user_1/index.m3u8
所需的目录命名:/tmp/hls/73E179A6DB3796A3120319BFE80763427A2122253A5C1D347461268304B28CEB98CE3813DDF5FA8B7173937ED9386169FD3BF8E8C3765BC53BB151C7F5B1431E/index.m3
P.P.S 以为我的Nginx配置文件可能有帮助
RTMP配置
server {
listen 1935;
ping 30s;
notify_method get;
notify_update_timeout 10s;
application live {
live on;
hls on;
hls_nested on;
hls_path /tmp/hls;
hls_fragment 3;
hls_playlist_length 60;
on_publish http://app.local/api/stream/start;
on_done http://app.local/api/stream/stop;
on_update http://app.local/api/stream/update;
}
}
服务器配置(APP)
server {
listen 80;
listen [::]:80;
root #replaced#;
index index.php index.html index.htm index.nginx-debian.html;
server_name app.local www.app.local;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# PHP-FPM Configuration Nginx
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /api {
try_files $uri $uri/ /index.php?$query_string;
}
location /sitemap.xml {
try_files $uri $uri/ /index.php?$query_string;
}
location /login {
try_files $uri $uri/ /index.php?$query_string;
}
location /broadcasting {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
服务器配置(实时)
server {
listen 80;
listen [::]:80;
root #replaced#;
index index.html index.htm index.nginx-debian.html;
server_name live.local www.live.local;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet original_stat.xsl;
}
location /control {
rtmp_control all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /stream {
try_files $uri $uri/ /index.php?$query_string;
}
location /hls {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
if ($request_method = 'OPTIONS') {
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;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
location /dash {
root /tmp;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*' always;
}
}