Skip to content

Wrapper over Dahua NetSDK (v3.057.0000000.0.R.230309, win-x64). It allows login, fetch videso list, download, get config list and more.

License

Notifications You must be signed in to change notification settings

vov4uk/Dahua.Api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dahua.Api

  • Available as nuget

  • dotnet add package Dahua.Api --version 1.0.1

  • NuGet Downloads

  • Wrapper over Dahua SDK. It allows login, fetch videos list, download videos, get config list and more.

  • Or just run console app sample

Initialization

DahuaApi.Init();

Login. Returns DahuaApi

var session = DahuaApi.Login("192.168.1.63", 37777, "admin", "pass");

Logout

session.Logout();
DahuaApi.Cleanup();

Print list of IP channels for NVR (IP Camera use hikapi.DefaultIpChannel)

Console.WriteLine("Channel:" + string.Join(",", session.AllChannels.Select(t => $"Channel{t.Id}_{t.Name}")));

Get machine name.

session.ConfigService.GetMachineName();

Get device serial number.

session.ConfigService.GetDeviceSerialNumber();

Get device type.

session.ConfigService.GetDeviceType();

Get device current time

session.ConfigService.GetTime();

Set device time

var currentTime = DateTime.Now;
session.ConfigService.SetTime(currentTime);

Video service

Get videos list from IP Camera (default IP channel). Returns IReadOnlyCollection<RemoteFile>

var videos = session.VideoService.FindFiles(DateTime.Today, DateTime.Now);

Get videos list from IP Camera (specific IP channel)

int channel = 2;
var videos = session.VideoService.FindFiles(DateTime.Today, DateTime.Now, channel);

Download video

foreach (var video in videos)
{
    Console.WriteLine(video.Name);
    var name = $"{video.Date.ToString(DateFormat)}_{video.Duration}.mp4";
    var destinationPath = Path.Combine(@$"C:\Users\{Environment.UserName}\Desktop", name);
    var downloadId = session.VideoService.StartDownloadFile(video, destinationPath);
    if (downloadId > 0)
    {
        Console.WriteLine($"Downloading {destinationPath}");
        do
        {
            await Task.Delay(5000);
            var downloadProgress = session.VideoService.GetDownloadPosition(downloadId);
            Console.WriteLine($"Downloading {downloadProgress} %");
            if (downloadProgress.downloadSize == downloadProgress.totalSize)
            {
                session.VideoService.StopDownloadFile(downloadId);
                break;
            }
            else if (!downloadProgress.success)
            {
                throw new InvalidOperationException($"UpdateDownloadProgress failed, progress value = {downloadProgress}");
            }
        }
        while (true);
        Console.WriteLine($"Downloaded {destinationPath}");
    }
}

About

Wrapper over Dahua NetSDK (v3.057.0000000.0.R.230309, win-x64). It allows login, fetch videso list, download, get config list and more.

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • C# 99.9%
  • Batchfile 0.1%