Skip to content

vov4uk/Hik.Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hik.Api

  • Available as nuget

  • dotnet add package Hik.Api

  • NuGet Downloads

  • Wrapper over Hikvision SDK version 5.3.6.30 x64. It allows login, fetch files list (videos and photos), download files, get config list and more.

  • Or just run console app sample

Initialization (static)

HikApi.Initialize();

Login (static). Returns HikApi

var hikApi = HikApi.Login("192.168.1.64", 8000, "admin", "password");

Logout

hikApi.Logout();

Cleanup (static)

HikApi.Cleanup();

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

foreach (var channel in hikApi.IpChannels)
{
    Console.WriteLine($"{channel.Name} {channel.ChannelNumber}; IsOnline : {channel.IsOnline};");
}

Get SD Card info, capacity, free space, status etc. Returns HdInfo

var info = hikApi.ConfigService.GetHddStatus();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(info));

Get device config. Returns DeviceConfig

var device = hikApi.ConfigService.GetDeviceConfig();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(config));

Get network config. Returns NetworkConfig

var network = hikApi.ConfigService.GetNetworkConfig();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(network));

Get device current time

var cameraTime = hikApi.ConfigService.GetTime();
Console.WriteLine($"Camera time :{cameraTime}");

Set device time

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

Photo service

Get photos list from IP Camera (default IP channel). Returns IReadOnlyCollection<HikRemoteFile>

//Get photos files for last 24 hours
DateTime fromPeriod = DateTime.Now.AddHours(-24);
DateTime toPeriod = DateTime.Now;
var photos = await hikApi.PhotoService.FindFilesAsync(fromPeriod, toPeriod);

Get photos list from specific IP channel.

int channel = 2;
var photos = await hikApi.PhotoService.FindFilesAsync(fromPeriod, toPeriod, channel);

Download photos

foreach (var photo in photos)
{
    hikApi.PhotoService.DownloadFile(
        photo.Name,
        photo.Size,
        photo.ToPhotoFileNameString());
}

or

hikApi.PhotoService.DownloadFile(photo, photo.ToPhotoFileNameString());

Video service

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

var videos = await hikApi.VideoService.FindFilesAsync(fromPeriod, toPeriod);

Get videos list from IP Camera (specific IP channel)

int channel = 2;
var videos = await hikApi.VideoService.FindFilesAsync(fromPeriod, toPeriod, channel);

Download video

foreach (var video in videos)
{
    Console.WriteLine($"Downloading {video.ToVideoFileNameString()}");
    var downloadId = hikApi.VideoService.StartDownloadFile(
        video.Name,
        video.ToVideoFileNameString());
    do
    {
        await Task.Delay(5000); // check progress every 5 sec
        int progress = hikApi.VideoService.GetDownloadPosition(downloadId);
        if (progress == 100)
        {
            hikApi.VideoService.StopDownloadFile(downloadId);
            break;
        }
        else if (progress < 0 || progress > 100)
        {
            throw new Exception($"Get progress failed, value = {downloadProgress}");
        }
    }
    while (true);
}

Playback service

Start live preview without callback

int channel = 2;
var playbackId = hikApi.PlaybackService.StartPlayBack(channel);

or start live view to WinForm PictureBox

int channel = 2;
System.Windows.Forms.PictureBox pctBox = new System.Windows.Forms.PictureBox();
var playbackId = hikApi.PlaybackService.StartPlayBack(channel, pctBox.Handle);

Start recording live stream to filePath in .mp4 format (need start playback first)

int channel = 2;
hikApi.PlaybackService.StartRecording(
    playbackId,
    "filePath.mp4",
    channel);

Stop recording live stream to filePath

hikApi.PlaybackService.StopRecording(playbackId);

Stop real play

hikApi.PlaybackService.StopPlayBack(playbackId);

About

Simple wrapper over Hikvision SDK, with min functionality. Login, fetch files list, download files, and logout.

Topics

Resources

License

Stars

Watchers

Forks