Two knobs for the ARF temporal filter -- window width and a mid-ARF strength
Browse files at this commitea60760987fae286ca761c1fcc56dc892ddd0177Parent: 7c94ff1- feat
- two knobs for the ARF temporal filter -- window width and a mid-ARF strength
3 changed files +49 -7
- crates/ec-av1/src/encode.rs +1 -1
- crates/ec-av1/src/encoder.rs +34 -6
- crates/ec-av1/src/speed.rs +14 -0
crates/ec-av1/src/encode.rsmodified+1 -1
| @@ -11357,7 +11357,7 @@ pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f | ||
| 11357 | 11357 | let neighbours: Vec<&Picture> = window |
| 11358 | 11358 | .iter() |
| 11359 | 11359 | .filter(|p| p.width == src.width && p.height == src.height) |
| 11360 | - .take(2) | |
| 11360 | + .take(crate::encoder::arf_tf_window()) | |
| 11361 | 11361 | .collect(); |
| 11362 | 11362 | if neighbours.is_empty() || strength <= 0.0 { |
| 11363 | 11363 | return src.clone(); |
crates/ec-av1/src/encoder.rsmodified+34 -6
| @@ -1077,6 +1077,29 @@ fn arf_tf_strength() -> f64 { | ||
| 1077 | 1077 | .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF)) |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 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 | + | |
| 1080 | 1103 | fn tpl_pyramid() -> bool { |
| 1081 | 1104 | match std::env::var("EC_AV1_TPL_PYRAMID").ok() { |
| 1082 | 1105 | Some(v) => v != "0", |
| @@ -1800,15 +1823,20 @@ impl Av1Encoder { | ||
| 1800 | 1823 | // ... and never at the very top of the quality range, where the |
| 1801 | 1824 | // anchor's own quantizer has hit the rate loop's floor |
| 1802 | 1825 | // ([`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 | + }; | |
| 1803 | 1833 | let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN { |
| 1804 | - true => arf_tf_strength(), | |
| 1834 | + true => tf, | |
| 1805 | 1835 | false => 0.0, |
| 1806 | 1836 | }; |
| 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, | |
| 1812 | 1840 | }; |
| 1813 | 1841 | let encoded = || -> Result<Encoded> { encode_inter_frame( |
| 1814 | 1842 | &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]; | ||
| 395 | 395 | /// still carry the grain the anchor no longer has. |
| 396 | 396 | pub(crate) const ARF_TF: [f64; 11] = [3.0; 11]; |
| 397 | 397 | |
| 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 | + | |
| 398 | 412 | /// lane-arfpred: the qindex below which the ARF temporal filter is OFF -- |
| 399 | 413 | /// libaom scales `arnr` strength with the quantizer and stops filtering at |
| 400 | 414 | /// the high-quality end for the same reason: a picture we are about to |