跳转至

回放

此模块包含了录像的查找、回放、下载、锁定、删除等功能。

接口概览

接口名称 功能描述
NET_SDK_FindFile 查找录像文件。
NET_SDK_FindNextFile 获取文件信息(文件名、大小、开始和结束时间)。
NET_SDK_FindClose 关闭查找文件。
NET_SDK_PlayBackByTime 按时间回放。
NET_SDK_PlayBackControl 控制回放状态。
NET_SDK_StopPlayBack 停止回放。

流程说明

---
title: 录像回放
---

flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)

    subgraph 查找录像文件
        direction LR
        S0(查找录像文件<br><strong>NET_SDK_FindFile</strong>)
        S1(逐个获取录像文件信息<br><strong>NET_SDK_FindNextFile</strong>)
        S2(停止录像查找<br><strong>NET_SDK_FindClose</strong>)
        S0 --> S1 --> S2
    end

    subgraph 录像文件回放
        direction LR
        S00(按时间回放<br><strong>NET_SDK_PlayBackByTime</strong>)
        S01(回放状态控制<br><strong>NET_SDK_PlayBackControl</strong>)
        S02(停止录像回放<br><strong>NET_SDK_StopPlayBack</strong>)
        S00 --> S01 --> S02
    end


    E(注销设备<br><strong>NET_SDK_Logout</strong>)
    F(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)

    A --> B --> 查找录像文件 --> 录像文件回放 --> E --> F
Note
  • NET_SDK_FindFile:查询某个时间段内是否有录像文件

  • NET_SDK_FindNextFile:通过 NET_SDK_FindFile 返回的句柄,查询录像文件的具体信息,包括录像的起止时间等

  • NET_SDK_PlayBackByTime:通过 NET_SDK_FindNextFile 返回的录像的起止时间,回放录像

示例代码

  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

/*
    Transform string time to CTime
*/
CTime parseStrTimeToCTime(string_view intime)
{
    tm tm = {};
    istringstream ss(intime.data());
    // Parse string time
    ss >> get_time(&tm, "%Y-%m-%d %H:%M:%S");
    // Transform tm to time_t
    time_t tt = mktime(&tm);
    // Transform time_t to CTime
    CTime ctime(tt);
    return ctime;
}
void Playback()
{
    // Initial
    NET_SDK_Init();
    // 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";
    // Login
    NET_SDK_DEVICEINFO device_info = {0};
    LONG 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)
    {
        cout << "Login successfully: " << userid << endl;
    }
    else
    {
        cout << "Failed to login: " << userid << endl;
        return;
    }

    // Find record file
    LONG chnn = 0;
    CTime startTime = parseStrTimeToCTime("2023-05-05 00:00:00");
    CTime endTime = parseStrTimeToCTime("2023-05-05 23:59:59");
    DD_TIME start = {startTime.GetSecond(), startTime.GetMinute(), startTime.GetHour(), 3, startTime.GetDay(), startTime.GetMonth() - 1, startTime.GetYear() - 1900};
    DD_TIME end = {endTime.GetSecond(), endTime.GetMinute(), endTime.GetHour(), 3, endTime.GetDay(), endTime.GetMonth() - 1, endTime.GetYear() - 1900};
    LONG ffHandle = NET_SDK_FindFile(userid, chnn, &start, &end);

    if (ffHandle == -1)
    {
        DWORD err1 = NET_SDK_GetLastError();
        cout << "Failed to find record file! Error code: " << err1 << endl;
    }
    else
    {
        cout << "Find record file successfully!" << endl;
        // Get file information (filename, size, startTime and stopTime)
        NET_SDK_REC_FILE file;
        LONG result = NET_SDK_FindNextFile(ffHandle, &file);
        HWND hWnd = GetConsoleWindow();

        if (result != NET_SDK_FILE_SUCCESS)
        {
            DWORD err4 = NET_SDK_GetLastError();
            cout << "Failed to get file information! Error code: " << err4 << endl;
        }
        else
        {
            cout << "Get file information successfully!" << endl;
            // Playback by time
            LONG plHandle = NET_SDK_PlayBackByTime(userid, &chnn, 1, &file.startTime, &file.stopTime, &hWnd);
            // Waiting for playback
            Sleep(3000);

            if (plHandle == -1)
            {
                DWORD err3 = NET_SDK_GetLastError();
                cout << "Pailed to playback! error code: " << err3 << endl;
            }
            else
            {
                cout << "Playback successfully!" << endl;
                // Control the status of playback
                BOOL control = NET_SDK_PlayBackControl(plHandle, NET_SDK_PLAYCTRL_PAUSE, NET_SDK_RPB_SPEED_1_32X, NULL);

                if (control != true)
                {
                    DWORD err2 = NET_SDK_GetLastError();
                    cout << "Failed to pause playback! " << err2 << endl;
                }
                else
                {
                    cout << "Pause playback successfully! " << endl;
                }

                // Stop to playback
                NET_SDK_StopPlayBack(plHandle);
            }
        }

        // Stop to Find record file
        NET_SDK_FindClose(ffHandle);
    }

    // Logout
    NET_SDK_Logout(userid);
    // Clean up the data
    NET_SDK_Cleanup();
}

相关说明

  • NET_SDK_PlayBackControl 只举例了暂停回放(NET_SDK_PLAYCTRL_PAUSE)的场景
错误码