1

下一个代码应该提供 inputInfo 和 outputInfo 配置以获取 IMFTransform,并且此 IMFTransform 用于将 ID3D11Texture2D(格式为 DXGI_FORMAT_B8G8R8A8_UNORM)编码为 H264

我了解格式 DXGI_FORMAT_B8G8R8A8_UNORM 可以作为 MFVideoFormat_NV12 上的 IMFTranform 是 D3D_AWARE 。但是我在获得 D3D_AWARE 的 IMFTranform 时遇到问题

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");;

在最后几行,当我这样做时:

CatchError(pTransform->GetAttributes(&imfAttributes), (LPSTR)"Error getAttributes from pTransform");
CatchError(imfAttributes->GetUINT32(MF_SA_D3D_AWARE,0), (LPSTR)"Error pTranform not D3D_AWARE");

我收到错误“错误 pTranform not D3D_AWARE”,我不知道如何获得 D3D_AWARE 的 pTranform

我用这个 Windows Duplication API 在我的计算机上尝试了一些程序,然后将其编码为 H264 并且它们可以工作

提前致谢

4

1 回答 1

1

您将很难使用 Direct3D [9] 感知转换,ID3D11Texture2D因此您需要 Direct3D 11 感知和MF_SA_D3D11_AWARE.

英特尔 H.264 视频编码器 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)

请注意,三是没有 Direct3D 9 感知标记(总而言之,这已经过时了)。

您可以使用MediaFoundationVideoEncoderTransforms 工具以交互方式检查可用的编码器 MFT 及其属性。

接下来是您使用MFT_ENUM_FLAG_SYNCMFT标准过滤转换。这将过滤掉所有硬件辅助编码器,您获得的 MFT 是 Microsoft 的软件 H.264 编码器。它既不支持 Direct3D 9 也不支持 Direct3D 11 - 请记住这一点。您可能需要更新代码以获取硬件编码器。

这是你得到的:

## 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)

[...]

于 2019-11-23T22:13:25.350 回答