Integrating Hikvision camera events with non-Hikvision recording software

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
Integrating Hikvision intrusion events with recording software

I currently have my Hikvision DS-2CD2042WD-I cameras recording to my Synology NAS using Synology's surveillance center. I can let the NAS do intrusion detection, but it impacts the machine pretty hard so ideally I want the cameras to do instrusion detection and notify the NAS (somehow?) when an event occurs.

My question is - how can I get the cameras to notify the NAS, or any other software, when an event occurs? Has anyone integrated Hikvision camera events with any software other than the Hikvision NVRs?
 
Last edited by a moderator:

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
Couldn't you use the camera to record to the machine directly, instead of using software?
The camera events can be read from the alert stream
http://YOURLOCALIP/ISAPI/Event/notification/alertStream
I might try that next. The software just makes it easier to sync multiple cameras with a timeline. Also, the camera's in-browser playback thing seems to only works on Windows, and I'm on a Mac. (There is some Hikvision thing that's supposed to get it working in Safari on OSX, but it just doesn't work. See my post here: https://www.ipcamtalk.com/showthread.php/13963-Pixelated-LiveView-on-Mac).

Thanks for the tip on the alert stream - that could be really helpful!
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
The alert stream is definitely usable.
I could never setup my camera to record properly.
I ended up using the alert stream in a very basic program I made for win.
It's not fancy but it works good enough for me and hasn't failed me yet.
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
The alert stream is definitely usable.
I could never setup my camera to record properly.
I ended up using the alert stream in a very basic program I made for win.
It's not fancy but it works good enough for me and hasn't failed me yet.
Very nice! Are you using any recording software that you integrate alerts with, or... what do you do with the alert stream events?

Also are you just polling (HTTP GET?) the event stream URL every few seconds?
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
I read the stream and when an event is triggered, the app tells the camera to record.
Strange because I could never get the camera to record events but I can through another app.

The bonus of having it through an app, I can move videos triggered by bugs to another folder or delete them, leaving only videos of interest.
I live in the country so I used to get 200 or so bug videos before, now I just get real detection.

I am using (http get) but only once. The stream is constantly downloading.
A small snippet, not the full code but the gist of it.
I'm not the best of coders but I know enough to just get by.
Code:
        void GetStream()
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://" + IPtxt.Text + "/ISAPI/Event/notification/alertStream");
            wr.Method = "GET";
            wr.Accept = "*/*";
            wr.ReadWriteTimeout = 5000;
            wr.KeepAlive = false;
            wr.Credentials = new NetworkCredential(Usertxt.Text, Passtxt.Text);
            using (WebResponse wr = wr.GetResponse())
            {
                using (StreamReader sr = new StreamReader(wr.GetResponseStream()))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                       Detection = (line == "<eventState>active</eventState>") ? true : (line == "<eventState>inactive</eventState>") ? false : Detection;
                       //The stream is parsed so the event can be read easily. No cpu load since the camera is doing the hard work.
                    }
                }
            }
        }
I can't view the live video or anything like that. I wanted it to run with the least amount of resources used, so I left that out.
I use my phone 99% of the time for viewing.
I've been using this method for over a year without issue.
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
I read the stream and when an event is triggered, the app tells the camera to record.
Strange because I could never get the camera to record events but I can through another app.

The bonus of having it through an app, I can move videos triggered by bugs to another folder or delete them, leaving only videos of interest.
I live in the country so I used to get 200 or so bug videos before, now I just get real detection.

I am using (http get) but only once. The stream is constantly downloading.
A small snippet, not the full code but the gist of it.
I'm not the best of coders but I know enough to just get by.
Code:
        void GetStream()
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://" + IPtxt.Text + "/ISAPI/Event/notification/alertStream");
            wr.Method = "GET";
            wr.Accept = "*/*";
            wr.ReadWriteTimeout = 5000;
            wr.KeepAlive = false;
            wr.Credentials = new NetworkCredential(Usertxt.Text, Passtxt.Text);
            using (WebResponse wr = wr.GetResponse())
            {
                using (StreamReader sr = new StreamReader(wr.GetResponseStream()))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                       Detection = (line == "<eventState>active</eventState>") ? true : (line == "<eventState>inactive</eventState>") ? false : Detection;
                       //The stream is parsed so the event can be read easily. No cpu load since the camera is doing the hard work.
                    }
                }
            }
        }
I can't view the live video or anything like that. I wanted it to run with the least amount of resources used, so I left that out.
I use my phone 99% of the time for viewing.
I've been using this method for over a year without issue.
That helps a lot, thanks. When you mention that you don't get bug videos anymore, what do you mean? How do you detect bug videos?
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
It doesn't detect bugs, it screens the file size.
It's a simple solution but it works. My camera uses 1mb per second of video.
Looking through the bug videos, they were all under 3mb.
When my app records a video, if it's under 3.5mb, it gets moved to a separate folder.

When I get a real detection, I simply look at the time stamp and compare it to the
moved files with similar time stamps. It's not a perfect system but it makes it pretty damn easy
to screen unwanted videos.
Because of it, I'm able to set the sensitivity high and not miss anything.
It isn't perfect because of the odd time a real detection gets moved because it's under 3.5mb, but I'm still able
to easily find it because of time stamps. Before it used to take me 15min to screen the detection's, now I view them straight away.
I plan on incorporating a motion feature to screen out heavy snow and rain, I still have issues with that.
That will use some cpu but it won't be doing it in real time, only on detection's from the cam so it shouldn't be a problem.

Here's an image. As you can see, it just a basic app but its good enough for my needs.
Motion App.png
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
Very nice - thanks for the info!

Since you're using the camera's built in recording capabilities, have you had any problems with the camera not recording as quickly as it should or missing a motion event entirely? Currently I'm recording 24/7 out of concern for missing something.
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
The only time I recall missing stuff is when I had the sensitivity low.
I have it set on expert mode.
Sensitivity 70
Proportion of object on area 1.
I think I used to have sensitivity on 3-4 because of bug issues and I'm sure I've missed stuff.

I've never had any issues with it not recording fast enough. I think I read somewhere that hik cameras have a 2-3 lag on recordings, so nothing is missed.
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
The only time I recall missing stuff is when I had the sensitivity low.
I have it set on expert mode.
Sensitivity 70
Proportion of object on area 1.
I think I used to have sensitivity on 3-4 because of bug issues and I'm sure I've missed stuff.

I've never had any issues with it not recording fast enough. I think I read somewhere that hik cameras have a 2-3 lag on recordings, so nothing is missed.
So does that mean recorded videos don't start until 2-3 seconds after the intrusion is detected?
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
So does that mean recorded videos don't start until 2-3 seconds after the intrusion is detected?
2-3sec before. Don't take my word on it though, I tend to misinterpret things I read sometimes.

If you don't mind me asking, are you having issues with vandalism or theft.
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
2-3sec before. Don't take my word on it though, I tend to misinterpret things I read sometimes.

If you don't mind me asking, are you having issues with vandalism or theft.
We've had a lot of break-ins in our neighborhood over the last year, including a few on my street. If our house does get hit, I at least want to catch something :)
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
We've had a lot of break-ins in our neighborhood over the last year, including a few on my street. If our house does get hit, I at least want to catch something :)
I would be on edge too. Two nights ago, I had some disturbances in my yard, I just put the sound down to a raccoon or some other type of animal.
Yesterday morning, one of my neighbors came to me asking if I've had anyone snooping around my yard, he said on multiple occasions someone has been snooping
around his yard at 3 in the morning, looking through his windows with a flashlight.

I've not seen anything though, just sounds. I'll start to worry a little if someone does try breaking in or I see someone.
 

ipslascam

Young grasshopper
Joined
Sep 13, 2016
Messages
44
Reaction score
4
I read the stream and when an event is triggered, the app tells the camera to record.
Strange because I could never get the camera to record events but I can through another app.

The bonus of having it through an app, I can move videos triggered by bugs to another folder or delete them, leaving only videos of interest.
I live in the country so I used to get 200 or so bug videos before, now I just get real detection.

I am using (http get) but only once. The stream is constantly downloading.
A small snippet, not the full code but the gist of it.
I'm not the best of coders but I know enough to just get by.
Code:
        void GetStream()
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://" + IPtxt.Text + "/ISAPI/Event/notification/alertStream");
            wr.Method = "GET";
            wr.Accept = "*/*";
            wr.ReadWriteTimeout = 5000;
            wr.KeepAlive = false;
            wr.Credentials = new NetworkCredential(Usertxt.Text, Passtxt.Text);
            using (WebResponse wr = wr.GetResponse())
            {
                using (StreamReader sr = new StreamReader(wr.GetResponseStream()))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                       Detection = (line == "<eventState>active</eventState>") ? true : (line == "<eventState>inactive</eventState>") ? false : Detection;
                       //The stream is parsed so the event can be read easily. No cpu load since the camera is doing the hard work.
                    }
                }
            }
        }
I can't view the live video or anything like that. I wanted it to run with the least amount of resources used, so I left that out.
I use my phone 99% of the time for viewing.
I've been using this method for over a year without issue.

Digging up this old thread - how do you tell the camera to record via your code? Is there an API for that?
 
Joined
Jul 16, 2016
Messages
9
Reaction score
1
Digging up this old thread - how do you tell the camera to record via your code? Is there an API for that?
The way I did it is to use HtmlElement. Here is what that function looked like.

Code:
        void RunCommand(string Command)
        {
            if (wb.Url == null) return;
            HtmlElement tmp = wb.Document.GetElementById("contentframe").Document.Window.Frames["contentframe"].Document.GetElementById(Command);
            tmp.InvokeMember("Click");
            while (wb.ReadyState != WebBrowserReadyState.Complete)
                Application.DoEvents();
        }
I used WebBrowser to navigate to the camera page. Then while monitoring the stream, if a detection was triggered, I'd run two commands which are case sensitive.
Code:
RunCommand("play");
RunCommand("startRecord");
Once the detection stopped, I ran
Code:
RunCommand("play");
I attached my messy, uncommented source. Do what you want with it
 

Attachments

Top