centos7+nginx+rtmp+ffmpeg搭建流媒體服務器
1院塞、安裝wget命令
yum install wget -y
2瓜客、生成緩存
yum makecache
3、升級所有包
yum update -y
4驯遇、安裝構建環(huán)境
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{
#監(jiān)聽端口
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
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>
18兴溜、瀏覽器輸入10.0.0.61/play.html