ubuntu14.04 nginx-rtmp-module 配置
来源:互联网 发布:大淘客数据接口怎么用 编辑:程序博客网 时间:2024/06/01 21:50
00 ubuntu14.04 ecs 配置nginx-rtmp-module
参考:http://www.cnblogs.com/cocoajin/p/4353767.html
01 安装 nginx 和 nginx-rtmp 编译依赖工具
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
02 创建工作目录
mkdir ~/nginx-rtmpcd ~/nginx-rtmp
03 下载nginx 和nginx-rtmp源码
wget http://nginx.org/download/nginx-1.10.3.tar.gzwget https://github.com/arut/nginx-rtmp-module/archive/v1.1.10.tar.gz
04 解压
tar -zxvf nginx-1.10.3.tar.gztar -zxvf v1.1.10.tar.gz
05 切换目录
cd nginx-1.10.3
06 编译nginx-rtmp模块到nginx
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-1.1.10
07 编译安装
makesudo make install
08 安装nginx init脚本
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginxsudo chmod +x /etc/init.d/nginxsudo update-rc.d nginx defaults
09. 启动和停止nginx 服务,生成配置文件
sudo service nginx startsudo service nginx stop
10. 安装 FFmpeg
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-nextsudo apt-get updatesudo apt-get install ffmpeg
11. 配置 nginx-rtmp 服务器
打开 /usr/local/nginx/conf/nginx.conf
在末尾添加如下 配置
rtmp { server { listen 1936; # 1935已被占用 chunk_size 4096; application live { live on; record off; # 可以使用类似下面的语句转换视频格式为新的视频播放源 #exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/livep/$name; } application livep { live on; record off; } }}
12. 保存上面配置文件,然后重新启动nginx服务
sudo service nginx restart
13. 如果你使用了防火墙,请允许端口 tcp 1936
14 配置obs-studio
本测试中的obs-studio是自己从源码编译的,并且修改了图标等资源。
设置->串流->
串流类型->自定义流媒体服务器
URL rtmp://118.178.128.20:1936/live
流密钥:test01
点击[开始串流]按钮,开始串流,该按钮变成[停止串流]
15 使用vlc播放推流
本测试中的vlc是自己从源码编译的,并且修改了部分资源。
注意播放地址是:rtmp://118.178.128.20:1936/live/test01
不带文件名称后缀.m3u8
播放效果
16 android上 vlc播放
vlc下载地址:http://www.videolan.org/vlc/download-android.html
在网络地址输入:rtmp://118.178.128.20:1936/live/test01
播放效果如图:
17 nginx上配置对hls的支持
sudo vim /usr/local/nginx/conf/nginx.conf#在server里面加入如下内容server { listen 8080; location /hls { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root html; expires -1; } location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /usr/local/nginx/html/; } location /control { rtmp_control all; }}# 在rtmp里加入对hls的支持rtmp { server { listen 1936; chunk_size 4096; application live { live on; record off; #exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/livep/$name; } application livep { live on; record off; } application hls { live on; hls on; hls_path /usr/local/nginx/html/hls; hls_fragment 5s; } }
使用hls方式推流
推流URL:rtmp://118.178.128.20:1936/hls
流密钥:test01
18 在android上使用vlc播放
vlc地址栏输入:http://118.178.128.20:8080/hls/test01.m3u8
或者 rtmp://118.178.128.20:1936/hls/test01
可以直接播放。
19 在android上使用html5播放
用自己编译的chromium浏览器直接访问test01.m3u8可以正常播放。
http://118.178.128.20:8080/hls/test01.m3u8
小米note自带的浏览器不行。能正常显示,不能连续播放。
在服务端测试hls的html5播放方式,没有成功。
sudo vim /usr/local/nginx/html/html5.html<!DOCTYPE html><html><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>HLS Player</title></head><body><video poster="poster.png" height="720" width="1280" controls> <source src="/hls/test01.m3u8" type="application/vnd.apple.mpegurl" /> <p class="warning">Your browser does not support HTML5 video.</p></video></body></html>
然后在android上面用浏览器打开 http://118.178.128.20:8080/html5.html
无法正常播放。
20 浏览器播放
默认android或者苹果系统的浏览器可以播放。PC浏览器机会不支持hls方式。可以采用js库处理hls视频播放。jwplayer、flowplayer、HLSPlayer、video-js等库都可以处理。
20.01 jwplayer
把jwplayer的基本库文件上传到服务端/usr/local/nginx/html目录下。
jwplayer/jwplayer.flash.swf
jwplayer/jwplayer.html5.js
jwplayer/js
jwplayer/player-tools-license.txt
jwplayer/README.txt
编写使用jwplayer访问hls流的html文件。
sudo vim /usr/local/nginx/html/jwplayer.html<!DOCTYPE html><html><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>HLS Player</title> <script type="text/javascript" src="jwplayer/jwplayer.js"></script></head><body><div id="test01player">test01player....</div><script type="text/javascript">jwplayer("test01player").setup({ playlist: [{ sources: [{ file: 'rtmp://118.178.128.20:1936/hls/test01' },{ file: 'http://118.178.128.20:8080/hls/test01.m3u8' }] }], height: 360, primary: "flash", width: 640 });</script></body></html>
用pc客户端浏览器访问,IE能正常访问直播流。
可以看到直播时,右上角有JWPlayer透明字样,应该是非授权版本带的水印。
IE:
chrome:(安装了flash的ppapi插件)
firefox:(不安装flash插件,无法播放,安装后可以)
android浏览器没有开启flash支持的,不能播放jwplayer.html页面。
- ubuntu14.04 nginx-rtmp-module 配置
- ubuntu14.04 nginx-rtmp-module 配置
- nginx.conf中关于nginx-rtmp-module配置指令详解
- nginx-rtmp-module
- Nginx-Rtmp-Module命令
- Nginx-Rtmp-Module命令
- Nginx Rtmp Module
- ubuntu14.04 nginx配置
- fedora测试nginx-rtmp-module
- nginx-rtmp-module 权限控制
- nginx-rtmp-module 指令详解
- nginx rtmp module install compile
- nginx-rtmp-module安装笔记
- nginx+nginx-rtmp-module部署直播服务器
- 安装Nginx相关模块+nginx-rtmp-module
- ubuntu下安装nginx + nginx-rtmp-module
- nginx的nginx-rtmp-module应用
- Nginx RTMP 模块 nginx-rtmp-module 指令详解
- Universal-ImageLoader源码流程浅析之(一)--参数配置及主要参数说明
- 斯诺登的密码
- PHP数据库 mysql(三)
- codevs天梯 cantor表 找规律
- 问题六十四:怎么用C++实现二叉查找树(binary search tree)及其相关操作
- ubuntu14.04 nginx-rtmp-module 配置
- (转)Android中获取应用程序(包)的信息-----PackageManager的使用(一)
- Mysql多列索引——最左精确匹配
- python的reduce()函数
- C# Invoke and BeginInvoke
- java中的代理模式
- 学习NIO
- ACM之LeetCode中Median of Two Sorted Arrays
- 摸爬滚打DirectX11_day_11——三维粒子系统