nginx+rtmp+livePush实现视频转流推流
需要的工具:
一台电脑。
一个美美的心情。
centos环境
nginx(linux下部署)
rtmp板块(linux下部署)
livePush.war包(windows下部署)
OBS(测试转流工具)
VLC(测试拉流工具)
———————–我的分割线——————–
先安装nginx+rtmp板块( nginx-rtmp-module-maste),没什么好说的。
1、wget http://nginx.org/download/nginx-1.8.0.tar.gz(假如连接没有或者者更换的,移步 nginx下载 )选择你喜欢的版本
2、tar -zxvf nginx-1.8.0.tar.gz
3、 cd nginx-1.8.0
4、./configure –prefix=/usr/local/src/nginx –add-module=../nginx-rtmp-module –with-http_ssl_module ./configure –prefix=/usr/local/src/nginx –add-module=../nginx-rtmp-module-maste –with-http_ssl_module
5、make && make install
中间假如少什么板块,就去装。
而后启动nginx。浏览器中可以打开就好。
可可以回有这样的一个问题 nginx: [emerg] unknown directive "rtmp"
网上说法很多,都是说没有安装rtmp板块,但是我之前是安装好了的。后来rtmp有多种。肯定要选择源码类的哦。(nginx-rtmp-module-maste)
直接上nginx配置文件。
[java] view plain copy
##################RTMP服务#################
rtmp {
server {
listen 1935;
chunk_size 4096;
application video {
play /usr/local/data/video;
}
application live{ #第一处增加的直播字段
live on;#直播模式
hls on; #这个参数把直播服务器改造成实时回放服务器。
wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。
hls_path /tmp/hls; #切片视频文件存放位置。
hls_fragment 10s; #每个视频切片的时长。
hls_playlist_length 60s; #总共能回看的事件,这里设置的是1分钟。
hls_continuous on; #连续模式。
hls_cleanup on; #对多余的切片进行删除。
hls_nested on; #嵌套模式。
}
}
}
####启动浏览器查看http://localhost:80/stat
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /stat {
#第二处增加的location字段。
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
#第二处增加的location字段。
root /usr/nginx/nginx-rtmp-module-master/;
}
location /live { #这里也是需要增加的字段。
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /opt/video/hls;
expires -1;
add_header Cache-Control no-cache;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
这个配置文件直接使用就ok了。
而后创立文件夹 /tmp/hls/
给hls赋权限。chmod 777 /tmp/hls
我这里设置的是最高权限哦。
至此到这里,nginx+rtmp就已经搞定了。
现在启动nginx
1、cd /usr/local/nginx/sbin/
2、./nginx -c /usr/nginx/nginx-1.8.1/conf/nginx.conf
再浏览器中打开就ip,看看nginx能否成功启动成功
打开OBS软件,设置一下
能再/tmp/hls下看到有一个名叫app的文件夹。我们看一下内容。
这里有数据就ok了。
而后下一步。
用VLC拉流。可以成功的获取到视频才算是成功的嘛。
能看到,这里已经可以成功的拉起到刚才推送的视频了。到此为止,已经满足一部分的看官了。
但是呢。我们需要继续往下走哦。
用livePush来代替OBS,毕竟实际项目用,没办法用OBS。他只可以推一个哦。
拿到livePush的war包,再tomcat下启动,访问网址就出现下面的页面
这个应使用名就是你推的流的名。
视频源是从网上随意找了个。发布地址应该指向到nginx上。而后点击发布。生成一个播放地址,拿这个播放地址去刚才的VLC中去拉流就ok了。
到此为止,已经结束咯。哦。对了,war包。传送门在此 失效请联络我。
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » nginx+rtmp+livePush实现视频转流推流