基于rtmp+nginx流媒体服务器的搭建

一、准备工作

(1)下载nginx ,参加官网

  (2)   下载nginx-rtmp-module 参加github地址 https://github.com/arut/nginx-rtmp-module

  (3)    把下载的nginx压缩包和nginx-rtmp-modle压缩包从windows传到centos的soft(这个文件夹可以自己指定)文件夹中。

(4)准备nginx安装的一些依赖库,在centos的命令行输入以下命令:

          yum install gcc-c++(安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc)

         yum install -y pcre pcre-devel(nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库)

         yum install -y zlib zlib-devel (nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库)

        yum install -y openssl openssl-devel (nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库)

(5) 执行cd /soft 命令进入下载文件,然后使用解压命令将两个压缩包解压如图所示

二、安装工作

(1)然后进入nginx-1.8.1文件夹,执行以下命令

        ./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module --with-http_ssl_module

        make && make install

2)执行vim /usr/local/nginx/conf/nginx.conf命令编辑nginx.conf文件,移到文件的最末端,如何添加如下配置

rtmp {
    server {
            listen 1935;
            chunk_size 4096;
            application live {
                    live on;
                    record off;
        hls on;  
                    hls_path /usr/share/nginx/html/hls;  
                    hls_fragment 2s;
                    exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name;
            }
    }
}

(3) 创建传输流需要的文件夹,执行命令 mkdir -p /usr/share/nginx/html/hls

 (4) 执行 cd /usr/local/nginx/sbin 命令进入到nginx安装目录,然后执行以下命令就能启动nginx

(5)开启端口(80、1935)权限,如果不开启,主机将访问不到服务器,执行命令如下

/sbin/iptables -I INPUT -p tcp --dport 1935 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT  
/etc/init.d/iptables save  
/etc/init.d/iptables restart
 

三、流媒体测试

使用obs软件推流:

rtmp://192.168.1.163(这里填写你的nginx服务器IP)/live/test

使用vlc软件拉流:

rtmp://192.168.1.163/live/test

4、感谢

感谢以下博主的博客:

u011298145的博客 博文地址 https://blog.csdn.net/u011298145/article/details/78883598

弗兰-随风小欢的博客 博文地址 https://blog.csdn.net/qq_32575047/article/details/78269413

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值