jayboss
jayboss

Reputation: 61

Hardware H264 encoding ID3D11Texture2D with Media Foundation

I am working on a project which captures screen and encodes it. I can already capture screen using desktop duplication API (Win8+). Using the API I can get ID3D11Texture2D textures and transfer them from GPU to CPU and then use libx264 to encode them.

However, pulling textures from GPU to CPU can be a bottle neck which potentially can decrease the fps. Also libx264 takes up CPU cycles (depending on quality) to encode frames. I am looking for encoding ID3D11Texture2D textures in GPU itself instead of using CPU for encoding as an optimization.

I have already checked the documentation and some sample codes but I have had no success. I would appreciate if someone could point me to some resource that does exactly what I want reliably.

Upvotes: 2

Views: 3347

Answers (2)

mofo77
mofo77

Reputation: 1515

You have to check if sharing texture between GPU encoder and DirectX is possible.

I know it's possible to share texture between Nvidia Decoder and DirectX, because i've done it successfully. Nvidia has some interop capacity, so first, look if you can share texture to do all things in GPU.

With Nvidia you can do this : Nvidia Decoding->DirectX Display in GPU.

Check if DirectX Display->Nvidia Enconding is possible (knowing nvidia offers Interop)

For Intel and ATI, i don't know if they provide interop with DirectX.

The main thing to know is to check if you can interop your DirectX texture with GPU encoder texture.

Upvotes: 0

Roman Ryltsov
Roman Ryltsov

Reputation: 69734

Video encoders, hardware and software, might be available in different form factors. Windows itself offers extensible APIs with choice of encoders, and then additional encoders might be available as libraries and SDKs. You are already using one of such libraries (x264). Hardware encoders are typically vendor-specific and depend on available hardware, which is involved directly in the process of encoding. If you are interested in solution for specific hardware, it might make sense to check for respective SDK.

Otherwise, typical generic interface for hardware backed video encoding in Windows is Media Foundation Transform (MFT). Microsoft provides stock software only H.264 video encoder which is unlikely to give any advantage over x264, except the fact that it shares MFT interface with other options. Video hardware drivers, however, would often install additional MFTs for the hardware available, which add more MFTs backed by hardware implementation. Examples of such are:

  • Intel® Quick Sync Video H.264 Encoder MFT
  • NVIDIA H.264 Encoder MFT
  • AMDh264Encoder

Offered by different vendors, they offer similar functionality and your using these MFTs to encode H.264 is a good way to take advantage of hardware video encoding with a wide range of hardware.

See also:

Upvotes: 3

Related Questions