0

I am following details as given in below link for creating DirectX 11 Device and using it for rendering:
https://msdn.microsoft.com/en-us/library/windows/desktop/dn643747(v=vs.85).aspx

This example demonstrates rendering cube in the video window.
But I want to render Video Buffer using this example.

I have IMFMediaBuffer which is having video frame read from a file.
I want to decode this buffer and then display it using DirectX 11 APIs.
I can decode this buffer using decoder, but not sure how to render it.

1 Answer 1

4

Obtain the IMFDXGIBuffer interface from your IMFMediaBuffer via QueryInterface: https://msdn.microsoft.com/en-us/library/windows/desktop/hh447901(v=vs.85).aspx. Use GetResource to access the ID3D11Texture2D wrapped by this media buffer. Store the sub resource index using GetSubresourceIndex. Use ID3D11DeviceContext::CopySubresourceRegion (https://msdn.microsoft.com/en-us/library/windows/desktop/ff476394(v=vs.85).aspx), by specifying the stored sub resource index as SrcSubresource parameter, to copy the obtained ID3D11Texture2D as pSrcResource parameter, to your device's swapchain (set in pDstResource). Call Present(1) of your swapchain.

CopySubresourceRegion(pSwapChain, 0, 0, 0, 0, pTexture2D, index, NULL); 

Note: You should set the same D3D11 device via IMFDXGIDeviceManager to the decoder for this to work.

More details:

ComPtr<IMFMediaBuffer> buffer; CHK(sample->GetBufferByIndex(0, &buffer)); // Get the MF DXGI buffer ComPtr<IMFDXGIBuffer> dxgiBuffer; if (FAILED(buffer.As(&dxgiBuffer))) { ComPtr<ID3D11Texture2D> texture; unsigned int subresource; CHK(dxgiBuffer->GetResource(IID_PPV_ARGS(&texture))); CHK(dxgiBuffer->GetSubresourceIndex(&subresource)); ComPtr<ID3D11Device> device; ComPtr<ID3D11DeviceContext> context; texture->GetDevice(&device); device->GetImmediateContext(&context); context->CopySubresourceRegion(m_pSwapChain, 0, 0, 0, 0, texture.Get(), subresource, nullptr); } 
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, will it be possible to provide sample API calls OR example for this, it will be more helpful.
I added a more detailed sample at the end of the answer.
@VuVirt - I noticed in the MSDN documentation that 'CopySubresourceRegion' does not allow stretching. Do you have any advice on how to stretch the image between the decoder and 'CopySubresourceRegion'?
@GaryG. Instead of using CooySubResourceRegion you can render a textured quad using the decoder texture. This quad can be rendered with scaling/stretching onto your render target.
On Windows Server 2016 interface IMFDXGIBuffer cannot be found.. with Media Foundation feature installed .. is there a way to fix that?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.