FFmpegAVCodecContext结构体剖析

flag变量分析

10年积累的成都做网站、网站设计、外贸营销网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有柴桑免费网站建设让你可以放心的选择与我们合作。

尝试降低解码延时:CODEC_FLAG_LOW_DELAY

#define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.

h364 解码中
int ff_h364_set_parameter_from_sps(H264Context *h)

    if (h->flags & CODEC_FLAG_LOW_DELAY ||
        (h->sps.bitstream_restriction_flag &&
         !h->sps.num_reorder_frames)) {
        if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])
            av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. "
                   "Reenabling low delay requires a codec flush.\n");
        else
            h->low_delay = 1;
    }

结果

avcodec_decode_video2接收到SPS/PPS,和I帧码流之后,测试显示需要20毫秒之后,解码出图像,跟CODEC_FLAG_LOW_DELAY解码标志位,优化快速解码出图像,没有任何的效果
场景
 目前使用2.3.6版本设置AVCodecContext的flags:
 flags |= CODEC_FLAG_LOW_DELAY
 没有任何的效果
2.3.6版本
avcodec.h (libavcodec) line 744 : #define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.
/**
 * @deprecated use the flag "naq" in the "mpv_flags" private option of the
 * mpegvideo encoders
 */
#define CODEC_FLAG_NORMALIZE_AQP  0x00020000
#endif
#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
#define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.

4.0.2版本
avcodec.h (libavcodec) line 878 : #define AV_CODEC_FLAG_LOW_DELAY       (1 << 19)
/* encoding support
   These flags can be passed in AVCodecContext.flags before initialization.
   Note: Not everything is supported yet.
*/
/**
 * Force low delay.
 */
#define AV_CODEC_FLAG_LOW_DELAY       (1 << 19)

debug变量分析

            当设置AVCodecContext结构体debug字段为1的时候,将会打印如下的调试信息:1)对每一个分片打印详细记录  2)打印SPS/PPS参数值
这两项参数对于解码来说,相当重要,IDR帧是解码的关键,SPS/PPS记录了解码图像相关参数

代码剖析
1)static int h364_slice_init(H264Context *h, H264SliceContext *sl, const H2645NAL *nal)

    if (h->avctx->debug & FF_DEBUG_PICT_INFO) {
        av_log(h->avctx, AV_LOG_DEBUG,
               "slice:%d %s mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
               sl->slice_num,
               (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),
               sl->mb_y * h->mb_width + sl->mb_x,
               av_get_picture_type_char(sl->slice_type),
               sl->slice_type_fixed ? " fix" : "",
               nal->type == H264_NAL_IDR_SLICE ? " IDR" : "",
               h->poc.frame_num,
               h->cur_pic_ptr->field_poc[0],
               h->cur_pic_ptr->field_poc[1],
               sl->ref_count[0], sl->ref_count[1],
               sl->qscale,
               sl->deblocking_filter,
               sl->slice_alpha_c0_offset, sl->slice_beta_offset,
               sl->pwt.use_weight,
               sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",
               sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
    }

打印:
slice:1 F mb:0 I IDR frame:0 poc:65536/65536 ref:0/0 qp:25 loop:1:0:0 weight:0
slice:1 F mb:0 P frame:4 poc:65540/65540 ref:1/1 qp:26 loop:1:0:0 weight:0
/* do all the per-slice initialization needed before we can start decoding the
 * actual MBs */


2)int ff_h364_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)

    if (avctx->debug & FF_DEBUG_PICT_INFO) {
        av_log(avctx, AV_LOG_DEBUG,
               "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
               pps_id, pps->sps_id,
               pps->cabac ? "CABAC" : "CAVLC",
               pps->slice_group_count,
               pps->ref_count[0], pps->ref_count[1],
               pps->weighted_pred ? "weighted" : "",
               pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1],
               pps->deblocking_filter_parameters_present ? "LPAR" : "",
               pps->constrained_intra_pred ? "CONSTR" : "",
               pps->redundant_pic_cnt_present ? "REDU" : "",
               pps->transform_8x8_mode ? "8x8DCT" : "");
    }

打印
pps:0 sps:0 CAVLC slice_groups:1 ref:1/1  qp:26/26/0/0 LPAR  


3)int ff_h364_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)

    if (avctx->debug & FF_DEBUG_PICT_INFO) {
        static const char csp[4][5] = { "Gray", "420", "422", "444" };
        av_log(avctx, AV_LOG_DEBUG,
               "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%u/%u/%u/%u %s %s %"PRId32"/%"PRId32" b%d reo:%d\n",
               sps_id, sps->profile_idc, sps->level_idc,
               sps->poc_type,
               sps->ref_frame_count,
               sps->mb_width, sps->mb_height,
               sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),
               sps->direct_8x8_inference_flag ? "8B8" : "",
               sps->crop_left, sps->crop_right,
               sps->crop_top, sps->crop_bottom,
               sps->vui_parameters_present_flag ? "VUI" : "",
               csp[sps->chroma_format_idc],
               sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
               sps->timing_info_present_flag ? sps->time_scale : 0,
               sps->bit_depth_luma,
               sps->bitstream_restriction_flag ? sps->num_reorder_frames : -1
               );
    }

打印
sps:0 profile:66/42 poc:0 ref:1 120x68 FRM 8B8 crop:0/0/0/8 VUI 420 1800/90000 b8 reo:-1


本文标题:FFmpegAVCodecContext结构体剖析
文章分享:http://bzwzjz.com/article/jhhhhi.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 手机网站建设 成都营销网站建设 泸州网站建设 成都网站建设 重庆网站建设 专业网站建设 企业网站设计 成都网站建设 网站设计 成都网站制作 成都网站制作 移动手机网站制作 网站建设费用 成都网站建设 成都网站设计 成都网站设计 高端网站设计推广 网站建设 成都网站制作 成都网站建设 成都网站建设公司 品牌网站建设