文章目錄
- 一、海康威視NVR SDK下載
- 二、引入海康SDK
- 1.將海康提供的jar包匯入到本地Maven庫
- 2.將SDK放在專案中
- 3.組態檔讀取
- 三、寫常用的介面
- 3.1根據時間獲取檔案
- 四、介面請求引數
- 五、專案地址
- 六、總結
一、海康威視NVR SDK下載
SDK下載地址
根據你的設備或者運行環境選擇相應的版本(文章用的是win64版)

二、引入海康SDK
1.將海康提供的jar包匯入到本地Maven庫
【傳送門】匯入步驟
百度網盤Maven匯入JAR
提取碼:q4w3
Maven匯入方式
<!-- 海康JNA jar包 -->
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 海康examples jar包 -->
<dependency>
<groupId>com.sun.jna.examples</groupId>
<artifactId>examples</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

2.將SDK放在專案中

將DLL檔案庫放到靜態資源目錄下,一面打JAR包時找不到檔案庫
3.組態檔讀取
獲取靜態資源檔案夾路徑
public class CommonKit {
/**
* 獲取DLL檔案路徑
* @return
*/
public static String getWebPath(){
String path = CommonKit.class.getClassLoader().getResource("").getPath().substring(1);
return path+"dll\\";
}
}
修改SDK中DLL庫讀取
public interface HCNetSDK extends StdCallLibrary {
/*加載海康DLL*/
HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary(CommonKit.getWebPath()+"HCNetSDK.dll", HCNetSDK.class);
}
同理PlayCtrl也一樣
public interface PlayCtrl extends StdCallLibrary {
/*加載播放DLL*/
PlayCtrl INSTANCE = (PlayCtrl) Native.loadLibrary(CommonKit.getWebPath()+"PlayCtrl.dll", PlayCtrl.class);
}
三、寫常用的介面
3.1根據時間獲取檔案
Controller:
package com.hikvision.nvr.controller;
import com.hikvision.nvr.common.AjaxResult;
import com.hikvision.nvr.domain.RequestVo;
import com.hikvision.nvr.service.FindVideoFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping(value = "/nvr")
@Api(value = "呼叫NVR介面", description = "呼叫NVR介面", tags = {"呼叫NVR介面"})
public class NvrControcller {
@Autowired
private FindVideoFileService downloadVideoService;
@RequestMapping(value = "/playback")
@ApiOperation(value = "根據時間獲取檔案", httpMethod = "POST", notes = "根據時間獲取檔案")
public AjaxResult playback(@RequestBody RequestVo requestVo) throws InterruptedException {
return AjaxResult.success(downloadVideoService.playback(requestVo));
}
@RequestMapping(value = "/downloadByFileNmae")
@ApiOperation(value = "根據檔案名下載", httpMethod = "POST", notes = "根據檔案名下載")
public AjaxResult downloadByFileNmae(@RequestParam String fileName, @RequestBody RequestVo requestVo) {
return AjaxResult.success(downloadVideoService.downloadByFileNmae(fileName, requestVo));
}
@RequestMapping(value = "/downloadByFileTime")
@ApiOperation(value = "根據時間下載", httpMethod = "POST", notes = "根據時間下載")
public AjaxResult downloadByFileTime(@RequestBody RequestVo requestVo) {
return AjaxResult.success(downloadVideoService.downloadByFileTime(requestVo));
}
@RequestMapping(value = "/getDeviceInformation")
@ApiOperation(value = "獲取設備資訊", httpMethod = "POST", notes = "獲取設備資訊")
public AjaxResult getDeviceInformation(@RequestBody RequestVo requestVo) {
return AjaxResult.success(downloadVideoService.getDeviceInformation(requestVo));
}
@RequestMapping(value = "/getBackUrl")
@ApiOperation(value = "獲取回放視頻流", httpMethod = "POST", notes = "獲取回放視頻流")
public AjaxResult getBackUrl(@RequestBody RequestVo requestVo) {
requestVo.getPlayBack().setUrlType(1);
Map map = downloadVideoService.getBackUrl(requestVo);
String value = (String) map.get("msg");
if (value.startsWith("rtsp:")) {
return AjaxResult.success(map);
}
return AjaxResult.error();
}
@RequestMapping(value = "/getLiveUrl")
@ApiOperation(value = "獲取實時視頻流", httpMethod = "POST", notes = "獲取實時視頻流")
public AjaxResult getLiveUrl(@RequestBody RequestVo requestVo){
requestVo.getPlayBack().setUrlType(0);
Map map = downloadVideoService.getBackUrl(requestVo);
String value = (String) map.get("msg");
if (value.startsWith("rtsp:")) {
return AjaxResult.success(map);
}
return AjaxResult.error();
}
}
Service:
package com.hikvision.nvr.service;
import com.hikvision.nvr.domain.RequestVo;
import com.hikvision.nvr.domain.SignIn;
import com.hikvision.nvr.domain.VideoFile;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
public interface FindVideoFileService {
List<VideoFile> playback(RequestVo requestVo) throws InterruptedException;
boolean downloadByFileNmae(String fileName,RequestVo requestVo);
boolean downloadByFileTime(RequestVo requestVo);
List<SignIn> getDeviceInformation(RequestVo requestVo);
Map getBackUrl(RequestVo requestVo);
}
ServiceImpl:
package com.hikvision.nvr.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hikvision.nvr.domain.NvrTime;
import com.hikvision.nvr.domain.PlayBack;
import com.hikvision.nvr.domain.RequestVo;
import com.hikvision.nvr.domain.SignIn;
import com.hikvision.nvr.domain.VideoFile;
import com.hikvision.nvr.service.FindVideoFileService;
import com.hikvision.nvr.service.hk.HCNetSDK;
import com.hikvision.nvr.util.*;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @author wgq
*/
@Slf4j
@Service
public class FindVideoFileServiceImpl implements FindVideoFileService {
/*獲取IP接入配置資訊*/
public static final int NET_DVR_GET_IPPARACFG = 1048;
/*允許加入的最多IP通道數*/
public static final int MAX_IP_CHANNEL = 32;
/*獲得檔案資訊*/
public static final int NET_DVR_FILE_SUCCESS = 1000;
/*正在查找檔案*/
public static final int NET_DVR_ISFINDING = 1002;
/*沒有檔案*/
public static final int NET_DVR_FILE_NOFIND = 1001;
/*開始播放*/
public static final int NET_DVR_PLAYSTART = 1;
/*獲取檔案回放的進度*/
public static final int NET_DVR_PLAYGETPOS = 13;
NativeLong lUserID;
/*下載句柄*/
NativeLong m_lDownloadHandle;
/*設備資訊*/
NET_DVR_DEVICEINFO_V30 m_strDeviceInfo;
HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private DataUtil dataUtil;
/**
* 根據時間搜索視頻
*
* @param requestVo
*/
@Override
public List<VideoFile> playback(RequestVo requestVo) throws InterruptedException {
SignIn signIn = requestVo.getSignIn();
PlayBack playBack = requestVo.getPlayBack();
NativeLong m_lUserID = userId(signIn);
/*設定檢索開始結束時間*/
NvrTime startTime = dataUtil.dateToNum(playBack.getStartTime());
NvrTime endTime = dataUtil.dateToNum(playBack.getEndTime());
NET_DVR_TIME struStartTime;
NET_DVR_TIME struStopTime;
NET_DVR_FILECOND m_strFilecond = new NET_DVR_FILECOND();
m_strFilecond.struStartTime = new NET_DVR_TIME();
m_strFilecond.struStopTime = new NET_DVR_TIME();
/*組裝開始時間*/
m_strFilecond.struStartTime.dwYear = startTime.getDwYear();
m_strFilecond.struStartTime.dwMonth = startTime.getDwMonth();
m_strFilecond.struStartTime.dwDay = startTime.getDwDay();
m_strFilecond.struStartTime.dwHour = startTime.getDwHour();
m_strFilecond.struStartTime.dwMinute = startTime.getDwMinute();
m_strFilecond.struStartTime.dwSecond = startTime.getDwSecond();
/*組裝結束時間*/
m_strFilecond.struStopTime.dwYear = endTime.getDwYear();
m_strFilecond.struStopTime.dwMonth = endTime.getDwMonth();
m_strFilecond.struStopTime.dwDay = endTime.getDwDay();
m_strFilecond.struStopTime.dwHour = endTime.getDwHour();
m_strFilecond.struStopTime.dwMinute = endTime.getDwMinute();
m_strFilecond.struStopTime.dwSecond = endTime.getDwSecond();
/*檔案型別*/
m_strFilecond.dwFileType = 0;
m_strFilecond.dwIsLocked = 0xff;
m_strFilecond.dwUseCardNo = 0;
/*通道號*/
m_strFilecond.lChannel = new NativeLong(playBack.getChannelNumber());
/*獲取檔案*/
NativeLong lFindFile = hCNetSDK.NET_DVR_FindFile_V30(m_lUserID, m_strFilecond);
NET_DVR_FINDDATA_V30 strFile = new NET_DVR_FINDDATA_V30();
long findFile = lFindFile.longValue();
if (findFile > -1) {
log.info("file:{}" + findFile);
}
NativeLong lnext;
strFile = new NET_DVR_FINDDATA_V30();
List<VideoFile> videoFiles = new ArrayList<>();
while (true) {
lnext = hCNetSDK.NET_DVR_FindNextFile_V30(lFindFile, strFile);
if (lnext.longValue() == NET_DVR_FILE_SUCCESS) {
log.info("搜索成功");
/*添加檔案名資訊*/
String[] s = new String[2];
s = new String(strFile.sFileName).split("\0", 2);
VideoFile videoFile = new VideoFile();
/*添加檔案大小資訊*/
int iTemp;
String MyString;
if (strFile.dwFileSize < 1024 * 1024) {
iTemp = (strFile.dwFileSize) / (1024);
MyString = iTemp + "K";
} else {
iTemp = (strFile.dwFileSize) / (1024 * 1024);
MyString = iTemp + "M ";
iTemp = ((strFile.dwFileSize) % (1024 * 1024)) / (1204);
MyString = MyString + iTemp + "K";
}
videoFile.setFileNme(new String(s[0]));
videoFile.setFileSize(MyString);
videoFile.setStartTime(strFile.struStartTime.toStringTime());
videoFile.setEndTime(strFile.struStopTime.toStringTime());
videoFiles.add(videoFile);
} else {
/*搜索中*/
if (lnext.longValue() == NET_DVR_ISFINDING) {
log.info("搜索中");
continue;
} else {
if (lnext.longValue() == NET_DVR_FILE_NOFIND) {
log.info("沒有搜到檔案");
return videoFiles;
} else {
log.info("搜索檔案結束");
boolean flag = hCNetSDK.NET_DVR_FindClose_V30(lFindFile);
if (flag == false) {
log.info("結束搜索失敗");
}
return videoFiles;
}
}
}
}
}
/**
* 按照檔案下載
*
* @param fileName
* @param requestVo
* @return
*/
@Override
public boolean downloadByFileNmae(String fileName, RequestVo requestVo) {
/*初始化用戶*/
NativeLong nativeLong = userId(requestVo.getSignIn());
/*初始化下載值*/
m_lDownloadHandle = new NativeLong(-1);
if (m_lDownloadHandle.intValue() == -1) {
/*根據輸入的檔案名查找檔案*/
m_lDownloadHandle = hCNetSDK.NET_DVR_GetFileByName(nativeLong, fileName, "D:\\fileNme.3GP");
if (m_lDownloadHandle.intValue() >= 0) {
/*下載檔案*/
boolean downloadFlag = hCNetSDK.NET_DVR_PlayBackControl(m_lDownloadHandle, NET_DVR_PLAYSTART, 0, null);
int tmp = -1;
IntByReference pos = new IntByReference();
while (true) {
boolean backFlag = hCNetSDK.NET_DVR_PlayBackControl(m_lDownloadHandle, NET_DVR_PLAYGETPOS, 0, pos);
/*防止單個執行緒死回圈*/
if (!backFlag) {
return downloadFlag;
}
int produce = pos.getValue();
/*獲取下載進度*/
if ((produce % 10) == 0 && tmp != produce) {
tmp = produce;
log.info("視頻下載進度:{}", produce + "%");
}
/*下載成功*/
if (produce == 100) {
hCNetSDK.NET_DVR_StopGetFile(m_lDownloadHandle);
m_lDownloadHandle.setValue(-1);
/*退出錄像機*/
hCNetSDK.NET_DVR_Logout(lUserID);
log.info("退出狀態:{}", hCNetSDK.NET_DVR_GetLastError());
return true;
}
/*下載失敗*/
if (produce > 100) {
hCNetSDK.NET_DVR_StopGetFile(m_lDownloadHandle);
m_lDownloadHandle.setValue(-1);
log.warn("由于網路原因或NVR較忙,下載例外終止!錯誤原因:{}", hCNetSDK.NET_DVR_GetLastError());
hCNetSDK.NET_DVR_Logout(lUserID);
return false;
}
}
} else {
log.info("視頻下載失敗!失敗原因:{}", hCNetSDK.NET_DVR_GetLastError());
return false;
}
}
return true;
}
/**
* 按照時間下載檔案
*
* @param requestVo
* @return
*/
@Override
public boolean downloadByFileTime(RequestVo requestVo) {
PlayBack playBack = requestVo.getPlayBack();
/*初始化用戶*/
NativeLong nativeLong = userId(requestVo.getSignIn());
if (nativeLong.intValue() == -1) {
return false;
}
m_lDownloadHandle = new NativeLong(-1);
if (m_lDownloadHandle.intValue() == -1) {
/*根據輸入的檔案名查找檔案*/
m_lDownloadHandle = hCNetSDK.NET_DVR_GetFileByTime(nativeLong, new NativeLong(playBack.getChannelNumber().longValue())
, dataUtil.getHkTime(playBack.getStartTime()), dataUtil.getHkTime(playBack.getEndTime()), "D:\\fileNme.mp4");
if (m_lDownloadHandle.intValue() >= 0) {
/*下載檔案*/
boolean downloadFlag = hCNetSDK.NET_DVR_PlayBackControl(m_lDownloadHandle, NET_DVR_PLAYSTART, 0, null);
int tmp = -1;
IntByReference pos = new IntByReference();
while (true) {
boolean backFlag = hCNetSDK.NET_DVR_PlayBackControl(m_lDownloadHandle, NET_DVR_PLAYGETPOS, 0, pos);
/*防止單個執行緒死回圈*/
if (!backFlag) {
return downloadFlag;
}
int produce = pos.getValue();
/*獲取下載進度*/
if ((produce % 10) == 0 && tmp != produce) {
tmp = produce;
log.info("視頻下載進度:{}", produce + "%");
}
/*下載成功*/
if (produce == 100) {
hCNetSDK.NET_DVR_StopGetFile(m_lDownloadHandle);
m_lDownloadHandle.setValue(-1);
/*退出錄像機*/
hCNetSDK.NET_DVR_Logout(lUserID);
log.info("退出狀態:{}", hCNetSDK.NET_DVR_GetLastError());
return true;
}
/*下載失敗*/
if (produce > 100) {
hCNetSDK.NET_DVR_StopGetFile(m_lDownloadHandle);
m_lDownloadHandle.setValue(-1);
log.warn("由于網路原因或NVR較忙,下載例外終止!錯誤原因:{}", hCNetSDK.NET_DVR_GetLastError());
hCNetSDK.NET_DVR_Logout(lUserID);
return false;
}
}
} else {
log.info("視頻下載失敗!失敗原因:{}", hCNetSDK.NET_DVR_GetLastError());
return false;
}
}
return true;
}
/**
* 獲取用戶登錄資訊
*
* @return 回傳用戶狀態
*/
public NativeLong userId(SignIn signIn) {
boolean initSuc = hCNetSDK.NET_DVR_Init();
if (initSuc != true) {
log.info("初始化失敗");
}
/*判斷用戶狀態*/
if (lUserID != null && lUserID.longValue() > -1) {
hCNetSDK.NET_DVR_Logout_V30(lUserID);
lUserID = new NativeLong(-1);
}
/*用戶登錄*/
lUserID = hCNetSDK.NET_DVR_Login_V30(signIn.getIp(),
(short) signIn.getPort(), signIn.getUserName(), signIn.getPassword(), m_strDeviceInfo);
return lUserID;
}
/**
* 用戶登錄 初始化設備
*
* @param requestVo
* @return
*/
@Override
public List<SignIn> getDeviceInformation(RequestVo requestVo) {
SignIn sign = requestVo.getSignIn();
/*IP引數*/
NET_DVR_IPPARACFG m_strIpparaCfg;
/* 設備串列*/
List<SignIn> signIns = new ArrayList<>();
m_strDeviceInfo = new NET_DVR_DEVICEINFO_V30();
NativeLong lUserID = userId(sign);
long userID = lUserID.longValue();
if (userID == -1) {
log.info("注冊失敗");
return signIns;
} else {
log.info("注冊成功");
/*通道樹節點數目*/
int m_iTreeNodeNum = 0;
/*獲取IP接入配置引數*/
IntByReference ibrBytesReturned = new IntByReference(0);
/*IP接入配置結構獲取*/
m_strIpparaCfg = new NET_DVR_IPPARACFG();
m_strIpparaCfg.write();
Pointer lpIpParaConfig = m_strIpparaCfg.getPointer();
/*獲取通道引數*/
boolean bRet = hCNetSDK.NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_IPPARACFG, new NativeLong(0),
lpIpParaConfig, m_strIpparaCfg.size(), ibrBytesReturned);
m_strIpparaCfg.read();
if (!bRet) {
/*設備不支持,則表示沒有IP通道*/
for (int iChannum = 0; iChannum < m_strDeviceInfo.byChanNum; iChannum++) {
SignIn s = new SignIn();
s.setDeviceId("Camera" + (iChannum + m_strDeviceInfo.byStartChan));
signIns.add(s);
}
} else {
/*設備支持IP通道*/
for (int iChannum = 0; iChannum < m_strDeviceInfo.byChanNum; iChannum++) {
if (m_strIpparaCfg.byAnalogChanEnable[iChannum] == 1) {
SignIn s = new SignIn();
s.setDeviceId("Camera" + (iChannum + m_strDeviceInfo.byStartChan));
signIns.add(s);
m_iTreeNodeNum++;
}
}
for (int iChannum = 0; iChannum < MAX_IP_CHANNEL; iChannum++) {
/*判斷該通道號是否存在攝像頭*/
if (m_strIpparaCfg.struIPChanInfo[iChannum].byChannel == 1) {
SignIn s = new SignIn();
NET_DVR_IPDEVINFO dev = m_strIpparaCfg.struIPDevInfo[iChannum];
s.setIp(new String(dev.struIP.sIpV4).trim());
s.setUserName(new String(dev.sUserName).trim());
s.setPort(dev.wDVRPort);
s.setIsLine(String.valueOf(m_strIpparaCfg.struIPChanInfo[iChannum].byEnable));
s.setDeviceId("IPCamera" + (iChannum + m_strDeviceInfo.byStartChan));
Integer channelNumber = getChannelNumber(s.getDeviceId());
s.setChannelNumber(channelNumber);
signIns.add(s);
}
}
}
log.info("攝像頭資源:{}", signIns);
}
return signIns;
}
/**
* 回放拉流
*
* @param requestVo
* @return
*/
@Override
public Map getBackUrl(RequestVo requestVo) {
Map map = new HashMap();
/*初始化用戶*/
SignIn sign = requestVo.getSignIn();
PlayBack playBack = requestVo.getPlayBack();
NativeLong nativeLong = userId(sign);
if (nativeLong.intValue() == -1) {
log.info("回放推流用戶初始化失敗");
map.put("msg", "回放推流用戶初始化失敗");
return map;
}
String url = sign.getAppId() + "/" + sign.getDeviceId();
/*獲取設備通道號*/
List<SignIn> signIns = getDeviceInformation(requestVo);
int channelNum = 0;
for (SignIn signIn : signIns) {
if (signIn.getIp().equals(sign.getDeviceIp())) {
channelNum = signIn.getChannelNumber();
}
}
if (channelNum == 0) {
log.info("獲取設備通道失敗");
map.put("msg", "獲取設備通道失敗!");
return map;
}
String backUrl = "";
if (playBack.getUrlType() == 1) {
/*組裝回放流地址*/
backUrl = "rtsp://admin:" + sign.getPassword() + "@" + sign.getIp() + ":554/Streaming/tracks/" + (channelNum - 32) + "01/?" +
"starttime=" + dataUtil.backTimeAssemble(playBack.getStartTime()) + "&endtime=" + dataUtil.backTimeAssemble(playBack.getEndTime());
} else {
/*組裝實時流地址*/
backUrl = "rtsp://admin:" + sign.getPassword() + "@" + sign.getDeviceIp() + ":554/Streaming/tracks/" + (channelNum - 32) + "02/?" +
"transportmode=multicast";
}
map.put("msg", backUrl);
return map;
}
/**
* 獲取選中的通道名,對通道名進行分析:
*
* @param sChannelName
* @return
*/
public int getChannelNumber(String sChannelName) {
int iChannelNum = -1;
/*Camara開頭表示模擬通道*/
if (sChannelName.charAt(0) == 'C') {
/*子字串中獲取通道號*/
iChannelNum = Integer.parseInt(sChannelName.substring(6));
} else {
/*IPCamara開頭表示IP通道*/
if (sChannelName.charAt(0) == 'I') {
/*子字符創中獲取通道號,IP通道號要加32,如IPCamera3 == 35*/
iChannelNum = Integer.parseInt(sChannelName.substring(8)) + 32;
} else {
return -1;
}
}
return iChannelNum;
}
}
HCNetSDK:
package com.hikvision.nvr.service.hk;
import com.hikvision.nvr.util.*;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
public interface HCNetSDK extends StdCallLibrary {
/*加載海康DLL*/
HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary(CommonKit.getWebPath()+"HCNetSDK.dll", HCNetSDK.class);
/*初始化*/
boolean NET_DVR_Init();
/*用戶登錄*/
NativeLong NET_DVR_Login_V30(String sDVRIP, short wDVRPort, String sUserName, String sPassword, NET_DVR_DEVICEINFO_V30 lpDeviceInfo);
/* 引數配置 begin*/
boolean NET_DVR_GetDVRConfig(NativeLong lUserID, int dwCommand, NativeLong lChannel, Pointer lpOutBuffer, int dwOutBufferSize, IntByReference lpBytesReturned);
/*查詢視頻檔案*/
NativeLong NET_DVR_FindFile_V30(NativeLong lUserID, NET_DVR_FILECOND pFindCond);
/*查找下一個檔案*/
NativeLong NET_DVR_FindNextFile_V30(NativeLong lFindHandle, NET_DVR_FINDDATA_V30 lpFindData);
/*結束搜索檔案*/
boolean NET_DVR_FindClose_V30(NativeLong lFindHandle);
/*用戶注銷*/
boolean NET_DVR_Logout_V30(NativeLong lUserID);
/* 根據名稱搜索檔案 */
NativeLong NET_DVR_GetFileByName(NativeLong lUserID, String sDVRFileName, String sSavedFileName);
/*下載檔案*/
boolean NET_DVR_PlayBackControl(NativeLong lPlayHandle, int dwControlCode, int dwInValue, IntByReference LPOutValue);
/* 停止檔案下載 */
boolean NET_DVR_StopGetFile(NativeLong lFileHandle);
/*退出NVR*/
boolean NET_DVR_Logout(NativeLong lUserID);
/*獲取退出狀態*/
int NET_DVR_GetLastError();
/*根據時間下載視頻*/
NativeLong NET_DVR_GetFileByTime(NativeLong lUserID, NativeLong lChannel, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime, String sSavedFileName);
}
以及HCNetSDK中其他物體類:

四、介面請求引數
創建一個NVR.postman_collection.json的檔案,將以下文本放入匯入到PostMan中即可請求
{
"info": {
"_postman_id": "bb70a6f1-e3a6-45cf-b914-76e3a7622628",
"name": "NVR",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "根據時間獲取檔案資訊",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "ip",
"value": "192.168.18.133",
"type": "text",
"disabled": true
},
{
"key": "port",
"value": "8000",
"type": "text",
"disabled": true
},
{
"key": "userName",
"value": "admin",
"type": "text",
"disabled": true
},
{
"key": "password",
"value": "a12345678",
"type": "text",
"disabled": true
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 34,\r\n \"endTime\": \"2021-11-04 18:00:00\",\r\n \"startTime\": \"2021-11-04 15:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/playback",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"playback"
]
}
},
"response": []
},
{
"name": "獲取鏈接設備資訊",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 34,\r\n \"endTime\": \"2021-11-04 18:00:00\",\r\n \"startTime\": \"2021-11-04 15:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/getDeviceInformation",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"getDeviceInformation"
]
}
},
"response": []
},
{
"name": "根據檔案名下載視頻",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 34,\r\n \"endTime\": \"2021-11-04 18:00:00\",\r\n \"startTime\": \"2021-11-04 15:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/downloadByFileNmae?fileName=ch0002_00010000096000000",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"downloadByFileNmae"
],
"query": [
{
"key": "fileName",
"value": "ch0002_00010000096000000"
}
]
}
},
"response": []
},
{
"name": "根據時間下載視頻",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 33,\r\n \"endTime\": \"2021-11-05 18:00:00\",\r\n \"startTime\": \"2021-11-05 16:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/downloadByFileTime",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"downloadByFileTime"
]
}
},
"response": []
},
{
"name": "獲取回放流地址",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 34,\r\n \"endTime\": \"2021-11-08 15:00:00\",\r\n \"startTime\": \"2021-11-08 13:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\",\r\n \"deviceIp\":\"192.168.18.183\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/getBackUrl",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"getBackUrl"
]
}
},
"response": []
},
{
"name": "獲取實時視頻流",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"playBack\": {\r\n \"channelNumber\": 34,\r\n \"endTime\": \"2021-11-08 15:00:00\",\r\n \"startTime\": \"2021-11-08 13:00:00\"\r\n },\r\n \"signIn\": {\r\n \"ip\": \"192.168.18.133\",\r\n \"password\": \"a12345678\",\r\n \"port\": 8000,\r\n \"userName\": \"admin\",\r\n \"deviceIp\":\"192.168.18.180\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/nvr/getLiveUrl",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"nvr",
"getLiveUrl"
]
}
},
"response": []
}
]
}
五、專案地址
避免檔案使用積分問題本專案已上傳至百度網盤
百度網盤Maven匯入JAR
提取碼:s75w
六、總結
這是第一次對接硬體,還有很多不完善的地方希望大家諒解,有寫的不好的地方請大家指出,日后考慮放到gitee以便大家一起維護,在此感謝!
原創不易,歡迎來噴…
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/354796.html
標籤:其他
上一篇:【影像檢測】基于Hough變換演算法檢測視頻車道線檢測matlab代碼
下一篇:Jenkins升級
