42亮哥实操

centos7+nginx+rtmp+ffmpeg搭建流媒体服务器
1、安装wget命令

yum install wget -y

2、生成缓存

yum makecache

3、升级所有包

yum update -y

4、安装构建环境

yum install git gcc make pcre-devel openssl-devel -y

5、切换到/usr/local/目录

cd /usr/local/

6、下载nginx-rtmp-module

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

7、下载nginx并解压缩

wget http://nginx.org/download/nginx-1.15.0.tar.gz
tar -xf nginx-1.15.0.tar.gz

8、切换到/usr/local/nginx-1.15.0目录

cd /usr/local/nginx-1.15.0

9、编译

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make && make install

10.切换到/usr/local/nginx/sbin目录

cd /usr/local/nginx/sbin

11、启动nginx

/usr/local/nginx/sbin/nginx

12、关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

14、修改nginx的conf文件 配置rtmp端口 1935端口
增加内容:

rtmp{

  server{
   #监听端口
   listen 1935;
   chunk_size 5000;
   #hls配置
   application hls{
    live on;
    hls on;
    record off;
    hls_path /usr/local/nginx/html/hls;
    hls_fragment 3s;

   }

}

}
和
location /hls {  
        #server hls fragments  
        types{  
            application/vnd.apple.mpegurl m3u8;  
            video/mp2t ts;  
        }  
        alias /temp/hls;  
        expires -1;  
} 

15、停止服务

/usr/local/nginx/sbin/nginx -s stop

16、启动服务并加载配置文件

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

17、添加PC端_HLS播放器源代码文件:play.html
内容如下:需要更改直播视频源







PC HLS video




PC 端播放 HLS(.m3u8) 视频

借助 video.js 和 videojs-contrib-hls

由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域

18、浏览器输入10.0.0.61/play.html

你可能感兴趣的:(42亮哥实操)