當前位置:
首頁 >
海康sdkC++二次开发之回放下载
發布時間:2024/1/8
29
豆豆
生活随笔
收集整理的這篇文章主要介紹了
海康sdkC++二次开发之回放下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
功能簡介
因為項目只用到下載錄像機硬盤視頻的功能,所以就想找比較簡單的代碼,最后是在官方sdk文檔的幫助文檔中找到的,每個功能都有一個小示例,下面貼出來`
#include <stdio.h> #include <iostream> #include "Windows.h" #include "videoInclude/HCNetSDK.h" using namespace std;int main() { //--------------------------------------- // 初始化 NET_DVR_Init(); //設置連接時間與重連時間 NET_DVR_SetConnectTime(2000, 1); NET_DVR_SetReconnect(10000, true);//--------------------------------------- // 注冊設備 LONG lUserID;//登錄參數,包括設備地址、登錄用戶、密碼等 NET_DVR_USER_LOGIN_INFO struLoginInfo = { 0 }; struLoginInfo.bUseAsynLogin = 0; //同步登錄方式 strcpy_s(struLoginInfo.sDeviceAddress, "192.168.8.121"); //設備IP地址 struLoginInfo.wPort = 8000; //設備服務端口 strcpy_s(struLoginInfo.sUserName, "admin"); //設備登錄用戶名 strcpy_s(struLoginInfo.sPassword, "tnzn123456"); //設備登錄密碼//設備信息, 輸出參數 NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = { 0 };lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40); if (lUserID < 0) {printf("Login failed, error code: %d\n", NET_DVR_GetLastError());NET_DVR_Cleanup();return 1; } else {printf("Login success!!\n"); } //查找文件 //LPNET_DVR_FILECOND_V40 FileCond; // //查找類型:全部 //FileCond->dwFileType = 0xff; //FileCond->dwIsLocked = 0xff; //FileCond->dwUseCardNo = 0xff;//查找通道://設置查找時間//NET_DVR_FindFile_V40(lUserID, FileCond);NET_DVR_PLAYCOND struDownloadCond = { 0 }; struDownloadCond.dwChannel = 33;struDownloadCond.struStartTime.dwYear = 2020; struDownloadCond.struStartTime.dwMonth = 5; struDownloadCond.struStartTime.dwDay = 24; struDownloadCond.struStartTime.dwHour = 15; struDownloadCond.struStartTime.dwMinute = 01; struDownloadCond.struStartTime.dwSecond = 0; struDownloadCond.struStopTime.dwYear = 2020; struDownloadCond.struStopTime.dwMonth = 6; struDownloadCond.struStopTime.dwDay = 27; struDownloadCond.struStopTime.dwHour = 18; struDownloadCond.struStopTime.dwMinute = 3; struDownloadCond.struStopTime.dwSecond = 0;//--------------------------------------- //按時間下載 int hPlayback; const char* saveFileSite = "E:\\work\\video\\test.mp4"; hPlayback = NET_DVR_GetFileByTime_V40(lUserID,(char*) saveFileSite, &struDownloadCond); if (hPlayback < 0) {printf("NET_DVR_GetFileByTime_V40 fail,last error %d\n", NET_DVR_GetLastError());NET_DVR_Logout(lUserID);NET_DVR_Cleanup();return 1; }//--------------------------------------- //開始下載 if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART, NULL, 0, NULL, NULL)) {printf("Play back control failed [%d]\n", NET_DVR_GetLastError());NET_DVR_Logout(lUserID);NET_DVR_Cleanup();return 1; }int nPos = 0; for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayback)) {printf("Be downloading... %d %%\n", nPos);Sleep(5000); //millisecond } if (!NET_DVR_StopGetFile(hPlayback)) {printf("failed to stop get file [%d]\n", NET_DVR_GetLastError());NET_DVR_Logout(lUserID);NET_DVR_Cleanup();return 1; } if (nPos < 0 || nPos>100) {printf("download err [%d]\n", NET_DVR_GetLastError());NET_DVR_Logout(lUserID);NET_DVR_Cleanup();return 1; } printf("Be downloading... %d %%\n", nPos);//注銷用戶 NET_DVR_Logout(lUserID); //釋放SDK資源 NET_DVR_Cleanup(); return 11; }這里面有一個要注意的點,在選擇通道的時候要寫所要查找攝像機的通道ID,有從1開始、也有從33開始的
獲取通道ID方法
官方示 部分功能 回放下載src代碼中可以獲得
詳細內容,看官方手冊最好,里面每個參數講的清清楚楚,明明白白
總結
以上是生活随笔為你收集整理的海康sdkC++二次开发之回放下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 追求成功三要诀 文 | 刘东华
- 下一篇: 海康视频下载,以及实时视频预览