Skip to content
This SDK only works with devices released within the past 3 years. We regularly optimize and update the SDK to ensure compatibility and performance. We do not guarantee compatibility or provide technical support for devices older than 3 years.

# PTZ Control

PTZ control includes basic control, preset points, setting cruise routes, trajectory operation, automatic scanning, and obtaining PTZ-related information.

## Interface Overview

interface Name | Functional Description
--- | ---
`NET_SDK_PTZControl` | The PTZ controls the operation. (Preview needs to be activated first)
`NET_SDK_PTZControl_Other` | The PTZ controls the operation.
`NET_SDK_PTZControl_3D` | IPC equipment PTZ 3D control function. (Preview needs to be activated - first)
`NET_SDK_PTZControl_3D_Ex` | IPC equipment PTZ 3D control function.
`NET_SDK_PTZPreset` | PTZ preset point operation. (Preview needs to be activated first)
`NET_SDK_PTZPreset_Other` | PTZ preset point operation.
`NET_SDK_PTZCruise` | PTZ cruise operation. (Preview needs to be activated first)
`NET_SDK_PTZCruise_Other` | PTZ cruise operation.
`NET_SDK_PTZSetCruise` | Set up the PTZ cruise route. (Preview needs to be activated first)
`NET_SDK_PTZSetCruise_Other` | Set up the PTZ cruise route.
`NET_SDK_PTZTrack` | PTZ trajectory operation. (Preview needs to be activated first)
`NET_SDK_PTZTrack_Other` | PTZ trajectory operation.
`NET_SDK_PTZAutoScan` | Automatic PTZ scanning operation. (Preview needs to be activated first)
`NET_SDK_PTZAutoScan_Other` | Automatic PTZ scanning operation.
`NET_SDK_GetPTZCameraType` | Get the types of cameras that support PTZ. (Camera only)
`NET_SDK_GetSupportPtzList` | Get a list of supported PTZs in the NVR device channel. (N9000 - devices only)
`NET_SDK_GetPTZConfig` | Get PTZ related configurations. (N9000 only)

## Process Description

    ---
    title: PTZ Control
    ---

    flowchart TD
        A(Device SDK initialization <br><strong>NET_SDK_Init</strong>)
        B(User registers device <br><strong>NET_SDK_Login</strong> or <br><strong>NET_SDK_LoginEx</strong>)

        C("Start preview <br><strong>NET_SDK_LivePlay</strong>")
        D("PTZ control <br><strong>NET_SDK_PTZControl</strong>")
        E("PTZ preset point operation <br><strong>NET_SDK_PTZPreset</strong>")
        F("... ...")
        G("Stop preview <br><strong>NET_SDK_StopLivePlay</strong>")

        H("PTZ cruise operation <br><strong>NET_SDK_PTZTrack_Other</strong>")
        I("PTZ auto scan operation <br><strong>NET_SDK_PTZAutoScan_Other</strong>")
        J("... ...")

        Y(Device logout <br><strong>NET_SDK_Logout</strong>)
        Z(Release SDK resources<br><strong>NET_SDK_Cleanup</strong>)
        C --> D --> G
        C --> E --> G
        C --> F --> G
        A --> B ---> C
        G --> Y --> Z
        B --> H ---> Y
        B --> I ---> Y
        B --> J ---> Y

## Sample Code

     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
    #include "PTZ.h"
    #include <afx.h>
    #include <string>
    #include <stdio>
    #include <iostream>
    #include "DVR_NET_SDK.h"

    void PTZControl()
    {
        // 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;
        }

        // Live Play.
        NET_SDK_CLIENTINFO clientInfo{0};
        clientInfo.hPlayWnd = GetConsoleWindow();
        // Channel number, starting from 0.
        clientInfo.lChannel = 0;
        /*
        Video stream type, including:
            NET_SDK_MAIN_STREAM、
            NET_SDK_SUB_STREAM、
            NET_SDK_THIRD_STREAM、
            NET_SDK_FOURTH_STREAM，
        Depends on the device's support.
        */
        clientInfo.streamType = NET_SDK_MAIN_STREAM;
        // Whether to decode.
        // 0: Decoding;
        // 1: Non-decoding, only for the Windows platform, default 0.
        clientInfo.bNoDecode = 0;
        // Start Live Play.
        LONG playHandle = NET_SDK_LivePlay(userid, &clientInfo, NULL, NULL);

        if (playHandle != -1)
        {
            std::cout << "Live Play successful!" << std::endl;
            // PTZ control operation.
            // Control the PTZ to tilt up.
            BOOL ptzStatus = NET_SDK_PTZControl(playHandle, PTZ_CMD_UP, PTZ_SPEED_1);

            if (ptzStatus)
            {
                std::cout << "PTZ control successful!" << std::endl;
            }
            else
            {
                errCode = NET_SDK_GetLastError();
                std::cout << "PTZ control failed!" << "Error code:" << errCode << std::endl;
            }

            // The PTZ stops after continuously rotating for 5 seconds.
            Sleep(5000);
            BOOL stopStatus = NET_SDK_PTZControl(playHandle, PTZ_CMD_STOP, PTZ_SPEED_1);

            if (!stopStatus)
            {
                errCode = NET_SDK_GetLastError();
                std::cout << "PTZ stop failed!" << "Error code:" << errCode << std::endl;
            }

            // Stop Live Play.
            NET_SDK_StopLivePlay(playHandle);
        }
        else
        {
            errCode = NET_SDK_GetLastError();
            std::cout << "Live Play failed!" << "Error code:" << errCode << std::endl;
        }

        // Logout.
        NET_SDK_Logout(userid);
        // Release SDK resources.
        NET_SDK_Cleanup();
        return;
    }

Error Code