PR #26198 opened by Baptiste Coudurier (bcoudurier) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26198 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26198.patch
Raw JPEG 2000 codestreams with three full-resolution components can represent RGB or YUV 4:4:4. Resolve writes the interpretation in the MXF picture descriptor. Without that hint, FFmpeg's native decoder selected RGB for the YUV 4:4:4 exports. Use RGBA PixelLayout for explicit RGB and D-Cinema XYZ, and use CDCI depth and subsampling for planar YUV 4:4:4. The separate OP-Atom end-of-essence diagnostic is tracked in #26196. Validation: both Resolve YUV 4:4:4 MXFs decode all 90 frames as yuv444p10le. All 177 byte-identical MOV/MXF codestream pairs match pixel-for-pixel. The RGB and YUV 4:2:2 controls match their baseline hashes. The JPEG 2000 timestamp FATE test passes. [Resolve YUV 4:4:4 OP-Atom sample](https://code.ffmpeg.org/attachments/f4d2965d-43a3-4915-822d-668fda4a3131) >From d21510ddab493bf9cd701454c375ac9a87a72950 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Wed, 18 Nov 2026 21:33:02 -0800 Subject: [PATCH] avformat/mxfdec: use picture descriptors for JPEG 2000 pixel formats Use RGBA PixelLayout to signal RGB or D-Cinema XYZ and CDCI depth and subsampling to signal planar YUV 4:4:4. This resolves the ambiguity of three full-resolution JPEG 2000 components, which otherwise causes Resolve YUV 4:4:4 MXF to decode as RGB. --- libavformat/mxfdec.c | 57 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index a47a01812f1..9466c3318ef 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -196,8 +196,12 @@ typedef struct { #define MXF_WHITE_REF_LEVEL_PRESENT (1 << 1) #define MXF_COLOR_RANGE_PRESENT (1 << 2) +#define MXF_CDCI_DESCRIPTOR_CLASS 0x28 +#define MXF_RGBA_DESCRIPTOR_CLASS 0x29 + typedef struct MXFDescriptor { MXFMetadataSet meta; + uint8_t descriptor_class; UID essence_container_ul; UID essence_codec_ul; UID codec_ul; @@ -230,6 +234,7 @@ typedef struct MXFDescriptor { uint8_t *extradata; int extradata_size; enum AVPixelFormat pix_fmt; + char pixel_layout[16]; UID color_primaries_ul; UID color_trc_ul; UID color_space_ul; @@ -358,7 +363,6 @@ static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 }; static const uint8_t mxf_ffv1_extradata[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x04,0x01,0x06,0x0c,0x01,0x00,0x00,0x00 }; // FFV1InitializationMetadata static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf }; -static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00 }; static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; static const uint8_t mxf_indirect_value_utf16be[] = { 0x42,0x01,0x10,0x02,0x00,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; static const uint8_t mxf_apple_coll_max_cll[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x01 }; @@ -1341,6 +1345,7 @@ static void mxf_read_pixel_layout(AVIOContext *pb, MXFDescriptor *descriptor) break; /* don't read byte by byte on sneaky files filled with lots of non-zeroes */ } while (code != 0); /* SMPTE 377M E.2.46 */ + memcpy(descriptor->pixel_layout, layout, sizeof(layout)); ff_mxf_decode_pixel_layout(layout, &descriptor->pix_fmt); } @@ -1461,12 +1466,6 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int descriptor->extradata_size = size; avio_read(pb, descriptor->extradata, size); } - if (IS_KLV_KEY(uid, mxf_jp2k_rsiz)) { - uint32_t rsiz = avio_rb16(pb); - if (rsiz == AV_PROFILE_JPEG2000_DCINEMA_2K || - rsiz == AV_PROFILE_JPEG2000_DCINEMA_4K) - descriptor->pix_fmt = AV_PIX_FMT_XYZ12; - } if (IS_KLV_KEY(uid, mxf_mastering_display_prefix)) { if (!descriptor->mastering) { descriptor->mastering = av_mastering_display_metadata_alloc_size(&descriptor->mastering_size); @@ -2719,6 +2718,43 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript return 0; } +static enum AVPixelFormat mxf_get_full_resolution_pixel_format(const MXFDescriptor *descriptor) +{ + static const uint8_t dcinema_layout[16] = { 0xD8, 12, 0xD9, 12, 0xDA, 12 }; /* ST 429-4 */ + const char *layout = descriptor->pixel_layout; + + if (descriptor->descriptor_class == MXF_RGBA_DESCRIPTOR_CLASS) { + const unsigned int depth = (uint8_t)layout[1]; + + if (!memcmp(layout, dcinema_layout, sizeof(dcinema_layout))) + return AV_PIX_FMT_XYZ12; + + /* PixelLayout may include filler bits after the three RGB components. */ + if (layout[0] == 'R' && layout[2] == 'G' && layout[4] == 'B' && + layout[1] == layout[3] && layout[1] == layout[5] && + (layout[6] == 0 || (layout[6] == 'F' && layout[8] == 0)) && + depth > 0 && depth <= 16) + return depth <= 8 ? AV_PIX_FMT_RGB24 : AV_PIX_FMT_RGB48; + + return AV_PIX_FMT_NONE; + } + + /* CDCI vertical subsampling defaults to 1 when absent. */ + if (descriptor->descriptor_class != MXF_CDCI_DESCRIPTOR_CLASS || + descriptor->horiz_subsampling != 1 || descriptor->vert_subsampling > 1) + return AV_PIX_FMT_NONE; + + switch (descriptor->component_depth) { + case 8: return AV_PIX_FMT_YUV444P; + case 9: return AV_PIX_FMT_YUV444P9; + case 10: return AV_PIX_FMT_YUV444P10; + case 12: return AV_PIX_FMT_YUV444P12; + case 14: return AV_PIX_FMT_YUV444P14; + case 16: return AV_PIX_FMT_YUV444P16; + default: return AV_PIX_FMT_NONE; + } +} + static int mxf_parse_structural_metadata(MXFContext *mxf) { MXFPackage *material_package = NULL; @@ -3041,7 +3077,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } - if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) { + /* Full-resolution codestream components need a color interpretation. */ + st->codecpar->format = mxf_get_full_resolution_pixel_format(descriptor); + } else if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { st->codecpar->format = descriptor->pix_fmt; if (st->codecpar->format == AV_PIX_FMT_NONE) { pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls, @@ -3386,6 +3425,8 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF return AVERROR(ENOMEM); ctx = meta; mxf_metadataset_init(meta, type, mxf->current_partition); + if (type == Descriptor) + ((MXFDescriptor *)ctx)->descriptor_class = klv->key[14]; } else { meta = NULL; ctx = mxf; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
