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

发布于 2024-12-07 04:24:43 字数 1129 浏览 0 评论 0原文

我使用 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 { }
}

但我还需要从 IP 摄像机获取流。有什么想法获得它的最佳方式吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

若水微香 2024-12-14 04:24:43

使用来自同一个 AForge.net 的 MJPEGStream 解决了这个问题:)

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

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();
通知家属抬走 2024-12-14 04:24:43

IP 摄像机在 Windows 中没有特定的媒体接口/API,它们只是 LAN 上的设备。此外,还有成百上千的模型,它们不共享通用的访问接口(甚至接近)。

因此,首先,您必须具体说明您感兴趣的型号。

此外,一些供应商还提供额外的“驱动程序”,将 IP 摄像机公开为多媒体设备,例如“IP 摄像机的 DirectShow 驱动程序”。在大多数情况下,这些是特定于供应商的,并且不能与其他相机一起使用。

下一个机会是相机实现了众所周知的流协议,在这种情况下,一些通用驱动程序也可能运行良好。

或者,只要您是 C# 人员,您就可以检查 IP 摄像机的 HTTP/CGI API,并在代码中自己实现流式传输,通过 HTTP/TCP/UDP 连接与设备发送和接收数据。

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.

幻梦 2024-12-14 04:24:43

我曾经使用过 directShow.net 库。它使您可以访问 DirectShow 的大部分功能,其中之一就是捕获。如果您可以将 ip 网络摄像头与 DirectShow 一起使用,您也可以在您的程序中使用它。

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.

绅士风度i 2024-12-14 04:24:43

像你一样的我也遇到了同样的问题,那是我使用 C# 开发或定制 Ip 摄像头解决方案的最后一年项目。但我浪费了很多时间,通过浏览来获取任何用 C# 编写的可以轻松访问 ip 摄像机流的代码,我很快就找到了第三方 Ozeeki sdk。但这是试用版,将在一周左右到期,也不会起作用。或者可能是 Ozeeki 只想为他们的网站提供反向链接。
首先你必须限制自己选择一款相机。就我而言,我有一台海康威视网络摄像机。
只需从此处下载适用于海康威视摄像头的设备网络 SDK:
http://www.hikvision.com/en/us/download_more.asp ?id=1482

解压后可以在SDK文件夹中找到4个子文件夹。
在“doc”文件夹中,您将找到“Device Network SDK 编程手册”
打开它并展开“编程指南”树。
单击主程序 API 参考或预览模块程序。在这里您将找到所有路线图,您必须采取哪些步骤来调用函数以从摄像机获取实时流。
所有函数的声明都在“基本接口定义”树里面,展开它一一阅读。
游戏还没有结束,而是刚刚开始;
具有所有功能的 SDk 都是用 C/C++ 非托管代码库编写的。并且无法添加到托管 C# 项目解决方案参考中。因此,您必须为所有用于从相机获取流的函数创建一个包装器,并从 c# 中调用它们。只需阅读文档手册即可了解它们的功能。
在推特上关注我:
https://twitter.com/CodingVampire
祝你好运

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

微暖i 2024-12-14 04:24:43

Nager.VideoStream 基于 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);
}

Nager.VideoStream is based on ffmpeg and can therefore easily be used across platforms. Network cameras and webcams can be accessed via 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文