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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With