在C / C ++中使用nvdech264_cuvid解码原始h.264帧数据

问题描述

所有人...

我试图为h.264原始流编写解码器类...但是效果不好。

流仅包含数据大小和编码的原始数据... (分辨率= 1280 x 720)

这是我写的代码...(例外...除外)


第1部分:初始化

AVCodec *m_pDecoder = avcodec_find_decoder_by_name("h264_cuvid");
AVCodecContext *m_pDecoderContext = avcodec_alloc_context3(m_pDecoder);

AVBufferRef *m_HWContext;
av_hwdevice_ctx_create(&m_HWContext,AV_HWDEVICE_TYPE_CUDA,NULL,0);

AVPacket m_pkt_decode;
av_init_packet(&m_pkt_decode);

m_pDecoderContext->pix_fmt = AV_PIX_FMT_CUDA;
m_pDecoderContext->width = 1280;
m_pDecoderContext->height = 720;
avcodec_open2(m_pDecoderContext,m_pDecoder,NULL);

第2部分:填充流数据

m_pkt_decode.data = (uint8_t *)pStreamData;
m_pkt_decode.size = nDataSize;

第3部分:解码流数据

AVFrame *frame = nullptr;
frame = av_frame_alloc();

avcodec_send_packet(m_pDecoderContext,&m_pkt_decode);
avcodec_receive_frame(m_pDecoderContext,frame);

然后...

avcodec_receive_frame函数总是返回错误...
我的代码中是否缺少任何步骤?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)