IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> Spring Boot集成海康威视NVR -> 正文阅读

[Java知识库]Spring Boot集成海康威视NVR

一、海康威视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以便大家一起维护。在此感谢!
原创不易,欢迎来喷…在这里插入图片描述

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2021-11-10 12:16:21  更:2021-11-10 12:16:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 0:16:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码