budebu 发表于 2022-3-11 11:22:25

简易直播间搭建

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

下载安装 Nginx

启动 /usr/local/src/nginx/sbin/nginx
重启 /usr/local/src/nginx/sbin/nginx –s reload
访问服务器出现一下界面则安装成功

配置Nginx的rtmp服务站点:

修改完成重启Nginx
推拉与拉流
在obs中设置推流,服务器和密码为你conf中配置的

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

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



budebu 发表于 2022-3-11 11:24:02

#安装 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

budebu 发表于 2022-3-11 11:24:48

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


budebu 发表于 2022-3-11 11:25:01

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;
}


budebu 发表于 2022-3-11 11:25:13

<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><!---->


页: [1]
查看完整版本: 简易直播间搭建