我正在尝试使用Media Foundation Transforms,并且遇到一个障碍,当我使用MFTEnumEx时,取回1个编码器,并使用ActivateObject时出现此错误:
Unhandled exception at 0x00007FF9C7084078 in endec.exe: Microsoft C++ exception: std::runtime_error at memory location 0x00000056FF75CC38. occurred
处的activate[0]->ActivateObject(IID_PPV_ARGS(&encoder))
Microsoft Windows Server 2016数据中心。 10.0.14393 N / A内部版本14393。x64。
代码:
IMFTransform* get_encoder() {
ComPtr<IMFTransform> encoder = NULL;
IMFActivate **activate = nullptr;
uint32_t flags = MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER;
// Unused for testing...
MFT_REGISTER_TYPE_INFO input_info;// = NULL; // NULL pInputType means "match all"
MFT_REGISTER_TYPE_INFO output_info;
input_info.guidMajorType = MFMediaType_Video;
input_info.guidSubtype = MFVideoFormat_ARGB32;
output_info.guidMajorType = MFMediaType_Video;
output_info.guidSubtype = MFVideoFormat_NV12;
CLSID *clsids = NULL;
uint32_t count = 0;
_com_error error = NULL;
//error = MFTEnum(MFT_CATEGORY_VIDEO_PROCESSOR, flags, input_info, &output_info, NULL, &clsids, &count);
ThrowIfFailed(MFTEnumEx(MFT_CATEGORY_VIDEO_ENCODER, flags, NULL, NULL, &activate, &count),
&count, "Unexpected error occurred with finding encoders"); // <--- ERROR
if (!count && !activate[0]) {
cout << "Did not find any encoders...\n";
return nullptr;
}
cout << "Number of encoders available: " << count << endl;
if (!activate[0]) {
cout << "Couldn't get a valid activate obj\n";
}
ThrowIfFailed(activate[0]->ActivateObject(IID_PPV_ARGS(&encoder)), &flags,
"Wasn't able to activate encoder");
return encoder.Get();
}
发生异常时的局部变量:
+ activate 0x0000016ebc24db20 {0x0000016ebdb1d950 {...}} IMFActivate * *
+ clsids 0x0000000000000000 <NULL> _GUID *
count 1 unsigned int
+ encoder 0x0000000000000000 <NULL> Microsoft::WRL::ComPtr<IMFTransform>
+ error {S_OK} _com_error
flags 68 unsigned int
+ input_info {guidMajorType={73646976-0000-0010-8000-00AA00389B71} guidSubtype={00000015-0000-0010-8000-00AA00389B71} } __MIDL___MIDL_itf_mfobjects_0000_0008_0003
+ output_info {guidMajorType={73646976-0000-0010-8000-00AA00389B71} guidSubtype={3231564E-0000-0010-8000-00AA00389B71} } __MIDL___MIDL_itf_mfobjects_0000_0008_0003```