Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# directshow问题_C#_Directshow - Fatal编程技术网

C# directshow问题

C# directshow问题,c#,directshow,C#,Directshow,我正在使用DirectShow.net从网络摄像机中捕获图像,在搜索网络后,我得到了以下代码,它工作正常: 要查看原始完整代码,请点击下面的链接 bool SetupGraph() { int hr; try { hr = capGraph.SetFiltergraph(graphBuilder); if (hr < 0)

我正在使用DirectShow.net从网络摄像机中捕获图像,在搜索网络后,我得到了以下代码,它工作正常:

要查看原始完整代码,请点击下面的链接

bool SetupGraph() { int hr; try { hr = capGraph.SetFiltergraph(graphBuilder); if (hr < 0) Marshal.ThrowExceptionForHR(hr); hr = graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device"); if (hr < 0) Marshal.ThrowExceptionForHR(hr); DsUtils.ShowCapPinDialog(capGraph, capFilter, this.Handle); AMMediaType media = new AMMediaType(); media.majorType = MediaType.Video; media.subType = MediaSubType.RGB24; media.formatType = FormatType.VideoInfo; // ??? hr = sampGrabber.SetMediaType(media); if (hr < 0) Marshal.ThrowExceptionForHR(hr); hr = graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Grabber"); if (hr < 0) Marshal.ThrowExceptionForHR(hr); Guid cat = PinCategory.Preview; Guid med = MediaType.Video; hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, null); // baseGrabFlt if (hr < 0) Marshal.ThrowExceptionForHR(hr); cat = PinCategory.Capture; med = MediaType.Video; hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, baseGrabFlt); // baseGrabFlt if (hr < 0) Marshal.ThrowExceptionForHR(hr); media = new AMMediaType(); hr = sampGrabber.GetConnectedMediaType(media); if (hr < 0) Marshal.ThrowExceptionForHR(hr); if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero)) throw new NotSupportedException("صيغه غير معروفه"); videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero; hr = sampGrabber.SetBufferSamples(false); if (hr == 0) hr = sampGrabber.SetOneShot(false); if (hr == 0) hr = sampGrabber.SetCallback(null, 0); if (hr < 0) Marshal.ThrowExceptionForHR(hr); return true; } catch (Exception ee) { MessageBox.Show(this, "Could not setup graph\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop); return false; } } bool SetupGraph() { 国际人力资源; 尝试 { hr=capGraph.SetFiltergraph(graphBuilder); 如果(hr<0) 元帅。通过hr(hr)的例外情况; hr=graphBuilder.AddFilter(capFilter,“Ds.NET视频捕获设备”); 如果(hr<0) 元帅。通过hr(hr)的例外情况; DsUtils.showcapindialog(capGraph、capFilter、this.Handle); AMMediaType media=新的AMMediaType(); media.majorType=MediaType.Video; media.subType=MediaSubType.RGB24; media.formatType=formatType.VideoInfo;/??? hr=sampGrabber.SetMediaType(媒体); 如果(hr<0) 元帅。通过hr(hr)的例外情况; hr=graphBuilder.AddFilter(baseGrabFlt,“Ds.NET抓取器”); 如果(hr<0) 元帅。通过hr(hr)的例外情况; Guid cat=PinCategory.Preview; Guid med=MediaType.Video; hr=capGraph.RenderStream(ref cat,ref med,capFilter,null,null);//baseGrabFlt 如果(hr<0) 元帅。通过hr(hr)的例外情况; 猫=钳形分类。捕获; med=MediaType.Video; hr=capGraph.RenderStream(ref cat,ref med,capFilter,null,baseGrabFlt);//baseGrabFlt 如果(hr<0) 元帅。通过hr(hr)的例外情况; 媒体=新的AMMediaType(); hr=sampGrabber.GetConnectedMediaType(媒体); 如果(hr<0) 元帅。通过hr(hr)的例外情况; if((media.formatType!=formatType.VideoInfo)| |(media.formatPtr==IntPtr.Zero)) 抛出新的NotSupportedException(不支持异常); videoInfoHeader=(videoInfoHeader)Marshal.ptr结构(media.formatPtr,typeof(videoInfoHeader)); Marshal.FreeCoTaskMem(media.formatPtr);media.formatPtr=IntPtr.Zero; hr=采样率。设置采样率(假); 如果(hr==0) hr=sampGrabber.SetOneShot(假); 如果(hr==0) hr=sampGrabber.SetCallback(null,0); 如果(hr<0) 元帅。通过hr(hr)的例外情况; 返回true; } 捕获(异常ee) { MessageBox.Show(这是“无法设置图形\r\n”+ee.Message,“DirectShow.NET”、MessageBoxButtons.OK、MessageBoxIcon.Stop); 返回false; } } 我的问题是,当我第二次从另一个窗体调用此窗体时,它会给我以下错误:
“值不在预期范围内”
当编译器转到此节时:
hr=capGraph.RenderStream(ref cat,ref med,capFilter,null,null)

事实上,我发现当我从物理上拔出网络并再次拔出它时,问题就消失了,所以我得出结论,我需要使用代码拔出它 所以,如果你知道怎么做,或者如果你有更好的主意,请告诉我

您可以在上访问原始代码 [^]


感谢您的时间和耐心

一次只能运行单个视频源的一个图形,请将其视为具有单个源的管道


如果要启动另一个图形,必须先停止第一个图形-您的代码当前在
CloseInterfaces()中执行此操作-因此,如果在构建第二个图形之前调用该函数,应该没问题。

问题可能是在关闭接口时,您必须在DirectShow的所有接口中使用
封送.ReleaseComObject
,并且,您必须使用
IGraphBuilder
的方法
RemoveFilter
来释放使用过的捕获过滤器,如果不这样做,图形生成器将不会被释放。

是的,在CloseInterfases()方法中,添加以下行:

if (graphBuilder != null)
{
    graphBuilder.RemoveFilter(capFilter);
}
baseGrabFlt = null;

谢谢您的快速回复,但我确实打电话给CloseInterfaces();我仍然得到错误,返回的值是:hr=capGraph.RenderStream(ref cat,ref med,capFilter,null,null);是-2147024809代码的一些功能描述,以及它为什么会有帮助。