简体   繁体   English

如何使用DirectShow与网络摄像头断开连接?

[英]How to disconnect from the webcam using directshow?

I used directshow.net with my web-cam and it worked so well. 我将directshow.net与网络摄像头一起使用,效果很好。 But when I closed the form and opened it again, it gives me an error in the method SetupGraph() because the value that come from the next code line is negative. 但是,当我关闭窗体并再次打开它时,它在SetupGraph()方法中给了我一个错误,因为来自下一条代码行的值是负数。

hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, null);

but when I unplugged my camera, it works good the second time. 但是当我拔下相机电源时,第二次效果很好。

I hope it's not a big deal. 我希望这没什么大不了的。

You can try to call yourMediaControl.StopWhenReady() method and after that release all com object instances like graph , source , grabber , capture graph with Marshal.ReleaseComObject . 您可以尝试调用yourMediaControl.StopWhenReady()方法,然后使用Marshal.ReleaseComObject释放所有com对象实例,例如graphsourcegrabbercapture graph

The IMediaControl.StopWhenReady method pauses the filter graph, allowing filters to queue data, and then stops the filter graph. IMediaControl.StopWhenReady方法暂停过滤器图,允许过滤器将数据排队,然后停止过滤器图。

Main thing is that each time you start webcam video you need to do all this: 最主要的是,每次启动网络摄像头视频时,都需要执行以下所有操作:

  1. create graph builder, filter graph, device object, grabber... 创建图生成器,过滤器图,设备对象,抓取器...
  2. render stream 渲染流
  3. run media control 运行媒体控制
  4. wait until user signals to stop the video 等到用户发出停止视频的信号
  5. stop media control (StopWhenReady) 停止媒体控制(StopWhenReady)
  6. release / destroy created objects 释放/销毁创建的对象

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

相关问题 如何使用directShow在WPF ImageControl内部托管来自网络摄像头的输出 - how to host output from a Webcam inside of a WPF ImageControl using directShow 使用 DirectShow.NET 从网络摄像头捕获帧 - Capturing frames from webcam using DirectShow.NET DirectShow 库-如何使用 DirectShow 库捕获图像而不在 PictureBox 或 Panel 上显示网络摄像头实时图像 - DirectShow Library-How to capture image using directshow library without showing the webcam live images on the PictureBox or Panel 从网络摄像头到文件的DirectShow MPEG-2编码 - DirectShow MPEG-2 encoding from webcam to file 是否可以使用 Excel 中的嵌入式控件使用 DirectShow 预览来自网络摄像头的视频源? - Is it possible to use an embbeded control in Excel to preview video feed from webcam using DirectShow? 如何不使用DirectShow从相机捕获数据? - How to capture data from camera NOT using DirectShow? 使用DirectShow.Net将USB网络摄像头录制为MKV和其他格式 - Record USB Webcam to MKV and other formats using DirectShow.Net 从网络摄像头访问原始视频流-DirectShow,C# - Access raw video stream from Webcam - DirectShow, C# 使用DirectShow从内存渲染 - Rendering from memory using DirectShow 如何断开连接,然后使用EasyNetQ从RabbitMQ重新连接? - How to disconnect, then reconnect from RabbitMQ using EasyNetQ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM