I'm doing video capture from a webcam in two separate ways (think two applications): using Direct Show and Media Foundation.
Using Direct Show, my Logitech c920 webcam has 3 output pins:
- Video capture (i.e.
PIN_CATEGORY_CAPTURE
orPIN_CATEGORY_PREVIEW
) in I420, RGB24 and MJPG pixel formats, with FPS from 2 to 30, depending on media type. - Still image capture (i.e.
PIN_CATEGORY_STILL
) in I420 and RGB24 with just 1 FPS. - Video capture (i.e.
PIN_CATEGORY_CAPTURE
orPIN_CATEGORY_PREVIEW
) in h264 with FPS from 5 to 30.
So, since I'm concerned only with video capture, I ignore all pins that are not PIN_CATEGORY_CAPTURE
or PIN_CATEGORY_PREVIEW
, which works great.
Using Media Foundation, the same camera has 3 stream descriptors (IMFPresentationDescriptor::GetStreamDescriptorCount
). Each stream descriptor provides IMFMediaTypeHandler
that allows you to iterate over media types. So I have 3 IMFMediaTypeHandlers:
- Video capture (i.e.
IMFMediaTypeHandler::GetMajorType == MFMediaType_Video
) in I420, RGB24 and MJPG pixel formats, with FPS from 2 to 30, depending on media type. - Video capture (i.e.
IMFMediaTypeHandler::GetMajorType == MFMediaType_Video
) in i420 and RGB24 with just 1 FPS. - Video capture (i.e.
IMFMediaTypeHandler::GetMajorType == MFMediaType_Video
) in h264 with FPS from 5 to 30.
You can notice that Media Foundation's stream descriptors seem to map to Direct Show's output pins 1 on 1. Except that Media Foundation didn't mark the stream descriptor #2 as still image capture (MFMediaType_Image
), in contrast to what Direct Show is doing.
Still image capture requires different handling than video capture, so my Direct Show code errors and doesn't do any capturing at all when trying to use media types from pin #2. Well, I only care about video capturing in the first place, so that is fine.
But even through Media Foundation tells that the stream descriptor #2 is video capture, my Media Foundation code, which works perfectly with all media types from steam descriptors #1 and #3, crashes on media types from stream descriptor #2, similarly to how Direct Show crashes on still image capture only.
So I get the impression that it's either Media Foundation (or the Windows 7 webcam driver provided by Logitech) is buggy and not marking stream descriptor #2 as still image capture when it should, or I'm checking the wrong flag to determine if it's video capture or still image capture. If it's my mistake, then what is the right way to differentiate between video (#1 and #3) and still image (#2) capture stream descriptors?