


Use Java Hikvision SDK secondary development to build a powerful video surveillance system
Use Java Hikvision SDK for secondary development to build a powerful video surveillance system
Abstract:
This article will introduce how to use Java Hikvision SDK for secondary development , build a powerful video surveillance system. Through the rich interfaces and functions provided by Hikvision SDK, we can easily implement video recording, real-time preview, remote control and other functions, and add customized business logic. This article will introduce in detail how to use Java Hikvision SDK for secondary development, and provide some sample code to help readers better understand.
Part One: Environment Preparation
Before starting, we need to make the following preparations:
- Download and install Java JDK.
- Download and install IDE, such as Eclipse.
- Download and install Hikvision SDK.
Part 2: Project Creation and Configuration
- Create a Java project and import the jar package of Hikvision SDK.
- Configure the relevant parameters of Hikvision SDK, such as device IP, port number, user name, password, etc.
- Create a main class to initialize the SDK and perform related operations.
Part 3: Real-time preview function
Real-time preview is one of the most basic functions in the video surveillance system. The following is a sample code that demonstrates how to use Hikvision SDK for real-time preview:
import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.NativeLongByReference; import com.sun.jna.ptr.PointerByReference; import com.hikvision.netsdk.HCNetSDK; import com.hikvision.netsdk.NET_DVR_DEVICEINFO_V30; import com.hikvision.netsdk.NET_DVR_PREVIEWINFO; public class RealTimePreview { private static HCNetSDK hikSDK = HCNetSDK.INSTANCE; public static void main(String[] args) { // 初始化SDK hikSDK.NET_DVR_Init(); // 登录设备 NativeLong lUserID; NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30(); lUserID = hikSDK.NET_DVR_Login_V30("192.168.1.100", (short) 8000, "admin", "password", deviceInfo); if (lUserID.intValue() == -1) { System.out.println("登录失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 设置预览参数 NativeLong lRealPlayHandle; NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO(); previewInfo.lChannel = 1; previewInfo.dwStreamType = 0; previewInfo.dwLinkMode = 0; previewInfo.hPlayWnd = null; // 开始预览 lRealPlayHandle = hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null); if (lRealPlayHandle.intValue() == -1) { System.out.println("预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 等待预览停止 System.out.println("按任意键停止预览..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); } // 停止预览 if (!hikSDK.NET_DVR_StopRealPlay(lRealPlayHandle)) { System.out.println("停止预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 退出登录 hikSDK.NET_DVR_Logout(lUserID); hikSDK.NET_DVR_Cleanup(); System.out.println("退出成功"); } }
Part 4: Video recording function
In addition to real-time preview, the video surveillance system also needs to provide video recording function. The following is a sample code that demonstrates how to use Hikvision SDK for video recording:
import com.sun.jna.NativeLong; import com.sun.jna.ptr.NativeLongByReference; import com.hikvision.netsdk.HCNetSDK; import com.hikvision.netsdk.NET_DVR_DEVICEINFO_V30; import com.hikvision.netsdk.NET_DVR_PREVIEWINFO; import com.hikvision.netsdk.NET_DVR_TIME; public class VideoRecording { private static HCNetSDK hikSDK = HCNetSDK.INSTANCE; public static void main(String[] args) { // 初始化SDK hikSDK.NET_DVR_Init(); // 登录设备 NativeLong lUserID; NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30(); lUserID = hikSDK.NET_DVR_Login_V30("192.168.1.100", (short) 8000, "admin", "password", deviceInfo); if (lUserID.intValue() == -1) { System.out.println("登录失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 设置预览参数 NativeLong lRealPlayHandle; NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO(); previewInfo.lChannel = 1; previewInfo.dwStreamType = 0; previewInfo.dwLinkMode = 0; previewInfo.hPlayWnd = null; // 开始预览 lRealPlayHandle = hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null); if (lRealPlayHandle.intValue() == -1) { System.out.println("预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 开始录像 NativeLongByReference lRecordHandle = new NativeLongByReference(); NET_DVR_TIME startTime = new NET_DVR_TIME(); startTime.dwYear = 2022; startTime.dwMonth = 12; startTime.dwDay = 1; startTime.dwHour = 0; startTime.dwMinute = 0; startTime.dwSecond = 0; if (!hikSDK.NET_DVR_SetFileTime(0, startTime)) { System.out.println("设置录像时间失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } lRecordHandle.setValue(hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null)); if (lRecordHandle.intValue() == -1) { System.out.println("录像失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 等待录像停止 System.out.println("按任意键停止录像..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); } // 停止录像 if (!hikSDK.NET_DVR_StopRealPlay(lRecordHandle.getValue())) { System.out.println("停止录像失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 退出登录 hikSDK.NET_DVR_Logout(lUserID); hikSDK.NET_DVR_Cleanup(); System.out.println("退出成功"); } }
Summary:
This article introduces how to use Java Hikvision SDK for secondary development to build a powerful video surveillance system. Through the interfaces and functions provided by Hikvision SDK, we can implement functions such as real-time preview and video recording, and add customized business logic. I hope this article can help readers learn and use Java Hikvision SDK.
The above is the detailed content of Use Java Hikvision SDK secondary development to build a powerful video surveillance system. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function