avcodec_decode_video 解码失败,got_picture返回0

2024-01-13 01:38

本文主要是介绍avcodec_decode_video 解码失败,got_picture返回0,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

//H264解码器初始化
bool H264DecodeInit(void)
{
        //
        int  numBytes;

        avcodec_init();
        /* register all the codecs */
        avcodec_register_all();

        codecContext= NULL;

        /* find the mpeg1 video decoder */
        codec = avcodec_find_decoder(CODEC_ID_H264);

        if (!codec) {
                fprintf(stderr, "codec not found\n");
        }

        codecContext= avcodec_alloc_context();

        codecContext->width=800;
        codecContext->height=600;
        codecContext->sample_fmt=SAMPLE_FMT_S16;

        codecContext->pix_fmt=PIX_FMT_YUV420P;

        m_pFrame= avcodec_alloc_frame();

        if (m_pFrame==NULL)
        {
                return false;
        }

        m_pFrameRGB = avcodec_alloc_frame();
        if(m_pFrameRGB == NULL)
        {
                return false;   
        }

        if(codec->capabilities&CODEC_CAP_TRUNCATED)
                codecContext->flags|= CODEC_FLAG_TRUNCATED;                /* we do not send complete frames */

        /* For some codecs, such as msmpeg4 and mpeg4, width and height
                MUST be initialized there because this information is not
        available in the bitstream. */

        /* open it */

        if (avcodec_open(codecContext, codec) < 0) {
                fprintf(stderr, "could not open codec\n");
        }

        numBytes=avpicture_get_size(PIX_FMT_RGB24, 800, 600);
        m_buffer=new uint8_t[numBytes];   

        // Assign appropriate parts of buffer to image planes in pFrameRGB
        avpicture_fill((AVPicture *)m_pFrameRGB, m_buffer, PIX_FMT_RGB24, 800 ,600);

        return true;
}



//H264 解码函数
void H264DecodeProcess(struct buffer_desc desc)
{
       
        int got_picture,len;

        len = avcodec_decode_video(codecContext, m_pFrame, &got_picture,
                (uint8_t *)desc.buffer, desc.valid_len);      //Rtp码流已经解包放在desc.buffer中,buffer的长度为desc.valid_len  调用这个函数got_picture=0;

        if (len != desc.valid_len) {
                printf("decode error\n");
        }
       
        img_convert((AVPicture *)m_pFrameRGB, PIX_FMT_BGR24,(AVPicture*)m_pFrame,codecContext->pix_fmt, codecContext->width,codecContext->height);

        //显示图像
       
        return;
}

如果我将Rtp码流解包后,直接丢给解码模块,实时解码,发现//Rtp码流已经解包放在desc.buffer中,buffer的长度为desc.valid_len  第一次调用avcodec_decode_video

这个函数got_picture=0;第2次调用avcodec_decode_video这个函数就可以得到正确的值,即我的每解码一帧要调用avcodec_decode_video,2次,很诧异,有路过的高手指点下。

我的码流中只有IDR帧和P帧,对Rtp包解码后,对sps和pps,idr,p帧前面都加了00 00 00 01开始标记

这篇关于avcodec_decode_video 解码失败,got_picture返回0的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/599829

相关文章

ORACLE 11g 创建数据库时 Enterprise Manager配置失败的解决办法 无法打开OEM的解决办法

在win7 64位系统下安装oracle11g,在使用Database configuration Assistant创建数据库时,在创建到85%的时候报错,错误如下: 解决办法: 在listener.ora中增加对BlueAeri-PC或ip地址的侦听,具体步骤如下: 1.启动Net Manager,在“监听程序”--Listener下添加一个地址,主机名写计

STM32 ADC+DMA导致写FLASH失败

最近用STM32G070系列的ADC+DMA采样时,遇到了一些小坑记录一下; 一、ADC+DMA采样时进入死循环; 解决方法:ADC-dma死循环问题_stm32 adc dma死机-CSDN博客 将ADC的DMA中断调整为最高,且增大ADCHAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_Buffer_Size); 的ADC_Bu

Apple quietly slips WebRTC audio, video into Safari's WebKit spec

转自:http://www.zdnet.com/article/apple-quietly-slips-webrtc-audio-video-into-safaris-webkit-spec/?from=timeline&isappinstalled=0 http://www.zdnet.com/article/apple-quietly-slips-webrtc-audio-video-

php中json_decode()和json_encode()

1.json_decode() json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_decode — 对 JSON 格式的字符串进行编码 说明 mixed json_decode ( string $json [, bool $assoc ] ) 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数 json

Android中如何实现adb向应用发送特定指令并接收返回

1 ADB发送命令给应用 1.1 发送自定义广播给系统或应用 adb shell am broadcast 是 Android Debug Bridge (ADB) 中用于向 Android 系统发送广播的命令。通过这个命令,开发者可以发送自定义广播给系统或应用,触发应用中的广播接收器(BroadcastReceiver)。广播机制是 Android 的一种组件通信方式,应用可以监听广播来执行

struts2中的json返回指定的多个参数

要返回指定的多个参数,就必须在struts.xml中的配置如下: <action name="goodsType_*" class="goodsTypeAction" method="{1}"> <!-- 查询商品类别信息==分页 --> <result type="json" name="goodsType_findPgae"> <!--在这一行进行指定,其中lis是一个List集合,但

FFmpeg系列-视频解码后保存帧图片为ppm

在正常开发中遇到花屏时怎么处理呢?可以把解码后的数据直接保存成帧图片保存起来,然后直接看图片有没有花屏来排除是否是显示的问题,如果花屏,则代表显示无问题,如果图片中没有花屏,则可以往显示的方向去排查了。 void saveFrame(AVFrame* pFrame, int width, int height, int iFrame){FILE *pFile;char szFilename[

MonoHuman: Animatable Human Neural Field from Monocular Video 翻译

MonoHuman:来自单目视频的可动画人类神经场 摘要。利用自由视图控制来动画化虚拟化身对于诸如虚拟现实和数字娱乐之类的各种应用来说是至关重要的。已有的研究试图利用神经辐射场(NeRF)的表征能力从单目视频中重建人体。最近的工作提出将变形网络移植到NeRF中,以进一步模拟人类神经场的动力学,从而动画化逼真的人类运动。然而,这种流水线要么依赖于姿态相关的表示,要么由于帧无关的优化而缺乏运动一致性

论文精读-Supervised Raw Video Denoising with a Benchmark Dataset on Dynamic Scenes

论文精读-Supervised Raw Video Denoising with a Benchmark Dataset on Dynamic Scenes 优势 1、构建了一个用于监督原始视频去噪的基准数据集。为了多次捕捉瞬间,我们手动为对象s创建运动。在高ISO模式下捕获每一时刻的噪声帧,并通过对多个噪声帧进行平均得到相应的干净帧。 2、有效的原始视频去噪网络(RViDeNet),通过探

ssh版本升级导致连接失败

公司系统使用的是第三方ssh插件jsch-0.1.39.jar,之前采集正常的,但是厂家服务器ssh升级成2.0版本,然后程序就报错,异常如下: com.jcraft.jsch.JSchException: Algorithm negotiation failat com.jcraft.jsch.Session.receive_kexinit(Session.java:510)at com.