问题描述
我有 IMFSample 数据是 RGB32,我想将此格式转换为 BMP 或我想提取实际的 RGB32 字节并保存到文件,然后使用一些外部工具转换为 BMP 或任何其他格式.
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.
那么问题是如何从 IMFSample
推荐答案
IMFMediaBuffer 接口可以通过 ConvertToContiguousBuffer 调用获取(如另一个答案中提到的).此外,可以查询 IMFMediaBuffer 以获取 IMF2DBuffer:https://msdn.microsoft.com/en-us/library/windows/desktop/ms699894(v=vs.85).aspx.它的 Lock2D 方法在访问原始数据时更加方便快捷:https://msdn.microsoft.com/en-us/library/windows/desktop/aa473821(v=vs.85).aspx.例如,指向数据的指针和 Lock2D 返回的音高可以在 SetDiBitsToDevice 调用中使用.
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.
此外,如果缓冲区来自硬件加速解码器,您还可以查询 IMFMediaBuffer 的 IMFDXGIBuffer 以访问底层 DXGI 表面作为 ID3D11Texture2D:https://msdn.microsoft.com/en-us/library/windows/desktop/hh447901(v=vs.85).aspx.您可以通过 Map/Unmap DirectX 11 方法访问 DXGI 缓冲区中的原始数据:https://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx
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
您还可以查询 IMFMediaBuffer 以获取 IMFGetService 并从中获取 IDirect3DSurface9 接口.底层数据可以通过它的 Lock/Unlock 方法访问.以下是访问 IMFSample 的 IMFMediaBuffer 中原始数据的首选顺序:https://msdn.microsoft.com/en-us/library/windows/desktop/bb530112(v=vs.85).aspx如果 IMFGetService/IDirect3DSurface9 失败,则可以查询 IMFDXGIBuffer.
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).aspxThe IMFDXGIBuffer could be queried if the IMFGetService / IDirect3DSurface9 fails.
这篇关于从 IMFSample 中提取 RGB32 字节数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!