Commit fb07d7c6f1 for ffmpeg
commit fb07d7c6f1d8376484056cdfe16e1428b9cf082c
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Fri Oct 16 19:01:08 2026 +0200
avcodec/mpeg4videodec: report reserved colour tags as unspecified
The Visual Object colour description is copied into the codec context as it
is, so a reserved value reaches the decoded frames.
The swscale frame checks reject reserved values, so scaling such a stream fails
with ENOTSUP. h2645_vui.c reports them as unspecified since c80002aa81
("avcodec/h2645_vui: Ensure color primaries/trc/space isn't reserved value"),
do the same here. Valid values are untouched.
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index e080c83f9d..03b145379d 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -26,6 +26,7 @@
#include "libavutil/avassert.h"
#include "libavutil/internal.h"
+#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "codec_internal.h"
@@ -2462,6 +2463,19 @@ static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
s->avctx->color_primaries = get_bits(gb, 8);
s->avctx->color_trc = get_bits(gb, 8);
s->avctx->colorspace = get_bits(gb, 8);
+
+ // Reserved and unassigned values carry no colour information
+ if (s->avctx->color_primaries == AVCOL_PRI_RESERVED0 ||
+ s->avctx->color_primaries == AVCOL_PRI_RESERVED ||
+ !av_color_primaries_name(s->avctx->color_primaries))
+ s->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
+ if (s->avctx->color_trc == AVCOL_TRC_RESERVED0 ||
+ s->avctx->color_trc == AVCOL_TRC_RESERVED ||
+ !av_color_transfer_name(s->avctx->color_trc))
+ s->avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
+ if (s->avctx->colorspace == AVCOL_SPC_RESERVED ||
+ !av_color_space_name(s->avctx->colorspace))
+ s->avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
}
}
}
diff --git a/tests/ref/fate/mpeg4-reserved-color-tags b/tests/ref/fate/mpeg4-reserved-color-tags
index 55c9df3bad..b86330d693 100644
--- a/tests/ref/fate/mpeg4-reserved-color-tags
+++ b/tests/ref/fate/mpeg4-reserved-color-tags
@@ -1,3 +1,3 @@
-color_space=reserved
-color_primaries=reserved
-color_transfer=reserved
+color_space=unknown
+color_primaries=unknown
+color_transfer=unknown