AOMedia AV1 Codec: Golden Frame Group

| AOMedia AV1 Codec

Functions
Golden Frame Group
Encoder Algorithm » High-level Algorithm

## Functions
static void | calculate_gf_length (AV1_COMP *cpi, int max_gop_length, int max_intervals)
| Determine the length of future GF groups.
static void | define_gf_group_pass0 (AV1_COMP *cpi)
| Define a GF group in one pass mode when no look ahead stats are available.
static void | define_gf_group (AV1_COMP *cpi, EncodeFrameParams *frame_params, int is_final_pass)
| Define a GF group.
static int | define_gf_group_pass3 (AV1_COMP *cpi, EncodeFrameParams *frame_params, int is_final_pass)
| Define a GF group for the third apss.
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.
static void | find_next_key_frame (AV1_COMP *cpi, FIRSTPASS_STATS *this_frame)
| Determine the next key frame group.

## Detailed Description

Algorithms regarding determining the length of GF groups and defining GF group structures.

## Function Documentation

## ◆ calculate_gf_length()

static void calculate_gf_length | ( | AV1_COMP * | cpi,
|  | int | max_gop_length,
|  | int | max_intervals )
| static

Determine the length of future GF groups.

This function decides the gf group length of future frames in batch

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | max_gop_length | Maximum length of the GF group
  [in] | max_intervals | Maximum number of intervals to decide

Remarks
  Nothing is returned. Instead, cpi->ppi->rc.gf_intervals is changed to store the decided GF group lengths.

References AV1_COMP::common, FIRSTPASS_STATS::cor_coeff, PRIMARY_RATE_CONTROL::cur_gf_index, RATE_CONTROL::frames_to_key, PRIMARY_RATE_CONTROL::gf_intervals, AV1_PRIMARY::gf_state, has_no_stats_stage(), AV1Common::height, RATE_CONTROL::intervals_till_gf_calculate_due, AV1_PRIMARY::lap_enabled, FIRSTPASS_STATS::noise_var, AV1_PRIMARY::p_rc, AV1_COMP::ppi, AV1_COMP::rc, AV1_PRIMARY::twopass, AV1_COMP::twopass_frame, and AV1Common::width.

Referenced by av1_get_second_pass_params().

## ◆ define_gf_group_pass0()

static void define_gf_group_pass0 | ( | AV1_COMP * | cpi | ) |
| static

Define a GF group in one pass mode when no look ahead stats are available.

This function defines the structure of a GF group, along with various parameters regarding bit-allocation and quality setup in the special case of one pass encoding where no lookahead stats are avialable.

Parameters

  [in] | cpi | Top-level encoder structure

Remarks
  Nothing is returned. Instead, cpi->ppi->gf_group is changed.

References AOM_CBR, av1_cyclic_refresh_set_golden_update(), av1_gop_setup_structure(), PRIMARY_RATE_CONTROL::cur_gf_index, RATE_CONTROL::frames_to_key, AV1_PRIMARY::gf_group, PRIMARY_RATE_CONTROL::gf_intervals, PRIMARY_RATE_CONTROL::gfu_boost, RATE_CONTROL::intervals_till_gf_calculate_due, RateControlCfg::mode, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1_COMP::ppi, AV1_COMP::rc, and AV1EncoderConfig::rc_cfg.

Referenced by define_gf_group().

## ◆ define_gf_group()

static void define_gf_group | ( | AV1_COMP * | cpi,
|  | EncodeFrameParams * | frame_params,
|  | int | is_final_pass )
| static

Define a GF group.

This function defines the structure of a GF group, along with various parameters regarding bit-allocation and quality setup.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | frame_params | Structure with frame parameters
  [in] | is_final_pass | Whether this is the final pass for the GF group, or a trial (non-zero)

Remarks
  Nothing is returned. Instead, cpi->ppi->gf_group is changed.

References AOM_Q, AOM_RC_THIRD_PASS, av1_gop_setup_structure(), AV1_COMP::common, RateControlCfg::cq_level, PRIMARY_RATE_CONTROL::cur_gf_index, define_gf_group_pass0(), define_gf_group_pass3(), EncodeFrameParams::frame_type, RATE_CONTROL::frames_to_key, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, PRIMARY_RATE_CONTROL::gf_intervals, has_no_stats_stage(), AV1Common::height, AV1_PRIMARY::internal_altref_allowed, RATE_CONTROL::intervals_till_gf_calculate_due, AV1_PRIMARY::lap_enabled, RateControlCfg::mode, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1EncoderConfig::pass, AV1_COMP::ppi, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, EncodeFrameParams::show_frame, AV1_COMP::third_pass_ctx, AV1_PRIMARY::twopass, AV1_COMP::twopass_frame, and AV1Common::width.

Referenced by av1_get_second_pass_params().

## ◆ define_gf_group_pass3()

static int define_gf_group_pass3 | ( | AV1_COMP * | cpi,
|  | EncodeFrameParams * | frame_params,
|  | int | is_final_pass )
| static

Define a GF group for the third apss.

This function defines the structure of a GF group for the third pass, along with various parameters regarding bit-allocation and quality setup based on the two-pass bitstream. Much of the function still uses the strategies used for the second pass and relies on first pass statistics. It is expected that over time these portions would be replaced with strategies specific to the third pass.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | frame_params | Structure with frame parameters
  [in] | is_final_pass | Whether this is the final pass for the GF group, or a trial (non-zero)

Returns
  0: Success; -1: There are conflicts between the bitstream and current config The values in cpi->ppi->gf_group are also changed.

References av1_gop_setup_structure(), AV1_COMP::common, EncodeFrameParams::frame_type, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, AV1Common::height, AV1_PRIMARY::internal_altref_allowed, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1_COMP::ppi, AV1_COMP::rc, EncodeFrameParams::show_frame, AV1_COMP::third_pass_ctx, AV1_COMP::twopass_frame, and AV1Common::width.

Referenced by define_gf_group().

## ◆ 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 )
| static

Determine the location of the next key frame.

This function decides the placement of the next key frame when a scenecut is detected or the maximum key frame distance is reached.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | firstpass_info | struct for firstpass info
  [in] | num_frames_to_detect_scenecut | Maximum lookahead frames.
  [in] | search_start_idx | the start index for searching key frame. Set it to one if we already know the current frame is key frame. Otherwise, set it to zero.

Returns
  Number of frames to the next key including the current frame.

References KeyFrameCfg::auto_key, av1_firstpass_info_future_count(), av1_firstpass_info_peek(), AV1_COMP::common, RATE_CONTROL::frames_to_key, AV1_COMP::initial_mbs, KeyFrameCfg::key_freq_max, KeyFrameCfg::key_freq_min, AV1EncoderConfig::kf_cfg, AV1_PRIMARY::lap_enabled, CommonModeInfoParams::MBs, AV1Common::mi_params, RateControlCfg::mode, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1_COMP::ppi, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, and AV1_PRIMARY::twopass.

Referenced by av1_get_second_pass_params(), and find_next_key_frame().

## ◆ find_next_key_frame()

static void find_next_key_frame | ( | AV1_COMP * | cpi,
|  | FIRSTPASS_STATS * | this_frame )
| static

Determine the next key frame group.

This function decides the placement of the next key frame, and calculates the bit allocation of the KF group and the keyframe itself.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | this_frame | Pointer to first pass stats

References AOM_Q, KeyFrameCfg::auto_key, av1_firstpass_info_peek(), AV1_COMP::common, AV1Common::current_frame, define_kf_interval(), AV1_COMP::frame_info, AV1_COMP::framerate, RATE_CONTROL::frames_till_gf_update_due, RATE_CONTROL::frames_to_key, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, has_no_stats_stage(), FIRSTPASS_STATS::intra_error, KeyFrameCfg::key_freq_max, PRIMARY_RATE_CONTROL::kf_boost, AV1EncoderConfig::kf_cfg, AV1_PRIMARY::lap_enabled, RateControlCfg::mode, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1_COMP::ppi, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, FIRSTPASS_INFO::total_stats, AV1_PRIMARY::twopass, AV1_COMP::twopass_frame, RateControlCfg::vbr_corpus_complexity_lap, and RateControlCfg::vbrbias.

Referenced by av1_get_second_pass_params().