Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing frames from a Hikvision IP-camera

Tags:

c#

.net

ip-camera

I'm having problems with grabbing frames from a remote IP-camera. My employer wants it done in C# .NET (for Windows) and if possible to use a light-weight solution, i.e. not using any huge frameworks.

The device model is DS-2CD2632F-I, it us currently connected to my LAN and the camera's Web-interface works perfectly fine.

I already tried out several popular frameworks, e.g. AForge, EmguCV, OzekiSDK and Directshow.NET, but none of them seem to be working. Particularly the OzekiSDK (apparently, recommended by Hikvision?) isn't able to get a video stream from the camera, even if I simply use of the sample projects provided, which simply shows a black screen and throws an "Empty camera object" exception if I try to grab a frame.

The camera's Web-interface works correctly and even the VLC Player manages to successfully play the stream from the camera via a rtsp:// link (rtsp://my_ip:554//Streaming/Channels/1), without asking for the login and the password.

I thought about using libvlcnet, but I'm not sure it's a viable solution.

Do you have any recommendations?

like image 572
xonxt Avatar asked Jul 14 '15 06:07

xonxt


People also ask

How can I get RTSP stream from HikVision camera?

If the ID is 102, we will get sub stream of the 1st channel. If the ID is 101, we will get main stream. RTSP URL supports to add username and password: rtsp://admin:12345@IP:Port/Streaming/Channels/ID/?transportmode=multicast. The type of authorization supports BASIC and DIGEST.

Where are HikVision videos saved?

Files created by taking a snapshot, recording video, or downloading saved clips, go into their respective sub-folders under the C:\Users\%username%\Web folder. AND I think they get removed immediately. The easiest way to address this is to add your camera's IP address to the list of trusted sites.


1 Answers

Ok, so I think I figured it out. I'll post the solution here, in case someone needs it in future. I found out, that for this particular type of camera there is a url, that simply returns the current frame from the camera as a JPEG picture, which looks like this: http://IP_ADDRESS:PORT/Streaming/channels/1/picture?snapShotImageType=JPEG

Since my employer only needs to be able to grab one frame from the camera whenever he wants to and doesn't need to stream the video itself, I just wrote an application that copies this JPEG from that url by using an Async Web-Request:

private Bitmap loadedBitmap;
...
private void requestFrame()
{    
 string cameraUrl = @"http://192.168.0.1XX:80/Streaming/channels/1/picture?snapShotImageType=JPEG";
 var request = System.Net.HttpWebRequest.Create(cameraUrl);   
 request.Credentials = new NetworkCredential(cameraLogin, cameraPassword);
 request.Proxy = null;
 request.BeginGetResponse(new AsyncCallback(finishRequestFrame), request);
}

void finishRequestFrame(IAsyncResult result)
{
 HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
 Stream responseStream = response.GetResponseStream();

 using (Bitmap frame = new Bitmap(responseStream)) {
  if (frame != null) {
   loadedBitmap = (Bitmap) frame.Clone();                        
  }
 }
}
...
requestFrame(); // call the function
like image 58
xonxt Avatar answered Sep 24 '22 20:09

xonxt