关于d3dva11解码H264编码报-1094995529错误的问题

项目中使用了d3dva11硬解码器解码,参数一切正常,在执行

int ret = avcodec_send_packet(decoder_ctx_, avpkt);

这个函数时报错了,错误码:

AVERROR_INVALIDDATA

也就是-1094995529错误。

经过排查源码,发现这个函数在底层执行的时候,会进行颜色空间检测。吧


#if CONFIG_LCMS2
static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
{
    AVCodecInternal *avci = avctx->internal;
    enum AVColorTransferCharacteristic trc;
    AVColorPrimariesDesc coeffs;
    enum AVColorPrimaries prim;
    cmsHPROFILE profile;
    AVFrameSideData *sd;
    int ret;
    if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
        return 0;

    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE);
    if (!sd || !sd->size)
        return 0;

    if (!avci->icc.avctx) {
        ret = ff_icc_context_init(&avci->icc, avctx);
        if (ret < 0)
            return ret;
    }

    profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
    if (!profile)
        return AVERROR_INVALIDDATA;

    ........
}

 也就是cmsOpenProfileFromMemTHR 这个函数报错了,经过Chatgpt,这个函数是预加载颜色空间后,与实际的传入的颜色内存空间进行校对。校对失败就会出现这个问题。

具体为什么为什么会失败?解码器的配置都是正确的,一番操作,发现是H264 profile的问题

H264有多种profile

Base Profile

Main Profile

High Profile 

简称为BP,MP,HiP这三种配置,Base Profile是对于一些比较差的设备用来解码的。颜色空间肯定较少且功能少。

问题的根本就在于D3Dva11硬解码器,是不支持BP的,他对H264的颜色空间有一定要求。所以更改了相机的编码配置,就一切正常了。

猜你喜欢

转载自blog.csdn.net/zanglengyu/article/details/132559116