Home > Java > javaTutorial > body text

Advanced Java Hikvision SDK Secondary Development Technical Guide

WBOY
Release: 2023-09-06 11:22:48
Original
1213 people have browsed it

Advanced Java Hikvision SDK Secondary Development Technical Guide

Advanced Java Hikvision SDK Secondary Development Technical Guide

Introduction:
With the development of technology and the continuous expansion of application scenarios, video surveillance systems have gradually become an integral part of modern society. In the market, Hikvision's products have always been in a leading position, providing a series of high-quality video surveillance solutions. However, for some special needs, relying solely on native functions may not be able to meet them, which requires secondary development of Hikvision SDK. This article will focus on the advanced Java Hikvision SDK secondary development technology and give corresponding code examples.

1. SDK download and installation

  1. Go to Hikvision official website and find the SDK download page. According to your needs, select the corresponding SDK version and click to download.
  2. After the download is completed, unzip the file to the local directory.
  3. Import SDK into Java development tools.

2. SDK environment configuration

  1. Create a new Java project in the development tool.
  2. Add the jar package in the SDK to the project's dependencies.
  3. Configure JVM parameters and add the corresponding dynamic link library path.

3. SDK Initialization and Login
Before secondary development, we need to initialize and log in to the SDK to obtain the corresponding operating permissions.

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.hikvision.netsdk.HCNetSDK;

public class SDKDemo {
    private static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public static void main(String[] args) {
        // SDK初始化
        boolean initSuc = hCNetSDK.NET_DVR_Init();
        if (initSuc != true) {
            System.out.println("SDK初始化失败!");
            return;
        }

        // 登录
        HCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        NativeLong lUserId = hCNetSDK.NET_DVR_Login_V30("192.168.1.100", (short) 8000,
                "admin", "password", deviceInfo);
        if (lUserId.longValue() < 0) {
            System.out.println("登录失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        // 登出
        boolean logoutSuc = hCNetSDK.NET_DVR_Logout(lUserId);
        if (logoutSuc != true) {
            System.out.println("登出失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        // SDK反初始化
        boolean cleanupSuc = hCNetSDK.NET_DVR_Cleanup();
        if (cleanupSuc != true) {
            System.out.println("SDK反初始化失败!");
            return;
        }
    }
}
Copy after login

4. Video Preview
This section will introduce how to perform video preview operations and show how to set up a callback function to obtain video data in real time.

import com.sun.jna.CallbackThreadInitializer;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.hikvision.netsdk.*;

public class SDKDemo {
    private static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public static void main(String[] args) {
        // SDK初始化...

        // 登录...

        // 实时预览
        NativeLong lRealPlayHandle = hCNetSDK.NET_DVR_RealPlay_V30(lUserId, deviceInfo.byStartChan, null, null, true);
        if (lRealPlayHandle.longValue() < 0) {
            System.out.println("实时预览失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        // 设置预览回调函数
        HCNetSDK.FRealDataCallBack fRealDataCallBack = new HCNetSDK.FRealDataCallBack() {
            public void invoke(NativeLong lRealHandle, int dwDataType, Pointer pBuffer, int dwBufSize, Pointer pUser) {
                if (dwDataType == HCNetSDK.NET_DVR_SYSHEAD) {
                    // 获取系统头数据
                    System.out.println("收到系统头数据");
                } else if (dwDataType == HCNetSDK.NET_DVR_STREAMDATA) {
                    // 获取流数据
                    byte[] data = pBuffer.getByteArray(0, dwBufSize);
                    System.out.println("接收到视频数据:" + data.length);
                }
            }
        };

        boolean setCallbackSuc = hCNetSDK.NET_DVR_SetRealDataCallBack(lRealPlayHandle, fRealDataCallBack, null);
        if (setCallbackSuc != true) {
            System.out.println("设置预览回调函数失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }
        
        // 停止预览
        boolean stopPlaySuc = hCNetSDK.NET_DVR_StopRealPlay(lRealPlayHandle);
        if (stopPlaySuc != true) {
            System.out.println("停止预览失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        // 登出...

        // SDK反初始化...
    }
}
Copy after login

Conclusion:
The above is an introduction to the advanced Java Hikvision SDK secondary development technology. Through the implementation of SDK initialization, login, video preview and other operations, more personalized functional requirements can be realized. I hope this article will be helpful to developers who want to carry out secondary development of Hikvision SDK.

The above is the detailed content of Advanced Java Hikvision SDK Secondary Development Technical Guide. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template