{"record":{"id":"079d7ad683b110ce","repo":"MathewSachin/Captura","slug":"unknown-grabber-media-format","errorCode":null,"errorMessage":"Unknown Grabber Media Format","messagePattern":"Unknown Grabber Media Format","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Captura.Windows/Webcam/CaptureWebcam.cs","lineNumber":465,"sourceCode":"                    Marshal.ThrowExceptionForHR(hr);\n\n                // Make the video window visible, now that it is properly positioned\n                hr = _videoWindow.put_Visible(OABool.True);\n\n                if (hr < 0)\n                    Marshal.ThrowExceptionForHR(hr);\n\n                _isPreviewRendered = true;\n                didSomething = true;\n\n                var media = new AMMediaType();\n                hr = _sampGrabber.GetConnectedMediaType(media);\n\n                if (hr < 0)\n                    Marshal.ThrowExceptionForHR(hr);\n\n                if (media.formatType != FormatType.VideoInfo || media.formatPtr == IntPtr.Zero)\n                    throw new NotSupportedException(\"Unknown Grabber Media Format\");\n\n                _videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));\n\n                Marshal.FreeCoTaskMem(media.formatPtr);\n                media.formatPtr = IntPtr.Zero;\n            }\n\n            if (didSomething)\n                _actualGraphState = GraphState.Rendered;\n        }\n\n        /// <summary>\n        ///  Setup and start the preview window if the user has\n        ///  requested it (by setting PreviewWindow).\n        /// </summary>\n        void StartPreviewIfNeeded()\n        {\n            // Render preview ","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/MathewSachin/Captura/blob/3fdf41529bf4d50cd7a85aedd856f30e34279a47/src/Captura.Windows/Webcam/CaptureWebcam.cs#L447-L483","documentation":"Thrown by CaptureWebcam (src/Captura.Windows/Webcam/CaptureWebcam.cs:465) as NotSupportedException when the DirectShow sample grabber's connected media type is not FormatType.VideoInfo or has a zero formatPtr. The code only handles the VideoInfo header layout, so any camera that negotiates VideoInfo2 (or another format type) is rejected.","triggerScenarios":"After ISampleGrabber.GetConnectedMediaType, media.formatType != FormatType.VideoInfo or media.formatPtr == IntPtr.Zero. Webcams commonly expose VideoInfo2 (carrying interlacing/anamorphic info) instead of VideoInfo, especially at certain resolutions or on newer drivers.","commonSituations":"A camera that only offers VideoInfo2 at the chosen resolution; a UVC driver preferring VideoInfo2; requesting a resolution/pixel format that the camera satisfies via VideoInfo2; a disconnected/zero-format pin.","solutions":["Add a branch that handles FormatType.VideoInfo2 by reading VideoInfoHeader2 and deriving the equivalent VideoInfoHeader.","Force the grabber input pin to negotiate a VideoInfo media type (set AMMediaType before connection).","Try a different resolution or pixel format on the camera that is offered as VideoInfo.","Test with another webcam to confirm it is media-type-specific."],"exampleFix":"// before\nif (media.formatType != FormatType.VideoInfo || media.formatPtr == IntPtr.Zero)\n    throw new NotSupportedException(\"Unknown Grabber Media Format\");\n_videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));\n// after\nif (media.formatType == FormatType.VideoInfo && media.formatPtr != IntPtr.Zero)\n    _videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));\nelse if (media.formatType == FormatType.VideoInfo2 && media.formatPtr != IntPtr.Zero)\n    _videoInfoHeader = ((VideoInfoHeader2)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader2))).ToVideoInfoHeader();\nelse\n    throw new NotSupportedException($\"Unsupported grabber media format: {media.formatType}\");","handlingStrategy":"fallback","validationCode":"// before connecting the grabber, enumerate offered media types and prefer VideoInfo\nvar preferred = offered.FirstOrDefault(m => m.formatType == FormatType.VideoInfo);\nif (preferred != null) pin.Connect(preferred);","typeGuard":"static bool SupportsVideoInfo(AMMediaType m)\n    => m.formatType == FormatType.VideoInfo && m.formatPtr != IntPtr.Zero;","tryCatchPattern":"try { /* configure grabber */ }\ncatch (NotSupportedException e) when (e.Message.Contains(\"Grabber Media Format\")) { /* add VideoInfo2 handling or switch camera */ }","preventionTips":["Handle FormatType.VideoInfo2 in addition to VideoInfo before throwing.","Enumerate the camera pin's offered media types and force a VideoInfo subtype.","Test across multiple webcams and resolutions to confirm format dependence."],"tags":["directshow","webcam","media-type","unsupported","windows","csharp"],"backgroundTag":null,"analyzedSha":"3fdf41529bf4d50cd7a85aedd856f30e34279a47","analyzedAt":"2026-08-13T19:35:27.486Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}