代码之家  ›  专栏  ›  技术社区  ›  Adrian

尝试使用CoCreateInstance()创建H.264解码器时发生链接器错误[重复]

  •  0
  • Adrian  · 技术社区  · 1 年前

    问题

    我正在尝试使用 H.264 Video Decoder 我无法使用 CLSID_CMSH264DecoderMFT 在我的电话 CoCreateInstance() 因为我收到链接器错误:

    未解析的外部符号CLSID_CMSH264解码器MFT

    里面 C:\Windows\System32 我确实有 msmpeg2vdec.dll 。我尝试从下载另一个 here 但我不能替换原来的,它不让我这么做。

    以下是我链接的库:

    Urlmon.lib
    Mfreadwrite.lib
    mf.lib
    mfplat.lib
    mfuuid.lib
    strmiids.lib
    Ole32.lib
    Uuid.lib
    

    这些是我的包括:

    #include <windows.h>
    #include <mfapi.h>
    #include <mfplay.h>
    #include <mfobjects.h>
    #include <mfidl.h>
    #include <mfreadwrite.h>
    #include <d3d9.h>
    #include <objbase.h>
    #include <iostream>
    #include <vector>
    #include <dshow.h>
    #include <initguid.h>
    #include <wmcodecdsp.h> // <- contains CLSID_CMSH264DecoderMFT
    #include <stdio.h>
    

    我尝试了什么

    • regsvr32 MSMPEG2VDEC.DLL
    • 修改我的链接库
    • 使用MFTEnum查找解码器,但失败 IMFTransform::SetOutputType

    这是使用时的代码 MFTEnum 最后失败了 cout :

    MFT_REGISTER_TYPE_INFO tyin = {};
    tyin.guidMajorType = MFMediaType_Video;
    tyin.guidSubtype = MFVideoFormat_H264;
    
    MFT_REGISTER_TYPE_INFO tyout = {};
    tyout.guidMajorType = MFMediaType_Video;
    tyout.guidSubtype = MFVideoFormat_NV12;
    
    CLSID* clsid_arr=0;
    UINT32 clsid_arr_count;
    hr = MFTEnum(
        MFT_CATEGORY_VIDEO_DECODER,
        0,
        &tyin,
        &tyout,
        0,
        &clsid_arr,
        &clsid_arr_count
    ); // finds 1
    IMFTransform* pDecoder=0;
    CoCreateInstance(clsid_arr[0], NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDecoder));
    
    IMFMediaType* type = 0;
    MFCreateMediaType(&type);
    type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
    type->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
    hr = pDecoder->SetInputType(0, type, 0);
    
    IMFMediaType* pOutputAttributes = 0;
    MFCreateMediaType(&pOutputAttributes);
    pOutputAttributes->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
    pOutputAttributes->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
    hr = pDecoder->SetOutputType(0, pOutputAttributes, 0);
    if (FAILED(hr)) {
        std::cout << "Failed SetOutputType\n";
    }
    
    1 回复  |  直到 1 年前
        1
  •  1
  •   Remy Lebeau    1 年前

    CLSID_CMSH264DecoderMFT 声明为 extern 在里面 wmcodecdsp.h 链接器抱怨说它找不到这个的定义 CLSID 任何地方的值,例如在 .lib 文件,因此出现错误。

    在这种情况下,您需要链接到 wmcodecdspuuid.lib .

    或者,您可以直接在自己的代码中定义值,例如:

    const CLSID CLSID_CMSH264DecoderMFT = {0x62CE7E72, 0x4C71, 0x4d20, {0xB1, 0x5D, 0x45, 0x28, 0x31, 0xA8, 0x7D, 0x9D}};