我正在嘗試從媒體基金會獲得硬體解碼器。我確定我的 gpu 支持 nvdec 硬體解碼。我在 github 上找到了一個示例,它可以毫無問題地獲取編碼器 nvenc。但是當我將引數切換到解碼器時,我要么得到一個糟糕的 hresult 要么崩潰。我什至嘗試通過更改硬體標志來獲得軟體解碼器,但結果仍然很糟糕。有人知道出了什么問題嗎?我想不出還有什么可以讓我嘗試或改變的
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;
}
uj5u.com熱心網友回復:
可能沒有用于硬體解碼的專用解碼器 MFT(即使某些供應商提供這些)。與編碼相比,硬體視頻解碼可通過 DXVA 2 API 獲得,并且反過來由Microsoft H264 Video Decoder MFT涵蓋。
該庫存 MFT 能夠使用硬體進行解碼,并且還與啟用 D3D9 和 D3D11 的管道兼容。
Microsoft H264 視頻解碼器 MFT
6個屬性:
- MFT_TRANSFORM_CLSID_Attribute:{62CE7E72-4C71-4D20-B15D-452831A87D9D}(型別 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
屬性
- MF_SA_D3D_AWARE:1(型別 VT_UI4)
- MF_SA_D3D11_AWARE:1(型別 VT_UI4)
- CODECAPI_AVDecVideoThumbnailGenerationMode:0(型別 VT_UI4)
- CODECAPI_AVDecVideoMaxCodedWidth:7680(型別 VT_UI4)
- CODECAPI_AVDecVideoMaxCodedHeight:4320(型別 VT_UI4)
- CODECAPI_AVDecNumWorkerThreads:4294967295(型別 VT_UI4,-1)
- CODECAPI_AVDecVideoAcceleration_H264: 1 (型別 VT_UI4) ...
來自MSDN:
CODECAPI_AVDecVideoAcceleration_H264啟用或禁用硬體加速。...
最大解析度 4096 × 2304 像素 DXVA 加速的最大保證解析度為 1920 × 1088 像素;在更高解析度下,如果底層硬體支持,則使用 DXVA 進行解碼,否則使用軟體進行解碼。
...
DXVA 解碼器支持 DXVA 版本 2,但不支持 DXVA 版本 1。DXVA 解碼僅支持與 Main 兼容的 Baseline、Main 和 High profile 位元流。(主要兼容的基線位元流定義為 profile_idc=66 和 constrained_set1_flag=1。)
要使用硬體加速進行解碼,只需使用 Microsoft H264 Video Decoder MFT。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411748.html
標籤:
