how to convert IMFMediaBuffer to ID3D11Texture2D?

mc 5,406 Reputation points
2025-05-30T11:30:07.4233333+00:00

I am using IMFTransform and there is IMFMediaBuffer that format is DXGI_Format_NV12

and I use this code:

BYTE* ppbBuffer3 = NULL;
DWORD pcbMaxLength = 0, pcbCurrentLength = 0;
buff->Lock(&ppbBuffer3, &pcbMaxLength, &pcbCurrentLength);
//buff->Unlock();
ID3D11Texture2D* texture = NULL;
D3D11_TEXTURE2D_DESC desc{};
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.MiscFlags = 0;
desc.CPUAccessFlags = 0;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_NV12;
desc.Height = height;
desc.Width = width;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
auto h3 = device->CreateTexture2D(&desc, NULL, &texture);
ctx->UpdateSubresource(texture, D3D11CalcSubresource(1, 0, 1), NULL, ppbBuffer3, 7680, 0);
buff->Unlock();

and I the ID3D11Texture2D is all black and there is nothing

why?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,772 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,191 Reputation points
    2025-05-30T15:27:47.8033333+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.