I have IMFSample data that is RGB32, and I want to convert this format to BMP or I want to extract the actual RGB32 bytes and save to file and then using some external tool convert to BMP or any other format.
So question is how can I get RGB32 data from IMFSample
The IMFMediaBuffer interface can be taken via the ConvertToContiguousBuffer call (as mentioned in another answer). Additionally, the IMFMediaBuffer can be queried for IMF2DBuffer: https://msdn.microsoft.com/en-us/library/windows/desktop/ms699894(v=vs.85).aspx. It's Lock2D method is more convenient and faster when accessing the raw data: https://msdn.microsoft.com/en-us/library/windows/desktop/aa473821(v=vs.85).aspx. The pointer to the data and the pitch returned by Lock2D could be used in a SetDiBitsToDevice call for example.
Furthermore, you could also query the IMFMediaBuffer for IMFDXGIBuffer to access the underlying DXGI surface as ID3D11Texture2D, if the buffer comes from a hardware accelerated decoder: https://msdn.microsoft.com/en-us/library/windows/desktop/hh447901(v=vs.85).aspx. You can access the raw data in the DXGI buffer via the Map/Unmap DirectX 11 methods: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx
You could also query the IMFMediaBuffer for IMFGetService and obtain the IDirect3DSurface9 interface from it. The underlying data could be accessed via it's Lock/Unlock methods. Here is the preferred order for accessing the raw data in the IMFSample's IMFMediaBuffer: https://msdn.microsoft.com/en-us/library/windows/desktop/bb530112(v=vs.85).aspx The IMFDXGIBuffer could be queried if the IMFGetService / IDirect3DSurface9 fails.
IMFSample::ConvertToContiguousBuffer
gets youIMFMediaBuffer
interface with dataIMFMediaBuffer::Lock
gets you access to raw dataMake sure to unlock when you're done. Then release COM interface pointers as usually.