本文主要介绍使用 WVP
+ZLMediaKit
+MediaServerUI
实现通过 GB28181
进行海康、大华、宇视等品牌的 IPC
、NVR
、DVR
接入,完成摄像头监控播放,控制,录制。
准备工作
1.服务运行环境,Linux / OS X / Windows 均可,但推荐 Linux
2.海康云台摄像头一个
3.运行 sip
服务 WVP
https://github.com/swwheihei/wvp-GB28181
4.运行流媒体服务 ZLMediaKit
https://github.com/xiongziliang/ZLMediaKit
5.运行前端展示项目 MediaServerUI
https://gitee.com/kkkkk5G/MediaServerUI/tree/gb28181/
以上三个项目其实都有文档可供查看,因为踩了一些坑,所以写了本文,文章可能会写得比较细一点,建议结合它们的文档一起看。
运行 WVP
安装 Redis
WVP 项目中将设备信息等存放在 Redis 中,所以需要安装 Redis,安装教程请自行搜索。
配置运行 SIP
首先修改 WVP 项目配置文件:
spring:
application:
name: iot-vmp-vmanager
# 影子数据存储方式,支持redis、jdbc
database: redis
# 通信方式,支持kafka、http
communicate: http
redis:
# Redis服务器IP
host: 127.0.0.1
#端口号
port: 6379
datebase: 0
#访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
password: 123123
#超时时间
timeout: 10000
datasource:
name: eiot
url: jdbc:mysql://host.docker.internal:3306/eiot?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
sip:
# SIP 所在服务IP,就是本机IP
ip: 192.168.1.102
port: 5060
# 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007)
# 后两位为行业编码,定义参照附录D.3
# 3701020049标识山东济南历下区 信息行业接入
domain: 3701020049
id: 37010200492000000002
# 默认设备认证密码,后续扩展使用设备单独密码
password: 123456
media:
# 流媒体服务的IP,内网测试可填内网IP,公网填公网服务器IP并放开端口
ip: 177.11.11.111
port: 10000
然后登录海康摄像头管理页面,修改配置:
平台接入选择 28181
;传输协议可自选,公网建议选择TCP;协议版本选择 GB/T28181-2016
(目前WVP只支持这个协议,2011后面会适配)
SIP服务器ID
和 SIP服务器域
,密码
要和 WVP
项目中配置的一致。
SIP服务器地址
填写 WVP
项目的地址,内网填写内网IP地址,云服务器填写公网IP,端口写配置文件中配置的端口。
因为摄像头平台接入配置好后,摄像头会请求 SIP 服务,所以这个一定要配置好。
配置完成后就可以运行项目了!如果 SIP 服务启动成功后,会看到这个日志 "Sip Server 启动成功":
如果摄像头连接到 SIP
服务,项目会有这样的日志,显示 200 OK(公网服务器记得放开sip端口):
建立好连接后,就可以控制查询摄像头了。
GET /api/devices
查询所有设备的信息
[
{
"deviceId":"37010200492000000001",
"name":"IP DOME",
"manufacturer":"Hikvision",
"model":"DS-2DC4223IW-D/GLT",
"firmware":"V5.6.15",
"transport":"TCP",
"host":{
"ip":"192.168.1.101",
"port":1609,
"address":"192.168.1.101:1609"
},
"online":1,
"channelMap":{
"34020000001320000001":{
"channelId":"34020000001320000001",
"name":"IPdome",
"manufacture":"Hikvision",
"model":"IP Camera",
"owner":"Owner",
"civilCode":"37010123123",
"block":null,
"address":"Address",
"parental":0,
"parentId":null,
"safetyWay":0,
"registerWay":1,
"certNum":null,
"certifiable":0,
"errCode":0,
"endTime":null,
"secrecy":"0",
"ipAddress":null,
"port":0,
"password":null,
"status":1,
"longitude":0,
"latitude":0
}
}
}
]
POST /api/ptz/{deviceId}/{channelId}
云台控制指定设备通道
http://127.0.0.1:8080/api/ptz/34020000001320000001/34020000001320000001?leftRight=1&upDown=0&inOut=0&moveSpeed=50&zoomSpeed=1
zoomSpeed 的数字不能太大,不然运行不了,无效。
WVP 项目所有接口:https://github.com/swwheihei/wvp-GB28181/wiki/API-%E6%8E%A5%E5%8F%A3
运行流媒体服务 ZLMediaKit
获取代码
#国内用户推荐从同步镜像网站gitee下载
git clone --depth 1 https://gitee.com/xiahcu/ZLMediaKit
cd ZLMediaKit
#千万不要忘记执行这句命令
git submodule update --init
构建项目
项目开发者贴心的提供了三个shell脚本在项目根目录:
- build_docker_images.sh 构建为docker镜像
- build_for_linux.sh linux下构建项目
- build_for_mac.sh mac下构建项目
打开以后可以看到是使用CMake来编译的,我们可以直接选择运行shell脚本,Windows的话就看文档)跟着一步步来吧?。
构建好后打开 release/xx/Debug
目录,可以看到有 config.ini
是项目的配置文件:https://github.com/xiongziliang/ZLMediaKit/blob/master/conf/config.ini
其中需要特别注意的有两个地方:
一是 [http] 的 port,因为 ZLMediaKit 项目也有很多 API 接口,都需要通过这个接口来访问,包括生成的播放的URL,都是这个端口,如遇到端口被你的其它服务占用,可自行配置。
二是 [rtp_proxy] 的 port,是我们上面 SIP 项目配置的 media.port
配置好了就可以运行项目了。
运行项目
Linux 下启动:
cd ZLMediaKit/release/linux/Debug
#通过-h可以了解启动参数
./MediaServer -h
#以守护进程模式启动
./MediaServer -d &
使用守护进程模式启动后,可以通过 ps -axj
来查看进程
运行成功后会打印出如下日志:
我们可以做下推流测试,非必须操作,不需要可直接跳到下一节“项目推流”,具体操作可以查看文档:https://github.com/xiongziliang/ZLMediaKit/wiki/ZLMediaKit%E6%8E%A8%E6%B5%81%E6%B5%8B%E8%AF%95
下载一个视频文件 big_buck_bunny.mp4
放在当前目录上,使用rtp方式推流试试,在文件所在目录输入命令(没安装ffmpeg的话需要先安装下):
ffmpeg -re -i "big_buck_bunny.mp4" -vcodec h264 -acodec aac -f rtp_mpegts rtp://127.0.0.1:10000
运行后,查看 ZLMediaKit 项目会有类似这样的日志:
使用可以播放流的播放器(如:PotPlayer,IINA)打开 http://服务器IP/rtp/xxxxx.flv
就能播放了。
如 http://服务器IP/rtp/061484E1.flv
项目推流
SIP
服务和流媒体服务以及就绪了,我们就可以推流了。
拿到 /api/devices
查到的 deviceId 和 channelId,然后调用 SIP
服务的播放接口
GET /api/play/37010200492000000001/34020000001320000001
预览指定设备通道的音视频
成功调用后会返回ssrc:
{"ssrc":"0102008033"}
ssrc 转换为16进制后为 061484E1
我们查看流媒体服务的日志,就能看到如下:
注:公网服务器如果没有收到推流日志,记得开放端口并检查 wvp
项目的 media
配置是否正确。
那我们怎么拿到播放地址呢?其实文档已经有了:https://github.com/xiongziliang/ZLMediaKit/wiki/%E6%92%AD%E6%94%BEurl%E8%A7%84%E5%88%99
如果我的公网IP是177.11.11.111,转换过来就是:
rtsp://177.11.11.111:554/rtp/061484E1?token=abcdefg&field=value
rtmp://177.11.11.111/rtp/061484E1
http://177.11.11.111/rtp/061484E1.flv
http://177.11.11.111/rtp/061484E1/hls.m3u8
此外 ZLMediaKit 还提供了录制,截图,动态添加拉流代理等功能,很棒,大家感兴趣可以看API文档。
运行MediaServerUI
拉下项目代码:https://gitee.com/kkkkk5G/MediaServerUI/tree/gb28181/
项目启动后,SIP
服务调用 play 接口,流媒体服务受到消息,在项目的“视频广场”中就能看到我们的视频了。
这个项目需要注意的也是配置,本项目是和流媒体服务关联的,调用的接口也是流媒体 ZLMediaKit 的 API。
打开项目根目录下的 global.js
:
const serverip="172.16.63.208"
const host = 'http://' + serverip + '/index/api';
const secret = '035c73f7-bb6b-4889-a715-d9eb2d1925cc';
const baseMediaUrl='ws://' + serverip + '/';
function genApiUrl(method){
return host+method+"?secret="+secret;
}
export default{
serverip,
host,
secret,
genApiUrl,
baseMediaUrl
}
serverip是流媒体服务的IP,如果 ZLMediaKit 的配置文件中 [http] 配置项的端口改成了其它的,也记得在这里加上端口号(不同服务器请配置放开端口哦)。
secret
需要和流媒体服务配置的一样。
baseMediaUrl
是你拉流的url,你可以改成其它的,如 rtsp,rtmp,http。
整个视频请求的流程图
其中流媒体模块指 ZLMediaServer
,接口模块与信令模块指 WVP
,视频设备指 IPC、NVR
后记
最后感谢大佬们这么棒的开源项目,谢谢!
skyWord 2023-08-24 13:09
请问NVR DVR怎么接入进去,一直没搞明白
puzzle9 2023-02-27 13:38
这两关系是这样啊 明白了 谢谢你
陈志荣 2022-05-09 17:04
点播的时候请求地址返回501是什么情况
Mozzzz 2022-04-11 19:34
找不到原因,不是到是不是网络问题,布了4套,两套不行,两套可以,都是在CentOS上编译运行的
request:以下是ZLM的报错信息,目前是跟WVP结合实现国标设备实时点播的
2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] GB28181Process.cpp:182 onRtpDecode | 34020000001321300025_34020000001320000001 judged to be PS
2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] Decoder.cpp:227 onTrack | got track: H264
2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] Decoder.cpp:144 onStream | add track finished
2022-04-11 19:21:05.621 T MediaServer[20557-event poller 0] HttpSession.cpp:27 HttpSession | 22-25(192.168.3.182:56165)
2022-04-11 19:21:05.622 D MediaServer[20557-event poller 0] WebApi.cpp:243 http api debug |
POST /index/api/getServerConfig
header:Accept-Encoding : gzip
content:Connection : Keep-Alive
Content-Length : 43
Content-Type : application/x-www-form-urlencoded
Host : 192.168.3.130:8086
User-Agent : okhttp/4.9.0
secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
response size:46372022-04-11 19:21:11.737 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
2022-04-11 19:21:12.257 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:12.778 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:13.297 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:13.818 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:14.337 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:14.858 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:15.377 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:15.896 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:16.424 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:16.424 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 2 times
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 21-18(192.168.3.182:56164) session timeout
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 20-17(192.168.3.182:56163) session timeout
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 21-18(192.168.3.182:56164)
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 20-17(192.168.3.182:56163)
2022-04-11 19:21:16.541 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
2022-04-11 19:21:17.057 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:17.057 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 5 times
2022-04-11 19:21:17.279 W MediaServer[20557-event poller 0] RtpSelector.cpp:112 onManager | RtpProcess timeout:34020000001321300025_34020000001320000001
2022-04-11 19:21:17.279 I MediaServer[20557-event poller 0] TcpServer.cpp:40 ~TcpServer | close tcp server 0.0.0.0:30005
2022-04-11 19:21:17.279 W MediaServer[20557-event poller 0] RtpProcess.cpp:54 ~RtpProcess | 34020000001321300025_34020000001320000001(192.168.3.167:15060) RTP推流器(defaultVhost/rtp/34020000001321300025_34020000001320000001)断开,耗时(s):0
2022-04-11 19:21:22.530 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 22-25(192.168.3.182:56165) session timeout
2022-04-11 19:21:22.530 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 22-25(192.168.3.182:56165)
2022-04-11 19:21:28.122 W MediaServer[20557-event poller 0] WebHook.cpp:173 operator() | hook http://127.0.0.1:18080/index/hook/on_server_keepalive 4ms,failed[network err]:connection refused:{
"data" : {
"Buffer" : 2,
"BufferLikeString" : 0,
"BufferList" : 0,
"BufferRaw" : 2,
"Frame" : 0,
"FrameImp" : 0,
"MediaSource" : 0,
"MultiMediaSourceMuxer" : 0,
"RtmpPacket" : 0,
"RtpPacket" : 0,
"Socket" : 18,
"TcpClient" : 0,
"TcpServer" : 16,
"TcpSession" : 0,
"UdpServer" : 2,
"UdpSession" : 0
},
"mediaServerId" : "QrE80piAbkLmY2wF"
}
Mozzzz 2022-04-11 19:31
2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] GB28181Process.cpp:182 onRtpDecode | 34020000001321300025_34020000001320000001 judged to be PS
request:2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] Decoder.cpp:227 onTrack | got track: H264
2022-04-11 19:21:03.680 I MediaServer[20557-event poller 0] Decoder.cpp:144 onStream | add track finished
2022-04-11 19:21:05.621 T MediaServer[20557-event poller 0] HttpSession.cpp:27 HttpSession | 22-25(192.168.3.182:56165)
2022-04-11 19:21:05.622 D MediaServer[20557-event poller 0] WebApi.cpp:243 http api debug |
POST /index/api/getServerConfig
header:Accept-Encoding : gzip
content:Connection : Keep-Alive
Content-Length : 43
Content-Type : application/x-www-form-urlencoded
Host : 192.168.3.130:8086
User-Agent : okhttp/4.9.0
secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
response size:46372022-04-11 19:21:11.737 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
2022-04-11 19:21:12.257 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:12.778 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:13.297 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:13.818 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:14.337 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:14.858 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:15.377 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:15.896 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:16.424 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:16.424 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 2 times
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 21-18(192.168.3.182:56164) session timeout
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 20-17(192.168.3.182:56163) session timeout
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 21-18(192.168.3.182:56164)
2022-04-11 19:21:16.528 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 20-17(192.168.3.182:56163)
2022-04-11 19:21:16.541 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
2022-04-11 19:21:17.057 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 13 times
2022-04-11 19:21:17.057 W MediaServer[20557-event poller 0] RtpProcess.cpp:122 inputFrame | cached frame of track(H264) is too much, now dropped
Last message repeated 5 times
2022-04-11 19:21:17.279 W MediaServer[20557-event poller 0] RtpSelector.cpp:112 onManager | RtpProcess timeout:34020000001321300025_34020000001320000001
2022-04-11 19:21:17.279 I MediaServer[20557-event poller 0] TcpServer.cpp:40 ~TcpServer | close tcp server 0.0.0.0:30005
2022-04-11 19:21:17.279 W MediaServer[20557-event poller 0] RtpProcess.cpp:54 ~RtpProcess | 34020000001321300025_34020000001320000001(192.168.3.167:15060) RTP推流器(defaultVhost/rtp/34020000001321300025_34020000001320000001)断开,耗时(s):0
2022-04-11 19:21:22.530 T MediaServer[20557-event poller 0] HttpSession.cpp:121 onError | 22-25(192.168.3.182:56165) session timeout
2022-04-11 19:21:22.530 T MediaServer[20557-event poller 0] HttpSession.cpp:33 ~HttpSession | 22-25(192.168.3.182:56165)
2022-04-11 19:21:28.122 W MediaServer[20557-event poller 0] WebHook.cpp:173 operator() | hook http://127.0.0.1:18080/index/hook/on_server_keepalive 4ms,failed[network err]:connection refused:{
"data" : {
"Buffer" : 2,
"BufferLikeString" : 0,
"BufferList" : 0,
"BufferRaw" : 2,
"Frame" : 0,
"FrameImp" : 0,
"MediaSource" : 0,
"MultiMediaSourceMuxer" : 0,
"RtmpPacket" : 0,
"RtpPacket" : 0,
"Socket" : 18,
"TcpClient" : 0,
"TcpServer" : 16,
"TcpSession" : 0,
"UdpServer" : 2,
"UdpSession" : 0
},
"mediaServerId" : "QrE80piAbkLmY2wF"
}
chonge 2021-12-22 10:13
设备获取正常,播放视频,点播超时,什么情况,大佬
梁启飞 2021-12-11 16:54
海康nvr接入,视频下半部分是花的,是啥情况
li 2021-10-11 18:34
请问海康ipc设备能够推流成功,NVR设备却点播超时什么原因。同样的环境,就是把nvr恢复了出厂设置,突然就不行了
何世杰 2021-09-02 15:22
BYE sip:15010200491328056682@113.57.111.119:16049 SIP/2.0
Via: SIP/2.0/UDP 0.0.0.0:10001;branch=z9hG4bK-383434-7c5e7f74abd35b8f53e506654d0a78ee
CSeq: 9 BYE
From: sip:15010000002020000001@1501000000;tag=live
To: sip:15010200491328056682@1501000000;tag=97c6a1d119fd200b958e9096dfd730dc
Call-ID: 36784ba9cec093eb5560cd952ef00a04@0.0.0.0
Max-Forwards: 70
Content-Length: 0
返回 Status: 481 Call/Transaction Does Not Exist 这是哪儿的问题 ?
chonge 2021-12-22 10:11
请问解决了吗
习习薰风 2021-08-31 14:02
局域网中的摄像头能实现断流吗?