2

我正在尝试将 intel-media-sdk 解码器用于 h.264 视频。这是我初始化解码器的代码:

mfxStatus decoder::initDecoder(HWND window, mfxBitstream *Header) {
    mfxStatus sts = MFX_ERR_NONE;
    mfxVersion ver = { { 0, 1 } };
    mfxVideoParam mfxVideoParams;
    mfxFrameAllocator mfxAllocator;
    mfxFrameAllocResponse mfxResponse;

    sts = m_mfxSession.Init(MFX_IMPL_AUTO_ANY, &ver); //sts = MFX_ERR_NONE

    if (sts == MFX_ERR_NONE) {
        sts = m_mfxSession.SetHandle(MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9, 
            m_renderer.initD3d(GetIntelDeviceAdapterNum(), window)); //sts = MFX_ERR_NONE
        if (sts == MFX_ERR_NONE) {
            mfxAllocator.pthis = m_mfxSession;
            sts = m_mfxSession.SetFrameAllocator(&mfxAllocator); //sts = MFX_ERR_NONE
            if (sts == MFX_ERR_NONE) {
                MFXVideoDECODE mfxDEC(m_mfxSession);
                m_mfxVideoDecode = mfxDEC;
                memset(&mfxVideoParams, 0, sizeof(mfxVideoParams));
                mfxVideoParams.mfx.CodecId = MFX_CODEC_AVC;
                mfxVideoParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;

                sts = m_mfxVideoDecode.DecodeHeader(Header, &mfxVideoParams); //sts = MFX_ERR_NONE
                if (sts == MFX_ERR_NONE) {
                    memset(&m_mfxRequest, 0, sizeof(m_mfxRequest));
                    sts = m_mfxVideoDecode.QueryIOSurf(&mfxVideoParams, &m_mfxRequest); //sts = MFX_ERR_NONE
                    if (sts == MFX_ERR_NONE) {
                        sts = m_renderer.allocSurfaces(mfxAllocator.pthis, &m_mfxRequest, &mfxResponse);
                        if (sts == MFX_ERR_NONE) {
                            m_pmfxSurfaces = new mfxFrameSurface1 *[m_mfxRequest.NumFrameSuggested];
                            for (int i = 0; i < m_mfxRequest.NumFrameSuggested; i++) {
                                m_pmfxSurfaces[i] = new mfxFrameSurface1;
                                memset(m_pmfxSurfaces[i], 0, sizeof(mfxFrameSurface1));
                                memcpy(&(m_pmfxSurfaces[i]->Info), &(mfxVideoParams.mfx.FrameInfo), sizeof(mfxFrameInfo));
                                // MID (memory id) represents one video NV12 surface
                                m_pmfxSurfaces[i]->Data.MemId = mfxResponse.mids[i];
                            };
                            sts = m_mfxVideoDecode.Init(&mfxVideoParams); //sts = MFX_ERR_MEMORY_ALLOC
                        }
                    }
                }
            }
        }
    }

    return sts;
}

所以你可以看到MFXVideoDECODE::Init(mfxVideoParam*)(内部调用MFXVideoDECODE_Init)返回MFX_ERR_MEMORY_ALLOC,奇怪的是在这个文档中它说这个函数没有这个返回值。

以下是有关以下内容的一些调试信息mfxVideoParams

AllocId = 0,AsyncDepth = 0,IOPattern = 16,mfx.CodecId = 541283905,mfx.CodecProfile = 77,mfx.CodecLevel = 30,vpp.In.FourCC = 842094158,vpp.In.Width = 864,vpp.In。高度 = 480,vpp.In.CropW = 854,vpp.In.CropH = 480,vpp.In.BufferSize = 31458144,vpp.In.AspectRatioW = 1,vpp.In.AspectRatioH = 1,vpp.In.PicStruct = 1、vpp.In.ChromaFormat = 1

这是此处使用的标头中的一些成员数据定义:

MFXVideoSession m_mfxSession;
MFXVideoDECODE m_mfxVideoDecode;
mfxFrameAllocRequest m_mfxRequest;
mfxFrameSurface1** m_pmfxSurfaces;

以下是有关我当前工作设备的一些信息,可能与此问题有关:

  • 操作系统:Windows 8.1
  • 处理器:Intel(R) Core(TM) i5-3470 CPU @ 3.20GHZ
  • 系统类型:64位操作系统,基于x64的处理器
  • 安装内存 (RAM) : 8.00 GB

最后,为了重现完全相同的情况,我big_buck_bunny_1080p_h264.mov该站点下载了名为的视频,然后使用 ffmpeg 将其提取到 h264 并在我的程序中使用。

4

1 回答 1

2

您需要使用适当的函数初始化 mfxFrameAlocator 回调函数(Alloc、Free、GetHDL,...)。例如 :

//static member
mfxStatus decoder::gethdl(mfxHDL pthis, mfxMemId mid, mfxHDL* handle)
{
    pthis; // To avoid warning for this unused parameter

    if (handle == 0) return MFX_ERR_INVALID_HANDLE;

    *handle = mid;
    return MFX_ERR_NONE;
}



mfxStatus decoder::initDecoder(HWND window, mfxBitstream *Header) {

    //blah blah
    mfxAllocator.pthis = m_mfxSession;
    mfxAllocator.GetHDL = gethdl;
    //define for these too
    //mfxAllocator.Alloc = alloc;
    //mfxAllocator.Free = free;
    //mfxAllocator.Lock = lock;
    //mfxAllocator.Unlock = unlock;

    //rest of your code
}
于 2017-10-28T09:20:26.673 回答