为什么在尝试创建解码器时出现OutOfMemory异常

Why I get OutOfMemory exception when trying create a decoder

本文关键字:OutOfMemory 异常 解码器 创建 为什么      更新时间:2023-10-16

我正在尝试使用h264解码器配置文件获取ID3D11VideoDecoder解码器,但在Windows Phone 8上遇到异常。使用此代码:

DX::ThrowIfFailed(device.Get()->QueryInterface(__uuidof(ID3D11VideoDevice), (void**)&videoDevice));
GUID guid = {0x1b81be68, 0xa0c7,0x11d3,{0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5}};
D3D11_VIDEO_DECODER_DESC *desc = new D3D11_VIDEO_DECODER_DESC();
desc->Guid = guid;
desc->OutputFormat = DXGI_FORMAT_420_OPAQUE;
desc->SampleHeight = 480;
desc->SampleWidth = 800;
D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
ID3D11VideoDecoder *decoder;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

PS。我为此尝试了SharpDX,但遇到了同样的问题。

您似乎没有传入有效的D3D11_VIDEO_DECODER_CONFIG变量。您只定义了结构D3D11_VIDEO_DECODER_CONFIG的指针,在调用函数CreateVideoDecoder之前没有设置它的值。

D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

你可以按下面的方式试试。

D3D11_VIDEO_DECODER_CONFIG conf
ZeroMemory(&conf, sizeof(conf));
conf.guidConfigBitstreamEncryption = xxx;
...
conf.ConfigDecoderSpecific = xxx;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

所以,我找到了解决方案。

对于H264解码器,ConfigBitstreamRaw字段必须为"2"。不是"1",也不是"0"。只有"2"。像这个

    VideoDecoderDescription decoderDescription = new VideoDecoderDescription();
    decoderDescription.OutputFormat = Format.Opaque420;
    decoderDescription.SampleHeight = 480;
    decoderDescription.SampleWidth = 800;
    decoderDescription.Guid = _formatGuid;
    VideoDecoderConfig config = new VideoDecoderConfig();
    config.ConfigMinRenderTargetBuffCount = 1;
    config.ConfigBitstreamRaw = 2;