调用 on_publish 后如何更改 nginx rtmp 流名称
Posted
技术标签:
【中文标题】调用 on_publish 后如何更改 nginx rtmp 流名称【英文标题】:How to change nginx rtmp stream name after call on_publish 【发布时间】:2017-04-23 06:41:43 【问题描述】:我的原始流名称是7a0938b1a5e64c5597f959610cb219c9
。我想在调用on_publish
之后将我的流名称更改为testchannel1
。但是在hls_path
中,流名称仍然与以前相同。如何将我的配置文件更改为实现它。
nginx配置文件
application myapp
on_publish http://192.168.50.98:8080/auth/on_publish;
on_publish_done http://192.168.50.98:8080/auth/live/on_connect;
live on;
hls on;
hls_path /usr/share/nginx/html/live;
hls_nested on;
hls_fragment 2s;
hls_playlist_length 6s;
hls_fragment_naming system;
HTTP 请求参数
app: myapp
flashver: FMLE/3.0 (compatible; FMSc/1.0)
swfurl: rtmp://vm1.mysite.com/myapp
tcurl: rtmp://vm1.mysite.com/myapp
pageurl:
addr: 192.168.50.98
clientid: 7
call: publish
name: 7a0938b1a5e64c5597f959610cb219c9
type: live
HTTP 响应标头
HTTP/1.1 302
Location: testchannel1
Content-Length: 0
Date: Sun, 23 Apr 2017 05:54:23 GMT
hls 路径
[root@localhost live]# pwd
/usr/share/nginx/html/live
[root@localhost live]# ls
7a0938b1a5e64c5597f959610cb219c9 nginx_error.log test.html
nginx 版本
nginx version: nginx/1.11.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=../nginx-rtmp-module-1.1.10 --with-http_auth_request_module
nginx-rtmp-module 版本
nginx-rtmp-module-1.1.10
【问题讨论】:
【参考方案1】:解决方案
Nginx-RTMP 模块支持使用通常的 HTTP 重定向 301 或 302(永久或临时)的 on_publish 回调 URL 将流重定向到另一个。 (请注意,它仅适用于对 rtmp 服务器的请求,而不适用于 hls,因为它是由 http 服务器处理的)
例如在一个简单的烧瓶应用中
from flask import Flask, redirect
app = Flask('Hello')
@app.route('/publish-check')
def publish_check():
return redirect('rtmp://127.0.0.1/hls-live/testchannel1', code=302)
新的 HTTP 响应标头
HTTP/1.1 302
Location: rtmp://127.0.0.1/hls-live/testchannel1
新的nginx配置文件
application myapp
on_publish http://vm1.mysite.com/auth/on_publish;
on_publish_done http://vm1.mysite.com/auth/live/on_connect;
live on;
# hls on;
# hls_path /usr/share/nginx/html/live;
# hls_nested on;
# hls_fragment 2s;
# hls_playlist_length 6s;
# hls_fragment_naming system;
application hls-live
#on_publish http://vm1.chenshenglong.com;
live on;
hls on;
hls_path /usr/share/nginx/html/live;
hls_nested on;
hls_fragment 2s;
hls_playlist_length 6s;
hls_fragment_naming system;
【讨论】:
以上是关于调用 on_publish 后如何更改 nginx rtmp 流名称的主要内容,如果未能解决你的问题,请参考以下文章
在 Autofac 中,如何更改调用 Build 后注册的实例?
在 App Delegate 上调用服务器后如何更改根控制器?
更改 nginx - Docker 容器 nginx.conf 中的 client_max_body_size 调用包括 HTTP、服务器和位置部分; Drupal 导入