使用nginx搭建直播环境

直播流媒体协议容器

最近直播行业兴起,很多明星直播带货,有朋友思考过如何搭建一套直播环境吗,接下去教大家搭建一套直播环境。

nginx安装

安装相关依赖

  
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel* libaio libaio-devel bzr libtool

安装openssl

  
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz  
tar -zxvf openssl-1.0.2s.tar.gz  
cd /usr/local/src/openssl-1.0.2s  
./config --prefix=/usr/local/openssl  
make  
make install

安装pcre

  
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz  
tar -zxvf pcre-8.43.tar.gz  
cd /usr/local/src/pcre-8.43  
./configure --prefix=/usr/local/pcre  
make  
make install

安装zlib

  
wget https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz  
tar -zxvf zlib-1.2.11.tar.gz  
cd /usr/local/src/zlib-1.2.11  
./configure --prefix=/usr/local/zlib  
make  
make install

下载nginx-rtmp-module

nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

  
git clone https://github.com/arut/nginx-rtmp-module.git

安装nginx

  
wget http://nginx.org/download/nginx-1.19.1.tar.gz  
tar -zxvf nginx-1.19.1.tar.gz  
cd /usr/local/src/nginx-1.19.1  
./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/src/openssl --with-pcre=/usr/local/src/pcre --with-zlib=/usr/local/src/zlib --add-module=/usr/local/src/nginx-rtmp-module --with-http_ssl_module  
make  
make install

配置nginx

  
rtmp {  
 server {  
 listen 1935; #监听的端口  
 chunk_size 4096;   
 application hls { #rtmp推流请求路径   
 live on;   
 hls on;   
 hls_path /usr/share/nginx/html/hls;   
 hls_fragment 5s;   
 }   
 }   
}

hls_path需要可读可写的权限,创建hls目录并赋予权限

  
mkdir -p /usr/share/nginx/html/hls  
chmod -R 777 /usr/share/nginx/html/hls

修改http的server

  
server {   
 listen 81;   
    server_name  localhost;    
 location / {   
 root /usr/share/nginx/html;   
 index index.html index.htm;   
    }    
 error_page 500 502 503 504 /50x.html;   
 location = /50x.html {   
 root html;   
 }  
}

启动nginx

  
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

OBS推流

OBS(Open Broadcaster)是以互联网流媒体直播内容为目的免费和开放源码软件。下载链接:https://obsproject.com/zh-cn/download

picture.image

安装会有这样一个图片,打开我们需要创建一个场景,并且在这个场景下要配置一个流的来源(可以是窗口,如果选的是视频就会自动识别摄像头),接下来就是进行配置。

picture.image

配置中我们最关注的就是流的配置,因为我们是自已创建的流媒体服务器,所以要这样配置,设置完成就可以推流。

picture.image

拉流测试地址

我们可以使用下面的拉流测试地址,它针对各种协议都能测试拉流测试。但是图中几个地方要注意,由于我们使用的是rtmp协议,我们要选择这一栏,底下填写我们推流的地址和我们上面obs的设置里面配置的流的名称,然后点击start即可。地址:https://www.wowza.com/pricing/trial

picture.image

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
亿万用户下高可用融合直播的应用实践
直播融合 CDN 调度系统承担了公司内所有直播流量的接入工作,对高并发高带宽场景支持友好,有完善的体系进行容灾降级、质量优化、成本优化。本次演讲将带大家了解直播融合 CDN 调度系统的整体架构及在抖音上的应用。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论