wangzhengquan
2020-06-16 27a32410481fc10e789315b3a1dab88a33020270
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "usg_common.h"
#include <stdio.h>
#include <iostream>
#include "HCNetSDK.h"
using namespace std;
int main()
{
//---------------------------------------
// 初始化
  NET_DVR_Init();
//设置连接时间与重连时间
  NET_DVR_SetConnectTime(2000, 1);
  NET_DVR_SetReconnect(10000, true);
//---------------------------------------
// 注册设备
  LONG lUserID;
  NET_DVR_DEVICEINFO_V30 struDeviceInfo;
  lUserID = NET_DVR_Login_V30("192.168.20.11", 8000, "admin", "a1234567", &struDeviceInfo);
  if (lUserID < 0)
  {
    printf("Login error, %d\n", NET_DVR_GetLastError());
    NET_DVR_Cleanup();
    return 0;
  }
  NET_DVR_PLAYCOND struDownloadCond = {0};
  struDownloadCond.dwChannel = 1; //通道号
  struDownloadCond.struStartTime.dwYear = 2020; //开始时间
  struDownloadCond.struStartTime.dwMonth = 4;
  struDownloadCond.struStartTime.dwDay = 11;
  struDownloadCond.struStartTime.dwHour = 9;
  struDownloadCond.struStartTime.dwMinute = 50;
  struDownloadCond.struStartTime.dwSecond = 0;
  struDownloadCond.struStopTime.dwYear = 2020; //结束时间
  struDownloadCond.struStopTime.dwMonth = 4;
  struDownloadCond.struStopTime.dwDay = 11;
  struDownloadCond.struStopTime.dwHour = 10;
  struDownloadCond.struStopTime.dwMinute = 0;
  struDownloadCond.struStopTime.dwSecond = 0;
//---------------------------------------
//按时间下载
  int hPlayback;
  hPlayback = NET_DVR_GetFileByTime_V40(lUserID, "./test.mp4", &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 0;
  }
//---------------------------------------
//开始下载
  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 0;
  }
  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 0;
  }
  if (nPos < 0 || nPos > 100)
  {
    printf("download err [%d]\n", NET_DVR_GetLastError());
    NET_DVR_Logout(lUserID);
    NET_DVR_Cleanup();
    return 0;
  }
  printf("Be downloading... %d %%\n", nPos);
//注销用户
  NET_DVR_Logout(lUserID);
//释放 SDK 资源
  NET_DVR_Cleanup();
  return 0;
}