[FFmpeg-cvslog] avcodec/libjxlenc: avoid hard failure with unspecified primaries

Leo Izen git at videolan.org
Sun Sep 25 17:16:28 EEST 2022


ffmpeg | branch: release/5.1 | Leo Izen <leo.izen at gmail.com> | Fri Jul 15 13:27:10 2022 -0400| [05d6157aab34bc49f23284645a8f34ece870f44d] | committer: James Almer

avcodec/libjxlenc: avoid hard failure with unspecified primaries

This patch prevents the libjxl encoder wrapper from failing to
encode images when the input video has untagged primaries. It will
instead assume BT.709/sRGB primaries and print a warning.

Signed-off-by: Leo Izen <leo.izen at gmail.com>
(cherry picked from commit 940169b8aab406a8b1ccee4a9705a1e06b76d035)

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

 libavcodec/libjxlenc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index 6a948cc3ae..9d98a112e1 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -190,7 +190,7 @@ static av_cold int libjxl_encode_init(AVCodecContext *avctx)
  * Populate a JxlColorEncoding with the given enum AVColorPrimaries.
  * @return < 0 upon failure, >= 0 upon success
  */
-static int libjxl_populate_primaries(JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
+static int libjxl_populate_primaries(void *avctx, JxlColorEncoding *jxl_color, enum AVColorPrimaries prm)
 {
     const AVColorPrimariesDesc *desc;
 
@@ -211,6 +211,11 @@ static int libjxl_populate_primaries(JxlColorEncoding *jxl_color, enum AVColorPr
         jxl_color->primaries = JXL_PRIMARIES_P3;
         jxl_color->white_point = JXL_WHITE_POINT_D65;
         return 0;
+    case AVCOL_PRI_UNSPECIFIED:
+        av_log(avctx, AV_LOG_WARNING, "Unknown primaries, assuming BT.709/sRGB. Colors may be wrong.\n");
+        jxl_color->primaries = JXL_PRIMARIES_SRGB;
+        jxl_color->white_point = JXL_WHITE_POINT_D65;
+        return 0;
     }
 
     desc = av_csp_primaries_desc_from_id(prm);
@@ -340,7 +345,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
     else
         jxl_color.color_space = JXL_COLOR_SPACE_RGB;
 
-    ret = libjxl_populate_primaries(&jxl_color,
+    ret = libjxl_populate_primaries(avctx, &jxl_color,
             frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED
             ? frame->color_primaries : avctx->color_primaries);
     if (ret < 0)



More information about the ffmpeg-cvslog mailing list