gpt4 book ai didi

c++ - MFXVideoDECODE_Init 失败并显示 MFX_ERR_MEMORY_ALLOC

转载 作者:搜寻专家 更新时间:2023-10-31 02:08:57 27 4
gpt4 key购买 nike

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

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 并且这里有奇怪的事情在this document它说这个函数没有这个返回值。

这里是一些关于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.Height = 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

这里是在header中使用的一些成员数据定义:

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

最后,为了重现完全相同的情况,我从 this site 下载了名为 big_buck_bunny_1080p_h264.mov 的视频。然后用 ffmpeg 将其解压缩为 h264 并在我的程序中使用它。

最佳答案

您需要使用适当的函数初始化 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
}

关于c++ - MFXVideoDECODE_Init 失败并显示 MFX_ERR_MEMORY_ALLOC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46948537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com