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;
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)
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?