1

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.

  • If you want to use compression you will need to do a bottom up image. height = -480 instead of 480. Not sure how to do this in your application. – Yaur Aug 05 '15 at 17:15
  • You already figured out that the code stands for YUY2. Now all you have to do is insert on the output pin a transform filter that translates YUY2 into RGB and connect your renderer or whatever is downstream to that. Alternatively you can put an tee in there and connect the transform to one of the tee pins and grab it from there. Depends what you are trying to do with it. I'm not familiar with the library, so I don't know how much influence you have onto the filter graph. Sounds like a wrapper around DShow to me. – Frank J Aug 05 '15 at 20:24
  • Hi Frank, Thanks for feedback. I'm dealing with VFW, and I've already done the conversion from YUY2 to Bitmap. It works ok. What I'm trying to understand is... what happens on SET_VIDEOFORMAT, because if I'm right. and it really looks for a proper CODEC to attach to current Graph, then better to me to supply every customer with YUV2 codec for sure, and use the conversion from YUV2 to RGD24bpp. –  Aug 07 '15 at 00:03

1 Answers1

0

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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Ok, camera itself already has coder inside its chipset. How do I know what codec installed by default in a camera? –  Aug 13 '15 at 09:43
  • DirectShow allows to build graphs with pin using com tech, where we have a stream and then attach a codec to it, then at the end of that codec another codec (decode), therefore we are able to get video stream in a desirable format and then grab video or/and audio. Is there a way to do that in VFW? –  Aug 13 '15 at 09:48
  • With VFW I don't think you can enumerate capabilities. You can only invoke UI to change that interactively, and then get/set current format. No, you don't have DirectShow's Intelligent Connect analog in VFW. – Roman R. Aug 13 '15 at 09:54
  • How VFW does the conversion from YUY2 to BMP when I ask to grab an image into Clipboard? It comes in simple 32 or 24bpp Bitmap. Does it mean that VFW contains all types of convertions from any codec into Bitmap? How to get access to that powerfull instrument? –  Aug 13 '15 at 10:45
  • or the defauit driver codes the video stream from camera into YUY2? Maybe from camera to driver video comes in uncompressed BMP format? –  Aug 13 '15 at 10:47
  • I am not sure if clipboard image is RGB, it could be simply the same original format. Either way, you can enumerate ICM/VCM codecs and query their capabilities, esp. whether they can convert format you have (YUY2) to RGB. A codec which responds with this capability can be further called to do the conversion. Perhaps `ICDecompressOpen` can even lookup a codec. All this was obsoleted years ago, by the way. I would suggest using [Color Converter DSP](https://msdn.microsoft.com/en-us/library/windows/desktop/ff819079). – Roman R. Aug 13 '15 at 12:45
  • Yes, it's strange, but from Clipboard comes RGB, that's why majority use it, though it's weird, but on FrameCallback - YUY2, and I've done conversion to RGB, but that's why I'm asking - because I'm not sure if every Webcam that user can buy in computer store, will provide YUY2 streaming. Your suggestion about CCDSP is good, I will learn it, though I should write format recognition code, that will come from WM_CAP_GET_VIDEOFORMAT. Another challenge to bridge from C# to DSP and back to C#. Also, I have to research webcams in store if they have internal codecs list in their characteristics. –  Aug 13 '15 at 13:10
  • Color Converter DSP is Vista+. It is obviously better in every way (except OS availability) than any VFW era API, at the very least implementing efficient SIMD-enabled conversions. I believe that older VFW based code used ICM API (`ICDecompressOpen` and friends), through which it did RGB conversions. RGB was - at that time - considered a "common denominator" between formats and OS provided decoders of popular formats to RGB. Not every camera does YUY2. Some do UYVY, RGB, I420. – Roman R. Aug 13 '15 at 13:22
  • Roman, what if the native camera driver does the normalization to RGB and other widely used formats? Good to know if there any standards for Webcam drivers? That would be the quick solution. I'm going to go to CStore and see what I can buy to test. Thanks. Will update on upcomming news :) –  Aug 13 '15 at 14:16
  • With DirectShow you can relatively easily enumerate capabilities and formats. VFW is not that feature rich. – Roman R. Aug 13 '15 at 14:21