Unable to change video capture resolution using C #

I am trying to change the default resolution of a webcam using DirectShowNet in C #, from what I'm going to, I need to change it from calling the built-in VideoInfoHeader class in windows win32 api dll to capture avi. 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;

The thing is, I can’t access videoInfoHeader because on this line: hr = sampGrabber.GetConnectedMediaType (media); it goes and says that hr is less than 0, therefore it causes this error: the interface has too many methods for triggering events from (Exception from HRESULT: 0x80040209)

It will not read the VideoInfoHeader bit, so I can’t change the capture resolution of the webcam, does anyone know how to do this better or how to fix it?

+3
2

, HR , " DirectShow" , HR- . , 0x80040209:

VFW_E_NOT_CONNECTED , .

, . grabber RenderStream.

+3

- - IAMStreamConfig. . GraphEditPlus , . ( "" ) , #.

0

Source: https://habr.com/ru/post/1779669/


All Articles