开发海康威视sdk ,IPC设备,视频回调用的是官方提供的Demo中的(fRealDataCallBack )
在最下面代码可以设置Thread.sleep()设置拍摄时长
-
文件结构
-
CameraInfo的内容
package ClientDemo;
import com.sun.jna.NativeLong;
public class CameraInfo {
private String address;
private String userName;
private String pwd;
private short port;
private NativeLong userId;
private NativeLong channel;
private NativeLong key;
public NativeLong getKey() {
return key;
public void setKey(NativeLong key) {
this.key = key;
public void setAddress(String address){
this.address = address;
public void setUserName(String userName){
this.userName = userName;
public void setPwd(String pwd){
this.pwd = pwd;
public void setPort(short port){
this.port = port;
public NativeLong getUserId(){
return userId;
public NativeLong getChannel(){
return channel;
public String getAddress(){
return address;
public short getPort(){
return port;
public String getUserName() {
return userName;
public String getPwd() {
return pwd;
public void setChannel(NativeLong channel) {
this.channel = channel;
public void setUserId(NativeLong userId) {
this.userId = userId;
package ClientDemo;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import java.io.File;
public class HIKSDKSaveRealData {
public static void main(String[] args) {
HIKSDKSaveRealData HikSdk= new HIKSDKSaveRealData();
short port =8000;
CameraInfo cameraInfo = new CameraInfo();
cameraInfo.setAddress("192.168.1.64");
cameraInfo.setPort(port);
cameraInfo.setUserName("admin");
cameraInfo.setPwd("gw*123456");
HikSdk.getDVRConfig(cameraInfo);
HikSdk.SaveRealDataformDir(cameraInfo);
* 获取实时视频方法 传入连接信息对象
* 目的:获取到实时视频存入指定文件中 保存为Mp4格式文件
public void getDVRConfig(CameraInfo cameraInfo){
HCNetSDK sdk =HCNetSDK.INSTANCE;
if (!sdk.NET_DVR_Init()){
System.out.println("初始化失败..........");
return;
sdk.NET_DVR_SetConnectTime(2000, 1);
sdk.NET_DVR_SetReconnect(10000, true);
HCNetSDK.NET_DVR_DEVICEINFO_V30 deInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
System.out.println("设备信息: " +deInfo);
NativeLong id = sdk.NET_DVR_Login_V30(cameraInfo.getAddress(), cameraInfo.getPort(),
cameraInfo.getUserName(), cameraInfo.getPwd(), deInfo);
cameraInfo.setUserId(id);
if(cameraInfo.getUserId().intValue()<0){
System.out.println("注册失败,错误码为"+sdk.NET_DVR_GetLastError());
return;
HCNetSDK.NET_DVR_WORKSTATE_V30 devwork = new HCNetSDK.NET_DVR_WORKSTATE_V30();
if(!sdk.NET_DVR_GetDVRWorkState_V30(cameraInfo.getUserId(),devwork )){
System.out.println("返回设备状态失败");
return;
IntByReference ibrBytesReturned = new IntByReference(0);
HCNetSDK.NET_DVR_IPPARACFG ipcfg = new HCNetSDK.NET_DVR_IPPARACFG();
ipcfg.write();
Pointer lpIpParaConfig = ipcfg.getPointer();