搭建 RTMP 服务器

主要步骤

  1. 下载 nginx 的 rtmp 模块
  2. 编译nginx,带 hls,rtmp
  3. 配置 nginx.conf,设置 rtmp 的推流文件路径,开启推拉流

具体步骤

1、路径:/usr/local/src

2、下载nginx-rtmp-module (我这里的目录是在/usr/local/src/下面)

   cd /usr/local/src

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

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

   ( 如果没有git进行安装,yum install git)

3、nginx版本及安装
下载 nginx-1.8.0.tar.gz 解压并安装

    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  --add-module=../nginx-rtmp-module  --with-http_ssl_module    

    make && make install 

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

FAQ

./configure: error: the HTTP rewrite module requires the PCRE library.………………………………
安装pcre-devel与openssl-devel解决问题
yum -y install pcre-devel openssl openssl-devel

这里我下载并安装了 pcre-8.12.tar.gz 和 openssl-1.0.1c.tar.gz ,并没有出现上面的错误。

docker 搭建版

sudo docker pull tiangolo/nginx-rtmp
sudo docker run -d -p 1935:1935 --name nginx-rtmp tiangolo/nginx-rtmp

安装&运行

推拉流测试
ffmpeg -re -i "http://test-pub.iamlj.com/mp4/720p/2%E7%A7%91%E7%9B%AE2-3%E5%8F%B7%E9%81%93%E8%AE%B2%E8%A7%A3.mp4" -acodec copy -vcodec copy -an -f flv -y "rtmp://10.211.55.4/live/123"

ffplay rtmp://10.211.55.4/live/123

参考

nginx + rtmp 搭建流媒体服务器
https://www.cnblogs.com/monjeo/p/8492357.html
【docker 版】大概是最简单的 rtmp 推流服务器搭建方法
https://www.jianshu.com/p/4b6f442c8526

Go!!!
原文地址:https://www.cnblogs.com/shliujing/p/da-jian-RTMP-fu-wu-qi.html