如何通知nginx rtmp 直播配置结束直播流

插件-RTMP的直播视频流在手机浏览器怎么播放?
作者:用户
浏览:1822 次
RTMP的直播视频流在手机浏览器怎么播放?10CRTMP的直播视频流在手机浏览器怎么播放?听说是通过flash插件,怎么实现呢?本人小白,望详细说明,谢谢http://justcoding.iteye
RTMP的直播视频流在手机浏览器怎么播放?
RTMP的直播视频流在手机浏览器怎么播放?听说是通过flash插件,怎么实现呢?本人小白,望详细说明,谢谢
【云栖快讯】红轴机械键盘、无线鼠标等753个大奖,先到先得,云栖社区首届博主招募大赛9月21日-11月20日限时开启,为你再添一个高端技术交流场所&&
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
6款热门基础云产品6个月免费体验;2款产品1年体验;1款产品2年体验
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
开发者常用软件,超百款实用软件一站式提供下次自动登录
现在的位置:
& 综合 & 正文
使用Nginx-rtmp-module搭建hls直播
HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议。是苹果公司QuickTime X和iPhone软件系统的一部分。它的工作原理是把整个流分成一个个小的基于HTTP的文件来下载,每次只下载一些。当媒体流正在播放时,客户端可以选择从许多不同的备用源中以不同的速率下载同样的资源,允许流媒体会话适应不同的数据速率。在开始一个流媒体会话时,客户端会下载一个包含元数据的extended M3U (m3u8) playlist文件,用于寻找可用的媒体流。
HLS只请求基本的HTTP报文,与实时传输协议(RTP)不同,HLS可以穿过任何允许HTTP数据通过的防火墙或者代理服务器。它也很容易使用内容分发网络来传输媒体流。
此协议详细内容请参考apple官方网站:
hls的技术细节就不说了,这里搭建hls直播的目的就是想研究下Nginx-rtmp-module针对rtmp直播流实时转换为hls直播流的基本细节。
经过测试,我发现,rtmp直播流会被动态切分为ts片段和一个不断刷新的u3m8文件,我正需要关注这一点,必要时可能对相关代码进行调试。
这里按顺序分几个部分讲述我的搭建步骤:软件编译,nginx配置,rtmp源的提供,html代码修改,客户端播放
1.软件编译
从下面的网址分别下载nginx和nginx-rtmp-module:
http://nginx.org/en/download.html
/arut/nginx-rtmp-module
我目前的现状是已经安装好了nginx-1.4.4,需要在它的基础上安装这个模块,可以使用下面的方法增加后续的第三方模块。
进入nginx的源码目录下面
./configure --add-module=/path/to/nginx-rtmp-module --with-http_ssl_module --with-debug
来增加这个模块,然后
make install
注意新生成的配置文件不会覆盖原来的配置文件。参见下面的截图
可见,在config时已经看到了这个新加入的模块,下面的截图说明,现在Nginx只针对新添加的模块进行编译
由上图可见,在make install时,对原来已经存在的nginx.conf,只会进行原封不动的复制。这一点比较人性化,特别是在线上运维上,这样我们可以任意增加后续模块,然后基于前一次的nginx.conf进行修改就可以了,超赞。
如果是全新安装,就更简单了,这里略去安装步骤。
下面是我的实战记录(注意我原来使用了google perftools模块,所以以后添加的所有模块需要都加上这个编译)
cd /usr/local/src
git clone /arut/nginx-rtmp-module.git
cd ../nginx-1.4.4
./configure --prefix=/usr/local/nginx --with-google_perftools_module
--add-module=/usr/local/src/nginx-rtmp-module
--with-http_ssl_module --with-debug
make install
2.nginx配置
Nginx可以支持多虚机配置,如果是一个ip或域名多虚机的情况,就是要不同的虚机对应不同的端口服务,而如果是多ip或域名一个虚机的情况,则又不一样。这里的实际情况就是,80和8080分别对应一个http协议的虚机,1935对应一个rtmp协议的虚机。关于hls具体配置项的解释参见
/arut/nginx-rtmp-module/wiki/Directives
在原有的nginx.conf中加入如下配置
listen 1935;
chunk_size 4000;
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
# ffmpeg -loglevel verbose -re -i movie.avi
-vcodec libx264
-vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
-f flv rtmp://localhost:1935/hls/movie
# If you need to transcode live stream use 'exec' feature.
application hls {
hls_path /usr/local/nginx/html/
hls_fragment 5s;
location /hls {
# Serve HLS fragments
application/vnd.apple.mpegurl m3u8;
expires -1;
其中rtmp部分与原有的http部分在同一个级别,但是下面的http部分要放到已有的http部分中,也就是增加一个server部分。
然后运行如下命令检查nginx.conf是否有语法错误
service nginx configtest
重新加载配置文件
service nginx reload
运行下面的命令查看nginx状态
service nginx status
然后查看端口
netstat -nlp
注意,这里reload并不能开启这几个服务,需要使用
service nginx restart
来将rtmp服务和hls服务的端口都打开,参看下面的截图
3.rtmp源提供
我目前采用ffmpeg来将本地文件处理来模拟产生一个rtmp直播流,现在使用下面的命令来产生一个rtmp直播流
ffmpeg -re -i sample.flv -vcodec copy -acodec copy -f flv rtmp://192.168.90.26/hls/mystream
注意,这里提供rtmp源的机器不一定和nginx在同一台物理主机上,可以是网络上的另一台机器,但是要保证它能与nginx所在的主机建立tcp链接,
也就是nginx主机需要开启rtmp服务的监听端口,这里是1935,当然你也可以修改为其他的端口。
根据nginx.conf中的hls_path配置,这个命令会向192.168.90.26主机的/usr/local/nginx/html/hls下面写入ts片段和m3u8文件,参见下面的截图:
这个目录下的文件会动态刷新,前面写入的ts片段会被后面的ts片段覆盖。当这个直播流播完后,所有相关的ts片段和m3u8文件都将被删除。
4.修改html代码,保存为playhls.html, 这是一个HTML5+HLS视频的例子
&!DOCTYPE html&
&meta http-equiv="content-type" content="text/ charset=utf-8"&
&title&HLS Player&/title&
&video poster="poster.png" height="720" width="1280" controls&
&source src="http://192.168.90.26:8080/hls/mystream.m3u8" type="application/vnd.apple.mpegurl" /&
&p class="warning"&Your browser does not support HTML5 video.&/p&
这个html文件存放在和m3u8文件相同的目录下面:/usr/local/nginx/html/hls
5.客户端播放
在支持html5的浏览器中,输入如下网址
http://192.168.90.26:8080/hls/playhls.html
但是测试支持html5的浏览器比较糟糕,没有一个可以正常播放的,在android手机上测试百度浏览器,画面出来了,但是播放时出了问题,崩掉了。我使用ipad 4,打开Safari浏览器,
就可以正常播放这个直播的视频了。参见下面的截图。
在vlc中加入如下地址也可以播放
http://192.168.90.26:8080/hls/mystream.m3u8
参见下面的截图,注意直播不能拖动!
6,状态查看
要查看到状态信息,需要在nginx.conf中加入stat模块的相关配置信息,也就是加入下面的几行信息,注意root的值是nginx-rtmp-module所在的目录
location /stat {
rtmp_stat_stylesheet stat.
location /stat.xsl {
root /usr/local/src/nginx-rtmp-module/;
注意为了得到统计信息,还需要开启下面的控制模块
location /control {
将它们添加到8080那台http虚机上的配置如下:
listen 1935;
chunk_size 4000;
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
# ffmpeg -loglevel verbose -re -i movie.avi
-vcodec libx264
-vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
-f flv rtmp://localhost:1935/hls/movie
# If you need to transcode live stream use 'exec' feature.
application hls {
hls_path /usr/local/nginx/html/
hls_fragment 5s;
location /stat {
rtmp_stat_stylesheet stat.
location /stat.xsl {
root /usr/local/src/nginx-rtmp-module/;
location /control {
location /hls {
# Serve HLS fragments
application/vnd.apple.mpegurl m3u8;
expires -1;
然后,在浏览器中打开
http://192.168.90.26:8080/stat
如果一切正常应该能看到相关的统计信息了,参见下面的截图
如果不添加控制模块的配置,就不能看到统计数据了,参见截图
7.环境搭建后遇到的问题
[1].http://blog.csdn.net/kl222/article/details/
[2].http://blog.csdn.net/cjsafty/article/details/9108587
[3].http://blog.csdn.net/cccallen/article/details/8440191
[4].http://www.rosoo.net/a/73.html
[5]./2013/04/video-streaming-and-ffmpeg-transcoding/
&&&&推荐文章:
【上篇】【下篇】1498人阅读
流媒体(2)
目前来说,我们可以用到的rtmp服务器有以下几种
1.开源类型:red5,crtmpserver,erlyvideo,haXevideo,FluorineFX,simple rtmp server(SRS),还有nginx-rtmp,Cumulus Server,Mistserver
2.商业软件:wowza media server,slyseal,fms(ams),helix,Evostream media server
rtmp server与播放器的交互
就性能来说,nginx算是最强大的之一了,wowza3的内存和cpu都是一坨屎,red5直接就低了两个级别,FMS性能确实不错,傻瓜式安装也挺好,就是....
环境:centos 6.7 64位
目的:使Nginx支持Rtmp协议推流,并支持HLS分发功能及FFmpeg转码多码率功能。
1、安装依赖包:3.安装上面下载下来的软件包:
++++++++Yasm+++++++++++
#tar xzvf yasm-1.2.0.tar.gz
#cd yasm-1.2.0
#./configure
#make install
++++++++x264+++++++++++
#tar xzvf x264.tar
#./configure --enable-shared
#make install
++++++++LAME+++++++++++
#tar xzvf lame-3.99.5.tar.gz
#cd lame-3.99.5
#./configure --enable-nasm
#make install
++++++++libogg+++++++++++
#tar xzvf libogg-1.3.0.tar.gz
#cd libogg-1.3.0
#./configure
#make install
++++++++libvorbis+++++++++++
#tar xzvf libvorbis-1.3.3.tar.gz
#cd libvorbis-1.3.3
#./configure
#make install
++++++++FAAD2+++++++++++
#tar zxvf faad2-2.7.tar.gz
#cd faad2-2.7
#./configure
#make install
++++++++FAAC+++++++++++
#tar zxvf faac-1.28.tar.gz
#cd faac-1.28
#./configure
#make install
【错误处理】
编译FAAC-1.28时遇到错误:
mpeg4ip.h:126: error: new declaration‘char* strcasestr(const char*, const char*)’
解决方法:
从123行开始修改此文件mpeg4ip.h,到129行结束。
#ifdef __cplusplus
extern &C& {
char *strcasestr(const char *haystack,const char *needle);
#ifdef __cplusplus
#ifdef __cplusplus
extern &C++& {
const char *strcasestr(const char*haystack, const char *needle);
#ifdef __cplusplus
++++++++Xvid+++++++++++
#tar zxvf xvidcore-1.3.2.tar.gz
#cd xvidcore/build/generic
#./configure
#make install
cd ../../../
tar xvf&libvpx-v1.1.0.tar
cd libvpx-v1.1.0
./configure --enable-shared --enable-vp8
make install
++++++++ffmpeg+++++++++++
#tar xvf ffmpeg.tar
#cd ffmpeg
#./configure&&--prefix=/opt/ffmpeg/ --enable-version3&&--enable-libvpx --enable-libfaac --enable-libmp3lame&&--enable-libvorbis --enable-libx264 --enable-libxvid
--enable-shared --enable-gpl --enable-postproc --enable-nonfree&&--enable-avfilter --enable-pthreads
#make && make install
如果提示libvpx decoder version must be&=0.91
tar xvf&libvpx-v1.1.0.tar
cd libvpx-v1.1.0
./configure --enable-shared --enable-vp8
make install
修改/etc/ld.so.conf如下:
include ld.so.conf.d/*.conf
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/ffmpeg/lib
#yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 gcc-c++
yum install git -y
3.下载所需的软件包
Yasm:wget /nginx-rtmp-hls-auth/packages/yasm-1.2.0.tar.gz
X264:wget /nginx-rtmp-hls-auth/packages/x264.tar
LAME:wget /nginx-rtmp-hls-auth/packages/lame-3.99.5.tar.gz
libogg:wget /nginx-rtmp-hls-auth/packages/libogg-1.3.0.tar.gz
libvorbis:wget /nginx-rtmp-hls-auth/packages/libvorbis-1.3.3.tar.gz
libvpx:wget /nginx-rtmp-hls-auth/packages/libvpx-v1.1.0.tar
FAAC:wget /nginx-rtmp-hls-auth/packages/faac-1.28.tar.gz
ffmpeg:wget /nginx-rtmp-hls-auth/packages/ffmpeg.tar
Xvid :wget /nginx-rtmp-hls-auth/packages/xvidcore-1.3.2.tar.gz
验证用到 的php代码如下,可以自己加入数据库等东西!
// ?user=user&pass=pass
$user = isset($_GET['user']) ? $_GET['user'] : '';
$pass = isset($_GET['pass']) ? $_GET['pass'] : '';
if (empty($user) || empty($pass)) {
& & echo &wrong query input&;
& & header('HTTP/1.0 404 Not Found');
& & exit();
$saveuser =
$savepass =
if (strcmp($user, $saveuser) == 0 && strcmp($pass, $savepass) == 0) {
& & echo &Username and Password OK&;
& & echo &Username or Password wrong&;
& & header('HTTP/1.0 404 Not Found');
& & exit();
修改nginx的配置文件如下:
error_log ./error.
& & worker_connections 1024;
& & server {
& && &&&listen 1935;
& && &&&chunk_size 4000;
& && &&&ping 30s;
& && &&&notify_
& && &&&#live
& && &&&application boardcast {
& && && && &
& && && && &on_publish http://127.0.0.1:8080/auth_client.&
& && && && &
& && && && &hls_path /tmp/
& && && && &hls_fragment 2s;
& && && && &hls_playlist_length 6s;
& & server {
& && &&&listen 80;
& && &&&#welcome
& && &&&location / {
& && && && &root&&
& && && && &index&&index.html index.
& && &&&#hls&
& && &&&location /hls {
& && && && &types {
& && && && && & application/vnd.apple.mpegusr m3u8;
& && && && && & video/mp2
& && && && &}
& && && && &root /
& && && && &add_header Cache-Control no-
& && &&&}&&
& & server {
& && &&&listen 8080;
& && &&&location /stat {
& && && && &rtmp_
& && && && &rtmp_stat_stylesheet stat.
& && &&&location /stat.xsl {
& && && && &root /usr/local/src/nginx-rtmp-
& && &&&location /control {
& && && && &rtmp_
& && &&&error_page 500 502 503 504 /50x.
& && && && &location = /50.html {
& && && && &
& && &&&location ~ \.php$ {
& && && && &root /usr/local/nginx/
& && && && &fastcgi_pass 127.0.0.1:9000;
& && && && &fastcgi_index index.
& && && && &fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_
& && && && &include fastcgi_
然后自己安装php-fpm去HI吧,记得把PHP和NGINX加入开机启动
rtmp服务器设置:rtmp://你的服务器IP/boardcast
视频流名字:test?user=user&pass=pass
播放端设置:rtmp://你的服务器IP/boardcast/test
或者http://你的服务器IP/hls/test.m3u8
二、安装Nginx相关模块
1.环境准备
yum install –y pcre pcre-devel
yum install –y zlib zlib-devel
2.下载nginx及rtmp模块
tar xzvf nginx_1.6.2.tar.gz
git clone git:///arut/nginx-rtmp-module.git
3.编译nginx-rtmp
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_stub_status_module 或者添加了统计功能的:
&&./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
make install
人数统计:
01.&xsl:stylesheet version=&1.0& xmlns:xsl=&http://www.w3.org/1999/XSL/Transform&&&&
03.&xsl:output method=&html&/&&&
05.&xsl:param name=&app&/&&&
06.&xsl:param name=&name&/&&&
08.&xsl:template match=&/&&&&
09.& & &xsl:value-of select=&count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])&/&&&
10.&/xsl:template&&&
12.&/xsl:stylesheet& &
location /stat {&&
02.& & rtmp_&&
03.& & allow 127.0.0.1;&&
05.location /nclients {&&
06.& & proxy_pass&&&
07.& & xslt_stylesheet /home/www/nclients.xsl app='$arg_app' name='$arg_name';&&
08.& & add_header Refresh &3; $request_uri&;&&
你的 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,最新下载地址:。
& && && &下载后将其解压缩得到 nginx-rtmp-module-master 目录。
& && && &3.下载 nginx-1.3.8.tar.gz 包
& && && &可以在&&找你需要的版本。
& && && &下载后解压缩得到 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 用于提取观看当前频道的用户数量,编辑其内容如下:
[html] view plain copy
print?01.&xsl:stylesheet version=&1.0& xmlns:xsl=&http://www.w3.org/1999/XSL/Transform&&&&
03.&xsl:output method=&html&/&&&
05.&xsl:param name=&app&/&&&
06.&xsl:param name=&name&/&&&
08.&xsl:template match=&/&&&&
09.& & &xsl:value-of select=&count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])&/&&&
10.&/xsl:template&&&
12.&/xsl:stylesheet&&&
& && && &然后将其放在一个目录中,比如 /home/www。
& && && &修改 nginx 主配置文件 nginx.conf,添加以下内容:
[html] view plain copy
print?01.location /stat {&&
02.& & rtmp_&&
03.& & allow 127.0.0.1;&&
05.location /nclients {&&
06.& & proxy_pass&&&
07.& & xslt_stylesheet /home/www/nclients.xsl app='$arg_app' name='$arg_name';&&
08.& & add_header Refresh &3; $request_uri&;&&
& && && &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 指令详解;
原文地址:
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:22313次
排名:千里之外
原创:26篇
转载:72篇
(11)(4)(23)(4)(14)(2)(15)(12)(3)(4)(8)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'用户名:li
文章数:21
访问量:13127
注册日期:
阅读量:1297
阅读量:3317
阅读量:582384
阅读量:467085
51CTO推荐博文
官方wiki: Nginx rtmp&功能特点1.&& 支持音视频直播2.&& 支持flv/mp4视频格式,输入可以是文件或者HTTP流3.&& 支持两种流的分发模式 pushand pull4.&& 可以将直播流录制成flv文件5.&& H264/AAC编码6.&& 支持在线转码 Onlinetranscoding with FFmpeg7.&& 支持HLS (HTTP LiveStreaming)需要 libavformat (&= 8. 53.31.100) from ffmpeg (ffmpeg.org)8.&& HTTPcallbacks (publish/play/record/update etc)9.&& 支持外部程序(exec)10.& HTTPcontrol module for recording audio/video and dropping clients11.& 先进内存控制技术,可以在使用少量内存的情况下完成流畅的直播功能。12 .&可以和以下协同工作。FMS server(Wirecast, FMS, Wowza,)Player(JWPlayer, FlowPlayer, StrobeMediaPlayback,)外部程序(ffmpeg,avconv,rtmpdump,flvstreamer )13.&Statistics in XML/XSL in machine- & human- readable form14.& 支持跨平台 Linux/FreeBSD/MacOS实现环境:rhel6.1172.16.6.36rhel6.1172.16.6.39编译环境:安装gcc、openssl-devel、pcre-devel网络yum源配置参考链接: 下载并解压nginx-rtmp-module模块编译安装nginx[root@localhost&~]#&tar&xf&nginx-1.4.7.tar.gz
[root@localhost&~]#&cd&nginx-1.4.7
[root@localhost&~]#&./configure&--prefix=/usr&--sbin-path=/usr/sbin/nginx&--conf-path=/etc/nginx/nginx.conf&--error-log-path=/var/log/nginx/error.log&--http-log-path=/var/log/nginx/access.log&--pid-path=/var/run/nginx/nginx.pid&&--lock-path=/var/lock/nginx.lock&--user=nginx&--group=nginx&--with-http_ssl_module&--with-http_flv_module&--with-http_stub_status_module&--with-http_gzip_static_module&--http-client-body-temp-path=/var/tmp/nginx/client/&--http-proxy-temp-path=/var/tmp/nginx/proxy/&--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/&--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi&--http-scgi-temp-path=/var/tmp/nginx/scgi&--add-module=/root/nginx-rtmp-module-master
[root@localhost&~]#&make&&&&make&install在/etc/init.d/目录下为nginx提供服务器脚本并赋予其执行权限#!/bin/sh
#&nginx&-&this&script&starts&and&stops&the&nginx&daemon
#&chkconfig:&&&-&85&15
#&description:&&Nginx&is&an&HTTP(S)&server,&HTTP(S)&reverse&\
#&&&&&&&&&&&&&&&proxy&and&IMAP/POP3&proxy&server
#&processname:&nginx
#&config:&&&&&&/etc/nginx/nginx.conf
#&config:&&&&&&/etc/sysconfig/nginx
#&pidfile:&&&&&/var/run/nginx.pid
#&Source&function&library.
.&/etc/rc.d/init.d/functions
#&Source&networking&configuration.
.&/etc/sysconfig/network
#&Check&that&networking&is&up.
[&"$NETWORKING"&=&"no"&]&&&&exit&0
nginx="/usr/sbin/nginx"
prog=$(basename&$nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[&-f&/etc/sysconfig/nginx&]&&&&.&/etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs()&{
#&make&required&directories
user=`nginx&-V&2&&1&|&grep&"configure&arguments:"&|&sed&'s/[^*]*--user=\([^&]*\).*/\1/g'&-`
options=`$nginx&-V&2&&1&|&grep&'configure&arguments:'`
for&opt&in&$&do
if&[&`echo&$opt&|&grep&'.*-temp-path'`&];&then
value=`echo&$opt&|&cut&-d&"="&-f&2`
if&[&!&-d&"$value"&];&then
#&echo&"creating"&$value
mkdir&-p&$value&&&&chown&-R&$user&$value
[&-x&$nginx&]&||&exit&5
[&-f&$NGINX_CONF_FILE&]&||&exit&6
echo&-n&$"Starting&$prog:&"
daemon&$nginx&-c&$NGINX_CONF_FILE
[&$retval&-eq&0&]&&&&touch&$lockfile
return&$retval
echo&-n&$"Stopping&$prog:&"
killproc&$prog&-QUIT
[&$retval&-eq&0&]&&&&rm&-f&$lockfile
return&$retval
restart()&{
configtest&||&return&$?
reload()&{
configtest&||&return&$?
echo&-n&$"Reloading&$prog:&"
killproc&$nginx&-HUP
force_reload()&{
configtest()&{
$nginx&-t&-c&$NGINX_CONF_FILE
rh_status()&{
status&$prog
rh_status_q()&{
rh_status&&/dev/null&2&&1
case&"$1"&in
rh_status_q&&&&exit&0
rh_status_q&||&exit&0
restart|configtest)
rh_status_q&||&exit&7
force-reload)
force_reload
condrestart|try-restart)
rh_status_q&||&exit&0
echo&$"Usage:&$0&{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
esac[root@localhost&~]#&chmod&+x&nginx添加nginx至服务列表并设置其开机自动启动[root@localhost&~]#&chkconfig&--add&nginx
[root@localhost&~]#&chkconfig&nginx&on备份/etc/nginx配置文件,把nginx-rtmp-module-master/test/nginx.conf复制到/etc/nginx目录下[root@localhost&~]#&cd&/etc/nginx/
[root@localhost&nginx]#&mv&nginx.conf&nginx.conf.bak
[root@localhost&~]#&cd&nginx-rtmp-module-master/test/
[root@localhost&test]#&mv&nginx.conf&/etc/nginx/修改/etc/nginx/nginx.conf配置文件172.16.6.39上面的环境与172.16.6.36相同,只不过要在172.16.6.39上实现pull的功能下载一个.flv结尾的视频文件,使用ffmpeg模拟视频直播源进行测试play、push及pull功能是否实现使用ffmpeg模拟直播效果,ffmpeg下载链接进入ffmpeg-2.2.1-64bit-static目录下,执行如下命令[root@localhost&ffmpeg-2.2.1-64bit-static]#&./ffmpeg&-re&-i&~/2014.flv&-f&flv&rtmp://172.16.6.36/myapp/test1然后登录此链接验证能够播放: 验证pull功能是否实现验证push功能使用ffmpeg推流的时候,应该推至/mypush中,/mypush有流之后才能push至172.16.6.39的/myapp中,所以执行如下命令[root@localhost&ffmpeg-2.2.1-64bit-static]#&./ffmpeg&-re&-i&~/2014.flv&-f&flv&rtmp://172.16.6.36/mypush/test1刚开始学习nginx-rtmp,可能很多地方写的有出入。本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:未分类┆阅读(0)┆评论(0)
22:57:17 07:51:55 15:41:37 15:42:30

我要回帖

更多关于 nginx rtmp 直播人数 的文章

 

随机推荐