@leaveye
2025-06-13T10:59:53.000000Z
字数 11862
阅读 51
hi3531d
ss528
venc
配置过程
VENC
的配置hi_mpi_venc_create_chn()
的参数config.is_rcn_ref_share_buf = HI_TRUE;
帧节省模式开关config.min_bitrate_hd = 128U;
高清编码最低码率config.rc_mode_cbr = HI_VENC_RC_MODE_H264_CVBR;
常量码率的配置选择config.rc_mode_vbr = HI_VENC_RC_MODE_H264_QVBR;
动态码率的配置选择config.rc_stats_time = 1;
码率统计时间config.gop_mode = HI_VENC_GOP_MODE_NORMAL_P;
编码GOP类型。NORMAL_P
对应的 ip_qp_delta=2
hi_mpi_venc_set_debreath_effect()
的参数如果带宽小于 1000Kbps ,则启用去呼吸效应,其中 strength0=0
、streanth1=16
。
/umap/proc/
venc
# cat /proc/umap/venc
[VENC] Version: [SS528V100V2.0.0.1 B020 Release], Build Time[May 3 2022, 10:26:14]
----------------------------------------module param--------------------------------------------------------------------
venc_buf_cache frame_buf_recycle venc_max_chn_num high_profile
0 0 128 n
----------------------------------------venc chn attr 1-----------------------------------------------------------------
id width height type by_frame sequence left_bytes left_frm cur_packs gop_mode priority
0 1920 1080 96 y 1224 0 0 1 normal_p 0
----------------------------------------venc chn attr 2-----------------------------------------------------------------
id started src_frame_rate dst_frame_rate time_ref pixel_format pic_addr wake_up_frame_cnt
0 y -1 -1 5114 yvu420 0x6d719840 1
----------------------------------------venc chn attr 3-----------------------------------------------------------------
id composite_en mosaic_en quality_level
0 n n 1
----------------------------------------venc jpege attr-----------------------------------------------------------------
id recv_mode mpf_cnt mpf0_width mpf0_height mpf1_width mpf1_height
----------------------------------------venc chn recv state-------------------------------------------------------------
id start start_ex recv_left enc_left jpeg_enc_mode
0 1 0 0 0 n/a
----------------------------------------venc vpss query-----------------------------------------------------------------
id query query_ok query_lost invalid full vb_fail query_fail info_err stop
0 2448 2448 0 0 0 0 0 0 0
----------------------------------------venc send1----------------------------------------------------------------------
id vpss_send vpss_err other_send other_err send stop full crop_err direct_send size_err
0 2447 0 0 0 2447 0 0 0 2447 0
----------------------------------------venc send2----------------------------------------------------------------------
id send_vgs start_ok start_fail interrupt_ok interrupt_fail src_add src_sub dst_add dst_sub
0 0 0 0 0 0 0 0 0 0
----------------------------------------venc pic queue state------------------------------------------------------------
id free busy vgs b_frame
0 6 0 0 0
----------------------------------------venc dcf/mpf queue state--------------------------------------------------------
id thumb_free thumb_busy mpf0_free mpf0_busy mpf1_free mpf1_busy
0 0 0 0 0 0 0
----------------------------------------venc channel info---------------------------------------------------------------
id query query_ok start start_ok config interrupt chg_reso_lost over_load ring_skip rc_skip
0 14487 2447 2447 1224 1224 1224 0 0 0 1223
----------------------------------------venc crop info------------------------------------------------------------------
id crop_en x y width height
0 n 0 0 0 0
----------------------------------------roi info------------------------------------------------------------------------
id type index roi_en abs_qp qp x y width height
----------------------------------------jpeg roi info-------------------------------------------------------------------
id index level x y width height
----------------------------------------venc stream state---------------------------------------------------------------
id free_cnt busy_cnt user_cnt user_get user_release get_times interval frame_rate
0 1 0 0 1347 1347 1224 33419 30
----------------------------------------venc pts state------------------------------------------------------------------
id first_frame_pts cur_frame_pts
0 189401506427 189442275668
----------------------------------------venc svc state------------------------------------------------------------------
id enable base_reso_width base_reso_height rect_num pts
----------------------------------------venc svc param------------------------------------------------------------------
id fg_en fg_rgn_param0 fg_rgn_param1 fg_rgn_param2 fg_rgn_param3 fg_rgn_param4 bg_rgn_param act_rgn_param
rc
# cat /proc/umap/rc
[RC] Version: [SS528V100V2.0.0.1 B020 Release],Build Time[May 3 2022, 10:26:14]
----------------------------------------base param 1--------------------------------------------------------------------
id gop stats_time src_frame_rate dst_frame_rate type mode bitrate(kbps) i_qp p_qp b_qp
0 30 1 60 30 96 cvbr 1024 n/a n/a n/a
----------------------------------------base param 2--------------------------------------------------------------------
id min_qp max_qp min_i_qp max_i_qp idr_en qpmap_en qpmap_mode
0 22 47 20 47 y n n/a
----------------------------------------base param 3--------------------------------------------------------------------
id long_term_stats_time short_term_stats_time long_term_max_bitrate long_term_min_bitrate
0 1 1 1024 256
----------------------------------------run common param 1--------------------------------------------------------------
id row_qp_delta threshold_i(16)
0 1 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
----------------------------------------run common param 2--------------------------------------------------------------
id first_frame_start_qp threshold_p(16)
0 -1 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
----------------------------------------run common param 3--------------------------------------------------------------
id direction threshold_b(16)
0 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
----------------------------------------run comm param 4----------------------------------------------------------------
id lost threshold lost_mode frame_gap
0 n 83886080 normal 0
----------------------------------------run comm param 5----------------------------------------------------------------
id super_frame_mod threshold_i threshold_p threshold_b rc_priority clear_stats
0 none 500000 500000 500000 bitrate 1
----------------------------------------run common param 6--------------------------------------------------------------
id detect_scene_chg_en adapt_insert_idr_frame_en
0 y n
----------------------------------------fg protect info 1---------------------------------------------------------------
id protect_en direction threshold_p(16)
0 0 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
----------------------------------------fg protect info 2---------------------------------------------------------------
id gain offset threshold_b(16)
0 8 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
----------------------------------------gop mode attr-------------------------------------------------------------------
id gop_mode ip_qp_delta sp_interval sp_qp_delta b_frame_num b_qp_delta bg_interval vi_qp_delta
0 normal_p 2 n/a n/a n/a n/a n/a n/a
----------------------------------------run cbr param-------------------------------------------------------------------
id min_i_proportion max_i_proportion max_qp min_qp max_i_qp min_i_qp max_reencode_times
----------------------------------------run vbr common param------------------------------------------------------------
id chg_pos min_i_proportion max_i_proportion max_qp min_qp max_i_qp min_i_qp max_reencode_times
0 100 1 100 47 22 47 20 2
----------------------------------------run avbr param------------------------------------------------------------------
id max_still_qp motion_sensitivity min_still_percent min_still_psnr min_qp_delta save_bitrate_en
----------------------------------------run qvbr param------------------------------------------------------------------
id min_bit_percent max_bit_percent min_psnr_fluctuate max_psnr_fluctuate
----------------------------------------run cvbr param------------------------------------------------------------------
id min_qp_delta max_qp_delta extra_bit_percent long_term_stats_time_unit save_bitrate_en
0 0 0 5 60 n
----------------------------------------run info1-----------------------------------------------------------------------
id inst_br:kbps inst_frm_rate wat_l cfg_bit:kb real_bit:kb ip_ratio dst_percent start_qp min_qp max_qp
0 776 30 5070 15 13 21 n/a 37 22 47
----------------------------------------rc debreath_effect info---------------------------------------------------------
id enable strength0 strength1 debreath_effect_cnt
0 n n/a n/a 0
----------------------------------------rc hierarchical_qp info---------------------------------------------------------
id enable frame_num[ 0 1 2 3] qp_delta[ 0 1 2 3]
0 n 1 1 0 0 -2 -4 0 0
hi_
前缀来自早期 SDK ,对于 ss528 ,应使用对应的 ss_
前缀或 ot_
前缀。RX_XXX()
:日志打印函数。mpp_show_xxx()
:为调试目的编写的,打印参数信息的函数。hi_Xcall(func, args...)
:辅助调用宏。用于调用 SDK 提供的接口函数。 func(args...)
。调用后观察返回值,出错则记录下错误信息。
auto &config = configs.venc;
config.is_rcn_ref_share_buf = HI_TRUE;
config.min_bitrate_hd = 128U;
config.rc_mode_cbr = HI_VENC_RC_MODE_H264_CVBR;
config.rc_mode_vbr = HI_VENC_RC_MODE_H264_QVBR;
config.rc_stats_time = 1;
config.gop_mode = HI_VENC_GOP_MODE_NORMAL_P;
// 准备了相关的 VI-VPSS 链路后,准备 VENC 的相关链路
viencsend_task *viencsend_task::start_venc() {
RX_DEBUG("%s: start %s ...", name(), venc->name());
const auto chn = venc->get_chan();
venc_fill_settings(chn, args);
const auto attr = &mpp_venc_context()->chn_attr;
venc_fill_chn_attr(chn, args, attr);
mpp_show_venc_chn_args(name(), args);
mpp_show_venc_chn_attr(venc->name(), attr);
hi_ncall(hi_mpi_venc_create_chn, chn, attr);
hi_ncall(venc_close_reencode, chn);
if (args->bit_rate < 1000) {
// 去呼吸效应
hi_venc_debreath_effect debreath{};
debreath.enable = HI_TRUE;
debreath.strength0 = 1;
debreath.strength1 = 16;
hi_ncall(hi_mpi_venc_set_debreath_effect, chn, &debreath);
}
hi_ncall(mpp_venc_start_chn_forever, chn);
flags.set(VENC_VALID);
return this;
}
typedef struct mpp_venc_args_s {
user_intf_t input;
videoResStd_t vi_std; //!< probe from H/W
videoRes_t res;
hi_u32 frame_rate;
hi_payload_type type;
hi_venc_profile profile;
hi_u32 bit_rate;
hi_venc_rc_mode rc_mode; //!< VBR/CBR only
hi_u32 gop;
hi_venc_gop_attr gop_attr_; //!< derived from others
hi_u32 stats_time_; //!< derived from others
} mpp_venc_args_t;
hi_s32 venc_fill_settings(hi_venc_chn chn, mpp_venc_args_t *venc) {
assert(chn == 0 && "only 1 VENC channel supported now");
assert(venc->profile < HI_VENC_PROFILE_BUTT);
mpp_venc_init_gop_attr(mpp_venc_config()->gop_mode, &venc->gop_attr_);
if (venc->gop_attr_.gop_mode == HI_VENC_GOP_MODE_SMART_P) {
venc->stats_time_ = venc->gop_attr_.smart_p.bg_interval / venc->gop;
RX_DEBUG("setting VENC:stats_time=%d", venc->stats_time_);
// } else if (venc->frame_rate != 0) {
// venc->stats_time_ = (venc->gop + venc->frame_rate - 1) / venc->frame_rate;
} else {
venc->stats_time_ = mpp_venc_config()->rc_stats_time;
}
// fix value collision
if (venc->gop_attr_.gop_mode == HI_VENC_GOP_MODE_BIPRED_B &&
venc->type == HI_PT_H264 && venc->profile == HI_VENC_PROFILE_H264_BASE) {
venc->profile = HI_VENC_PROFILE_H264_MAIN;
RX_NOTICE("H.264 Baseline not support BIPREDB, force it to Main Profile");
}
return HI_SUCCESS;
}
hi_s32 venc_fill_chn_attr(hi_venc_chn chn, mpp_venc_args_t *venc, hi_venc_chn_attr *attr) {
assert(chn == 0 && "only 1 VENC channel supported now");
// unpack settings
hi_venc_gop_attr *gop_attr = &venc->gop_attr_;
hi_payload_type type = venc->type;
hi_venc_profile profile = venc->profile;
auto vi_std = venc->vi_std != videoResStd_NONE ? venc->vi_std : videoResStd_MAX;
hi_size vi_size, venc_size;
vi_size.width = videoResStd_width(vi_std);
vi_size.height = videoResStd_height(vi_std);
venc_size.width = videoRes_width(venc->res);
venc_size.height = videoRes_height(venc->res);
// do assignment
attr->venc_attr.type = type;
attr->venc_attr.max_pic_width = vi_size.width;
attr->venc_attr.max_pic_height = vi_size.height;
attr->venc_attr.pic_width = venc_size.width;
attr->venc_attr.pic_height = venc_size.height;
attr->venc_attr.profile = profile_id(profile);
attr->venc_attr.is_by_frame = HI_TRUE; // frame mode or slice mode
deferrable(return HI_FAILURE);
switch (type) {
case HI_PT_H265: // 准备使用但还未启用
attr->venc_attr.buf_size = HI_ALIGN_UP(vi_size.width * vi_size.height * 3 / 4, 64);
hi_pcall(dgsj_comm_venc_h265_param_init, attr, venc);
// profile force MAIN if BIPRED moved ahead
attr->gop_attr = *gop_attr;
break;
case HI_PT_H264:
attr->venc_attr.buf_size = HI_ALIGN_UP(vi_size.width * vi_size.height * 3 / 4, 64);
hi_pcall(venc_attr_init_h264, chn, attr, venc);
// profile force MAIN if BIPRED moved ahead
attr->gop_attr = *gop_attr;
break;
// case ...
}
return HI_SUCCESS;
}