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_tr_coded_error;
46  double avg_pcnt_second_ref;
47  double avg_pcnt_third_ref;
48  double avg_pcnt_third_ref_nolast;
49  double avg_new_mv_count;
50  double avg_wavelet_energy;
51  double avg_raw_err_stdev;
52  int non_zero_stdev_count;
55 
59 typedef struct {
61  double frame_err;
62  double frame_coded_error;
63  double frame_sr_coded_error;
64  double frame_tr_coded_error;
69 void av1_init_second_pass(struct AV1_COMP *cpi);
70 
71 void av1_init_single_pass_lap(AV1_COMP *cpi);
72 
94 void av1_get_second_pass_params(struct AV1_COMP *cpi,
95  struct EncodeFrameParams *const frame_params,
96  const EncodeFrameInput *const frame_input,
97  unsigned int frame_flags);
98 
112 void av1_twopass_postencode_update(struct AV1_COMP *cpi);
113 
133 void av1_gop_bit_allocation(const AV1_COMP *cpi, RATE_CONTROL *const rc,
134  GF_GROUP *gf_group, int is_key_frame, int use_arf,
135  int64_t gf_group_bits);
136 
137 #ifdef __cplusplus
138 } // extern "C"
139 #endif
140 
141 #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:2648
InitialDimensions::width
int width
Definition: encoder.h:1707
FIRSTPASS_STATS::pcnt_neutral
double pcnt_neutral
Definition: firstpass.h:91
RATE_CONTROL::projected_frame_size
int projected_frame_size
Definition: ratectrl.h:139
CommonModeInfoParams::mb_rows
int mb_rows
Definition: av1_common_int.h:482
encoder.h
Declares top-level encoder structures and functions.
FIRSTPASS_STATS
The stucture of acummulated frame stats in the first pass.
Definition: firstpass.h:36
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.
RATE_CONTROL
Rate Control parameters and status.
Definition: ratectrl.h:118
GF_GROUP
Data related to the current GF/ARF group and the individual frames within the group.
Definition: firstpass.h:171
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:2184
AV1_COMP::partition_search_skippable_frame
int partition_search_skippable_frame
Definition: encoder.h:2212
AV1_COMP::lap_enabled
int lap_enabled
Definition: encoder.h:2641
FIRSTPASS_STATS::pcnt_third_ref
double pcnt_third_ref
Definition: firstpass.h:85
SPEED_FEATURES::part_sf
PARTITION_SPEED_FEATURES part_sf
Definition: speed_features.h:1139
RateControlCfg
Encoder rate control configuration parameters.
Definition: encoder.h:430
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:1923
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:279
AlgoCfg::enable_tpl_model
bool enable_tpl_model
Definition: encoder.h:753
RateControlCfg::vbr_corpus_complexity_lap
unsigned int vbr_corpus_complexity_lap
Definition: encoder.h:460
FIRSTPASS_STATS::tr_coded_error
double tr_coded_error
Definition: firstpass.h:67
FIRSTPASS_STATS::MVcv
double MVcv
Definition: firstpass.h:131
AV1_COMP::sf
SPEED_FEATURES sf
Definition: encoder.h:2314
RATE_CONTROL::gf_intervals
int gf_intervals[MAX_NUM_GF_INTERVALS]
Definition: ratectrl.h:199
RATE_CONTROL::best_quality
int best_quality
Definition: ratectrl.h:271
AV1_COMP::gf_frame_index
unsigned char gf_frame_index
Definition: encoder.h:2362
AV1_COMP::compressor_stage
COMPRESSOR_STAGE compressor_stage
Definition: encoder.h:2645
KeyFrameCfg::fwd_kf_enabled
bool fwd_kf_enabled
Definition: encoder.h:414
GF_FRAME_STATS
accumulated stats and features for a frame
Definition: pass2_strategy.h:59
AlgoCfg::arnr_max_frames
int arnr_max_frames
Definition: encoder.h:735
FIRSTPASS_STATS::pcnt_motion
double pcnt_motion
Definition: firstpass.h:75
GF_GROUP_STATS
accumulated stats and features in a gf group
Definition: pass2_strategy.h:28
AOM_CQ
@ AOM_CQ
Definition: aom_encoder.h:168
AV1_COMP::twopass
TWO_PASS twopass
Definition: encoder.h:2352
FIRSTPASS_STATS::pcnt_second_ref
double pcnt_second_ref
Definition: firstpass.h:81
TWO_PASS
Two pass status and control data.
Definition: firstpass.h:214
AV1EncoderConfig::kf_cfg
KeyFrameCfg kf_cfg
Definition: encoder.h:822
AV1Common::spatial_layer_id
int spatial_layer_id
Definition: av1_common_int.h:1034
FIRSTPASS_STATS::sr_coded_error
double sr_coded_error
Definition: firstpass.h:63
FIRSTPASS_STATS::frame
double frame
Definition: firstpass.h:41
KeyFrameCfg::sframe_mode
int sframe_mode
Definition: encoder.h:404
FIRSTPASS_STATS::MVrv
double MVrv
Definition: firstpass.h:127
aom_codec.h
Describes the codec algorithm interface to applications.
AV1EncoderConfig
Main encoder configuration data structure.
Definition: encoder.h:805
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:3154
RATE_CONTROL::kf_boost
int kf_boost
Definition: ratectrl.h:173
AV1_COMP::gf_group
GF_GROUP gf_group
Definition: encoder.h:2357
AV1_COMP
Top level encoder structure.
Definition: encoder.h:2095
define_kf_interval
static int define_kf_interval(AV1_COMP *cpi, FIRSTPASS_STATS *this_frame, double *kf_group_err, int num_frames_to_detect_scenecut)
Determine the location of the next key frame.
Definition: pass2_strategy.c:2879
AV1Common::height
int height
Definition: av1_common_int.h:749
av1_get_second_pass_params
void av1_get_second_pass_params(AV1_COMP *cpi, EncodeFrameParams *const frame_params, const EncodeFrameInput *const frame_input, unsigned int frame_flags)
Main per frame entry point for second pass of two pass encode.
Definition: pass2_strategy.c:3505
AOM_CBR
@ AOM_CBR
Definition: aom_encoder.h:167
AV1_COMP::initial_mbs
int initial_mbs
Definition: encoder.h:2461
KeyFrameCfg::key_freq_min
int key_freq_min
Definition: encoder.h:381
AV1Common::temporal_layer_id
int temporal_layer_id
Definition: av1_common_int.h:1024
KeyFrameCfg::sframe_dist
int sframe_dist
Definition: encoder.h:397
RateControlCfg::mode
enum aom_rc_mode mode
Definition: encoder.h:514
EncodeFrameParams::frame_type
FRAME_TYPE frame_type
Definition: encoder.h:2734
AV1_COMP::frames_left
int frames_left
Definition: encoder.h:2697
AV1_PRIMARY::lookahead
struct lookahead_ctx * lookahead
Definition: encoder.h:2071
FIRSTPASS_STATS::mv_in_out_count
double mv_in_out_count
Definition: firstpass.h:137
AV1_COMP::common
AV1_COMMON common
Definition: encoder.h:2138
RateControlCfg::under_shoot_pct
int under_shoot_pct
Definition: encoder.h:489
AV1_COMP::tpl_data
TplParams tpl_data
Definition: encoder.h:2202
RateControlCfg::cq_level
int cq_level
Definition: encoder.h:509
RATE_CONTROL::gfu_boost
int gfu_boost
Definition: ratectrl.h:169
FIRSTPASS_STATS::mvc_abs
double mvc_abs
Definition: firstpass.h:123
FIRSTPASS_STATS::new_mv_count
double new_mv_count
Definition: firstpass.h:141
AV1_COMP::initial_dimensions
InitialDimensions initial_dimensions
Definition: encoder.h:2453
FIRSTPASS_STATS::pcnt_inter
double pcnt_inter
Definition: firstpass.h:71
encode_strategy.h
Declares frame encoding functions.
FIRSTPASS_STATS::inactive_zone_rows
double inactive_zone_rows
Definition: firstpass.h:103
RateControlCfg::best_allowed_q
int best_allowed_q
Definition: encoder.h:505
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:3865
KeyFrameCfg::auto_key
bool auto_key
Definition: encoder.h:409
RateControlCfg::over_shoot_pct
int over_shoot_pct
Definition: encoder.h:495
RATE_CONTROL::frames_till_gf_update_due
int frames_till_gf_update_due
Definition: ratectrl.h:189
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:2089
RateControlCfg::vbrmin_section
int vbrmin_section
Definition: encoder.h:526
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:3053
InitialDimensions::height
int height
Definition: encoder.h:1708
av1_tpl_setup_stats
int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval, const struct EncodeFrameParams *const frame_params, const struct EncodeFrameInput *const frame_input)
Implements temporal dependency modelling for a GOP (GF/ARF group) and selects between 16 and 32 frame...
InitialDimensions
Initial frame dimensions.
Definition: encoder.h:1706
AV1_COMP::alt_ref_buffer
YV12_BUFFER_CONFIG alt_ref_buffer
Definition: encoder.h:2378
AV1EncoderConfig::pass
enum aom_enc_pass pass
Definition: encoder.h:930
RATE_CONTROL::intervals_till_gf_calculate_due
int intervals_till_gf_calculate_due
Definition: ratectrl.h:194
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:767
RateControlCfg::vbrbias
int vbrbias
Definition: encoder.h:521
RateControlCfg::target_bandwidth
int64_t target_bandwidth
Definition: encoder.h:454
RATE_CONTROL::base_frame_target
int base_frame_target
Definition: ratectrl.h:125
AV1_COMP::level_params
AV1LevelParams level_params
Definition: encoder.h:2582
SPEED_FEATURES::tpl_sf
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1129
AV1Common::quant_params
CommonQuantParams quant_params
Definition: av1_common_int.h:899
FIRSTPASS_STATS::duration
double duration
Definition: firstpass.h:145
aom_encoder.h
Describes the encoder algorithm interface to applications.
KeyFrameCfg
Encoder config related to the coding of key frames.
Definition: encoder.h:377
RATE_CONTROL::active_worst_quality
int active_worst_quality
Definition: ratectrl.h:306
AV1_COMP::rc
RATE_CONTROL rc
Definition: encoder.h:2294
CommonQuantParams::base_qindex
int base_qindex
Definition: av1_common_int.h:586
RateControlCfg::vbrmax_section
int vbrmax_section
Definition: encoder.h:531
AV1Common
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:723
AOM_Q
@ AOM_Q
Definition: aom_encoder.h:169
AV1EncoderConfig::algo_cfg
AlgoCfg algo_cfg
Definition: encoder.h:817
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:51
RATE_CONTROL::active_best_quality
int active_best_quality[MAX_ARF_LAYERS+1]
Definition: ratectrl.h:310
EncodeFrameInput
Input frames and last input frame.
Definition: encoder.h:2714
FIRSTPASS_STATS::inactive_zone_cols
double inactive_zone_cols
Definition: firstpass.h:107
FIRSTPASS_STATS::MVc
double MVc
Definition: firstpass.h:119
AV1_COMP::framerate
double framerate
Definition: encoder.h:2299
CommonModeInfoParams::MBs
int MBs
Definition: av1_common_int.h:492
EncodeFrameParams
contains per-frame encoding parameters decided upon by av1_encode_strategy() and passed down to av1_e...
Definition: encoder.h:2726
aom_rc_mode
aom_rc_mode
Rate control mode.
Definition: aom_encoder.h:165
FIRSTPASS_STATS::intra_skip_pct
double intra_skip_pct
Definition: firstpass.h:99
FIRSTPASS_STATS::raw_error_stdev
double raw_error_stdev
Definition: firstpass.h:154
FIRSTPASS_STATS::mvr_abs
double mvr_abs
Definition: firstpass.h:115
AV1_COMP::ppi
AV1_PRIMARY * ppi
Definition: encoder.h:2099
FIRSTPASS_STATS::MVr
double MVr
Definition: firstpass.h:111
RATE_CONTROL::cur_gf_index
int cur_gf_index
Definition: ratectrl.h:204
FIRSTPASS_STATS::count
double count
Definition: firstpass.h:150
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.
AV1Common::width
int width
Definition: av1_common_int.h:748
AV1_COMP::oxcf
AV1EncoderConfig oxcf
Definition: encoder.h:2143
AV1Common::seq_params
SequenceHeader seq_params
Definition: av1_common_int.h:953
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.
av1_temporal_filter
int av1_temporal_filter(struct AV1_COMP *cpi, const int filter_frame_lookahead_idx, FRAME_UPDATE_TYPE update_type, int is_forward_keyframe, int *show_existing_arf)
Performs temporal filtering if needed on a source frame. For example to create a filtered alternate r...
define_gf_group
static void define_gf_group(AV1_COMP *cpi, FIRSTPASS_STATS *this_frame, EncodeFrameParams *frame_params, int max_gop_length, int is_final_pass)
Define a GF group.
Definition: pass2_strategy.c:2324
FIRSTPASS_STATS::coded_error
double coded_error
Definition: firstpass.h:59
AV1EncoderConfig::rc_cfg
RateControlCfg rc_cfg
Definition: encoder.h:827
aom_bit_depth_t
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
AV1_COMP::gf_state
GF_STATE gf_state
Definition: encoder.h:2367
RATE_CONTROL::gf_group_bits
int64_t gf_group_bits
Definition: ratectrl.h:134
AV1Common::current_frame
CurrentFrame current_frame
Definition: av1_common_int.h:727
RATE_CONTROL::last_q
int last_q[FRAME_TYPES]
Definition: ratectrl.h:154
AV1_COMP::frame_info
FRAME_INFO frame_info
Definition: encoder.h:2443
AV1Common::mi_params
CommonModeInfoParams mi_params
Definition: av1_common_int.h:887
FIRSTPASS_STATS::frame_avg_wavelet_energy
double frame_avg_wavelet_energy
Definition: firstpass.h:55
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:2744
TplParams::skip_tpl_setup_stats
int skip_tpl_setup_stats
Definition: tpl_model.h:203
RATE_CONTROL::frames_to_key
int frames_to_key
Definition: ratectrl.h:223
RATE_CONTROL::worst_quality
int worst_quality
Definition: ratectrl.h:267
KeyFrameCfg::key_freq_max
int key_freq_max
Definition: encoder.h:386
FIRSTPASS_STATS::weight
double weight
Definition: firstpass.h:47