History

Add vp9_get_gop_coding_frame_count()

Call this function before coding a new group of picture to get information about it.

angiebird committed 6 years ago

Commit c33f8591 parent 94fb57d2 files · +61 −30Browse files

Unified · Split

2 files
  1. vp9/encoder/vp9_firstpass.c +39 −30
  2. vp9/encoder/vp9_firstpass.h +22 −0
vp9/encoder/vp9_firstpass.c+39−30
@@ -3627,56 +3627,65 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { · 3626 unmodified lines
36273627 }
36283628
36293629 #if CONFIG_RATE_CTRL
3630+int vp9_get_gop_coding_frame_count(
3631+ int *use_alt_ref, const VP9EncoderConfig *oxcf,
3632+ const FRAME_INFO *frame_info, const FIRST_PASS_INFO *first_pass_info,
3633+ const RATE_CONTROL *rc, int show_idx, int multi_layer_arf,
3634+ int allow_alt_ref, int first_is_key_frame, int last_gop_use_alt_ref) {
3635+ int frame_count;
3636+ double gop_intra_factor;
3637+ const int arf_active_or_kf = last_gop_use_alt_ref || first_is_key_frame;
3638+ RANGE active_gf_interval = get_active_gf_inverval_range(
3639+ frame_info, rc, arf_active_or_kf, show_idx, /*active_worst_quality=*/0,
3640+ /*last_boosted_qindex=*/0);
3641+
3642+ const int arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf,
3643+ active_gf_interval.max);
3644+ if (multi_layer_arf) {
3645+ gop_intra_factor = 1.0 + 0.25 * arf_layers;
3646+ } else {
3647+ gop_intra_factor = 1.0;
3648+ }
3649+
3650+ frame_count = get_gop_coding_frame_num(
3651+ use_alt_ref, frame_info, first_pass_info, rc, show_idx,
3652+ &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames);
3653+ *use_alt_ref &= allow_alt_ref;
3654+ return frame_count;
3655+}
3656+
36303657 // Under CONFIG_RATE_CTRL, once the first_pass_info is ready, the number of
36313658 // coding frames (including show frame and alt ref) can be determined.
3632−int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf,
3659+int vp9_get_coding_frame_num(const VP9EncoderConfig *oxcf,
36333660 const FRAME_INFO *frame_info,
36343661 const FIRST_PASS_INFO *first_pass_info,
36353662 int multi_layer_arf, int allow_alt_ref) {
36363663 int coding_frame_num = 0;
36373664 RATE_CONTROL rc;
3638− RANGE active_gf_interval;
3639− int arf_layers;
3640− double gop_intra_factor;
3641− int use_alt_ref;
3642− int gop_coding_frames;
3665+ int gop_coding_frame_count;
36433666 int gop_show_frames;
36443667 int show_idx = 0;
3645− int arf_active_or_kf = 1;
3668+ int last_gop_use_alt_ref = 0;
36463669 rc.static_scene_max_gf_interval = 250;
36473670 vp9_rc_init(oxcf, 1, &rc);
36483671
36493672 while (show_idx < first_pass_info->num_frames) {
3673+ int use_alt_ref;
3674+ int first_is_key_frame = 0;
36503675 if (rc.frames_to_key == 0) {
36513676 rc.frames_to_key = vp9_get_frames_to_next_key(
36523677 oxcf, frame_info, first_pass_info, show_idx, rc.min_gf_interval);
3653− arf_active_or_kf = 1;
3654− } else {
3655− }
3656−
3657− {
3658− int dummy = 0;
3659− active_gf_interval = get_active_gf_inverval_range(
3660− frame_info, &rc, arf_active_or_kf, show_idx, dummy, dummy);
3678+ first_is_key_frame = 1;
36613679 }
36623680
3663− arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf,
3664− active_gf_interval.max);
3665− if (multi_layer_arf) {
3666− gop_intra_factor = 1.0 + 0.25 * arf_layers;
3667− } else {
3668− gop_intra_factor = 1.0;
3669− }
3670−
3671− gop_coding_frames = get_gop_coding_frame_num(
3672− &use_alt_ref, frame_info, first_pass_info, &rc, show_idx,
3673− &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames);
3674−
3675− use_alt_ref &= allow_alt_ref;
3681+ gop_coding_frame_count = vp9_get_gop_coding_frame_count(
3682+ &use_alt_ref, oxcf, frame_info, first_pass_info, &rc, show_idx,
3683+ multi_layer_arf, allow_alt_ref, first_is_key_frame,
3684+ last_gop_use_alt_ref);
36763685
36773686 rc.source_alt_ref_active = use_alt_ref;
3678− arf_active_or_kf = use_alt_ref;
3679− gop_show_frames = gop_coding_frames - use_alt_ref;
3687+ last_gop_use_alt_ref = use_alt_ref;
3688+ gop_show_frames = gop_coding_frame_count - use_alt_ref;
36803689 rc.frames_to_key -= gop_show_frames;
36813690 rc.frames_since_key += gop_show_frames;
36823691 show_idx += gop_show_frames;
vp9/encoder/vp9_firstpass.h+22−0
@@ -252,6 +252,28 @@ int vp9_get_frames_to_next_key(const struct VP9EncoderConfig *oxcf, · 251 unmodified lines
252252 const FIRST_PASS_INFO *first_pass_info,
253253 int kf_show_idx, int min_gf_interval);
254254 #if CONFIG_RATE_CTRL
255+/*!\brief Call this function before coding a new group of pictures to get
256+ * information about it.
257+ * \param[in] oxcf Encoder config
258+ * \param[in] frame_info Frame info
259+ * \param[in] first_pass_info First pass stats
260+ * \param[in] rc Rate control state
261+ * \param[in] show_idx Show index of the first frame in the group
262+ * \param[in] multi_layer_arf Is multi-layer alternate reference used
263+ * \param[in] allow_alt_ref Is alternate reference allowed
264+ * \param[in] first_is_key_frame Is the first frame in the group a key frame
265+ * \param[in] last_gop_use_alt_ref Does the last group use alternate reference
266+ *
267+ * \param[out] use_alt_ref Does this group use alternate reference
268+ *
269+ * \return Returns coding frame count
270+ */
271+int vp9_get_gop_coding_frame_count(
272+ int *use_alt_ref, const struct VP9EncoderConfig *oxcf,
273+ const FRAME_INFO *frame_info, const FIRST_PASS_INFO *first_pass_info,
274+ const RATE_CONTROL *rc, int show_idx, int multi_layer_arf,
275+ int allow_alt_ref, int first_is_key_frame, int last_gop_use_alt_ref);
276+
255277 int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf,
256278 const FRAME_INFO *frame_info,
257279 const FIRST_PASS_INFO *first_pass_info,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t