ubuntu14.04 nginx-rtmp-module 配置
2017-02-04 19:22
573 查看
00 ubuntu14.04 ecs 配置nginx-rtmp-module
参考:http://www.cnblogs.com/cocoajin/p/4353767.html01 安装 nginx 和 nginx-rtmp 编译依赖工具
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
02 创建工作目录
mkdir ~/nginx-rtmp cd ~/nginx-rtmp
03 下载nginx 和nginx-rtmp源码
wget http://nginx.org/download/nginx-1.10.3.tar.gz wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.10.tar.gz[/code]04 解压
tar -zxvf nginx-1.10.3.tar.gz tar -zxvf v1.1.10.tar.gz05 切换目录
cd nginx-1.10.306 编译nginx-rtmp模块到nginx
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-1.1.1007 编译安装
make sudo make install08 安装nginx init脚本
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx sudo chmod +x /etc/init.d/nginx sudo update-rc.d nginx defaults09. 启动和停止nginx 服务,生成配置文件
sudo service nginx start sudo service nginx stop10. 安装 FFmpeg
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next sudo apt-get update sudo apt-get install ffmpeg11. 配置 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 restart13. 如果你使用了防火墙,请允许端口 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
流密钥:test0118 在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与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加
- 在Ubuntu 14.04 上安装 Nginx-RTMP 流媒体服务器,并Android真机测试
- nginx.conf中关于nginx-rtmp-module配置指令详解
- Ubuntu 14.04 配置 Nginx, MySQL and PHP 环境
- ubuntu下安装nginx + nginx-rtmp-module
- Ubuntu14.04在线安装配置Nginx
- 阿里云ECS环境配置-Ubuntu14.04+php7.0+mysql+nginx
- Ubuntu14.04 下安装配置php5和nginx问题解决
- Setup Nginx-RTMP on Ubuntu 14.04
- 在Ubuntu14.04上配置nginx和fastcgi程序
- rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加
- Ubuntu 14.04 配置php+nginx+mysql
- ubuntu14.04安装与配置nginx服务器
- Nginx 在 ubuntu 14.04上的安装配置。
- Ubuntu 14.04 配置 Nginx + uWSGI 托管 virtualenv 下 Flask 应用的一点注意事项
- Ubuntu14.04配置nginx开机自启动项
- Ubuntu下使用nginx和nginx-rtmp-module搭建流媒体服务器的正确姿势
- nginx.conf中关于nginx-rtmp-module配置指令详解