From 6f54917f4dec44348b2a8cfc6259e134b277c041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Fri, 25 Oct 2019 15:16:56 -0400 Subject: [PATCH] Disable restoration filters for tiny frames This fixes a crash in LRF at widths or heights of 1 px as a side effect of disabling restoration at sizes where it is not likely to improve quality. --- src/encoder.rs | 10 ++++++++-- src/lrf.rs | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/encoder.rs b/src/encoder.rs index 5bafcb405b..5d677cad0a 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -187,6 +187,10 @@ impl Sequence { tier[i] = 0; } + // Restoration filters are not useful for very small frame sizes, + // so disable them in that case. + let enable_restoration_filters = config.width >= 32 && config.height >= 32; + Sequence { profile, num_bits_width: width_bits, @@ -220,8 +224,10 @@ impl Sequence { enable_warped_motion: false, enable_superres: false, enable_cdef: config.speed_settings.cdef - && config.chroma_sampling != ChromaSampling::Cs422, - enable_restoration: config.chroma_sampling != ChromaSampling::Cs422, + && config.chroma_sampling != ChromaSampling::Cs422 + && enable_restoration_filters, + enable_restoration: config.chroma_sampling != ChromaSampling::Cs422 + && enable_restoration_filters, enable_large_lru: true, operating_points_cnt_minus_1: 0, operating_point_idc, diff --git a/src/lrf.rs b/src/lrf.rs index c774ca71f8..40487879c6 100644 --- a/src/lrf.rs +++ b/src/lrf.rs @@ -1206,6 +1206,11 @@ impl RestorationState { let (lrf_y_shift, lrf_uv_shift) = if fi.sequence.enable_large_lru && fi.sequence.enable_restoration { + assert!( + fi.width > 1 && fi.height > 1, + "Width and height must be higher than 1 for LRF setup" + ); + // Specific content does affect optimal LRU size choice, but the // quantizer in use is a surprisingly strong selector. let lrf_base_shift = if fi.base_q_idx > 200 {