流媒体服务器部署

音视频开发基础-流媒体服务器

作者: yym439 时间: 2020-12-31

一、Nginx搭建流媒体服务器

1. 编译安装nginx服务

  • 下载nginx源码
  • 下载nginx-rtmp-module

  • 编译安装nginx:
      ./configure --add-module=/path/to/nginx-rtmp-module
      make
      make install
    
  • 安装nginx必要的库:
    • zlib
    • openssl

      yum install openssl openssl-devel

    • pcre
  • 启动停止nginx
      ./nginx
      ./nginx -s stop
      ./nginx -s reload
    
      ps -ef|grep nginx 查看nginx进程
    

    2. nginx配置文件,配置支持RTMP协议

nginx.conf文件:
rtmp{
    server{

        #指定RTMP服务端口
        listen 1935;
        chunk_size 4000;
        
        #指定流应用
        application live
        {
            live on;
            allow play all;
        }
    }
}
  • 启动nginx:
sudo ./sbin/nginx -c ./conf/nginx.conf

推拉流访问:rtmp://localhost/live/6666
ffmpeg:推流
fplay:拉流

3. nginx配置文件,配置支持HLS协议

rtmp{
    server{

        #指定RTMP服务端口
        listen 1935;
        chunk_size 4000;

        #指定流应用
        application live
        {
            #开启直播
            live on;
            #开启HLS直播
            hls on; 
            #配置HLS m3u8文件存放地址
            hls_path /usr/local/nginx/m3u8File;
            allow play all;
        }
    }
}

http{
    server {
        listen       80;
        location /live_hls {
            types{
                #m3u8 type设置
                application/vnd.apple.mpegurl m3u8;
                #ts分片文件设置
                video/mp2t ts;
            }
            #指向访问m3u8文件目录
            alias /usr/local/nginx/m3u8File;
            #禁止缓存
            add_header Cache-Control no-cache;
        }
    }
}

  • 推流:ffmpeg -i 1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.101.21:1935/live/6666

  • 拉流: http://192.168.101.21/live_hls/6666.m3u8

二、SRS流媒体服务器

SRS单机部署

SRS源码地址

SRS集群部署

部署多个源站和多个边缘,形成源站集群:

  • SRS边缘集群(拉流,访问边缘节点)
  • SRS源节点集群(推流,访问源节点)
  • 博客
  • github wiki