Nginx模块之———— RTMP模块 统计某频道在线观看流的客户数
获得订阅者人数,可以方便地显示观看流的客户数。
查看已经安装好的模块
/usr/local/nginx/sbin/nginx -V
安装从源编译Nginx和Nginx-RTMP所需的工具
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
下载Nginx和Nginx-RTMP源码
wget http://nginx.org/download/nginx-1.7.5.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
提取Nginx和Nginx-RTMP源
tar -zxvf nginx-1.7..tar.gz
unzip master.zip
切换到Nginx目录
cd nginx-1.7.
添加Nginx将编译的模块,包括Nginx-RTMP
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_xslt_module --with-http_flv_module --with-debug --with-http_gzip_static_module --add-module=../nginx-rtmp-module-master
提示错误:
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
配置 --with-http_xslt_module 时提示 the HTTP XSLT module requires the libxml2/libxslt libraries:安装一下扩展
sudo apt-get install libxml2 libxml2-dev libxslt-dev
编译和安装Nginx与Nginx-RTMP。
make
sudo make install
安装Nginx初始化脚本
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
启动和停止Nginx生成配置文件
sudo service nginx start
sudo service nginx stop
观看安装是否成功:
/usr/local/nginx/sbin/nginx -V
安装结果
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_xslt_module --with-http_flv_module --with-debug --with-http_gzip_static_module --add-module=../nginx-rtmp-module-master
修改Nginx 配置文件添加一下信息,在位置设置统计信息页面
location /stat {
rtmp_stat all;
allow 127.0.0.1;
}
创建一个简单的xsl样式表nclients.xsl提取流用户数
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:param name="app"/>
<xsl:param name="name"/> <xsl:template match="/">
<xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>
</xsl:template> </xsl:stylesheet>
设置一个返回订阅者数量的位置
location /nclients {
proxy_pass http://127.0.0.1/stat;
xslt_stylesheet /home/www/nclients.xsl app='$arg_app' name='$arg_name';
add_header Refresh "3; $request_uri";
}
Nginx.config 完整配置:
user www www;
worker_processes ; error_log logs/error.log debug; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '[$time_local][$remote_addr][$http_x_forwarded_for] $status "$request" "$http_referer" "$http_user_agent"'; access_log logs/access.log main; sendfile on;
keepalive_timeout ; server { set $wwwroot /home/www/node/html; listen ;
server_name localhost;
index index.html;
root $wwwroot;
access_log logs/node.access.log main;
error_log logs/error.log debug; location /rtmp/stat {
rtmp_stat all;
rtmp_stat_stylesheet rtmpstat.xsl;
} location /rtmpstat.xsl {
} location /rtmp/control {
rtmp_control all;
} location /stat {
rtmp_stat all;
allow 127.0.0.1;
} location /nclients {
proxy_pass http://127.0.0.1/stat;
xslt_stylesheet /home/www/nclients.xsl app='$arg_app' name='$arg_name';
add_header Refresh "3; $request_uri";
} location ~* /hls/.*\.m3u8$ {
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
} location ~* /hls/.*\.ts$ {
types {
video/mp2t ts;
}
root /tmp;
expires 1m;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
} #error_page /.html; error_page /50x.html;
location = /50x.html {
root html;
} location / { } } } rtmp {
server {
listen ;
chunk_size ;
application live {
live on;
record off;
}
}
}
重启Nginx
root@iZ239kcyg8rZ:/usr/local/nginx/conf# service nginx restart
* Stopping Nginx Server... [ OK ]
* Starting Nginx Server... [ OK ]
root@iZ239kcyg8rZ:/usr/local/nginx/conf#
根据直播频道访问以下地址:
http://你的推流服务器IP/nclients?app=live&name=
客户端打开三个播放测试:
打开2个VLC播放流:
查看在线人数:
结束。
Nginx模块之———— RTMP模块 统计某频道在线观看流的客户数的更多相关文章
- 流媒体技术学习笔记之(三)Nginx-Rtmp-Module统计某频道在线观看流的客户数
获得订阅者人数,可以方便地显示观看流的客户数. 查看已经安装好的模块 /usr/local/nginx/sbin/nginx -V 安装从源编译Nginx和Nginx-RTMP所需的工具 sudo a ...
- 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能
你的 Nginx 已经有了 RTMP 直播功能的话,如果你还想统计某直播频道当前观看用户量的话,可以加入 with-http_xslt_module 模块.具体步骤如下: 1.查看原来的 ...
- Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)
一.目前只有一个Live节点存在 单节点获取方式如下: public function getStreamByIp($outerIP, $streamName) { //查询录像模块的IP地址外网,根 ...
- Nginx模块之————RTMP模块在Ubuntu 14.04年的设置与搭建
Nginx的设置,RTMP在Ubuntu 14.04 https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04
- Nginx模块之————RTMP模块的FFmpeg的配置问题是FFmpeg的连续退出
rtmp { server { listen ; application live { allow publish all; allow play all; live on; exec /root/b ...
- Nginx模块之————RTMP模块在Ubuntu上以串流直播HLS视频
Nginx的安装在Ubuntu上以串流直播HLS视频 https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video
- Nginx 的 RTMP 模块的在线统计功能 stat 在 multi-worker 模式下存在 Bug
< 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能>一文介绍了 Nginx 的在线统计模块. 我们的在线直播服务使用了 Nginx 的 Rtmp ...
- Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)
一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...
- Mac上搭建直播服务器Nginx+rtmp,实现手机推流、拉流
转载自http://www.cnblogs.com/jys509/p/5649066.html 简介 nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择,本人在网 ...
随机推荐
- win10 pro 1511 激活成功
slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX slmgr /skms franklv.ddns.net slmgr /ato
- idea转eclipse 设置注意。
下载适合的eclipse
- CentOS 6.5下Zabbix的安装配置
1.确保开发环境lamp已经安装 2.下载zabbix 官方下载地址:http://www.zabbix.com/download.php 选择和自己系统对应的版本,这里选择安装与Linux内核为2. ...
- Hash工具下载地址
因为经常要在非常用电脑使用,这里放一个链接,方便下载: http://files.cnblogs.com/files/cxun/Hash.zip HASH计算工具,可计算MD5.SHA-1.CRC32 ...
- Jenkins Slave 通过JNLP 的方式 访问Master IP 总是127.0.0.1
解决办法,重启机器 可能是我以前用的jenkins url 是127.0.0.1 然后是缓存什么没有释放掉所致 <jnlp codebase="http://183.62.104.48 ...
- [T-SQL]INSERT INTO SELECT 与 SELECT INTO FROM
1.INSERT INTO SELECT 语法:INSERT INTO Table2(field1,field2,...) select value1,value2,... from Table1 要 ...
- Duilib 开发中的小经验
# duilib开发中收集的小代码 # ## 1 窗体创建 ## - 窗体多继承于 public WindowImplBase ,简单的定义几个函数就可以实现:拖曳caption移动(设置xml窗体的 ...
- Linux中profile、bashrc、bash_profile之间的区别和联系
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. 英文描述为: # /etc/pr ...
- MySQL时间段查询
现实中我们会遇到统计报表.比如查询当月每一天的数据数量...等等之类的.以下内容就是有关这方面的咯. 首先要知道几个函数 mysql> select now(); //这个是显示的当前时间 +- ...
- android使用默认程序进行图片拍照已经裁剪,以及设备读取
//代码如下: package com.cbsw.yulechangsuo.activity; import java.io.File;import java.io.FileInputStream;i ...