你的 Nginx 已经有了 RTMP 直播功能的话,如果你还想统计某直播频道当前观看用户量的话,可以加入 with-http_xslt_module 模块。具体步骤如下:
        1.查看原来的参数
        /usr/local/nginx/sbin/nginx -V
        输出中可以得到原来编译时带有的参数,比如作者得到:
        --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_perl_module --with-mail
        这些参数在我们安装新模块时仍然有用。
        2.下载 nginx-rtmp-module 安装包
        nginx-rtmp-module-master.zip,最新下载地址:https://github.com/arut/nginx-rtmp-module
        下载后将其解压缩得到 nginx-rtmp-module-master 目录。
        3.下载 nginx-1.3.8.tar.gz 包
        可以在 http://nginx.org/download/ 找你需要的版本。
        下载后解压缩得到 nginx-1.3.8 目录。
        4.关闭 nginx
        ps - ef | grep nginx
        在进程列表里找到 master 进程,这是 nginx 的主进程号。
        kill -TERM 主进程号
        nginx 被关闭。
        5.安装其他依赖包
        yum install pcre-devel
        yum install openssl-devel
        yum install perl-devel perl-ExtUtils-Embed
        yum install gcc
        yum install libxml2 libxml2-devel libxslt libxslt-devel
        6.编译 with-http_xslt_module 模块
        在步骤一得到的一系列参数后增加以下参数:
        --with-http_xslt_module --add-module=/home/defonds/nginx-rtmp-module-master
        其中 /home/defonds/nginx-rtmp-module-master 是步骤二得到的目录。
        切换进入步骤三得到的 nginx-1.3.8 目录,使用新组合得到的参数列表重新配置:
        ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_perl_module --with-mail --with-http_xslt_module --add-module=/home/defonds/nginx-rtmp-module-master
        然后编译:
        make
        最后替换掉原来的二进制执行文件:
        cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
        cp ./objs/nginx /usr/local/nginx/sbin/
        7.修改 nginx 配置文件
        创建一个简单地 xls 表格文件 nclients.xsl 用于提取观看当前频道的用户数量,编辑其内容如下:

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="html"/>
  3. <xsl:param name="app"/>
  4. <xsl:param name="name"/>
  5. <xsl:template match="/">
  6. <xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>
  7. </xsl:template>
  8. </xsl:stylesheet>

然后将其放在一个目录中,比如 /home/www。
        修改 nginx 主配置文件 nginx.conf,添加以下内容:

  1. location /stat {
  2. rtmp_stat all;
  3. allow 127.0.0.1;
  4. }
  5. location /nclients {
  6. proxy_pass http://127.0.0.1/stat;
  7. xslt_stylesheet /home/www/nclients.xsl app='$arg_app' name='$arg_name';
  8. add_header Refresh "3; $request_uri";
  9. }

8.重启 nginx
        /usr/local/nginx/sbin/nginx
        No news is good news,终端没有输出证明启动成功。否则参照终端给的异常信息检查主配置文件。
        根据直播频道访问以下地址:
        http://直播服务器IP/nclients?app=app应用名&name=频道名
        有返回结果表示 with-http_xslt_module 模块安装成功。返回结果就是当前频道的观看人数。

参考资料:Nginx RTMP 模块 nginx-rtmp-module 指令详解
https://github.com/arut/nginx-rtmp-module/wiki/Getting-number-of-subscribers

让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能的更多相关文章

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

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

  2. 搭建rtmp直播流服务之1:使用nginx搭建rtmp直播流服务器(nginx-rtmp模块的安装以及rtmp直播流配置)

    欢迎大家积极开心的加入讨论群 群号:371249677 (点击这里进群) 一.方案简要 首先通过对开发方案的仔细研究(实时监控.流媒体.直播流方案的数据源-->协议转换-->服务器--&g ...

  3. 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解

    注意:这里不会讲到nginx流媒体模块如何安装的问题,只研究rtmp,hls直播和录制相关的nginx服务器配置文件的详细用法和说明.可以对照这些命令详解配置nginx -rtmp服务 一.nginx ...

  4. 基于nginx的rtmp直播服务器(nginx-rtmp-module实现)

    首先,在搭建服务之前先了解下目前主流的几个直播协议: 1.RTMP: 实时消息传输协议,Real Time Messaging Protocol,是 Adobe Systems 公司为 Flash 播 ...

  5. Nginx 搭建rtmp直播服务器

    1.到nginx源码目录新建个rtmp目录 ,进入  git clone https://github.com/arut/nginx-rtmp-module.git   2.重编译nginx 代码如下 ...

  6. ubuntu 上采用nginx做rtmp 直播 服务器

    首先安装必要的依赖库   sudo apt-get install autoconf automake sudo apt-get install libpcre3 libpcre3-dev   安装 ...

  7. Nginx 的 RTMP 模块的在线统计功能 stat 在 multi-worker 模式下存在 Bug

    < 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能>一文介绍了 Nginx 的在线统计模块.         我们的在线直播服务使用了 Nginx 的 Rtmp ...

  8. nginx开发(四)调用ffmpeg,搭建rtmp直播流。

    1: 修改conf文件,配置rtmp直播 打开usr/local/nginx/conf/nginx.conf,添加红色内容: rtmp {#rtmp点播配置    server {        li ...

  9. 极速搭建RTMP直播流服务器+webapp (vue) 简单实现直播效果

    在尝试使用webRTC实现webapp直播失败后,转移思路开始另外寻找可行的解决方案.在网页上尝试使用webRTC实现视频的直播与看直播,在谷歌浏览器以及safari浏览器上测试是可行的.但是基于基座 ...

随机推荐

  1. BOOST学习笔记

    BOOST学习笔记 1 tool #pragma once #include <vector> #include "boost/noncopyable.hpp" #in ...

  2. JDK_如何查看安装的jdk是32位还是64位?

    1. 1.1.32位系统只能装 32位 jdk 1.2.64位系统,安装的 32位JDK 和 64位JDK 是不同的目录 1.2.1.32位的路径 类似:C:\Program Files (x86)\ ...

  3. scala LocalDateTime String 转换

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");LocalDateTime ti ...

  4. js的callee和caller方法

    转载:http://www.css88.com/archives/1706 http://www.jb51.net/article/25561.htm 这里我们可以知道: caller的使用方法: f ...

  5. Ajax-05 使用XMLHttpRequest和jQuery实现Ajax实例

    需求: (django)使用XMLHttpRequest和jQuery实现Ajax加法运算 url.py: from django.conf.urls import url from hello im ...

  6. 【Demo】CSS图像拼合技术

    图像拼合 图像拼合 - 简单实例 <style> img.home { width: 46px; height: 44px; background: url(/images/img_nav ...

  7. Codeforces Round #448 (Div. 2)C. Square Subsets

    可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异 ...

  8. Isilon

    Isilon编辑 本词条缺少信息栏,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 美国Isilon公司是全球群集存储系统的主要供应商,是该领域的领导者.总部位于美国华盛顿州的西雅图.创建于2 ...

  9. 用shell将时间字符串与时间戳互转

    date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博 ...

  10. python:一个比较有趣的脚本

    宿舍火星wifi经常掉,然后要重启,于是用Python写了一个脚本,用来远程控制火星wifi的重启 思路: 01.使用socket通讯 02.在wifi主机(开wifi的电脑)上运行客户端,控制机运行 ...