How to get an IP camera stream into C#?

天大地大妈咪最大 提交于 2019-12-03 05:23:41

问题


I've used AForge library to make this little program, that shows live feed from a webcam into a PictureBox.

private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideoDevice;

private void Form1_Load(object sender, EventArgs e)
{
   VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
   try
   {
      foreach (FilterInfo VidCapDev in VideoCaptureDevices)
      {
         comboBox1.Items.Add(VidCapDev.Name);
         comboBox1.SelectedIndex = 0;
      }
      FinalVideoDevice = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
      FinalVideoDevice.NewFrame += new NewFrameEventHandler(FinalVideoDevice_NewFrame);
      FinalVideoDevice.Start();
   }
   catch
   {
      MessageBox.Show("No camera found. Please connect your camera and click RESET.");
   }
}

        //////////////////////////////////////////////////////////////////////////////////////////

void FinalVideoDevice_NewFrame(object sender, NewFrameEventArgs e)
{
   try
    {
       pictureBox1.Image = (Bitmap)e.Frame.Clone();
    }
    catch { }
}

But I also need to get a stream from an IP camera. Any ideas what would be the best way to get it?


回答1:


Solved it with MJPEGStream from the same AForge.net :)

MJPEGStream stream = new MJPEGStream("http://192.168.2.5:8080/videofeed");
            stream.NewFrame += new NewFrameEventHandler(video_NewFrame);
            stream.Start();



回答2:


IP cameras do not have specific media interfaces/APIs in Windows, they are just devices on LAN. Also there are hundreds and thousands of models and they don't share common access interfaces (even close).

So first of all, you have to be specific about the model of your interest.

Also some vendors provide additional "drivers" that expose IP cameras as multimedia devices, such as "DirectShow driver for IP camera". In most cases these are vendor specific and won't work with other cameras.

Next chance is that camera implements a well known streaming protocol, in which case some generic driver might work out fine as well.

Or, as long as you are C# guy, you can check HTTP/CGI API of the IP camera and implement streaming yourself in code, sending and receiving data over HTTP/TCP/UDP connection with the device.




回答3:


I once worked with the directShow.net library. It gives you access to the most functions of DirectShow and one of them is Capturing. If you can use the ip webcam with DirectShow you can use it in your program as well.




回答4:


Same problem was with me like you, and that was my final year project to develop or customize the Ip camera solutions using c#. But i wasted my time a lot on by doing browsing to get any piece of code that written in C# that can easily access the ip camera stream, and i found very soon third party Ozeeki sdk. But this one is the trial and expire near a week and wont work also.Or may be Ozeeki wants just a Backlinks for their site. First of all you have to limit yourself to select one of the camera. In my case i have a HIkvision Network Camera. Just download the Device Network SDK for Hikvision Camera from here: http://www.hikvision.com/en/us/download_more.asp?id=1482

Extract it and you may found in the SDK folder, 4 sub folders. Inside the "doc" folder, you will find "Device Network SDK Programming Manual" Open it and expand the "Programming Guideline" tree. Click on Main Procedure API Reference or Preview Module Procedure. Here you will find all the road Map what steps you have to take to call the functions to get live stream from the camera. The declaration of all the functions are inside the "Basic Interface Definition" tree expand it and read them all one by one. The Game is not over here but just got a start; The SDk with all of the functions are written in C/C++ Unmanaged code base.And cant be added in a Manged C# project solution References. So you have to make a wrapper for all of them that are use in getting a stream from the camera, and call them from c#.Just go through the documentation manual what functions they are. follow me on twitter : https://twitter.com/CodingVampire Wish you Best of Luck



来源:https://stackoverflow.com/questions/7595191/how-to-get-an-ip-camera-stream-into-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!