diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 8bb6ab73..ef3f098f 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -11357,7 +11357,7 @@ pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f let neighbours: Vec<&Picture> = window .iter() .filter(|p| p.width == src.width && p.height == src.height) - .take(2) + .take(crate::encoder::arf_tf_window()) .collect(); if neighbours.is_empty() || strength <= 0.0 { return src.clone(); diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 6feab2d1..60bf2fe5 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -1077,6 +1077,29 @@ fn arf_tf_strength() -> f64 { .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF)) } +/// lane-arftf: the same filter's strength on the MID ARF, whose own window +/// is the display-FUTURE leaves of its group (`tpl_window(at, false)`). +/// `EC_AV1_ARF_TF_MID=` overrides [`crate::speed::ARF_TF_MID`]; +/// `0` is off. +fn arf_tf_mid_strength() -> f64 { + std::env::var("EC_AV1_ARF_TF_MID") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_MID)) +} + +/// lane-arftf: how many of the window's pictures the filter averages in +/// ([`crate::speed::ARF_TF_WIN`], `EC_AV1_ARF_TF_WIN=`). The top ARF's +/// window holds only DISPLAY-PAST neighbours -- it is the group's last +/// picture and the next group's sources are not buffered when it is coded -- +/// so this widens the filter backwards only. +pub(crate) fn arf_tf_window() -> usize { + std::env::var("EC_AV1_ARF_TF_WIN") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_WIN)) +} + fn tpl_pyramid() -> bool { match std::env::var("EC_AV1_TPL_PYRAMID").ok() { Some(v) => v != "0", @@ -1800,15 +1823,20 @@ impl Av1Encoder { // ... and never at the very top of the quality range, where the // anchor's own quantizer has hit the rate loop's floor // ([`crate::speed::ARF_TF_QMIN`]). + let tf = match dq_level { + crate::encode::DqLevel::TopArf => arf_tf_strength(), + // lane-arftf: the mid ARF gets its own strength -- its window is + // the group's later leaves, i.e. the filter runs FORWARD there. + crate::encode::DqLevel::MidArf => arf_tf_mid_strength(), + crate::encode::DqLevel::Leaf => 0.0, + }; let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN { - true => arf_tf_strength(), + true => tf, false => 0.0, }; - let source = match (tf > 0.0, dq_level) { - (true, crate::encode::DqLevel::TopArf) => { - crate::encode::arf_temporal_filter(&source, lookahead, tf) - } - _ => source, + let source = match tf > 0.0 { + true => crate::encode::arf_temporal_filter(&source, lookahead, tf), + false => source, }; let encoded = || -> Result { encode_inter_frame( &source, diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 5ed6f668..58c0d023 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -395,6 +395,20 @@ pub(crate) const DQ_LEVEL_K: [f64; 3] = [1.5, 1.0, 1.0]; /// still carry the grain the anchor no longer has. pub(crate) const ARF_TF: [f64; 11] = [3.0; 11]; +/// lane-arftf: the same filter on the MID ARF (the second hidden frame of a +/// group), whose window is the group's later leaves -- so it filters FORWARD +/// where the top ARF filters backward. `EC_AV1_ARF_TF_MID=` +/// overrides it; `0` is off, which is where the long-GOP gate left it. +pub(crate) const ARF_TF_MID: [f64; 11] = [0.0; 11]; + +/// lane-arftf: how many window pictures [`crate::encode::arf_temporal_filter`] +/// averages in. The top ARF is its group's LAST picture and the next group's +/// sources are not buffered when it is coded, so the window holds only +/// display-PAST neighbours and this widens the filter backwards only (a +/// symmetric +-2 needs a one-group lookahead the encoder does not have). +/// `EC_AV1_ARF_TF_WIN=` overrides it. +pub(crate) const ARF_TF_WIN: [usize; 11] = [2; 11]; + /// lane-arfpred: the qindex below which the ARF temporal filter is OFF -- /// libaom scales `arnr` strength with the quantizer and stops filtering at /// the high-quality end for the same reason: a picture we are about to