1、安装wget命令
yum install wget -y
2、生成缓存
yum makecache
3、更新yum源
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
13、浏览器网址栏输入虚拟机的IP,出现如图画面,说明服务启动成功。
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
内容如下:需要更改直播视频源
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PC HLS video</title>
<link href="http://cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css" rel="stylesheet">
</head>
<body>
<h1>PC 端播放 HLS(<code>.m3u8</code>) 视频</h1>
<p>借助 video.js 和 videojs-contrib-hls</p>
<p>由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域</p>
<video id="hls-video" width="300" height="200" class="video-js vjs-default-skin"
playsinline webkit-playsinline
autoplay controls preload="auto"
x-webkit-airplay="true" x5-video-player-fullscreen="true" x5-video-player-typ="h5">
<!-- 直播的视频源 -->
<source src="http://live.zzbtv.com:80/live/live123/800K/tzwj_video.m3u8" type="application/x-mpegURL">
<!-- 点播的视频源 -->
<!--<source src="http://devstreaming.apple.com/videos/wwdc/2015/413eflf3lrh1tyo/413/hls_vod_mvp.m3u8" type="application/x-mpegURL">-->
</video>
<script src="http://cdn.bootcss.com/video.js/6.0.0-RC.5/video.js"></script>
<!-- PC 端浏览器不支持播放 hls 文件(m3u8), 需要 videojs-contrib-hls 来给我们解码 -->
<script src="http://cdn.bootcss.com/videojs-contrib-hls/5.3.3/videojs-contrib-hls.js"></script>
<script>
// XMLHttpRequest cannot load http://xxx/video.m3u8\. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.198.98:8000' is therefore not allowed access.
// 由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域
var player = videojs('hls-video');
player.play();
</script>
</body>
</html>