Extract RGB32 Byte Data from IMFSample

浪尽此生 提交于 2019-12-24 10:00:09

问题


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


回答1:


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.




回答2:


  1. IMFSample::ConvertToContiguousBuffer gets you IMFMediaBuffer interface with data
  2. IMFMediaBuffer::Lock gets you access to raw data

Make sure to unlock when you're done. Then release COM interface pointers as usually.



来源:https://stackoverflow.com/questions/43014780/extract-rgb32-byte-data-from-imfsample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!