溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

FFmpeg AVCodecContext結(jié)構(gòu)體剖析

發(fā)布時(shí)間:2020-08-10 17:00:17 來(lái)源:網(wǎng)絡(luò) 閱讀:1401 作者:fengyuzaitu 欄目:編程語(yǔ)言

flag變量分析

嘗試降低解碼延時(shí):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;
??? }


結(jié)果

avcodec_decode_video2接收到SPS/PPS,和I幀碼流之后,測(cè)試顯示需要20毫秒之后,解碼出圖像,跟CODEC_FLAG_LOW_DELAY解碼標(biāo)志位,優(yōu)化快速解碼出圖像,沒(méi)有任何的效果
場(chǎng)景
?目前使用2.3.6版本設(shè)置AVCodecContext的flags:
?flags |= CODEC_FLAG_LOW_DELAY
?沒(méi)有任何的效果
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變量分析

????????????當(dāng)設(shè)置AVCodecContext結(jié)構(gòu)體debug字段為1的時(shí)候,將會(huì)打印如下的調(diào)試信息:1)對(duì)每一個(gè)分片打印詳細(xì)記錄? 2)打印SPS/PPS參數(shù)值
這兩項(xiàng)參數(shù)對(duì)于解碼來(lái)說(shuō),相當(dāng)重要,IDR幀是解碼的關(guān)鍵,SPS/PPS記錄了解碼圖像相關(guān)參數(shù)


代碼剖析
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") : "");
??? }

打?。?br />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

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI