0

Are there any good examples that show how to render the IMFSample output from the H.264 decoder? My scenario uses a 4K resolution H.264 stream and the PC that I am targeting will only accept 1080p using the DXGI buffers. But the H.264 decoder will handle 4K so I need to find a way to feed that NV12 IMFSample directly to the DirectX 11 renderer. I have already tried using the DX11VideoRenderer sample but it fails due to this particular IMFSample not having an IMFDXGIBuffer interface.

It looks like in the DX11VideoRenderer the input IMFDXGIBuffer is NV12 type and that can be rendered successfully in hardware. So it seems logical that a non-DXGI buffer of NV12 type should be acceptable too?

Perhaps I need to create a ID3D11Texture2D texture or resource with an NV12 type? I found examples for how to create a texture from a file but none for how to create a texture from a sample, which would seem to be even more useful. And if I can create a NV12 texture, how to figure out the SysMemPitch and SysMemSlicePitch values in the D3D11_SUBRESOURCE_DATA structure for NV12?

Any help would be really appreciated! Thank you.

Gary G.
  • 318
  • 3
  • 12
  • 1
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f8b73c84-c205-4da5-b7bc-982ccc9ad1f8/nv12-textures-not-working-in-directx-111?forum=wpdevelop – VuVirt May 18 '18 at 10:23
  • @VuVirt That's interesting, thanks for the link. What if I use the [Color Converter DSP MFT](https://msdn.microsoft.com/en-us/library/windows/desktop/ff819079(v=vs.85).aspx) to convert from NV12 to RGB32 first. Would it then be easier to render that IMFSample? I believe that MFT is also hardware accelerated so it may also be faster than the conversion shown in the code sample you linked to. – Gary G. May 19 '18 at 00:20
  • 1
    Color converter doesn't use hardware acceleration ao it won't produce a dxgi sample for you. You might try to use advanced viseo processor but it might need a dxgi surface already on its input. It's better to create the dxgi sample yourself as shown in the link. – VuVirt May 19 '18 at 06:26
  • @VuVirt Thank you, that makes sense to me. Forgive me, I'm not a DirectX expert but there seem to be some important parts missing from the example in the link. Are there any other examples that would show how it all fits together? I'm guessing that the `memcpy` with `D3D11_MAPPED_SUBRESOURCE` in the link's code replaces the `CreateVideoProcessorInputView`, `CreateVideoProcessorOutputView`, and `VideoProcessorBlt` that I see used in the **DX11VideoRenderer** example? – Gary G. May 20 '18 at 03:17
  • CreateVideoProcessorInputView also expects a DX texture. – VuVirt May 21 '18 at 08:20

1 Answers1

1

I was able to find a complete example that renders an NV12 sample to the screen. Although there are some simple stride calculation errors in how it renders it's own example image, the actual rendering code does work correctly. It appears to be an old Microsoft sample that I cannot find any other information about.

D3D11NV12Rendering

Gary G.
  • 318
  • 3
  • 12
  • Many thanks for sharing your findings, but it would be great to describe those "simple stride calculation errors" here rather than just mentioning their existence – NexD. Aug 02 '18 at 16:25