获得订阅者人数,可以方便地显示观看流的客户数。

查看已经安装好的模块

/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-Module统计某频道在线观看流的客户数的更多相关文章

  1. Nginx模块之———— RTMP模块 统计某频道在线观看流的客户数

    获得订阅者人数,可以方便地显示观看流的客户数. 查看已经安装好的模块 /usr/local/nginx/sbin/nginx -V 安装从源编译Nginx和Nginx-RTMP所需的工具 sudo a ...

  2. 流媒体技术学习笔记之(二)RTMP和HLS分发服务器nginx.conmf配置文件(解决了,只能播放RTMP流而不能够播放HLS流的原因)

    user www www; worker_processes ; error_log logs/error.log debug; #pid logs/nginx.pid; events { worke ...

  3. 流媒体技术学习笔记之(十四)FFmpeg进行笔记本摄像头+麦克风实现流媒体直播服务

    FFmpeg推送视频流,Nginx RTMP模块转发,VLC播放器播放,实现整个RTMP直播 查看本机电脑的设备 ffmpeg -list_devices true -f dshow -i dummy ...

  4. 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能

    你的 Nginx 已经有了 RTMP 直播功能的话,如果你还想统计某直播频道当前观看用户量的话,可以加入 with-http_xslt_module 模块.具体步骤如下:        1.查看原来的 ...

  5. 流媒体技术学习笔记之(一)nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器

    参照网址: [1]http://blog.csdn.net/redstarofsleep/article/details/45092147 [2]HLS介绍:http://www.cnblogs.co ...

  6. 流媒体技术学习笔记之(十)HLS协议直播延时优化(35s到10S)

    1.首先要了解HLS延时的机制,也就是为什么会延时,延时主要发生在什么地方. HTTP Live Streaming 并不是一个真正实时的流媒体系统,这是因为对应于媒体分段的大小和持续时间有一定潜在的 ...

  7. 流媒体技术学习笔记之(十三)Windows安装FFmpeg

    一.下载地址: 网址:https://ffmpeg.org/ 选择Windows版本:https://ffmpeg.org/download.html#build-windows 二.解压安装: 下载 ...

  8. 流媒体技术学习笔记之(十八)互联网草案HTTP直播流2017年5月

    原文地址:https://tools.ietf.org/html/draft-pantos-http-live-streaming-23 1.HTTP直播流介绍 HTTP实时流媒体提供了一个可靠的,成 ...

  9. 流媒体技术学习笔记之(十七)FFmpeg 3.3《希尔伯特》-新版本的亮点

    FFmpeg 3.3“Hilbert”,一个新的主要版本的一些亮点: 苹果Pixlet解码器 NewTek SpeedHQ解码器 QDMC音频解码器 PSD(Photoshop Document)解码 ...

随机推荐

  1. 【Android UI设计与开发】第01期:引导界面(一)ViewPager介绍和使用详解

    做Android开发加起来差不多也有一年多的时间了,总是想写点自己在开发中的心得体会与大家一起交流分享.共同进步,刚开始写也不知该如何下手,仔细想了一下,既然是刚开始写,那就从一个软件给人最直观的感受 ...

  2. android studio 下载 sdk 失败

    android studio 打开项目出现以下错误时,点击去安装,会提示"All packages are not available for download" 错误. 解决办法 ...

  3. Js_获取当前日期时间

    一.获取当前时间 new Date()方法---------得到结果是当前电脑时间如2011-11-6,10:07 二.获取有个固定的时间方法---------var endtime=new Date ...

  4. ECS centos7 使用外部邮件服务商的465加密端口

    ECS centos7 使用外部邮件服务商的465加密端口发送邮件. 1.修改/etc/mail.rc 文件中添加以下的 set smtp="smtps://smtp.163.com:465 ...

  5. OpenMPI源码剖析:网络通信原理(二) 如何选择网络协议?

    因为比较常用的是 TCP 协议,所以在 opal/mca/btl/tcp/btl_tcp.h 头文件中找到对应的 struct mca_btl_tcp_component_t { mca_btl_ba ...

  6. [转载] JVM 内存结构

    转载自:http://gityuan.com/2015/10/17/java-memory/

  7. PAT甲题题解-1011. World Cup Betting (20)-误导人的水题。。。

    题目不严谨啊啊啊啊式子算出来结果是37.975样例输出的是37.98我以为是四舍五入的啊啊啊,所以最后输出的是sum+0.005结果告诉我全部错误啊结果直接保留两位小数就可以了啊啊啊啊 水题也不要这么 ...

  8. hexo发文章

    http://blog.csdn.net/qq_36099238/article/details/54576089

  9. Final互评------《I do》---- 二次元梦之队

    一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题; N(Need,需求):该产品是一款休闲类的解密游戏,背景是编程知识.作为一款休闲游戏,有着基本的娱乐功能,可以给用 ...

  10. psp进度统计

    每周例行报告 本周PSP 类别 任务 开始时间 结束时间 被打断时间 总计工作时间    11月8日 代码 参与团队项目 10:13 11:30 0 77min 写博客 词频统计总结 13:35 14 ...