X264压缩丢帧问题

使用x264 avcodec_decode_video2()解码后,avi录像丢了4帧。分析原因得知,在解码的过程中,分析该帧图像如果不是关键帧,那么解压就会丢弃该帧,本来想在压缩的时候就直接设置参数属性没有B帧数据的那种属性,可是没有找到,后来只能在解压的时候想办法了。

while (av_read_frame(fmt_ctx, &pkt) >= 0) 
    {
        if(pkt.stream_index == video_stream_idx)
        {
           ret = avcodec_decode_video2(video_dec_ctx, frame, &frame_finished, &pkt);
           
           if (frame_finished)
           {
               ret = sws_scale(sws_ctx, (const uint8_t * const*)frame->data,frame->linesize, 0,
                       video_dec_ctx->height, frame_rgb->data,frame_rgb->linesize);
               PRINTF("ret = %d\n",ret);
               if (frame_total == 0)
               {
                   //save the data
                   memcpy(buf, frame_rgb->data[0], picture_size);                 
                   av_free_packet(&pkt);
                   break;
               }
               else
               {
                   ptrFunc(frame_rgb->data[0], video_dec_ctx->width, video_dec_ctx->height); 
               }
           }
           else
           {
               skipped_frame++;
           }
        }
        av_free_packet(&pkt);
    }
    ///用skipped_frame记录丢失了哪些帧,此处开始重新解压丢失的那些帧
    PRINTF("skipper_frame: %d\n", skipped_frame);
    for(int i = 0; i < skipped_frame; i++)
    {
        ret = avcodec_decode_video2(video_dec_ctx, frame, &frame_finished, &pkt);
        if (frame_finished)
        {
            ret = sws_scale(sws_ctx, (const uint8_t * const*)frame->data,frame->linesize, 0,
                    video_dec_ctx->height, frame_rgb->data,frame_rgb->linesize);
            if (frame_total == 0)
            {
                //save the data
                memcpy(buf, frame_rgb->data[0], picture_size);                 
                av_free_packet(&pkt);
                break;
            }
            else
            {
                ptrFunc(frame_rgb->data[0], video_dec_ctx->width, video_dec_ctx->height); 
            }
        }
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值