场景: 在页面上选择摄像头,弹出窗口展示摄像头的监控视频
思路:在点选摄像头时根据选中的摄像头id,去数据库中读取rtsp地址,调用ffmpeg命令转换成hls格式,返回hls地址给前端,通过videojs进行播放
首先来搭建环境
环境说明:
1. 视频服务器(linux,java8,nginx 1.16.1)
2. 开发机 win10 ,影响不大
服务搭建部分参考
搭建视频服务需要用到nginx的nginx-rtmp-module
安装nginx
- 安装nginx
wget和unzip通过yum安装
yum install wget
yum install unzip
# mkdir module // 创建下载module的文件夹
# cd module
# wget https://github.com/arut/nginx-rtmp-module/archive/master.zip //下载模块
# unzip master.zip // 解压
- 编译安装nginx
# yum -y install pcre-devel openssl openssl-devel //安装依赖
# wget http://nginx.org/download/nginx-1.12.2.tar.gz //下载nginx包
# tar -zxvf nginx-1.12.2.tar.gz
# ./configure --prefix=/opt/nginx-1.9.5 --add-module=/root/module/nginx-rtmp-module-master --with-http_ssl_module // 编译安装nginx到/opt/nginx-1.9.5
# make
# make install
- 修改nginx配置文件,添加如下内容并重新载入配置文件
rtmp{
server {
listen 1935;
application myapp{
live on;
record off;
allow play all;
}
application hls{
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 10s;
hls_playlist_length 3s;
record off;
}
}
}
注意:rtmp协议和http协议不同,需要写在http外面
由于使用hls播放,需要在http中添加支持, 因为服务在8002端口 所以在ngin