forge
Explore
Log in

Don't you dare go Hollow

Two knobs for the ARF temporal filter -- window width and a mid-ARF strength

Browse files at this commit

ea60760987fae286ca761c1fcc56dc892ddd0177Ahmet Kaan GümüşParent: 7c94ff1
  • feat
    • two knobs for the ARF temporal filter -- window width and a mid-ARF strength
Show full message
feat(av1): two knobs for the ARF temporal filter -- window width and a mid-ARF strength

The filter's neighbour count was a literal 2 and it ran on the top ARF
only. Both are now speed-table entries with env overrides
(EC_AV1_ARF_TF_WIN, EC_AV1_ARF_TF_MID), defaults unchanged (2 / off), so
the sweep arms are env-only.
crates/ec-av1/src/encode.rsmodified+1 -1
@@ -11357,7 +11357,7 @@ pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f
1135711357 let neighbours: Vec<&Picture> = window
1135811358 .iter()
1135911359 .filter(|p| p.width == src.width && p.height == src.height)
11360- .take(2)
11360+ .take(crate::encoder::arf_tf_window())
1136111361 .collect();
1136211362 if neighbours.is_empty() || strength <= 0.0 {
1136311363 return src.clone();
crates/ec-av1/src/encoder.rsmodified+34 -6
@@ -1077,6 +1077,29 @@ fn arf_tf_strength() -> f64 {
10771077 .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF))
10781078 }
10791079
1080+/// lane-arftf: the same filter's strength on the MID ARF, whose own window
1081+/// is the display-FUTURE leaves of its group (`tpl_window(at, false)`).
1082+/// `EC_AV1_ARF_TF_MID=<strength>` overrides [`crate::speed::ARF_TF_MID`];
1083+/// `0` is off.
1084+fn arf_tf_mid_strength() -> f64 {
1085+ std::env::var("EC_AV1_ARF_TF_MID")
1086+ .ok()
1087+ .and_then(|v| v.parse().ok())
1088+ .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_MID))
1089+}
1090+
1091+/// lane-arftf: how many of the window's pictures the filter averages in
1092+/// ([`crate::speed::ARF_TF_WIN`], `EC_AV1_ARF_TF_WIN=<n>`). The top ARF's
1093+/// window holds only DISPLAY-PAST neighbours -- it is the group's last
1094+/// picture and the next group's sources are not buffered when it is coded --
1095+/// so this widens the filter backwards only.
1096+pub(crate) fn arf_tf_window() -> usize {
1097+ std::env::var("EC_AV1_ARF_TF_WIN")
1098+ .ok()
1099+ .and_then(|v| v.parse().ok())
1100+ .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_WIN))
1101+}
1102+
10801103 fn tpl_pyramid() -> bool {
10811104 match std::env::var("EC_AV1_TPL_PYRAMID").ok() {
10821105 Some(v) => v != "0",
@@ -1800,15 +1823,20 @@ impl Av1Encoder {
18001823 // ... and never at the very top of the quality range, where the
18011824 // anchor's own quantizer has hit the rate loop's floor
18021825 // ([`crate::speed::ARF_TF_QMIN`]).
1826+ let tf = match dq_level {
1827+ crate::encode::DqLevel::TopArf => arf_tf_strength(),
1828+ // lane-arftf: the mid ARF gets its own strength -- its window is
1829+ // the group's later leaves, i.e. the filter runs FORWARD there.
1830+ crate::encode::DqLevel::MidArf => arf_tf_mid_strength(),
1831+ crate::encode::DqLevel::Leaf => 0.0,
1832+ };
18031833 let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN {
1804- true => arf_tf_strength(),
1834+ true => tf,
18051835 false => 0.0,
18061836 };
1807- let source = match (tf > 0.0, dq_level) {
1808- (true, crate::encode::DqLevel::TopArf) => {
1809- crate::encode::arf_temporal_filter(&source, lookahead, tf)
1810- }
1811- _ => source,
1837+ let source = match tf > 0.0 {
1838+ true => crate::encode::arf_temporal_filter(&source, lookahead, tf),
1839+ false => source,
18121840 };
18131841 let encoded = || -> Result<Encoded> { encode_inter_frame(
18141842 &source,
crates/ec-av1/src/speed.rsmodified+14 -0
@@ -395,6 +395,20 @@ pub(crate) const DQ_LEVEL_K: [f64; 3] = [1.5, 1.0, 1.0];
395395 /// still carry the grain the anchor no longer has.
396396 pub(crate) const ARF_TF: [f64; 11] = [3.0; 11];
397397
398+/// lane-arftf: the same filter on the MID ARF (the second hidden frame of a
399+/// group), whose window is the group's later leaves -- so it filters FORWARD
400+/// where the top ARF filters backward. `EC_AV1_ARF_TF_MID=<strength>`
401+/// overrides it; `0` is off, which is where the long-GOP gate left it.
402+pub(crate) const ARF_TF_MID: [f64; 11] = [0.0; 11];
403+
404+/// lane-arftf: how many window pictures [`crate::encode::arf_temporal_filter`]
405+/// averages in. The top ARF is its group's LAST picture and the next group's
406+/// sources are not buffered when it is coded, so the window holds only
407+/// display-PAST neighbours and this widens the filter backwards only (a
408+/// symmetric +-2 needs a one-group lookahead the encoder does not have).
409+/// `EC_AV1_ARF_TF_WIN=<n>` overrides it.
410+pub(crate) const ARF_TF_WIN: [usize; 11] = [2; 11];
411+
398412 /// lane-arfpred: the qindex below which the ARF temporal filter is OFF --
399413 /// libaom scales `arnr` strength with the quantizer and stops filtering at
400414 /// the high-quality end for the same reason: a picture we are about to