[关闭]
@leaveye 2025-06-13T10:59:53.000000Z 字数 11862 阅读 51

SS528 Codec 配置

hi3531d ss528 venc 配置过程


VENC的配置

简要说明

hi_mpi_venc_create_chn() 的参数

hi_mpi_venc_set_debreath_effect() 的参数

如果带宽小于 1000Kbps ,则启用去呼吸效应,其中 strength0=0streanth1=16

附录:/umap/proc/

venc

  1. # cat /proc/umap/venc
  2. [VENC] Version: [SS528V100V2.0.0.1 B020 Release], Build Time[May 3 2022, 10:26:14]
  3. ----------------------------------------module param--------------------------------------------------------------------
  4. venc_buf_cache frame_buf_recycle venc_max_chn_num high_profile
  5. 0 0 128 n
  6. ----------------------------------------venc chn attr 1-----------------------------------------------------------------
  7. id width height type by_frame sequence left_bytes left_frm cur_packs gop_mode priority
  8. 0 1920 1080 96 y 1224 0 0 1 normal_p 0
  9. ----------------------------------------venc chn attr 2-----------------------------------------------------------------
  10. id started src_frame_rate dst_frame_rate time_ref pixel_format pic_addr wake_up_frame_cnt
  11. 0 y -1 -1 5114 yvu420 0x6d719840 1
  12. ----------------------------------------venc chn attr 3-----------------------------------------------------------------
  13. id composite_en mosaic_en quality_level
  14. 0 n n 1
  15. ----------------------------------------venc jpege attr-----------------------------------------------------------------
  16. id recv_mode mpf_cnt mpf0_width mpf0_height mpf1_width mpf1_height
  17. ----------------------------------------venc chn recv state-------------------------------------------------------------
  18. id start start_ex recv_left enc_left jpeg_enc_mode
  19. 0 1 0 0 0 n/a
  20. ----------------------------------------venc vpss query-----------------------------------------------------------------
  21. id query query_ok query_lost invalid full vb_fail query_fail info_err stop
  22. 0 2448 2448 0 0 0 0 0 0 0
  23. ----------------------------------------venc send1----------------------------------------------------------------------
  24. id vpss_send vpss_err other_send other_err send stop full crop_err direct_send size_err
  25. 0 2447 0 0 0 2447 0 0 0 2447 0
  26. ----------------------------------------venc send2----------------------------------------------------------------------
  27. id send_vgs start_ok start_fail interrupt_ok interrupt_fail src_add src_sub dst_add dst_sub
  28. 0 0 0 0 0 0 0 0 0 0
  29. ----------------------------------------venc pic queue state------------------------------------------------------------
  30. id free busy vgs b_frame
  31. 0 6 0 0 0
  32. ----------------------------------------venc dcf/mpf queue state--------------------------------------------------------
  33. id thumb_free thumb_busy mpf0_free mpf0_busy mpf1_free mpf1_busy
  34. 0 0 0 0 0 0 0
  35. ----------------------------------------venc channel info---------------------------------------------------------------
  36. id query query_ok start start_ok config interrupt chg_reso_lost over_load ring_skip rc_skip
  37. 0 14487 2447 2447 1224 1224 1224 0 0 0 1223
  38. ----------------------------------------venc crop info------------------------------------------------------------------
  39. id crop_en x y width height
  40. 0 n 0 0 0 0
  41. ----------------------------------------roi info------------------------------------------------------------------------
  42. id type index roi_en abs_qp qp x y width height
  43. ----------------------------------------jpeg roi info-------------------------------------------------------------------
  44. id index level x y width height
  45. ----------------------------------------venc stream state---------------------------------------------------------------
  46. id free_cnt busy_cnt user_cnt user_get user_release get_times interval frame_rate
  47. 0 1 0 0 1347 1347 1224 33419 30
  48. ----------------------------------------venc pts state------------------------------------------------------------------
  49. id first_frame_pts cur_frame_pts
  50. 0 189401506427 189442275668
  51. ----------------------------------------venc svc state------------------------------------------------------------------
  52. id enable base_reso_width base_reso_height rect_num pts
  53. ----------------------------------------venc svc param------------------------------------------------------------------
  54. 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

  1. # cat /proc/umap/rc
  2. [RC] Version: [SS528V100V2.0.0.1 B020 Release],Build Time[May 3 2022, 10:26:14]
  3. ----------------------------------------base param 1--------------------------------------------------------------------
  4. id gop stats_time src_frame_rate dst_frame_rate type mode bitrate(kbps) i_qp p_qp b_qp
  5. 0 30 1 60 30 96 cvbr 1024 n/a n/a n/a
  6. ----------------------------------------base param 2--------------------------------------------------------------------
  7. id min_qp max_qp min_i_qp max_i_qp idr_en qpmap_en qpmap_mode
  8. 0 22 47 20 47 y n n/a
  9. ----------------------------------------base param 3--------------------------------------------------------------------
  10. id long_term_stats_time short_term_stats_time long_term_max_bitrate long_term_min_bitrate
  11. 0 1 1 1024 256
  12. ----------------------------------------run common param 1--------------------------------------------------------------
  13. id row_qp_delta threshold_i(16)
  14. 0 1 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
  15. ----------------------------------------run common param 2--------------------------------------------------------------
  16. id first_frame_start_qp threshold_p(16)
  17. 0 -1 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
  18. ----------------------------------------run common param 3--------------------------------------------------------------
  19. id direction threshold_b(16)
  20. 0 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
  21. ----------------------------------------run comm param 4----------------------------------------------------------------
  22. id lost threshold lost_mode frame_gap
  23. 0 n 83886080 normal 0
  24. ----------------------------------------run comm param 5----------------------------------------------------------------
  25. id super_frame_mod threshold_i threshold_p threshold_b rc_priority clear_stats
  26. 0 none 500000 500000 500000 bitrate 1
  27. ----------------------------------------run common param 6--------------------------------------------------------------
  28. id detect_scene_chg_en adapt_insert_idr_frame_en
  29. 0 y n
  30. ----------------------------------------fg protect info 1---------------------------------------------------------------
  31. id protect_en direction threshold_p(16)
  32. 0 0 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
  33. ----------------------------------------fg protect info 2---------------------------------------------------------------
  34. id gain offset threshold_b(16)
  35. 0 8 8 [ 0 0 0 0 3 3 5 5 8 8 8 15 15 20 25 25]
  36. ----------------------------------------gop mode attr-------------------------------------------------------------------
  37. id gop_mode ip_qp_delta sp_interval sp_qp_delta b_frame_num b_qp_delta bg_interval vi_qp_delta
  38. 0 normal_p 2 n/a n/a n/a n/a n/a n/a
  39. ----------------------------------------run cbr param-------------------------------------------------------------------
  40. id min_i_proportion max_i_proportion max_qp min_qp max_i_qp min_i_qp max_reencode_times
  41. ----------------------------------------run vbr common param------------------------------------------------------------
  42. id chg_pos min_i_proportion max_i_proportion max_qp min_qp max_i_qp min_i_qp max_reencode_times
  43. 0 100 1 100 47 22 47 20 2
  44. ----------------------------------------run avbr param------------------------------------------------------------------
  45. id max_still_qp motion_sensitivity min_still_percent min_still_psnr min_qp_delta save_bitrate_en
  46. ----------------------------------------run qvbr param------------------------------------------------------------------
  47. id min_bit_percent max_bit_percent min_psnr_fluctuate max_psnr_fluctuate
  48. ----------------------------------------run cvbr param------------------------------------------------------------------
  49. id min_qp_delta max_qp_delta extra_bit_percent long_term_stats_time_unit save_bitrate_en
  50. 0 0 0 5 60 n
  51. ----------------------------------------run info1-----------------------------------------------------------------------
  52. 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
  53. 0 776 30 5070 15 13 21 n/a 37 22 47
  54. ----------------------------------------rc debreath_effect info---------------------------------------------------------
  55. id enable strength0 strength1 debreath_effect_cnt
  56. 0 n n/a n/a 0
  57. ----------------------------------------rc hierarchical_qp info---------------------------------------------------------
  58. id enable frame_num[ 0 1 2 3] qp_delta[ 0 1 2 3]
  59. 0 n 1 1 0 0 -2 -4 0 0

附录:代码片段

简要说明

配置加载

  1. auto &config = configs.venc;
  2. config.is_rcn_ref_share_buf = HI_TRUE;
  3. config.min_bitrate_hd = 128U;
  4. config.rc_mode_cbr = HI_VENC_RC_MODE_H264_CVBR;
  5. config.rc_mode_vbr = HI_VENC_RC_MODE_H264_QVBR;
  6. config.rc_stats_time = 1;
  7. config.gop_mode = HI_VENC_GOP_MODE_NORMAL_P;

编码器的创建过程

  1. // 准备了相关的 VI-VPSS 链路后,准备 VENC 的相关链路
  2. viencsend_task *viencsend_task::start_venc() {
  3. RX_DEBUG("%s: start %s ...", name(), venc->name());
  4. const auto chn = venc->get_chan();
  5. venc_fill_settings(chn, args);
  6. const auto attr = &mpp_venc_context()->chn_attr;
  7. venc_fill_chn_attr(chn, args, attr);
  8. mpp_show_venc_chn_args(name(), args);
  9. mpp_show_venc_chn_attr(venc->name(), attr);
  10. hi_ncall(hi_mpi_venc_create_chn, chn, attr);
  11. hi_ncall(venc_close_reencode, chn);
  12. if (args->bit_rate < 1000) {
  13. // 去呼吸效应
  14. hi_venc_debreath_effect debreath{};
  15. debreath.enable = HI_TRUE;
  16. debreath.strength0 = 1;
  17. debreath.strength1 = 16;
  18. hi_ncall(hi_mpi_venc_set_debreath_effect, chn, &debreath);
  19. }
  20. hi_ncall(mpp_venc_start_chn_forever, chn);
  21. flags.set(VENC_VALID);
  22. return this;
  23. }

从静态配置/活动配置,填充编码器参数

  1. typedef struct mpp_venc_args_s {
  2. user_intf_t input;
  3. videoResStd_t vi_std; //!< probe from H/W
  4. videoRes_t res;
  5. hi_u32 frame_rate;
  6. hi_payload_type type;
  7. hi_venc_profile profile;
  8. hi_u32 bit_rate;
  9. hi_venc_rc_mode rc_mode; //!< VBR/CBR only
  10. hi_u32 gop;
  11. hi_venc_gop_attr gop_attr_; //!< derived from others
  12. hi_u32 stats_time_; //!< derived from others
  13. } mpp_venc_args_t;
  14. hi_s32 venc_fill_settings(hi_venc_chn chn, mpp_venc_args_t *venc) {
  15. assert(chn == 0 && "only 1 VENC channel supported now");
  16. assert(venc->profile < HI_VENC_PROFILE_BUTT);
  17. mpp_venc_init_gop_attr(mpp_venc_config()->gop_mode, &venc->gop_attr_);
  18. if (venc->gop_attr_.gop_mode == HI_VENC_GOP_MODE_SMART_P) {
  19. venc->stats_time_ = venc->gop_attr_.smart_p.bg_interval / venc->gop;
  20. RX_DEBUG("setting VENC:stats_time=%d", venc->stats_time_);
  21. // } else if (venc->frame_rate != 0) {
  22. // venc->stats_time_ = (venc->gop + venc->frame_rate - 1) / venc->frame_rate;
  23. } else {
  24. venc->stats_time_ = mpp_venc_config()->rc_stats_time;
  25. }
  26. // fix value collision
  27. if (venc->gop_attr_.gop_mode == HI_VENC_GOP_MODE_BIPRED_B &&
  28. venc->type == HI_PT_H264 && venc->profile == HI_VENC_PROFILE_H264_BASE) {
  29. venc->profile = HI_VENC_PROFILE_H264_MAIN;
  30. RX_NOTICE("H.264 Baseline not support BIPREDB, force it to Main Profile");
  31. }
  32. return HI_SUCCESS;
  33. }
  34. hi_s32 venc_fill_chn_attr(hi_venc_chn chn, mpp_venc_args_t *venc, hi_venc_chn_attr *attr) {
  35. assert(chn == 0 && "only 1 VENC channel supported now");
  36. // unpack settings
  37. hi_venc_gop_attr *gop_attr = &venc->gop_attr_;
  38. hi_payload_type type = venc->type;
  39. hi_venc_profile profile = venc->profile;
  40. auto vi_std = venc->vi_std != videoResStd_NONE ? venc->vi_std : videoResStd_MAX;
  41. hi_size vi_size, venc_size;
  42. vi_size.width = videoResStd_width(vi_std);
  43. vi_size.height = videoResStd_height(vi_std);
  44. venc_size.width = videoRes_width(venc->res);
  45. venc_size.height = videoRes_height(venc->res);
  46. // do assignment
  47. attr->venc_attr.type = type;
  48. attr->venc_attr.max_pic_width = vi_size.width;
  49. attr->venc_attr.max_pic_height = vi_size.height;
  50. attr->venc_attr.pic_width = venc_size.width;
  51. attr->venc_attr.pic_height = venc_size.height;
  52. attr->venc_attr.profile = profile_id(profile);
  53. attr->venc_attr.is_by_frame = HI_TRUE; // frame mode or slice mode
  54. deferrable(return HI_FAILURE);
  55. switch (type) {
  56. case HI_PT_H265: // 准备使用但还未启用
  57. attr->venc_attr.buf_size = HI_ALIGN_UP(vi_size.width * vi_size.height * 3 / 4, 64);
  58. hi_pcall(dgsj_comm_venc_h265_param_init, attr, venc);
  59. // profile force MAIN if BIPRED moved ahead
  60. attr->gop_attr = *gop_attr;
  61. break;
  62. case HI_PT_H264:
  63. attr->venc_attr.buf_size = HI_ALIGN_UP(vi_size.width * vi_size.height * 3 / 4, 64);
  64. hi_pcall(venc_attr_init_h264, chn, attr, venc);
  65. // profile force MAIN if BIPRED moved ahead
  66. attr->gop_attr = *gop_attr;
  67. break;
  68. // case ...
  69. }
  70. return HI_SUCCESS;
  71. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注