前言:有时候需要用到 OBS 推流给朋友直播些内容,但是现有的直播平台基本都需要实名认证,并且直播间处于公开状态,考虑到我有公网 IP,干脆自己搭建 Rtmp 服务好了。
1.所需工具与环境
系统:CentOS 7.2
nginx:http://nginx.org/en/download.html
nginx-rtmp-module:https://github.com/arut/nginx-rtmp-module
推流工具:OBS
2.编译安装Nginx与Rtmp模块
#依赖安装
yum install -y wget git
yum install -y pcre-devel zlib-devel openssl openssl-devel
yum -y install gcc gcc-c++ autoconf automake make
#编译安装Nginx与Rtmp模块
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
git clone https://github.com/arut/nginx-rtmp-module.git
cd /root/nginx-1.18.0
./configure --add-module=../nginx-rtmp-module --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#启动Nginx服务
cd /usr/local/ngnix
./sbin/nginx
#其它参数
#停止Nginx服务
-s stop
#重启Nginx服务
-s reload
安装完成后使用浏览器访问服务地址,如果你能看到Welcome to nginx!即代表安装成功
3.配置
#编辑Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#加入如下配置
rtmp {
server {
listen 1935; #监听端口,RTMP默认端口为1935
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /usr/local/nginx/html/hls;#视频流存放地址,此路径需要读写权限
hls_fragment 5s; #设置HLS片段长度
hls_playlist_length 15s;#设置HLS播放列表长度
hls_continuous on; #连续模式
hls_cleanup on; #对多余的切片进行删除
hls_nested on; #嵌套模式
}
}
}
#创建视频流存放文件夹
mkdir /usr/local/nginx/html/hls
chmod 777 /usr/local/nginx/html/hls
#重启Nginx服务
cd /usr/local/ngnix
./sbin/nginx -s reload
4.推流
使用OBS推流,串流密钥可自定义
5.拉流
版权属于:版权声明:本文为原创文章,版权归 Merciless Blog 所有,转载请注明出处!
本文链接:https://www.merciless.cn/archives/39.html
如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。