简体   繁体   English

如何将 IP 摄像机流导入 C#?

[英]How to get an IP camera stream into C#?

I've used AForge library to make this little program, that shows live feed from a webcam into a PictureBox.我使用 AForge 库制作了这个小程序,它显示从网络摄像头到 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.但我还需要从 IP 摄像机获取流。 Any ideas what would be the best way to get it?任何想法什么是获得它的最佳方式?

Solved it with MJPEGStream from the same AForge.net :)用来自同一个 AForge.net 的 MJPEGStream 解决了它:)

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

Same problem was with me like you, and that was my final year project to develop or customize the Ip camera solutions using c#.我和你一样有同样的问题,那是我使用 c# 开发或定制 Ip 摄像头解决方案的最后一年项目。 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.但是我浪费了很多时间浏览以获取任何可以轻松访问 ip 摄像头流的 C# 编写的代码,而且我很快找到了第三方 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.但是这个是试用版,将近一周到期,也不会工作。或者可能 Ozeeki 只想要他们网站的反向链接。 First of all you have to limit yourself to select one of the camera.首先,您必须限制自己选择其中一台相机。 In my case i have a HIkvision Network Camera.就我而言,我有一台 HIkvision 网络摄像机。 Just download the Device Network SDK for Hikvision Camera from here: http://www.hikvision.com/en/us/download_more.asp?id=1482只需从这里下载适用于海康威视摄像头的设备网络 SDK: http ://www.hikvision.com/en/us/download_more.asp? id= 1482

Extract it and you may found in the SDK folder, 4 sub folders.解压它,您可能会在 SDK 文件夹中找到 4 个子文件夹。 Inside the "doc" folder, you will find "Device Network SDK Programming Manual" Open it and expand the "Programming Guideline" tree.在“doc”文件夹中,您会找到“Device Network SDK Programming Manual” 打开它并展开“Programming Guideline”树。 Click on Main Procedure API Reference or Preview Module Procedure.单击 Main Procedure API Reference 或 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.所有函数的声明都在“Basic Interface Definition”树里面展开,一一阅读。 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.包含所有功能的 SDk 是用 C/C++ 非托管代码库编写的。并且不能添加到托管 C# 项目解决方案参考中。 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.因此,您必须为用于从相机获取流的所有函数制作一个包装器,并从 c# 中调用它们。只需查看文档手册它们是什么功能即可。 follow me on twitter : https://twitter.com/CodingVampire Wish you Best of Luck在 twitter 上关注我: https : //twitter.com/CodingVampire祝你好运

IP cameras do not have specific media interfaces/APIs in Windows, they are just devices on LAN. IP 摄像机在 Windows 中没有特定的媒体接口/API,它们只是 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".还有一些供应商提供额外的“驱动程序”,将 IP 摄像机作为多媒体设备公开,例如“IP 摄像机的 DirectShow 驱动程序”。 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.或者,只要你是 C# 人,你就可以检查 IP 摄像机的 HTTP/CGI API 并在代码中实现自己的流式传输,通过与设备的 HTTP/TCP/UDP 连接发送和接收数据。

I once worked with the directShow.net library .我曾经使用过directShow.net 库 It gives you access to the most functions of DirectShow and one of them is Capturing.它使您可以访问 DirectShow 的大多数功能,其中之一是捕获。 If you can use the ip webcam with DirectShow you can use it in your program as well.如果您可以在 DirectShow 中使用 ip 网络摄像头,那么您也可以在您的程序中使用它。

Nager.VideoStream is based on ffmpeg and can therefore easily be used across platforms. Nager.VideoStream基于 ffmpeg,因此可以轻松跨平台使用。 Network cameras and webcams can be accessed via ffmpeg .网络摄像机和网络摄像头可以通过ffmpeg访问。

PM> install-package Nager.VideoStream
var inputSource = new StreamInputSource("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
//var inputSource = new WebcamInputSource("Microsoft® LifeCam HD-3000");

var cancellationTokenSource = new CancellationTokenSource();

var client = new VideoStreamClient();
client.NewImageReceived += NewImageReceived;
var task = client.StartFrameReaderAsync(inputSource, OutputImageFormat.Bmp, cancellationTokenSource.Token);
//Console.ReadLine();
client.NewImageReceived -= NewImageReceived;

private static void NewImageReceived(byte[] imageData)
{
    File.WriteAllBytes($@"{DateTime.Now.Ticks}.bmp", imageData);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM