流媒体服务器搭建详解

1 安装nginx 要增加nginx-rtmp-module的支持  下载好nginx-rtmp-module后解压,然后nginx安装时增加这个模块(--add-module)

./configure --prefix=/usr/local/nginx   --add-module=(nginx-rtmp-module路径)

2 安装完成后,打开Nginx的配置文件nginx.conf进行配置

 首先在里面加入rtmp的配置


rtmp {
  server {
       listen 1935;
       application video {
        live on;
      }
      application hls {
       live on;
       hls on;
       hls_path /tmp/hls;
      }
  }
}

然后,针对hls,还需要在http里面增加一个location配置

      

location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}

保存完配置文件后,启动nginx,通过netstat -ltn命令可以看到增加了一个1935端口的监听.8080是nginx默认的http监听端口.

  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动nginx  查看是否成功

3 安装ffmpeg 所需要源码包    yasm:http://yasm.tortall.net/Download.html

ffmpeg -re -i /app/test.mp4 -vcodec copy -vprofile baseline -ar 44100 -strict -2 -ac 1 -f flv -s 640x360 -q 10 rtmp://127.0.0.1:1935/hls/test4

原文地址:https://www.cnblogs.com/wxd0108/p/4813502.html