视频抓图 提供 JPEG 格式抓图功能,包括返回图片二进制数据、图像文件直接存储。
接口概览 流程说明 ---
title: 视频抓图
---
flowchart TD
A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
C("截取JPEG图片数据<br><strong>NET_SDK_CaptureJPEGData_V2</strong>")
D("截取JPEG图片文件<br><strong>NET_SDK_CaptureJPEGFile_V2</strong>")
E("...")
F("搜索图片<br><strong>NET_SDK_SearchPictures</strong>")
G("下载搜索到的图片<br><strong>NET_SDK_DownloadPicture</strong>")
Y(注销设备<br><strong>NET_SDK_Logout</strong>)
Z(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)
A --> B
Y --> Z
B ---> C ---> Y
B ---> D ---> Y
B ---> E ---> Y
B ---> F ---> Y
B ---> G ---> Y
示例代码 获取截图数据到缓存区 将截图下载至本地保存为文件
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 #include <afx.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include "DVR_NET_SDK.h"
void CaptureJPEGData ()
{
// Device information.
const std:: string device_ip = "10.80.1.177" ;
const DWORD decice_port = 6036 ;
const std:: string username = "admin" ;
const std:: string password = "123456" ;
// Initialize SDK.
NET_SDK_Init();
NET_SDK_DEVICEINFO device_info{0 };
DWORD errCode = 0 ;
// Device login.
int userid = NET_SDK_Login(const_cast < char *> (device_ip.c_str()), decice_port, const_cast < char *> (username.c_str()), const_cast < char *> (password.c_str()), & device_info);
if (userid > 0 )
{
std:: cout << "Login successful!" << std:: endl;
}
else
{
errCode = NET_SDK_GetLastError();
std:: cout << "Login failed!" << "Error code:" << errCode << std:: endl;
NET_SDK_Cleanup();
return ;
}
// Get the screenshot data and save it to the local disk.
DWORD dwRetLen = 0 ;
const int nJpgBufLen = 1024 * 1024 * 5 ;
char * pJpegBuf = new char [nJpgBufLen];
memset(pJpegBuf, 0x00 , nJpgBufLen);
char imgName[512 ]{0 };
sprintf_s(imgName, "D:/test.jpg" );
BOOL captureStatus = NET_SDK_CaptureJPEGData_V2(userid, 0 , pJpegBuf, nJpgBufLen, & dwRetLen);
if (! captureStatus)
{
errCode = NET_SDK_GetLastError();
std:: cout << "Screenshot failed!" << "Error code:" << errCode << std:: endl;
}
else
{
FILE * file;
errno_t err = fopen_s(& file, imgName, "wb" );
if (err = 0 || file != NULL )
{
fwrite(pJpegBuf, sizeof (char ), dwRetLen, file);
fclose(file);
std:: cout << "Screenshot successful!" << std:: endl;
}
else
{
std:: cout << "Screenshot failed! write file failed!" << std:: endl;
}
}
// Logout.
NET_SDK_Logout(userid);
// Release SDK resources.
NET_SDK_Cleanup();
return ;
}
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 #include <afx.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include "DVR_NET_SDK.h"
void CaptureJPEGFile ()
{
// Device information.
const std:: string device_ip = "10.80.1.177" ;
const DWORD decice_port = 6036 ;
const std:: string username = "admin" ;
const std:: string password = "123456" ;
// Initialize SDK.
NET_SDK_Init();
NET_SDK_DEVICEINFO device_info{0 };
DWORD errCode = 0 ;
// Device login.
int userid = NET_SDK_Login(const_cast < char *> (device_ip.c_str()), decice_port, const_cast < char *> (username.c_str()), const_cast < char *> (password.c_str()), & device_info);
if (userid > 0 )
{
std:: cout << "Login successful!" << std:: endl;
}
else
{
errCode = NET_SDK_GetLastError();
std:: cout << "Login failed!" << "Error code:" << errCode << std:: endl;
NET_SDK_Cleanup();
return ;
}
// Save the screenshot directly to the local disk.
char imgName[512 ]{0 };
sprintf_s(imgName, "D:/test.jpg" );
BOOL captureStatus = NET_SDK_CaptureJPEGFile_V2(userid, 0 , imgName);
if (! captureStatus)
{
errCode = NET_SDK_GetLastError();
std:: cout << "Screenshot failed!" << "Error code:" << errCode << std:: endl;
}
else
{
std:: cout << "Screenshot successful!" << std:: endl;
}
// Logout.
NET_SDK_Logout(userid);
// Release SDK resources.
NET_SDK_Cleanup();
return ;
}