文章地址:http://blog.csdn.net/zph1234/article/details/52846223

本次搭建流媒体使用的环境是centos 7.0+nginx;让我们一起开始奇妙的流媒体之旅吧!

1、下载nginx-rtmp-module:

nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

使用命令:

git clone https://github.com/arut/nginx-rtmp-module.git  
 

将nginx-rtmp-module下载到linux中。

2、安装nginx:

nginx的官方网站为:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install

注:这里的Nginx不需要修改路径名称。

本次默认安装目录为:/root, add-module为下载的nginx-rtmp-module文件路径。

安装时候可能会报错没有安装openssl,需要执行命令:

yum -y install openssl openssl-devel  
 

3、修改nginx配置文件:

vi /usr/local/nginx/conf/nginx.conf  

加入以下内容:

rtmp {    

    server {    

        listen 1935;  #监听的端口  

        chunk_size 4000;    

        application hls {  #rtmp推流请求路径
live on;
hls on;
hls_path /usr/share/nginx/html/hls;
hls_fragment 5s;
}
}
}

hls_path需要可读可写的权限。

修改http中的server模块:

server {
listen 81;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
 

当然了,root可以跟据自己的需求来改的。然后启动nginx:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

关于更多rtmp的参数可以参考:https://github.com/arut/nginx-rtmp-module/wiki

如果本机看不到虚拟机正确的Nginx访问页面,需要按照如下方式处理一下:

[root@localhost html]# /sbin/iptables -I INPUT -p tcp --dport 81 -j ACCEPT
[root@localhost html]# /etc/init.d/iptables save
[root@localhost html]# /etc/init.d/iptables restart

你还可以修改服务器监听的端口和服务器名称:

server {
listen 1990;
server_name 172.16.20.10; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

4、开始推流

做好以上的配置后,就可以开始推流了,我们可以使用obs(或者访问http://www.obsapp.net/)来推流。(截图同款请到http://www.pc6.com/mac/410309.html)

在设置->串流 中填写信息:URL为 rtmp://xxx:1935/hls,xxx为你的服务器的IP地址,hls是用来存放流媒体的。

秘钥可以随便填写一个,用来播放的时候识别播放哪个流媒体的,例如填写test等。

填写完毕后,点击开始串流,就说明我们的流媒体服务器搭建成功了。

5、观看直播(拉流)

观看直播就比较简单了,可以简单的使用h5的vedio标签就可以观看了。

可以访问http://xxx:81/hls/mystream.m3u8来观看直播,其中xxx为你的服务器IP地址,或者使用

<video>
<source src="http://xxx:81/hls/test.m3u8"/>
<p class="warning">Your browser does not support HTML5 video.</p>
</video>

  

同上, xxx写的是你服务器IP地址。

然后使用手机访问这个网站就能够观看直播了。延迟大概在20S左右。

(在IOS的safari浏览器中可以正常观看)

写在最后

为什么延迟 那么高呢?这是因为服务器将视频流切断成一个个小的以.ts结尾的文件。

(hls文件夹内容。即推流到该文件夹了)

而我们访问的是.m3u8文件,这个文件内容是将一个个ts文件串联起来的,这就达到了一个播放的效果,所以看起来会有很大的延迟。

(m3u8文件内容)

如果降低延迟也不是没有方法,可以设置切片生成的大小以及访问的速度,但是这样大大增加了服务器的压力。

当然,我们也可以用rtmp拉流工具(VLC等)来看该直播,延迟大概在2-5S左右,拉流地址与推流地址一致。

CentOS搭建nginx与nginx-rtmp-module搭建流媒体服务器的更多相关文章

  1. nginx搭建http和rtmp协议的流媒体服务器

    nginx搭建http和rtmp协议的流媒体服务器 时间:2013-09-23 23:52来源:佚名 作者:本站 举报 点击:232次 实验目的:让Nginx支持flv和mp4格式文件,同时支持Rtm ...

  2. 利用Nginx搭建http和rtmp协议的流媒体服务器[转]

    利用nginx搭建http和rtmp协议的流媒体服务器 实验目的:让Nginx支持flv和mp4格式文件,同时支持Rtmp协议:同时打开rtmp的hls功能资料:HTTPLive Streaming( ...

  3. rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加

    关键词:Nignx(http服务器):rtmp,hls(流媒体服务) 前言:感谢开源,感谢战斗民族.现在在做流媒体服务的一些工作,流媒体服务器搭建的网上教程多入牛毛,但是细细查看,发现很多同志贴上来的 ...

  4. 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器(二)

    前言 Nginx-rtmp-module插件针对RTMP协议中一些命令,实现了事件通知和exec外部脚本处理.这里我通过一个简单的SpringBoot项目和Python代码,快速搭建一个HTTP服务来 ...

  5. nginx搭建支持http和rtmp协议的流媒体server之中的一个

    实验目的:让Nginx支持flv和mp4格式文件,支持RTMP协议的直播和点播:同一时候打开RTMP的HLS功能 ​资料:HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的 ...

  6. 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器

    上篇文章是基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案,有兴趣的朋友可以查看. Nginx及nginx-rtmp-module安装 新建目录 mkdir /usr/loc ...

  7. Nginx系列1.2:nginx-rtmp流媒体服务器添加权限认证(推流权限和播放权限)

    用到的工具:OBS Studio(推流).nginx-rtmp流媒体服务器.VLC(拉取流播放) Nginx系列1:ubuntu16.04编译出适合自己的nginx服务器 Nginx系列1.1:ubu ...

  8. nginx::基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器

    待续 ffmpeg -re -i "/home/bk/hello.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 4 ...

  9. 利用Nginx搭建http和rtmp协议的流媒体服务器

    http://www.linuxidc.com/Linux/2013-02/79118.htm

  10. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器[转]

    转 :http://redstarofsleep.iteye.com/blog/2123752 Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个n ...

随机推荐

  1. [CF1063F]String Journey

    题意:定义长度为$k$的journey为一个字符串序列$t_{1\cdots k}$,对$\forall i\gt1$满足$t_i$是$t_{i-1}$的严格子串,定义字符串$s$上的journey为 ...

  2. Java高级架构师(一)第36节:Nginx的反向代理模块

    理解Http正向代理和Http反向代理的区别 Proxy模块,最常用的proxy_pass, Proxy_pass 可以转发请求到其他的浏览器.  # Nginx强项在于负载.反向.动静分离 #

  3. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  4. 迁移11g Rac中OCR和VOTEDISK

    环境:OEL+oracle rac 11.2.0.3 迁移描述:将ocr和votedisk从+DATE上迁移到+OCR_VOTE上: 操作如下: [root@ora2 ~]$ /u01/app/11. ...

  5. NHibernate 操作视图 第十三篇

    在NHibernate中,可以把视图当表一样操作,只需要记住一点就是,视图是只读的,因此映射实体的setter应该改为protected. 新建一个视图如下: 持久化类: public class C ...

  6. 云计算与OpenStack(虚拟机Nova篇)

    <云计算与OpenStack(虚拟机Nova篇)> 基本信息 作者: 伯龙 程志鹏 张杰 出版社:电子工业出版社 ISBN:9787121201202 上架时间:2013-8-5 出版日期 ...

  7. [Linux] Linux命令之pstree - 以树状图显示进程间的关系

    转载自: http://codingstandards.iteye.com/blog/842156 pstree命令以树状图显示进程间的关系(display a tree of processes). ...

  8. --secure-file-priv option so it cannot execute this statement

    MYSQL导入数据出现The MySQL server is running with the --secure-file-priv option so it cannot execute this ...

  9. 如何在sublime3项目设置中设置python模块的搜索路径?ImportError: No module named *的解决办法

    问题:之前使用pycharm,用的挺溜,但是电脑配置实在不争气,pycharm启动久了,耗去大量内存,导致运行起来越来越慢,于是转向使用sublime text. 把项目从pycharm切换到subl ...

  10. JS,jquery动态向已经存在的css文件中添加class样式

    $("h1,h2,p").addClass("blue") $(".class")addClass("class_name&quo ...