Search code examples
visual-studiovisual-c++video-processingms-media-foundation

What exactly is the difference between MediaFoundation RGB data and a BMP?


In trying to understand how to convert mediafoundation rgb32 data into a bitmap data that can be loaded into image/bitmap widgets or saved as a bitmap file, I am wondering what the RGB32 data actually is, in comparison to the data a BMP has?

Is it simply missing header information or key information a bitmap file has like width, height, etc?

What does RGB32 actually mean, in comparison to BMP data in a bitmap file or memory stream?


Solution

  • You normally have 32-bit RGB as IMFMediaBuffer attached to IMFSample. This is just bitmap bits, without format specific metadata. You can access this data by obtaining media buffer pointer, such as, for example, by doing IMFSample::ConvertToContiguousBuffer call, then doing IMFMediaBuffer::Lock to get a pixel data pointer.

    The obtained buffer is compatible to data in standard .BMP file (except maybe, at some times, the rows could be in reverse order), it is just .BMP file has a header before this data. .BMP file normally has BITMAPFILEHEADER structure, then BITMAPINFOHEADER and then the buffer in question. If you write it one after another initialized respectively, this would yield you a valid picture file. This and other questions here show the way to create a .BMP file from bitmap bits.

    See this GitHub code snippet, which is really close to the requested task and might be a good starting point.