[FFmpeg-devel] [PATCH 03/17] swscale/utils: set static/implied HDR metadata

Niklas Haas ffmpeg at haasn.xyz
Thu Dec 5 13:30:12 EET 2024


From: Niklas Haas <git at haasn.dev>

Provide default values for the fields added in the previous commit.
---
 libswscale/utils.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 569d037f25..95b083b2eb 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2654,6 +2654,8 @@ int ff_range_add(RangeList *rl, unsigned int start, unsigned int len)
 SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+    const AVColorPrimariesDesc *primaries;
+
     SwsFormat fmt = {
         .width  = frame->width,
         .height = frame->height,
@@ -2710,6 +2712,25 @@ SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field)
         fmt.interlaced = 1;
     }
 
+    /* Set luminance and gamut information */
+    fmt.color.min_luma = av_make_q(0, 1);
+    switch (fmt.color.trc) {
+    case AVCOL_TRC_SMPTE2084:
+        fmt.color.max_luma = av_make_q(10000, 1); break;
+    case AVCOL_TRC_ARIB_STD_B67:
+        fmt.color.max_luma = av_make_q( 1000, 1); break; /* HLG reference display */
+    default:
+        fmt.color.max_luma = av_make_q(  203, 1); break; /* SDR reference brightness */
+    }
+
+    primaries = av_csp_primaries_desc_from_id(fmt.color.prim);
+    if (primaries)
+        fmt.color.gamut = primaries->prim;
+
+    /* PQ is always scaled down to absolute zero, so ignore mastering metadata */
+    if (fmt.color.trc == AVCOL_TRC_SMPTE2084)
+        fmt.color.min_luma = av_make_q(0, 1);
+
     return fmt;
 }
 
-- 
2.47.0



More information about the ffmpeg-devel mailing list