Qt连接海康硬盘录像机

qt

 

最近碰到个做视频监控的项目,硬件是海康录像机,开发环境是 Windows 7 + QT 5.2

1.去海康官方网站下载sdk,http://www.hikvision.com/cn/download_more_401.html

2.解压后在lib目录下,找到HCNetSDK.dll,HCNetSDK.lib,PlayCtrl.dll,PlayCtrl.lib,StreamTransClient.dll,SystemTransform.dll

3.其中dll放到项目输出目录,lib文件做为隐式调用,incCn目录下的HCNetSDK.h,plaympeg4.h,DataType.h,DecodeCardSdk.h是include的头文件

4.测试代码

    LONG lUserID;
LONG IRealPlayHandle = -1;

NET_DVR_DEVICEINFO_V30 struDeviceInfo;
memset(&struDeviceInfo,0,sizeof(NET_DVR_DEVICEINFO_V30));
NET_DVR_CLIENTINFO ClientInfo={0};

// 初始化
NET_DVR_Init();

//设置连接时间与重连时间
NET_DVR_SetConnectTime(1000, 1);
NET_DVR_SetReconnect(10000, true);

// 注册设备
lUserID = NET_DVR_Login_V30("192.168.1.100", 8000, "admin", "12345", &struDeviceInfo);
if (lUserID < 0){
qDebug()<<"Login error"<<NET_DVR_GetLastError();
NET_DVR_Cleanup();
}else{
qDebug()<<"connect success";
}

HWND hWnd = (HWND)ui->labelView->winId();
ClientInfo.hPlayWnd = hWnd;
ClientInfo.lChannel = 1; //channel NO.
ClientInfo.lLinkMode = 0;
ClientInfo.sMultiCastIP = NULL;

IRealPlayHandle = NET_DVR_RealPlay_V30(lUserID,&ClientInfo,NULL,NULL,false);

// 关闭预览
NET_DVR_StopRealPlay(IRealPlayHandle);
// 注销用户
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();