From: angiebird Date: Fri, 25 Oct 2019 18:45:34 +0000 (-0700) Subject: vp9_get_coding_frame_num() X-Git-Tag: v1.8.2~60^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65f9ded3951f4ae7bda634e308862d5fd3bea730;p=libvpx vp9_get_coding_frame_num() Change-Id: I36fa92d9acfc272fc9a2f700bcd1466e95f1443c --- diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index f02616031..ee2294ff7 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -3630,3 +3630,63 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { } } } + +#if CONFIG_RATE_CTRL +// Under CONFIG_RATE_CTRL, once the first_pass_info is ready, the number of +// coding frames (including show frame and alt ref) can be determined. +int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf, + const FRAME_INFO *frame_info, + const FIRST_PASS_INFO *first_pass_info, + int multi_layer_arf, int allow_alt_ref) { + int coding_frame_num = 0; + RATE_CONTROL rc; + RANGE active_gf_interval; + int arf_layers; + double gop_intra_factor; + int use_alt_ref; + int gop_coding_frames; + int gop_show_frames; + int show_idx = 0; + int arf_active_or_kf = 1; + rc.static_scene_max_gf_interval = 250; + vp9_rc_init(oxcf, 1, &rc); + + while (show_idx < first_pass_info->num_frames) { + if (rc.frames_to_key == 0) { + rc.frames_to_key = get_frames_to_next_key( + oxcf, frame_info, first_pass_info, show_idx, rc.min_gf_interval); + arf_active_or_kf = 1; + } else { + } + + { + int dummy = 0; + active_gf_interval = get_active_gf_inverval_range( + frame_info, &rc, arf_active_or_kf, show_idx, dummy, dummy); + } + + arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf, + active_gf_interval.max); + if (multi_layer_arf) { + gop_intra_factor = 1.0 + 0.25 * arf_layers; + } else { + gop_intra_factor = 1.0; + } + + gop_coding_frames = get_gop_coding_frame_num( + &use_alt_ref, frame_info, first_pass_info, &rc, show_idx, + &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames); + + use_alt_ref &= allow_alt_ref; + + rc.source_alt_ref_active = use_alt_ref; + arf_active_or_kf = use_alt_ref; + gop_show_frames = gop_coding_frames - use_alt_ref; + rc.frames_to_key -= gop_show_frames; + rc.frames_since_key += gop_show_frames; + show_idx += gop_show_frames; + coding_frame_num += gop_show_frames + use_alt_ref; + } + return coding_frame_num; +} +#endif diff --git a/vp9/encoder/vp9_firstpass.h b/vp9/encoder/vp9_firstpass.h index 2158dfe4f..b1bdf1763 100644 --- a/vp9/encoder/vp9_firstpass.h +++ b/vp9/encoder/vp9_firstpass.h @@ -13,6 +13,9 @@ #include +#if CONFIG_RATE_CTRL +#include "vp9/common/vp9_onyxc_int.h" +#endif #include "vp9/encoder/vp9_lookahead.h" #include "vp9/encoder/vp9_ratectrl.h" @@ -245,6 +248,14 @@ void vp9_twopass_postencode_update(struct VP9_COMP *cpi); void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width, int *scaled_frame_height); +#if CONFIG_RATE_CTRL +struct VP9EncoderConfig; +int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf, + const FRAME_INFO *frame_info, + const FIRST_PASS_INFO *first_pass_info, + int multi_layer_arf, int allow_alt_ref); +#endif + #ifdef __cplusplus } // extern "C" #endif