Search code examples
c#video-capturevfw

Default Image format, returning by VFW (C#), has some undocumented values


I'm trying to conquer VFW from my C# App. Most of the things were quite misty before, and after all I've reached the last point before it will be done.

When I initiate camera driver with group of messages like

  • WM_CAP_GET_VIDEOFORMAT
  • WM_CAP_SET_VIDEOFORMAT

then I receive pointer to BITMAPINFO structure on GET_VIDEOFORMAT where (as I suppose, because the webcamera doesn't have its native driver installed) one item in struct called biCompression with very strange value = 0x32595559 (844715353). Always is the same value, and the RGBQUAD - all zeros. Pls, see the shot where that value is in decimal format: screen cut from VS2012

When I call out VFW Dialog with video format selection, I can see YUY2 (which is selectable and able to be set), and MJPG which is able to be selected, but that causes the black screen as video capture result.

When I call SET_VIDEOFORMAT and send to VFW the standard BMP RGB 640x480 format with no compression, it returns 0 (zero) on SendMessage, which means it can't be set. And, at the same time, sending the struct, with the strange compression value received on GET_VIDEOFORMAT, back to as SET_VIDEOFORMAT, returns 1, and it means that VFW accepted it.

So I'm wondering why is that? Either the OS (Win7) doesn't have a certain Codec for usual BMP uncompressed, or because the Web camera doesn't have its driver installed?

And the other question is: what means 0x32595559 value in the BITMAPINFO compression item?

I have already treated it as normal 24 bit YUV data, but the resulting image is B&W, no color, though during video streaming it's colored, and if I get it from Clipboard, it's also colored.

How to treat such collision, please, help me if you of cause know it. If you are very good with that, then I'd be happy to $$.

Thanks.

UPD. Wow, thanks to my spontaneous idea to transfer decimal data into hex (compression value) I found in Google its YUY2 codec kind of compression. Full table is here

Ok, but the question is still unanswered. If PC wouldn't contain a proper codec for RGB Bitmap uncompressed, then what actually happens in VFW BOX, when I send SET_VIDEOFORMAT? Does it search for proper codec and try to attach it to the existing Video streaming graph?

I think the answer to that question will help to get VFW understood for everyone.


Solution

  • 0x32595559 stands for "YUY2" literally. To build this constant in C++ code one would do MAKEFOURCC('Y', 'U', 'Y', '2'). This [well known] value indicates that captured video data is going to be encoded using this pixel format.

    WM_CAP_SET_VIDEOFORMAT and WM_CAP_GET_VIDEOFORMAT allow setting and getting video capture format, however the range of accepted values is limited to actual support in the camera itself, backed by respective driver. This is unrelated to installed codecs because software codecs do not extend ability of the camera to encode captured video.

    Also there is no video streaming graph here, you are asking about VFW API, and graphs are from another API, DirectShow. Using VFW you are getting a video frame in one of the formats the camera supports (and is configured to deliver video at), then you are on your own with this data and you prefer different encoding you might want to look a suitable ICM/VCM codec up and convert.