问题
The next code should give inputInfo and outputInfo configuration to get a IMFTransform back, and this IMFTransform be used to encode ID3D11Texture2D(with format DXGI_FORMAT_B8G8R8A8_UNORM) to H264
I understand the format DXGI_FORMAT_B8G8R8A8_UNORM can be taken as a MFVideoFormat_NV12 on a IMFTranform that is D3D_AWARE . But i'm having problems to get a IMFTranform that is D3D_AWARE
MFT_REGISTER_TYPE_INFO inputInfo = { MFMediaType_Video, MFVideoFormat_NV12 };
MFT_REGISTER_TYPE_INFO outputInfo = { MFMediaType_Video, MFVideoFormat_H264 };
MFT_OUTPUT_STREAM_INFO mosiBuffer;
UINT32 unFlags = MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_LOCALMFT | MFT_ENUM_FLAG_SORTANDFILTER;
CatchError( MFTEnumEx(
MFT_CATEGORY_VIDEO_ENCODER,
unFlags,
&inputInfo, // Input type
&outputInfo, // Output type
&ppActivate,
&count
),(LPSTR)"Line 385");
CatchError(ppActivate[0]->ActivateObject(
__uuidof(IMFTransform),
(void**)& pTransform
),(LPSTR)"Line 392");
CatchError(pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL),(LPSTR)"Line 396");
IMFAttributes* imfAttributes;
CatchError(pTransform->GetAttributes(&imfAttributes), (LPSTR)"Error getAttributes from pTransform");
CatchError(imfAttributes->GetUINT32(MF_SA_D3D_AWARE,0), (LPSTR)"Error pTranform not D3D_AWARE");;
On the last lines, when i do :
CatchError(pTransform->GetAttributes(&imfAttributes), (LPSTR)"Error getAttributes from pTransform");
CatchError(imfAttributes->GetUINT32(MF_SA_D3D_AWARE,0), (LPSTR)"Error pTranform not D3D_AWARE");
i get the error "Error pTranform not D3D_AWARE", I don't know how to get a pTranform that is D3D_AWARE
I tried some programs on my computer with this Windows Duplication API, that then encodes it to H264 and they work
thanks in advance
回答1:
You will have hard time to use Direct3D [9] aware transform with ID3D11Texture2D
so you need Direct3D 11 awareness and, respectively, MF_SA_D3D11_AWARE
.
Typical attributes for Intel H.264 video encoder MFT:
## Intel® Quick Sync Video H.264 Encoder MFT
11 Attributes:
* MFT_TRANSFORM_CLSID_Attribute: {4BE8D3C0-0515-4A37-AD55-E4BAE19AF471} (Type VT_CLSID)
* MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_HARDWARE
* MFT_ENUM_HARDWARE_VENDOR_ID_Attribute: VEN_8086 (Type VT_LPWSTR)
* MFT_ENUM_HARDWARE_URL_Attribute: AA243E5D-2F73-48c7-97F7-F6FA17651651 (Type VT_LPWSTR)
* MFT_INPUT_TYPES_Attributes: {3231564E-3961-42AE-BA67-FF47CCC13EED}, MFVideoFormat_NV12, MFVideoFormat_ARGB32
* MFT_OUTPUT_TYPES_Attributes: MFVideoFormat_H264, MFVideoFormat_H264_HDCP
* MFT_CODEC_MERIT_Attribute: 7 (Type VT_UI4)
* MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE: 1 (Type VT_UI4)
* MF_TRANSFORM_ASYNC: 1 (Type VT_UI4)
### IMFTransform
* Streams: Input 1, Output 1
#### Attributes
* MF_SA_D3D11_AWARE: 1 (Type VT_UI4) <<---------------------------------
* MFT_ENUM_HARDWARE_URL_Attribute: AA243E5D-2F73-48c7-97F7-F6FA17651651 (Type VT_LPWSTR)
* MFT_ENUM_HARDWARE_VENDOR_ID_Attribute: VEN_8086 (Type VT_LPWSTR)
* MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE: 1 (Type VT_UI4)
* MFT_TRANSFORM_CLSID_Attribute: {4BE8D3C0-0515-4A37-AD55-E4BAE19AF471} (Type VT_CLSID)
* MF_VIDEO_MAX_MB_PER_SEC: 1165381 (Type VT_UI4)
* MFT_GFX_DRIVER_VERSION_ID_Attribute: 0 (Type VT_UI8)
* MF_TRANSFORM_ASYNC: 1 (Type VT_UI4)
Note that three is no Direct3D 9 awareness markup (all in all, this is already out of date).
You can use MediaFoundationVideoEncoderTransforms tool to check available encoder MFTs and their properties interactively.
Next thing is that you filter transforms with MFT_ENUM_FLAG_SYNCMFT
criteria. This will filter out all hardware-assisted encoders and the MFT you are getting is Microsoft's software H.264 encoder. It is neither Direct3D 9 nor Direct3D 11 aware - keep this in mind. You probably need to update your code to pick up hardware encoders.
This is the one you get:
## H264 Encoder MFT
6 Attributes:
* MFT_TRANSFORM_CLSID_Attribute: {6CA50344-051A-4DED-9779-A43305165E35} (Type VT_CLSID, CLSID_CMSH264EncoderMFT)
* MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT
* MFT_INPUT_TYPES_Attributes: MFVideoFormat_IYUV, MFVideoFormat_YV12, MFVideoFormat_NV12, MFVideoFormat_YUY2
* MFT_OUTPUT_TYPES_Attributes: MFVideoFormat_H264
### IMFTransform
* Stream Limits: Input 1..1, Output 1..1
* Streams: Input 1, Output 1
#### Attributes
* MFT_ENCODER_SUPPORTS_CONFIG_EVENT: 1 (Type VT_UI4)
[...]
来源:https://stackoverflow.com/questions/58944556/how-to-get-an-imftransform-that-is-d3d-aware-to-encode-input-from-windows-dupli