如何获得d3d_aware的IMFTransform(将Windows Duplication API的输入编码为H264)? [英] How to get an IMFTransform that is d3d_aware (To encode input from Windows Duplication API to H264)?

查看:127
本文介绍了如何获得d3d_aware的IMFTransform(将Windows Duplication API的输入编码为H264)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我了解DXGI_FORMAT_B8G8R8A8_UNORM格式可以作为IMFTranform上的MFVideoFormat_NV12来使用,该格式为D3D_AWARE.但是我在获取IMFTranform 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");;

最后一行,当我这样做时:

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

我收到错误消息"Error pTranform not D3D_AWARE",我不知道如何获取D3D_AWARE的pTranform

我使用此Windows复制API在计算机上尝试了一些程序,然后将其编码为H264并且可以正常工作

预先感谢

解决方案

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

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

[...]

 

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

解决方案

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)

[...]

这篇关于如何获得d3d_aware的IMFTransform(将Windows Duplication API的输入编码为H264)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆