title: nginx+rtmp+微信小程序直播
date: 2018-12-11 10:14:49
tags: 直播
Nginx+rtmp实现直播
本文是Mac环境下的安装配置
1.安装Nginx及rtmp模块
brew tap denji/nginx
brew install nginx-full --with-rtmp-module
相关文章请参考:https://denji.github.io/homebrew-nginx/
2.配置Nginx
找到nginx.conf进行修改
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
... #省略默认代码
}
#RTMP服务
rtmp {
server{
listen 1935; #服务端口
#点播服务(播放视频)如果只是直播这里可以不要
application vod {
play /Users/lyj/prj/rtmp/vod; #视频文件存放位置。
}
application live{
live on; #直播
#回看功能 视频切片变成ts文件
#hls on; #这个参数把直播服务器改造成实时回放服务器。
#wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。
#hls_path /Users/lyj/prj/rtmp/hls; #切片视频文件存放位置。
#hls_fragment 10s; #每个视频切片的时长。
#hls_playlist_length 60s; #总共可以回看的事件,这里设置的是1分钟。
#hls_continuous on; #连续模式。
#hls_cleanup on; #对多余的切片进行删除。
#hls_nested on; #嵌套模式。
}
}
}
更详细的配置请参考:https://github.com/sergey-dryabzhinsky/nginx-rtmp-module
3.微信小程序直播设置
参考文章:
推流:https://developers.weixin.qq.com/miniprogram/dev/component/live-pusher.html
播放:https://developers.weixin.qq.com/miniprogram/dev/component/live-player.html
<live-pusher id="pusher"
url="rtmp://192.168.31.94:1935/live/123"
mode="FHD"
autopush ="false"
bindstatechange="statechange"
beauty = "9"
whiteness="5"
min-bitrate="500"
max-bitrate="1500"
style="height: 225px;"
/>
这里讲解一下url这一项,rtmp表示协议和http意思一样,192.168.31.94是你nginx所在ip地址,1935是上面我们配置的rtmp的端口,live是上面我们配置的application live,123表示主播的房间号,播放端和推流端代码类似。
直播测试网址:https://www.wowza.com/testplayers 可以测试推流是否成功
下图是我的小程序直播效果图


网友评论