无法使用C#更改视频捕获分辨率 [英] Can't change video capture resolution using c#

查看:208
本文介绍了无法使用C#更改视频捕获分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#中的DirectShowNet更改默认的网络摄像头分辨率,根据我的收集,我需要通过调用Windows win32 api dll中的内置VideoInfoHeader类进行AVI捕获来更改它。我从DirectShowNet获得以下代码:

I am trying to change the default webcam resolution using DirectShowNet in C#, from what I gather I need to change it from calling the built in VideoInfoHeader class in windows win32 api dll for avi capture. I have the following code from DirectShowNet:

        hr = capGraph.SetFiltergraph( graphBuilder );
        if( hr < 0 )
            Marshal.ThrowExceptionForHR( hr );

        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( capFilter, "Ds.NET Video Capture Device" );
        if( hr < 0 )
            Marshal.ThrowExceptionForHR( hr );

        DsUtils.ShowCapPinDialog( capGraph, capFilter, this.Handle );

        Guid sub = MediaSubType.Avi;
        hr = capGraph.SetOutputFileName( ref sub, fileName, out mux, out sink );
        if( hr < 0 )
            Marshal.ThrowExceptionForHR( hr );

        Guid cat = PinCategory.Capture;
        Guid med = MediaType.Video;
        hr = capGraph.RenderStream( ref cat, ref med, capFilter, null, mux ); // stream to file 
        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("Unknown Grabber Media Format");

        videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
        Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;

我无法访问videoInfoHeader,因为在这一行:hr = sampGrabber.GetConnectedMediaType(media) ;
会说hr小于0,因此引发此错误:接口有太多方法来触发事件(HRESULT的异常:0x80040209)

Thing is I can't access videoInfoHeader because at this line: hr = sampGrabber.GetConnectedMediaType(media); it goes and says hr is less than 0 so throws this error: An interface has too many methods to fire events from (Exception from HRESULT: 0x80040209)

它不会读取VideoInfoHeader位,所以我无法更改摄像头捕获的分辨率,有人知道更好的方法或如何解决此问题吗?

It won't read the VideoInfoHeader bit so I can't change the resolution of the webcam capture, anyone know a better way to do this or how to fix this?

推荐答案

请确保在查找HR错误代码时,使用 DirectShow错误和成功代码列表,而不是通用HR代码列表。您将从该列表中看到0x80040209的实际含义是:

Make sure that when you look up your HR error codes you look them up using the DirectShow Error and Success Code list, not the generic HR code list. You'll see from that list that the actual meaning of 0x80040209 is:


VFW_E_NOT_CONNECTED无法执行该操作,因为未连接引脚。

VFW_E_NOT_CONNECTED The operation cannot be performed because the pins are not connected.

看起来您的图形未连接示例采集器过滤器。确保在调用中将样本采集器传递给 RenderStream

Looks like your graph is not connecting your sample grabber filter. Make sure to pass the sample grabber in your call to RenderStream.

这篇关于无法使用C#更改视频捕获分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆