简易直播间搭建

搭建推流服务器

搭建基于rtmp协议的推流服务器
环境Linux centos 7.6 + Nginx
安装Nginx依赖库:

#安装 gcc gcc-c++
yum -y install gcc gcc-c++ 
    
#安装PCRE库
cd /usr/local/
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install
    
#安装openssl
cd /usr/local/ 
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz 
tar -zxvf openssl-1.0.1j.tar.gz 
cd openssl-1.0.1j
./config
make && make install

#安装zlib
cd /usr/local/
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
./configure
make && make install

下载 安装Nginx:

cd /usr/local/
yum -y install git
git clone https://github.com/arut/nginx-rtmp-module.git 

cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module  --add-module= 填写nginx-rtmp-module的位置  --with-openssl=<path> --with-http_ssl_module
make && make install 

启动 /usr/local/src/nginx/sbin/nginx

重启 /usr/local/src/nginx/sbin/nginx –s reload

访问服务器出现一下界面则安装成功

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2OJyQUyv-1592633342891)(C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20200620135825513.png)]

配置Nginx的rtmp服务站点:

vim  /usr/local/src/nginx/conf/nginx.conf

rtmp {
	server {
		listen 1935; #监听的端口
		chunk_size 4096;
		application hls {#rtmp推流请求路径 (切记路径错了会推不上流)
		live on; #开启实时	
		hls on; #开启hls
		hls_path /usr/local/src/nginx/html/masssa; #rtmp推流请求路径,文件存放路径
		hls_fragment 5s; #每个TS文件包含5秒的视频内容
		}
	}
}

#在server中添加

location /hls {
    # Serve HLS fragments
    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }
    root /home/wwwroot;
    add_header Cache-Control no-cache;
    #解决跨域问题
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS; 
}

修改完成重启Nginx

推拉与拉流

在obs中设置推流,服务器和密码为你conf中配置的

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JFvy1m1P-1592633342899)(C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20200620140525361.png)]

如果推流成功 右下角会变为绿色

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hlCA5jWr-1592633342903)(C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20200620140659925.png)]

在网页上使用video.js进行拉流

<video id="v_video"  height="450px" width="900px" class="video-js vjs-big-play-centered" controls preload="auto" data-setup='{}' poster="/img/2016671250.jpg">
        <source src="http://***.***.***.***/masssa/masssa.m3u8"
                type="application/x-mpegURL">

    </video><!---->

猜你喜欢

转载自blog.csdn.net/qq_43274298/article/details/106871629
今日推荐