AOMedia AV1 Codec
pass2_strategy.h
1 /*
2  * Copyright (c) 2019, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_PASS2_STRATEGY_H_
13 #define AOM_AV1_ENCODER_PASS2_STRATEGY_H_
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 struct AV1_COMP;
20 struct EncodeFrameParams;
21 
22 #include "av1/encoder/encoder.h"
23 
28 typedef struct {
30  double gf_group_err;
31  double gf_group_raw_error;
32  double gf_group_skip_pct;
33  double gf_group_inactive_zone_rows;
34 
35  double mv_ratio_accumulator;
36  double decay_accumulator;
37  double zero_motion_accumulator;
38  double loop_decay_rate;
39  double last_loop_decay_rate;
40  double this_frame_mv_in_out;
41  double mv_in_out_accumulator;
42  double abs_mv_in_out_accumulator;
43 
44  double avg_sr_coded_error;
45  double avg_pcnt_second_ref;
46  double avg_new_mv_count;
47  double avg_wavelet_energy;
48  double avg_raw_err_stdev;
49  int non_zero_stdev_count;
52 
56 typedef struct {
58  double frame_err;
59  double frame_coded_error;
60  double frame_sr_coded_error;
65 void av1_init_second_pass(struct AV1_COMP *cpi);
66 
67 void av1_init_single_pass_lap(AV1_COMP *cpi);
68 
89 void av1_get_second_pass_params(struct AV1_COMP *cpi,
90  struct EncodeFrameParams *const frame_params,
91  unsigned int frame_flags);
92 
106 void av1_twopass_postencode_update(struct AV1_COMP *cpi);
107 
127 void av1_gop_bit_allocation(const AV1_COMP *cpi, RATE_CONTROL *const rc,
128  GF_GROUP *gf_group, int is_key_frame, int use_arf,
129  int64_t gf_group_bits);
130 
131 #ifdef __cplusplus
132 } // extern "C"
133 #endif
134 
135 #endif // AOM_AV1_ENCODER_PASS2_STRATEGY_H_
av1_gop_bit_allocation
void av1_gop_bit_allocation(const AV1_COMP *cpi, RATE_CONTROL *const rc, GF_GROUP *gf_group, int is_key_frame, int use_arf, int64_t gf_group_bits)
Distributes bits to frames in a group.
Definition: pass2_strategy.c:2623
InitialDimensions::width
int width
Definition: encoder.h:1915
FIRSTPASS_STATS::pcnt_neutral
double pcnt_neutral
Definition: firstpass.h:88
RATE_CONTROL::projected_frame_size
int projected_frame_size
Definition: ratectrl.h:137
AV1_PRIMARY::frame_probs
FrameProbInfo frame_probs
Definition: encoder.h:2618
CommonModeInfoParams::mb_rows
int mb_rows
Definition: av1_common_int.h:510
encoder.h
Declares top-level encoder structures and functions.
FIRSTPASS_STATS
The stucture of acummulated frame stats in the first pass.
Definition: firstpass.h:41
av1_calc_iframe_target_size_one_pass_cbr
int av1_calc_iframe_target_size_one_pass_cbr(const struct AV1_COMP *cpi)
Calculates how many bits to use for an i frame in one pass cbr.
PRIMARY_RATE_CONTROL::gf_group_bits
int64_t gf_group_bits
Definition: ratectrl.h:249
RATE_CONTROL
Rate Control parameters and status.
Definition: ratectrl.h:121
PRIMARY_RATE_CONTROL::active_best_quality
int active_best_quality[MAX_ARF_LAYERS+1]
Definition: ratectrl.h:446
GF_GROUP
Data related to the current GF/ARF group and the individual frames within the group.
Definition: firstpass.h:344
define_gf_group_pass0
static void define_gf_group_pass0(AV1_COMP *cpi)
Define a GF group in one pass mode when no look ahead stats are available.
Definition: pass2_strategy.c:2121
av1_get_second_pass_params
void av1_get_second_pass_params(AV1_COMP *cpi, EncodeFrameParams *const frame_params, unsigned int frame_flags)
Main per frame entry point for second pass of two pass encode.
Definition: pass2_strategy.c:3607
RateControlCfg
Encoder rate control configuration parameters.
Definition: encoder.h:503
calculate_gf_length
static void calculate_gf_length(AV1_COMP *cpi, int max_gop_length, int max_intervals)
Determine the length of future GF groups.
Definition: pass2_strategy.c:1856
FIRSTPASS_STATS::is_flash
int64_t is_flash
Definition: firstpass.h:155
get_twopass_worst_quality
static int get_twopass_worst_quality(AV1_COMP *cpi, const double av_frame_err, double inactive_zone, int av_target_bandwidth)
Choose a target maximum Q for a group of frames.
Definition: pass2_strategy.c:307
AlgoCfg::enable_tpl_model
bool enable_tpl_model
Definition: encoder.h:833
RateControlCfg::vbr_corpus_complexity_lap
unsigned int vbr_corpus_complexity_lap
Definition: encoder.h:533
FIRSTPASS_STATS::MVcv
double MVcv
Definition: firstpass.h:128
PRIMARY_RATE_CONTROL
Primary Rate Control parameters and status.
Definition: ratectrl.h:243
AV1_PRIMARY::twopass
TWO_PASS twopass
Definition: encoder.h:2483
AV1_COMP::sf
SPEED_FEATURES sf
Definition: encoder.h:2833
PRIMARY_RATE_CONTROL::last_q
int last_q[FRAME_TYPES]
Definition: ratectrl.h:461
RATE_CONTROL::best_quality
int best_quality
Definition: ratectrl.h:202
AV1_COMP::gf_frame_index
unsigned char gf_frame_index
Definition: encoder.h:2864
AV1_COMP::compressor_stage
COMPRESSOR_STAGE compressor_stage
Definition: encoder.h:3125
GF_FRAME_STATS
accumulated stats and features for a frame
Definition: pass2_strategy.h:56
AlgoCfg::arnr_max_frames
int arnr_max_frames
Definition: encoder.h:815
FIRSTPASS_STATS::pcnt_motion
double pcnt_motion
Definition: firstpass.h:76
define_gf_group
static void define_gf_group(AV1_COMP *cpi, EncodeFrameParams *frame_params, int is_final_pass)
Define a GF group.
Definition: pass2_strategy.c:2408
PRIMARY_RATE_CONTROL::gf_intervals
int gf_intervals[MAX_NUM_GF_INTERVALS]
Definition: ratectrl.h:264
GF_GROUP_STATS
accumulated stats and features in a gf group
Definition: pass2_strategy.h:28
AOM_CQ
@ AOM_CQ
Definition: aom_encoder.h:187
AV1_PRIMARY::gf_group
GF_GROUP gf_group
Definition: encoder.h:2453
FIRSTPASS_STATS::pcnt_second_ref
double pcnt_second_ref
Definition: firstpass.h:82
TWO_PASS
Two pass status and control data.
Definition: firstpass.h:412
AV1EncoderConfig::kf_cfg
KeyFrameCfg kf_cfg
Definition: encoder.h:911
AV1Common::spatial_layer_id
int spatial_layer_id
Definition: av1_common_int.h:1054
FIRSTPASS_STATS::sr_coded_error
double sr_coded_error
Definition: firstpass.h:68
AV1_PRIMARY::lap_enabled
int lap_enabled
Definition: encoder.h:2463
AV1_COMP::third_pass_ctx
THIRD_PASS_DEC_CTX * third_pass_ctx
Definition: encoder.h:3279
PRIMARY_RATE_CONTROL::avg_frame_qindex
int avg_frame_qindex[FRAME_TYPES]
Definition: ratectrl.h:338
define_gf_group_pass3
static int define_gf_group_pass3(AV1_COMP *cpi, EncodeFrameParams *frame_params, int is_final_pass)
Define a GF group for the third apss.
Definition: pass2_strategy.c:2565
FIRSTPASS_STATS::MVrv
double MVrv
Definition: firstpass.h:124
aom_codec.h
Describes the codec algorithm interface to applications.
AV1_COMP::twopass_frame
TWO_PASS_FRAME twopass_frame
Definition: encoder.h:3274
AV1EncoderConfig
Main encoder configuration data structure.
Definition: encoder.h:894
FrameProbInfo::tx_type_probs
int tx_type_probs[FRAME_UPDATE_TYPES][TX_SIZES_ALL][TX_TYPES]
Definition: encoder.h:1082
av1_calc_pframe_target_size_one_pass_cbr
int av1_calc_pframe_target_size_one_pass_cbr(const struct AV1_COMP *cpi, FRAME_UPDATE_TYPE frame_update_type)
Calculates how many bits to use for a P frame in one pass cbr.
find_next_key_frame
static void find_next_key_frame(AV1_COMP *cpi, FIRSTPASS_STATS *this_frame)
Determine the next key frame group.
Definition: pass2_strategy.c:3128
PRIMARY_RATE_CONTROL::rate_error_estimate
int rate_error_estimate
Definition: ratectrl.h:487
AV1_COMP
Top level encoder structure.
Definition: encoder.h:2632
PRIMARY_RATE_CONTROL::gfu_boost
int gfu_boost
Definition: ratectrl.h:259
AV1Common::height
int height
Definition: av1_common_int.h:781
AV1_PRIMARY::tpl_data
TplParams tpl_data
Definition: encoder.h:2551
AOM_CBR
@ AOM_CBR
Definition: aom_encoder.h:186
AV1_COMP::initial_mbs
int initial_mbs
Definition: encoder.h:2915
KeyFrameCfg::key_freq_min
int key_freq_min
Definition: encoder.h:449
AV1Common::temporal_layer_id
int temporal_layer_id
Definition: av1_common_int.h:1048
RateControlCfg::mode
enum aom_rc_mode mode
Definition: encoder.h:587
EncodeFrameParams::frame_type
FRAME_TYPE frame_type
Definition: encoder.h:3310
FIRSTPASS_INFO
Data structure used for managing first pass stats.
Definition: firstpass.h:177
AV1_PRIMARY::tf_info
TEMPORAL_FILTER_INFO tf_info
Definition: encoder.h:2493
FIRSTPASS_INFO::total_stats
FIRSTPASS_STATS total_stats
Definition: firstpass.h:231
AV1Common::seq_params
SequenceHeader * seq_params
Definition: av1_common_int.h:981
av1_firstpass_info_peek
const FIRSTPASS_STATS * av1_firstpass_info_peek(const FIRSTPASS_INFO *firstpass_info, int offset_from_cur)
Peek at a stats from firstpass_info.
AV1_PRIMARY::lookahead
struct lookahead_ctx * lookahead
Definition: encoder.h:2425
FrameProbInfo::obmc_probs
int obmc_probs[FRAME_UPDATE_TYPES][BLOCK_SIZES_ALL]
Definition: encoder.h:1067
FIRSTPASS_STATS::mv_in_out_count
double mv_in_out_count
Definition: firstpass.h:134
AV1_COMP::common
AV1_COMMON common
Definition: encoder.h:2675
RateControlCfg::under_shoot_pct
int under_shoot_pct
Definition: encoder.h:562
RateControlCfg::cq_level
int cq_level
Definition: encoder.h:582
FIRSTPASS_STATS::mvc_abs
double mvc_abs
Definition: firstpass.h:120
FIRSTPASS_STATS::new_mv_count
double new_mv_count
Definition: firstpass.h:138
AV1_COMP::initial_dimensions
InitialDimensions initial_dimensions
Definition: encoder.h:2907
FIRSTPASS_STATS::pcnt_inter
double pcnt_inter
Definition: firstpass.h:72
encode_strategy.h
Declares frame encoding functions.
av1_tpl_setup_stats
int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval, const struct EncodeFrameParams *const frame_params)
Implements temporal dependency modelling for a GOP (GF/ARF group) and selects between 16 and 32 frame...
FIRSTPASS_STATS::inactive_zone_rows
double inactive_zone_rows
Definition: firstpass.h:100
RateControlCfg::best_allowed_q
int best_allowed_q
Definition: encoder.h:578
av1_twopass_postencode_update
void av1_twopass_postencode_update(AV1_COMP *cpi)
Adjustments to two pass and rate control after each frame.
Definition: pass2_strategy.c:3962
KeyFrameCfg::auto_key
bool auto_key
Definition: encoder.h:477
RateControlCfg::over_shoot_pct
int over_shoot_pct
Definition: encoder.h:568
RATE_CONTROL::frames_till_gf_update_due
int frames_till_gf_update_due
Definition: ratectrl.h:157
av1_calc_iframe_target_size_one_pass_vbr
int av1_calc_iframe_target_size_one_pass_vbr(const struct AV1_COMP *const cpi)
Calculates how many bits to use for an i frame in one pass vbr.
av1_lookahead_pop_sz
int av1_lookahead_pop_sz(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get pop_sz value.
AV1_PRIMARY::internal_altref_allowed
int internal_altref_allowed
Definition: encoder.h:2443
RateControlCfg::vbrmin_section
int vbrmin_section
Definition: encoder.h:599
has_no_stats_stage
static int has_no_stats_stage(const AV1_COMP *const cpi)
Check if the current stage has statistics.
Definition: encoder.h:3732
InitialDimensions::height
int height
Definition: encoder.h:1916
InitialDimensions
Initial frame dimensions.
Definition: encoder.h:1914
KeyFrameCfg::fwd_kf_dist
int fwd_kf_dist
Definition: encoder.h:482
AV1EncoderConfig::pass
enum aom_enc_pass pass
Definition: encoder.h:1019
AV1_PRIMARY::p_rc
PRIMARY_RATE_CONTROL p_rc
Definition: encoder.h:2488
RATE_CONTROL::intervals_till_gf_calculate_due
int intervals_till_gf_calculate_due
Definition: ratectrl.h:162
calculate_total_gf_group_bits
static int64_t calculate_total_gf_group_bits(AV1_COMP *cpi, double gf_group_err)
Calculates the bit target for this GF/ARF group.
Definition: pass2_strategy.c:764
RateControlCfg::vbrbias
int vbrbias
Definition: encoder.h:594
RateControlCfg::target_bandwidth
int64_t target_bandwidth
Definition: encoder.h:527
FrameProbInfo::switchable_interp_probs
int switchable_interp_probs[FRAME_UPDATE_TYPES][((SWITCHABLE_FILTERS+1) *4)][SWITCHABLE_FILTERS]
Definition: encoder.h:1091
RATE_CONTROL::base_frame_target
int base_frame_target
Definition: ratectrl.h:128
AV1Common::show_frame
int show_frame
Definition: av1_common_int.h:890
PRIMARY_RATE_CONTROL::rolling_target_bits
int rolling_target_bits
Definition: ratectrl.h:508
SPEED_FEATURES::tpl_sf
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1402
AV1Common::quant_params
CommonQuantParams quant_params
Definition: av1_common_int.h:927
FIRSTPASS_STATS::duration
double duration
Definition: firstpass.h:142
PRIMARY_RATE_CONTROL::vbr_bits_off_target
int64_t vbr_bits_off_target
Definition: ratectrl.h:492
PRIMARY_RATE_CONTROL::rolling_actual_bits
int rolling_actual_bits
Definition: ratectrl.h:514
define_kf_interval
static int define_kf_interval(AV1_COMP *cpi, const FIRSTPASS_INFO *firstpass_info, int num_frames_to_detect_scenecut, int search_start_idx)
Determine the location of the next key frame.
Definition: pass2_strategy.c:2861
AOM_RC_ONE_PASS
@ AOM_RC_ONE_PASS
Definition: aom_encoder.h:176
aom_encoder.h
Describes the encoder algorithm interface to applications.
KeyFrameCfg
Encoder config related to the coding of key frames.
Definition: encoder.h:445
RATE_CONTROL::active_worst_quality
int active_worst_quality
Definition: ratectrl.h:219
AV1_COMP::rc
RATE_CONTROL rc
Definition: encoder.h:2813
CommonQuantParams::base_qindex
int base_qindex
Definition: av1_common_int.h:618
RateControlCfg::vbrmax_section
int vbrmax_section
Definition: encoder.h:604
AV1Common
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:755
PRIMARY_RATE_CONTROL::kf_boost
int kf_boost
Definition: ratectrl.h:254
PRIMARY_RATE_CONTROL::total_actual_bits
int64_t total_actual_bits
Definition: ratectrl.h:472
AOM_Q
@ AOM_Q
Definition: aom_encoder.h:188
AV1EncoderConfig::algo_cfg
AlgoCfg algo_cfg
Definition: encoder.h:906
AV1_PRIMARY::level_params
AV1LevelParams level_params
Definition: encoder.h:2468
av1_cyclic_refresh_set_golden_update
void av1_cyclic_refresh_set_golden_update(struct AV1_COMP *const cpi)
Set golden frame update interval nased on cyclic refresh.
FIRSTPASS_STATS::intra_error
double intra_error
Definition: firstpass.h:56
FIRSTPASS_STATS::noise_var
double noise_var
Definition: firstpass.h:159
AV1_COMP::skip_tpl_setup_stats
int skip_tpl_setup_stats
Definition: encoder.h:2734
FIRSTPASS_STATS::inactive_zone_cols
double inactive_zone_cols
Definition: firstpass.h:104
FIRSTPASS_STATS::MVc
double MVc
Definition: firstpass.h:116
AV1_COMP::framerate
double framerate
Definition: encoder.h:2818
CommonModeInfoParams::MBs
int MBs
Definition: av1_common_int.h:520
EncodeFrameParams
contains per-frame encoding parameters decided upon by av1_encode_strategy() and passed down to av1_e...
Definition: encoder.h:3302
aom_rc_mode
aom_rc_mode
Rate control mode.
Definition: aom_encoder.h:184
FIRSTPASS_STATS::intra_skip_pct
double intra_skip_pct
Definition: firstpass.h:96
FIRSTPASS_STATS::raw_error_stdev
double raw_error_stdev
Definition: firstpass.h:151
FIRSTPASS_STATS::mvr_abs
double mvr_abs
Definition: firstpass.h:112
AV1_COMP::ppi
AV1_PRIMARY * ppi
Definition: encoder.h:2636
FIRSTPASS_STATS::MVr
double MVr
Definition: firstpass.h:108
av1_firstpass_info_future_count
int av1_firstpass_info_future_count(const FIRSTPASS_INFO *firstpass_info, int offset_from_cur)
Count the future stats from the target in firstpass_info Note that the target stats will be counted a...
FIRSTPASS_STATS::count
double count
Definition: firstpass.h:147
av1_lookahead_depth
unsigned int av1_lookahead_depth(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get the number of frames currently in the lookahead queue.
PRIMARY_RATE_CONTROL::vbr_bits_off_target_fast
int64_t vbr_bits_off_target_fast
Definition: ratectrl.h:497
FrameProbInfo
Encoder-side probabilities for pruning of various AV1 tools.
Definition: encoder.h:1061
TWO_PASS_FRAME
Frame level Two pass status and control data.
Definition: firstpass.h:455
FrameProbInfo::warped_probs
int warped_probs[FRAME_UPDATE_TYPES]
Definition: encoder.h:1074
AV1Common::width
int width
Definition: av1_common_int.h:780
AV1_PRIMARY::gf_state
GF_STATE gf_state
Definition: encoder.h:2458
AV1_PRIMARY::frames_left
int frames_left
Definition: encoder.h:2478
AV1_COMP::oxcf
AV1EncoderConfig oxcf
Definition: encoder.h:2680
av1_calc_pframe_target_size_one_pass_vbr
int av1_calc_pframe_target_size_one_pass_vbr(const struct AV1_COMP *const cpi, FRAME_UPDATE_TYPE frame_update_type)
Calculates how many bits to use for a P frame in one pass vbr.
FIRSTPASS_STATS::cor_coeff
double cor_coeff
Definition: firstpass.h:163
FIRSTPASS_STATS::coded_error
double coded_error
Definition: firstpass.h:64
AV1EncoderConfig::rc_cfg
RateControlCfg rc_cfg
Definition: encoder.h:916
aom_bit_depth_t
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
PRIMARY_RATE_CONTROL::cur_gf_index
int cur_gf_index
Definition: ratectrl.h:269
AV1Common::current_frame
CurrentFrame current_frame
Definition: av1_common_int.h:759
AV1_COMP::frame_info
FRAME_INFO frame_info
Definition: encoder.h:2897
AV1Common::mi_params
CommonModeInfoParams mi_params
Definition: av1_common_int.h:915
FIRSTPASS_STATS::frame_avg_wavelet_energy
double frame_avg_wavelet_energy
Definition: firstpass.h:60
PRIMARY_RATE_CONTROL::avg_q
double avg_q
Definition: ratectrl.h:456
av1_gop_setup_structure
void av1_gop_setup_structure(struct AV1_COMP *cpi)
Set up the Group-Of-Pictures structure for this GF_GROUP.
EncodeFrameParams::show_frame
int show_frame
Definition: encoder.h:3320
RATE_CONTROL::frames_to_key
int frames_to_key
Definition: ratectrl.h:172
RATE_CONTROL::worst_quality
int worst_quality
Definition: ratectrl.h:198
KeyFrameCfg::key_freq_max
int key_freq_max
Definition: encoder.h:454
FIRSTPASS_STATS::weight
double weight
Definition: firstpass.h:52
AOM_RC_THIRD_PASS
@ AOM_RC_THIRD_PASS
Definition: aom_encoder.h:179