[FFmpeg-devel] [PATCH 1/3] h274: correctly infer missing comp model values

Niklas Haas ffmpeg at haasn.xyz
Sat Mar 5 18:58:31 EET 2022


From: Niklas Haas <git at haasn.dev>

The ITU-R H.274 spec mentions defined behavior for what to do when
num_comp_model_values is less than the amount expected by the fg model
algorithm.

The current behavior is basically undefined behavior in this case. In
addition to fixing this, also defer the index offset calculation very
slightly to better lead into the following commit.

Signed-off-by: Niklas Haas <git at haasn.dev>
---
 libavcodec/h274.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h274.c b/libavcodec/h274.c
index a69f941142..170086543f 100644
--- a/libavcodec/h274.c
+++ b/libavcodec/h274.c
@@ -162,6 +162,7 @@ static av_always_inline void generate(int8_t *out, int out_stride,
 {
     const uint8_t shift = h274->log2_scale_factor + 6;
     const uint16_t avg = avg_8x8_c(in, in_stride);
+    const uint8_t num_values = h274->num_model_values[c];
     int16_t scale;
     uint8_t h, v;
     int8_t s = -1;
@@ -191,8 +192,8 @@ static av_always_inline void generate(int8_t *out, int out_stride,
         return;
     }
 
-    h = av_clip(h274->comp_model_value[c][s][1], 2, 14) - 2;
-    v = av_clip(h274->comp_model_value[c][s][2], 2, 14) - 2;
+    h = num_values > 1 ? av_clip(h274->comp_model_value[c][s][1], 2, 14) - 2 : 6;
+    v = num_values > 2 ? av_clip(h274->comp_model_value[c][s][2], 2, 14) - 2 : h;
     init_slice(database, h, v);
 
     scale = h274->comp_model_value[c][s][0];
-- 
2.35.1



More information about the ffmpeg-devel mailing list