Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
639 views
in Technique[技术] by (71.8m points)

c++ - How to create IMFSample from D11 texture for Intel MFT encoder

I want to encode video using the "Intel? Quick Sync Video H.264 Encoder MFT". If I create IMFSample from system buffers, it works well. Just like following:

IMFMediaBuffer *pBuffer = NULL;
MFCreateMemoryBuffer(cbSize, &pBuffer);
BYTE *pData = NULL;
pBuffer->Lock(&pData, NULL, NULL);
memcpy(pData, bufferIhaveinYYYYUV format, buffer size);
pBuffer->Unlock();
IMFSample *pSample = NULL;
MFCreateSample(&pSample);
pSample->AddBuffer(pBuffer);

Now I'm investigating whether I can feed it ID3D11Texture2D surfaces as input (DXGI_FORMAT_NV12, 1280x720) in order to improve performance. I tried to pass IMFSample instances created with MFCreateVideoSampleFromSurface or MFCreateDXGISurfaceBuffer to IMFTransform::ProcessInput and made multiple experiments (trying different texture creation flags), but the best result was that all input samples were accepted, but no output samples produced. In case it matters, I never actually tried uploading data to the textures, assuming this would not make a difference from textures filled with garbage pixel data.

Am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are basically repeating your earlier question but still without adding any code which does not work.

The fact that you can feed normal (in-memory) samples and have the encoder working suggest that you are doing everything about right. Note that in Direct3D mode you are supposed to not only provide Direct3D 9 surfaces or Direct3D 11 textures, but also comply with respective initialization of the MFT. Specifically, the textures and the MFT's internals have to belong to the same Direct3D device and hence the required steps before the streaming starts. It is not only MFCreateDXGISurfaceBuffer which is needed to be called.

In general, the approach is outlined on MSDN in Supporting Direct3D 11 Video Decoding in Media Foundation article. The same equally well applies to encoding scenario. You are expected to use IMFDXGIDeviceManager pointer and you are expected to use MFT_MESSAGE_SET_D3D_MANAGER message. The MFT operates as MSDN suggests and switches to Direct3D 11 mode accepting texture based samples carrying input frame data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...