[FFmpeg-cvslog] avcodec/h2645_sei: validate Mastering Display Colour Volume SEI values

Kacper Michajłow git at videolan.org
Sat Apr 13 18:51:02 EEST 2024


ffmpeg | branch: master | Kacper Michajłow <kasper93 at gmail.com> | Sat Apr 13 17:21:08 2024 +0200| [1c45104f74e59beb25ce7451c98527f7a3c518f6] | committer: Niklas Haas

avcodec/h2645_sei: validate Mastering Display Colour Volume SEI values

As we can read in ST 2086:

Values outside the specified ranges of luminance and chromaticity values
are not reserved by SMPTE, and can be used for purposes outside the
scope of this standard.

This is further acknowledged by ITU-T H.264 and ITU-T H.265. Which says
that values out of range are unknown or unspecified or specified by
other means not specified in this Specification.

Signed-off-by: Kacper Michajłow <kasper93 at gmail.com>
Signed-off-by: Niklas Haas <git at haasn.dev>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1c45104f74e59beb25ce7451c98527f7a3c518f6
---

 libavcodec/h2645_sei.c | 55 +++++++++++++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 933975f076..96a22e7cf6 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -587,38 +587,61 @@ static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei,
             return ret;
 
         if (metadata) {
+            metadata->has_luminance = 1;
+            metadata->has_primaries = 1;
+
             for (i = 0; i < 3; i++) {
                 const int j = mapping[i];
                 metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
                 metadata->display_primaries[i][0].den = chroma_den;
+                metadata->has_primaries &= sei->mastering_display.display_primaries[j][0] >= 5 &&
+                                           sei->mastering_display.display_primaries[j][0] <= 37000;
+
                 metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1];
                 metadata->display_primaries[i][1].den = chroma_den;
+                metadata->has_primaries &= sei->mastering_display.display_primaries[j][1] >= 5 &&
+                                           sei->mastering_display.display_primaries[j][1] <= 42000;
             }
             metadata->white_point[0].num = sei->mastering_display.white_point[0];
             metadata->white_point[0].den = chroma_den;
+            metadata->has_primaries &= sei->mastering_display.white_point[0] >= 5 &&
+                                       sei->mastering_display.white_point[0] <= 37000;
+
             metadata->white_point[1].num = sei->mastering_display.white_point[1];
             metadata->white_point[1].den = chroma_den;
+            metadata->has_primaries &= sei->mastering_display.white_point[1] >= 5 &&
+                                       sei->mastering_display.white_point[1] <= 42000;
 
             metadata->max_luminance.num = sei->mastering_display.max_luminance;
             metadata->max_luminance.den = luma_den;
+            metadata->has_luminance &= sei->mastering_display.max_luminance >= 50000 &&
+                                       sei->mastering_display.max_luminance <= 100000000;
+
             metadata->min_luminance.num = sei->mastering_display.min_luminance;
             metadata->min_luminance.den = luma_den;
-            metadata->has_luminance = 1;
-            metadata->has_primaries = 1;
-
-            av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
-            av_log(avctx, AV_LOG_DEBUG,
-                   "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
-                   av_q2d(metadata->display_primaries[0][0]),
-                   av_q2d(metadata->display_primaries[0][1]),
-                   av_q2d(metadata->display_primaries[1][0]),
-                   av_q2d(metadata->display_primaries[1][1]),
-                   av_q2d(metadata->display_primaries[2][0]),
-                   av_q2d(metadata->display_primaries[2][1]),
-                   av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
-            av_log(avctx, AV_LOG_DEBUG,
-                   "min_luminance=%f, max_luminance=%f\n",
-                   av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
+            metadata->has_luminance &= sei->mastering_display.min_luminance >= 1 &&
+                                       sei->mastering_display.min_luminance <= 50000 &&
+                                       sei->mastering_display.min_luminance <
+                                       sei->mastering_display.max_luminance;
+
+            if (metadata->has_luminance || metadata->has_primaries)
+                av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
+            if (metadata->has_primaries) {
+                av_log(avctx, AV_LOG_DEBUG,
+                       "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
+                       av_q2d(metadata->display_primaries[0][0]),
+                       av_q2d(metadata->display_primaries[0][1]),
+                       av_q2d(metadata->display_primaries[1][0]),
+                       av_q2d(metadata->display_primaries[1][1]),
+                       av_q2d(metadata->display_primaries[2][0]),
+                       av_q2d(metadata->display_primaries[2][1]),
+                       av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
+            }
+            if (metadata->has_luminance) {
+                av_log(avctx, AV_LOG_DEBUG,
+                       "min_luminance=%f, max_luminance=%f\n",
+                       av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
+            }
         }
     }
 



More information about the ffmpeg-cvslog mailing list