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

查看已经安装好的模块

/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. linux内核分析--操作系统是如何工作的?

    一个简单的时间片轮转多道程序 操作系统的"两把剑":中断上下文(保存现场和恢复现场)和进程上下文的切换 源代码的分析 *使用的源代码为视频中所使用的精简内核的源代码 首先分析myp ...

  2. KNY三人组对YiSmile小程序的项目总结

    设想和目标 1.我们的小程序要解决什么问题? 针对于本校学生,服务于本校学生.由于丢东西,找东西的事情每天都在上演,空间说说,朋友圈,官方QQ,信息比较冗杂,没有一个固定的平台来专门提供学生.此外,教 ...

  3. sql not in 优化问题

    问题情境: not in 耗时过长.想用join或exits代替.结果并不明显,这里先记录3种写法,以后探讨速度问题. sql语句: // not exists sql = @"select ...

  4. 软件工程团队项目第一次Sprint评审

    第一组:9-652 作品:炸弹人 评价:已经完成了界面的设计和基本功能,游戏已初具雏形.这款游戏可玩性很强,是个很不错的项目.但是对游戏并没有进行深入开发,不能持续的吸引玩家的兴趣,容易引起玩家的厌倦 ...

  5. Java单元测试框架 JUnit

    Java单元测试框架 JUnit JUnit是一个Java语言的单元测试框架.它由Kent Beck和Erich Gamma建立,逐渐成为源于KentBeck的sUnit的xUnit家族中为最成功的一 ...

  6. 使用git进行代码的推送

    首先是对于锐捷墙的问题,登陆github有时可以有时又连不上,网络又非常慢,所以用了十足的耐心才fork完了代码库.链接https://github.com/niconiconiconi/hellow ...

  7. beta1

    组长:吴晓晖 过去两天完成了哪些任务: 代码重构进行中,界面,预计两个beta单位完成 展示GitHub当日代码/文档签入记录 接下来的计划 更加人性化的推荐算法 还剩下哪些任务 有哪些困难 有哪些收 ...

  8. Beta版本冲刺(一)

    目录 组员情况 组员1(组长):胡绪佩 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最新成果 团 ...

  9. K8S 创建rc 时 不适用本地镜像的解决办法

    spec: containers: - name: nginx image: image: reg.docker.lc/share/nginx:latest imagePullPolicy: IfNo ...

  10. jdk动态代理 要把目标对象 和自己都传进去;以便自己对目标对象的代理