获取 H.264 视频的解码器 MFT
Obtaining decoder MFT for H.264 video
我正在尝试从媒体基金会获得硬件解码器。我确定我的 gpu 支持 nvdec 硬件解码。我在 github 上找到了一个示例,它可以毫无问题地获取编码器 nvenc。但是当我将参数切换到解码器时,我要么得到一个糟糕的结果要么崩溃。我什至尝试通过更改硬件标志来获得软件解码器,但结果仍然很糟糕。任何人都知道出了什么问题?我想不出还有什么可以让我尝试或改变的
HRESULT get_decoder(CComPtr<IMFTransform>& out_transform, CComPtr<IMFActivate>& out_activate,
CComPtr<IMFAttributes>& out_attributes)
{
HRESULT hr = S_OK;
// Find the decoder
CComHeapPtr<IMFActivate*> activate_raw;
uint32_t activateCount = 0;
// Input & output types
const MFT_REGISTER_TYPE_INFO in_info = { MFMediaType_Video, MFVideoFormat_H264 };
const MFT_REGISTER_TYPE_INFO out_info = { MFMediaType_Video, MFVideoFormat_NV12 };
// Get decoders matching the specified attributes
if (FAILED(hr = MFTEnum2(MFT_CATEGORY_VIDEO_DECODER, MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_SORTANDFILTER, &in_info, &out_info,
nullptr, &activate_raw, &activateCount)))
return hr;
// Choose the first returned decoder
out_activate = activate_raw[0];
// Memory management
for (int i = 1; i < activateCount; i++)
activate_raw[i]->Release();
// Activate
if (FAILED(hr = out_activate->ActivateObject(IID_PPV_ARGS(&out_transform))))
return hr;
// Get attributes
if (FAILED(hr = out_transform->GetAttributes(&out_attributes)))
return hr;
std::cout << "- get_decoder() Found " << activateCount << " decoders" << std::endl;
return hr;
}
可能没有用于硬件解码的专用解码器 MFT(即使某些供应商提供)。与编码相比,硬件视频解码可通过 DXVA 2 API 获得,并且 - 反过来 - 由 Microsoft H264 Video Decoder MFT.
涵盖
此库存 MFT 能够使用硬件解码,并且还与启用 D3D9 和 D3D11 的管道兼容。
Microsoft H264 Video Decoder MFT
6 Attributes:
- MFT_TRANSFORM_CLSID_Attribute: {62CE7E72-4C71-4D20-B15D-452831A87D9D} (Type VT_CLSID, CLSID_CMSH264DecoderMFT)
- MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT
- MFT_INPUT_TYPES_Attributes: MFVideoFormat_H264, MFVideoFormat_H264_ES
- MFT_OUTPUT_TYPES_Attributes: MFVideoFormat_NV12, MFVideoFormat_YV12, MFVideoFormat_IYUV, MFVideoFormat_I420, MFVideoFormat_YUY2
Attributes
- MF_SA_D3D_AWARE: 1 (Type VT_UI4)
- MF_SA_D3D11_AWARE: 1 (Type VT_UI4)
- CODECAPI_AVDecVideoThumbnailGenerationMode: 0 (Type VT_UI4)
- CODECAPI_AVDecVideoMaxCodedWidth: 7680 (Type VT_UI4)
- CODECAPI_AVDecVideoMaxCodedHeight: 4320 (Type VT_UI4)
- CODECAPI_AVDecNumWorkerThreads: 4294967295 (Type VT_UI4, -1)
- CODECAPI_AVDecVideoAcceleration_H264: 1 (Type VT_UI4)
...
来自MSDN:
CODECAPI_AVDecVideoAcceleration_H264
Enables or disables hardware acceleration.
...
Maximum Resolution 4096 × 2304 pixels
The maximum guaranteed resolution for DXVA acceleration is 1920 × 1088 pixels; at higher resolutions, decoding is done with DXVA, if it is supported by the underlying hardware, otherwise, decoding is done with software.
...
DXVA The decoder supports DXVA version 2, but not DXVA version 1. DXVA decoding is supported only for Main-compatible Baseline, Main, and High profile bitstreams. (Main-compatible Baseline bitstreams are defined as profile_idc=66 and constrained_set1_flag=1.)
要使用硬件加速进行解码,只需使用 Microsoft H264 Video Decoder MFT。
我正在尝试从媒体基金会获得硬件解码器。我确定我的 gpu 支持 nvdec 硬件解码。我在 github 上找到了一个示例,它可以毫无问题地获取编码器 nvenc。但是当我将参数切换到解码器时,我要么得到一个糟糕的结果要么崩溃。我什至尝试通过更改硬件标志来获得软件解码器,但结果仍然很糟糕。任何人都知道出了什么问题?我想不出还有什么可以让我尝试或改变的
HRESULT get_decoder(CComPtr<IMFTransform>& out_transform, CComPtr<IMFActivate>& out_activate,
CComPtr<IMFAttributes>& out_attributes)
{
HRESULT hr = S_OK;
// Find the decoder
CComHeapPtr<IMFActivate*> activate_raw;
uint32_t activateCount = 0;
// Input & output types
const MFT_REGISTER_TYPE_INFO in_info = { MFMediaType_Video, MFVideoFormat_H264 };
const MFT_REGISTER_TYPE_INFO out_info = { MFMediaType_Video, MFVideoFormat_NV12 };
// Get decoders matching the specified attributes
if (FAILED(hr = MFTEnum2(MFT_CATEGORY_VIDEO_DECODER, MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_SORTANDFILTER, &in_info, &out_info,
nullptr, &activate_raw, &activateCount)))
return hr;
// Choose the first returned decoder
out_activate = activate_raw[0];
// Memory management
for (int i = 1; i < activateCount; i++)
activate_raw[i]->Release();
// Activate
if (FAILED(hr = out_activate->ActivateObject(IID_PPV_ARGS(&out_transform))))
return hr;
// Get attributes
if (FAILED(hr = out_transform->GetAttributes(&out_attributes)))
return hr;
std::cout << "- get_decoder() Found " << activateCount << " decoders" << std::endl;
return hr;
}
可能没有用于硬件解码的专用解码器 MFT(即使某些供应商提供)。与编码相比,硬件视频解码可通过 DXVA 2 API 获得,并且 - 反过来 - 由 Microsoft H264 Video Decoder MFT.
涵盖此库存 MFT 能够使用硬件解码,并且还与启用 D3D9 和 D3D11 的管道兼容。
Microsoft H264 Video Decoder MFT
6 Attributes:
- MFT_TRANSFORM_CLSID_Attribute: {62CE7E72-4C71-4D20-B15D-452831A87D9D} (Type VT_CLSID, CLSID_CMSH264DecoderMFT)
- MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT
- MFT_INPUT_TYPES_Attributes: MFVideoFormat_H264, MFVideoFormat_H264_ES
- MFT_OUTPUT_TYPES_Attributes: MFVideoFormat_NV12, MFVideoFormat_YV12, MFVideoFormat_IYUV, MFVideoFormat_I420, MFVideoFormat_YUY2
Attributes
- MF_SA_D3D_AWARE: 1 (Type VT_UI4)
- MF_SA_D3D11_AWARE: 1 (Type VT_UI4)
- CODECAPI_AVDecVideoThumbnailGenerationMode: 0 (Type VT_UI4)
- CODECAPI_AVDecVideoMaxCodedWidth: 7680 (Type VT_UI4)
- CODECAPI_AVDecVideoMaxCodedHeight: 4320 (Type VT_UI4)
- CODECAPI_AVDecNumWorkerThreads: 4294967295 (Type VT_UI4, -1)
- CODECAPI_AVDecVideoAcceleration_H264: 1 (Type VT_UI4) ...
来自MSDN:
CODECAPI_AVDecVideoAcceleration_H264
Enables or disables hardware acceleration....
Maximum Resolution 4096 × 2304 pixels The maximum guaranteed resolution for DXVA acceleration is 1920 × 1088 pixels; at higher resolutions, decoding is done with DXVA, if it is supported by the underlying hardware, otherwise, decoding is done with software.
...
DXVA The decoder supports DXVA version 2, but not DXVA version 1. DXVA decoding is supported only for Main-compatible Baseline, Main, and High profile bitstreams. (Main-compatible Baseline bitstreams are defined as profile_idc=66 and constrained_set1_flag=1.)
要使用硬件加速进行解码,只需使用 Microsoft H264 Video Decoder MFT。