问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/43432670/how-to-create-imfsample-from-d11-texture-for-intel-mft-encoder