当前位置:网站首页>技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
2022-06-23 12:17:00 【InfoQ】
介绍
应用场景
- 支持浏览器无插件播放摄像头视频。
- 支持摄像机、平台、NVR等设备接入。 支持国标级联。
- 支持rtsp/rtmp等视频流转发到国标平台。
- 支持rtsp/rtmp等推流转发到国标平台。
服务部署
ZLMediaKit部署
## 准备环境
[[email protected] artc]# yum install -y epel-release
## gcc和yasm需要高版本 小编用的是gcc4.8.5 yasm1.2.0
[[email protected] artc]# yum -y install yasm gcc*
[[email protected] artc]# yum -y install openssl-devel SDL-devel
## 编译安装cmake 3.8.2
[[email protected] ~]# cd /home/artc
[[email protected] artc]# wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
[[email protected] artc]# tar zxvf cmake-3.8.2.tar.gz
[[email protected] artc]# cd cmake-3.8.2
[[email protected] cmake-3.8.2]# ./bootstrap
[[email protected] cmake-3.8.2]# gmake
[[email protected] cmake-3.8.2]# gmake install
## 国内库比较快
[[email protected] ~]# cd /usr/local/
[[email protected] local]# git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
[[email protected] local]# cd ZLMediaKit
#千万不要忘记执行这句命令
[[email protected] ZLMediaKit]# git submodule update --init
## 编译安装
[[email protected] ZLMediaKit]# mkdir build
[[email protected] ZLMediaKit]# cmake .
[[email protected] ZLMediaKit]# make -j4
## ZLMediaKit服务目录
[[email protected] ZLMediaKit]# cd release/linux/Debug
配置文件[general]
mediaServerId=12345678 ##后面和WVP-PRO对接
[hook]
admin_params=secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc ##后面和WVP-PRO对接
## 程序启动
[[email protected] Debug]# ./MediaServer ## 前台启动
[[email protected] Debug]# ./MediaServer -d & ## 后台启动
## 软连接
[[email protected] Debug]# ln -sf /home/ZLMediaKit/release/linux/Debug/MediaServer /usr/bin/
WVP-PRO部署
项目运行依赖redis、jdk1.8,打包依赖git、maven、nodejs、npm。Redis部署
## 下载epel仓库
[[email protected] ~]# yum install epel-release -y
## 下载redis数据库
[[email protected] ~]# yum install redis -y
## 启动redis和设置开启自启动
[[email protected] ~]# systemctl start redis
[[email protected] ~]# systemctl enable redis
## 设置redis 远程连接和密码 (如果都在同一台机器上 不用这一步)
[[email protected] ~]# vim /etc/redis.conf
注释 #bind 127.0.0.1
修改 protected-mode no
修改 daemonize yes
修改 requirepass 123456
## 关闭防火墙或者开放6379端口
[[email protected] ~]# systemctl stop firewalld //关闭防火墙
[[email protected] ~]# firewall-cmd --zone=public --add-port=6379/tcp --permanent //开放端口
[[email protected] ~]# firewall-cmd --reload //开放端口后 需要更新一下
## 重启redis
[[email protected] ~]# systemctl restart redis
MySQL部署
[[email protected] ~]# yum -y install mariadb mariadb-server
[[email protected] ~]# systemctl enable mariadb
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# mysql -uroot
mysql> set password = password('123456');
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; //设置mysql外网连接密码
mysql> flush privileges;
JDK部署
[[email protected] ~]# tar zxvf jdk-8u121-linux-x64.tar.gz
[[email protected] ~]# mv jdk1.8.0_121/ /usr/local/jdk
[[email protected] ~]# vim /etc/profile
##末尾添加
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
[[email protected] ~]# source /etc/profile
[[email protected] ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Maven部署
[[email protected] ~]# tar zxvf apache-maven-3.5.0-bin.tar.gz
[[email protected] ~]# mv apache-maven-3.5.0 /usr/local/maven
[[email protected] ~]# vim /etc/profile
##末尾添加
export MAVEN_HOME=/usr/local/maven
export PATH=$MAVEN_HOME/bin:$PATH
[[email protected] ~]# source /etc/profile
[[email protected] ~]# mvn -version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /usr/local/maven
编译WVP-PRO
## 安装依赖
[[email protected] ~]# yum -y install git nodejs npm
## 下载源码
[[email protected] ~]# cd /usr/local
[[email protected] local]# git clone https://gitee.com/pan648540858/wvp-GB28181-pro.git
## 编译静态页面
[[email protected] ~]# cd /usr/local/wvp-GB28181-pro/web_src/
[[email protected] web_src]# npm --registry=https://registry.npm.taobao.org install
[[email protected] web_src]# npm run build
## 打包项目, 生成可执行jar
[[email protected] web_src]# cd ..
[[email protected] wvp-GB28181-pro]# mvn package
## 编译完成后在target目录下出现wvp-pro-x.x-xxxxxxxx.jar
## 导入MySQL文件
[[email protected] ~]# cd /usr/local/wvp-GB28181-pro/sql
[[email protected] sql]# mysql -uroot -p123456
MariaDB [(none)]> create database wvp;
MariaDB [(none)]> use wvp;
MariaDB [(none)]> source mysql.sql ## 可能会出现字节错误 将mysql.sql里面的255字节修改小点
## 配置文件修改
[[email protected] wvp-GB28181-pro]# mv src/main/resources/application-dev.yml target/application.yml
[[email protected] wvp-GB28181-pro]# vim target/application.yml
spring:
# [可选]上传文件大小限制
servlet:
multipart:
max-file-size: 10MB
max-request-size: 100MB
# REDIS数据库配置
redis:
# [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1
host: 127.0.0.1
# [必须修改] 端口号
port: 6379
# [可选] 数据库 DB
database: 6
# [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
password:
# [可选] 超时时间
timeout: 10000
# mysql数据源
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/wvp?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true
username: root
password: 123456
druid:
initialSize: 10 # 连接池初始化连接数
maxActive: 200 # 连接池最大连接数
minIdle: 5 # 连接池最小空闲连接数
maxWait: 60000 # 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
keepAlive: true # 连接池中的minIdle数量以内的连接,空闲时间超过minEvictableIdleTimeMillis,则会执行keepAlive操作。
validationQuery: select 1 # 检测连接是否有效sql,要求是查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。
testWhileIdle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
testOnBorrow: false # 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
testOnReturn: false # 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
poolPreparedStatements: false # 是否開啟PSCache,並且指定每個連線上PSCache的大小
timeBetweenEvictionRunsMillis: 60000 # 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒
minEvictableIdleTimeMillis: 300000 # 配置一個連線在池中最小生存的時間,單位是毫秒
filters: stat,wall,slf4j # 配置监控统计拦截的filters,监控统计用的filter:sta, 日志用的filter:log4j, 防御sql注入的filter:wall
useGlobalDataSourceStat: true # 合并多个DruidDataSource的监控数据
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=1000
#stat-view-servlet.url-pattern: /admin/druid/*
#[可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口
server:
port: 18080
# 作为28181服务器的配置
sip:
# [必须修改] 本机的IP
ip: 192.168.1.13
# [可选] 28181服务监听的端口
port: 5060
# 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007)
# 后两位为行业编码,定义参照附录D.3
# 3701020049标识山东济南历下区 信息行业接入
# [可选]
domain: 4401020049
# [可选]
id: 44010200492000000001
# [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验
password: admin123
#zlm 默认服务器配置
media:
id: 12345678 ##ZLMediaKit配置的ID
# [必须修改] zlm服务器的内网IP
ip: 192.168.1.13
# [必须修改] zlm服务器的http.port
http-port: 80
# [可选] zlm服务器的hook.admin_params=secret
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
rtp:
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
enable: true
# [可选] 在此范围内选择端口用于媒体流传输, 必须提前在zlm上配置该属性,不然自动配置此属性可能不成功
port-range: 30000,30500 # 端口范围
# [可选] 国标级联在此范围内选择端口发送媒体流,
send-port-range: 30000,30500 # 端口范围
# 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载, 0 表示不使用
record-assist-port: 18081
# [可选] 日志配置, 一般不需要改
logging:
config: classpath:logback-spring-local.xml
# 版本信息, 不需修改
version:
version: "@[email protected]"
description: "@[email protected]"
artifact-id: "@[email protected]"
## 启动WVP
[[email protected] wvp-GB28181-pro]# cd target
[[email protected] target]# java -jar wvp-pro-2.3.1-06151618.jar
## 访问管理页面
http://192.168.1.13:18080
默认用户名:admin, 密码:admin
点击控制台--》媒体服务器配置--》有相关信息即可
自启动脚本[[email protected] target]# cat wvp-pro.sh
#!/bin/sh
##
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\aJnice: unable to locate functions lib. Cannot continue."
exit 0
fi
ulimit -n 65000
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
## jar文件名称
export JAVA_HOME=/usr/lib/jvm/java-1.8.0
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
JAR_HOME=/usr/local/wvp-GB28181-pro/target
JAR_NAME=wvp-pro-2.3.1-06151618.jar
## 过滤pid进程号
wvp_pro=`ps -ef|grep $JAR_NAME | grep -v grep | grep -v kill | awk '{print $2}'`
#---------------------------------------------------------------------------
# START
#---------------------------------------------------------------------------
Start()
{
if [ $tpid ]; then
echo -n "wvp_pro process [${prog}] already running"
echo_failure
echo
return 1
fi
if [ ! -f ${JAR_HOME}/${JAR_NAME} ]; then
echo -n "wvp_pro binary [${prog}] not found."
echo_failure
echo
return 1
fi
echo -n "starting service (wvp_pro): "
cd ${JAR_HOME}
nohup java -jar ${JAR_HOME}/${JAR_NAME} > /dev/null 2>&1 &
retval=$?
if [ ${retval} == 0 ]; then
echo_success
echo
else
echo_failure
echo
break
fi
sleep 1
return 0
}
#---------------------------------------------------------------------------
# STOP
#---------------------------------------------------------------------------
Stop()
{
echo -n "stopping service (wvp_pro): "
kill -9 $wvp_pro
echo
return 0
}
#---------------------------------------------------------------------------
# MAIN
#---------------------------------------------------------------------------
case "$1" in
start)
Start
;;
stop)
Stop
;;
restart)
Stop
sleep 3
Start
;;
*)
echo "please use : $0 {start|stop|restart}"
esac
exit
[[email protected] target]# crontab -l
*/1 * * * * sh /usr/local/wvp-GB28181-pro/target/wvp-pro.sh start >/dev/null 2>&1

边栏推荐
- QT5知识:DNS查询
- C# 文件下载方式
- ROS knowledge: reading point cloud data files
- CRMEB知识付费如何二开阿里云短信功能
- Shell process control - 39. Special process control statements
- Deep thinking: in-depth analysis of some scenes in Gaia Altman and the philosophy and perception reflected
- halcon原理:一维函数function_1d类型【2】
- 2022 construction worker - decoration direction - post skills (construction worker) operation certificate examination question bank simulated examination platform operation
- <Sicily>1000. 数字反转
- 如何卸载Gazebo与重装
猜你喜欢

Slam Laser 2D (en utilisant Laser Scan matcher)

解决:Argument type ‘String‘ expected to be an instance of a class or class-constrained type

Ablebits Ultimate Suite for Excel

AssetBundle资源管理

What should testers do if the requirements need to be changed when the project is half tested?

How to uninstall and reinstall gazebo

Halcon原理:auto_threshold算子

Oracle database's dominant position is gradually eroded by cloud competitors

What are the criteria for judging the end of the test?

ROS knowledge: point cloud files PCD format
随机推荐
CRMEB知识付费如何二开阿里云短信功能
CDH邮件报警配置
自己测试的范围内出现严重 BUG ,马上要上线,这种情况怎么办?
UI框架
二维激光SLAM( 使用Laser Scan Matcher )
【系统架构】-软件架构的5大风格
Halcon principle: correlation matching
How to test the third-party payment interface?
网络基础和框架
ROS知识:点云文件.pcd格式
机器学习系列5:距离空间(1)
Go zero micro Service Practice Series (VI. cache consistency assurance)
项目测试一半,需求要变更,测试人员怎么办?
解决:Argument type ‘String‘ expected to be an instance of a class or class-constrained type
全新项目,如何保证测试的覆盖率?
The project experience of resume and several problems that testers should pay attention to in writing
halcon原理:一维函数function_1d类型【1】
What should I do if a serious bug occurs within the scope of my own test and I am about to go online?
An idea of using keep alive to cache data in vue3 form pages
Use xtradiagram Diagramcontrol for drawing and controlling process graphics