ActivateObject:未处理的异常

问题描述 投票:0回答:1

我正在尝试使用Media Foundation Transforms&我遇到了麻烦,当我使用MFTEnumEx,获得1个编码器,并使用ActivateObject我得到此错误:Unhandled exception at 0x00007FF9C7084078 in endec.exe: Microsoft C++ exception: std::runtime_error at memory location 0x00000056FF75CC38. occurredactivate[0]->ActivateObject(IID_PPV_ARGS(&encoder))

Microsoft Windows Server 2016 Datacenter。 10.0.14393 N / A Build 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```

visual-studio winapi visual-c++ ms-media-foundation
1个回答
1
投票

你有没有打电话给CoInitializeEx和MFStartup?

HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

HRESULT hr = MFStartup(MF_VERSION, MFSTARTUP_LITE);

这是一个例子,使用所需的参数。

至少,你的函数“get_encoder”需要CoInitializeEx。

可能由于硬件/软件配置,即使有硬件编码器注册,Microsoft Windows Server 2016 Datacenter也无法进行硬件编码。

例如,一些运行缺失的多媒体服务。

© www.soinside.com 2019 - 2024. All rights reserved.