Skip to content

Commit

Permalink
Add heuristic quantizer adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Aug 21, 2019
1 parent 2b20894 commit db0da3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
18 changes: 17 additions & 1 deletion src/rdo.rs
Expand Up @@ -520,8 +520,24 @@ fn luma_chroma_mode_rdo<T: Pixel>(

// If skip is true, sidx is not coded.
// If quantizer RDO is disabled, sidx isn't coded either.
let sidx_range = if skip || !fi.config.speed_settings.quantizer_rdo {
let sidx_range = if skip {
0..=0
} else if !fi.config.speed_settings.quantizer_rdo {
let importance =
compute_mean_importance(fi, ts.to_frame_block_offset(tile_bo), bsize);
// Chosen based on the RDO segment ID statistics for speed 2 on the DOTA2
// clip. More precisely:
// - Mean importance and the corresponding best sidx chosen by RDO were
// dumped from encoding the DOTA2 clip on --speed 2.
// - The values were plotted in a logarithmic 2D histogram.
// - Based on that, the value below were chosen.
let heuristic_sidx = match importance {
x if x >= 0. && x < 2. => 1,
x if x >= 2. && x < 4. => 0,
x if x >= 4. => 2,
_ => unreachable!(),
};
heuristic_sidx..=heuristic_sidx
} else {
0..=2
};
Expand Down
37 changes: 18 additions & 19 deletions src/segmentation.rs
Expand Up @@ -18,28 +18,27 @@ use crate::FrameState;
pub fn segmentation_optimize<T: Pixel>(
fi: &FrameInvariants<T>, fs: &mut FrameState<T>,
) {
// Segmentation is currently used only for the quantizer RDO.
if fi.config.speed_settings.quantizer_rdo {
fs.segmentation.enabled = true;
fs.segmentation.update_map = true;
fs.segmentation.enabled = true;
fs.segmentation.update_map = true;

// We don't change the values between frames.
fs.segmentation.update_data = fi.primary_ref_frame == PRIMARY_REF_NONE;
// We don't change the values between frames.
fs.segmentation.update_data = fi.primary_ref_frame == PRIMARY_REF_NONE;

// A series of AWCY runs with deltas 10, 13, 15, 17, 20 showed this to be
// the optimal one.
const TEMPORAL_RDO_QI_DELTA: i16 = 15;
// A series of AWCY runs with deltas 10, 13, 15, 17, 20 showed this to be
// the optimal one.
const TEMPORAL_RDO_QI_DELTA: i16 = 15;

// Fill in 3 slots with 0, delta, -delta.
for i in 0..3 {
fs.segmentation.features[i][SegLvl::SEG_LVL_ALT_Q as usize] = true;
fs.segmentation.data[i][SegLvl::SEG_LVL_ALT_Q as usize] = match i {
0 => 0,
1 => TEMPORAL_RDO_QI_DELTA,
2 => -TEMPORAL_RDO_QI_DELTA,
_ => unreachable!(),
};
}
// Fill in 3 slots with 0, delta, -delta. The slot IDs are also used in
// luma_chroma_mode_rdo() so if you change things here make sure to check
// that place too.
for i in 0..3 {
fs.segmentation.features[i][SegLvl::SEG_LVL_ALT_Q as usize] = true;
fs.segmentation.data[i][SegLvl::SEG_LVL_ALT_Q as usize] = match i {
0 => 0,
1 => TEMPORAL_RDO_QI_DELTA,
2 => -TEMPORAL_RDO_QI_DELTA,
_ => unreachable!(),
};
}

/* Figure out parameters */
Expand Down

0 comments on commit db0da3c

Please sign in to comment.