From patchwork Mon Oct 21 19:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 52435 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2926134vqi; Mon, 21 Oct 2024 13:29:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUGuF9pWQBu24EjMG69k6wHb+RO5C2ZNxdiLnONSeDUButiMNB8867E8t5jHG/EL4Hp4gsHulQvpUwTTg9V5kR0@gmail.com X-Google-Smtp-Source: AGHT+IGDb+VcC0iXpr0HYE8zVREpvmfrDGV0Qbs+estjg9mx6o9Ck7zBDKh9my1wJ810Ob21BS7k X-Received: by 2002:a05:651c:2127:b0:2fa:ce3f:b57d with SMTP id 38308e7fff4ca-2fb831e65c5mr18287491fa.9.1729542543559; Mon, 21 Oct 2024 13:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729542543; cv=none; d=google.com; s=arc-20240605; b=FD0UV+My77aobXnrhUPaDGbU9bGV1tyvIu2lI/TL/kOd9Bhv197WpBpnToWEAXMRdV Kc/ysmXw8poA2hkcQ4pjAznGpYomdF0ZikEUfUO3M/UNVtCB0i58JQn3XrTFicCneOPE qM5gGB3D1EmbhCAUmo6hXh3VGM5RAIebamkiI3UbCV48RtwkqMeVR+MQIkTvZp1HMXqr VUOAnpQ8gd2MKq5ek8mE7hFrdtzye+k6uPoTKwpYblZAy548FEAjz/2CQvT0KG3AQjBJ yipquNgVQuKcvRt/9xqpY7i9FHQOo3zbxYhY10p9Mu5pJB+VsiE1MsJV3TGQCd4N0Y0z YiAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=gCUYO+qOejVfwdTbUBIvszIXqzAjRXU4Qlolk1SyGj0=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=UIXj2M2450vuCUA9aY1Fu6e94L1my2t2yxl3dkrwzUoALj5nBU8WEe05x1ofzvvEyI zq/a3oHzhxvchGeL/1Shq+7BzreihITc9qfIks6bsrpzhVI/THW4X12pjfSL6W8ELC6y dyA/sgQ/DN2quqnLVP4ZNbd7toIVWeJbawRhb04NLWAF9EzBQHs3R9Et51yp155IfA5y RT7+V1EAIozP1TDzEYObt0SX08FfoBwsFgGkV26wE0RUleDhKpzRGvA5hbEg3OfKazTX j3wnU8g84oGGiEzDl5azUU6Cw5sZodAi3Pj/ZvCILfLlNBciwkZfHmexqfP+Qr8u9qDb pEGA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=lhCl+3pK; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2fb9ae7d680si11272491fa.411.2024.10.21.13.29.03; Mon, 21 Oct 2024 13:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=lhCl+3pK; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24E2C68DE2B; Mon, 21 Oct 2024 23:18:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6820B68DCE1 for ; Mon, 21 Oct 2024 23:18:06 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 4E04B462EE; Mon, 21 Oct 2024 22:18:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1729541881; bh=a4pC868kjgaZIQIMeQlXhSuSddTKNWIOrLk4fmsYJQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhCl+3pK0OU1LoAA42bgzKsHj5XY5Ns1ESnYGZGY/5cKoM9QnxY937faGwrVk4xcC CGHqivJUOtDL/I4D5ctBfLDa+DVoO7iKqxP105NdXDXBc/X+bIZtr+NfLsvBGlv63v POUPmLxOoGPm4AyhE9iS6tydNikJNJEFBu+BGVC8PAUdpwrirDFzYLLs4a85WGyTjP TVlhea7UnhZuPDqE64nGIdYTdI7he4VQDAzUXwbWWu5xVbOe14OuC7Kwf18f3Mqniy uLRfJCkcSF2veVnPy4W9F/wk7YYgtATbo4GUV6a/6ViDLMcepMyVDLuj4gcZO6bNUc 6jhSG5hhtNKT5ia61mHebHLu2gfikRFaGkw0nUWvzCsMncI/NpKzWOrZu5lDEC8It/ oicGSRifs9PERfcVOfSRUU3azEofoGI71ZVVMzdzjYou+W/QwkGw+P24CDSPza5966 z1H3FDSqD0XbYp3m42bfyqcGleEGjex5SzgG3OfeuLiAqFaMata From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Oct 2024 21:57:21 +0200 Message-ID: <20241021195721.892544-10-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241021195721.892544-2-ms+git@mur.at> References: <20241021195721.892544-2-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v12 8/9] avformat/mxfdec: Workaround for RGB pc/video level detection. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sONwSOEmvpF6 In case of RGB content wrapped in MXF containers we can not use CDCIDescriptor fields for the video level detection. The corresponding information in RGBA Descriptors uses a significant differnt structure. As a workaround we pick the first found channel depth info value of the RGBALayout array and us it instead of the more general CDCI component_depth. --- libavformat/mxfdec.c | 51 +++++++++++++++++++++++++++++------- tests/ref/fate/mxf-probe-j2k | 2 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 27e8e0c..eb51585 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -212,6 +212,9 @@ typedef struct MXFDescriptor { unsigned int component_depth; unsigned int black_ref_level; unsigned int white_ref_level; + uint32_t component_max_ref; + uint32_t component_min_ref; + uint8_t red_component_depth; unsigned int color_range; unsigned int horiz_subsampling; unsigned int vert_subsampling; @@ -1316,6 +1319,9 @@ static void mxf_read_pixel_layout(AVIOContext *pb, MXFDescriptor *descriptor) value = avio_r8(pb); av_log(NULL, AV_LOG_TRACE, "pixel layout: code %#x\n", code); + if (code == 'R') + descriptor->red_component_depth = value; + if (ofs <= 14) { layout[ofs++] = code; layout[ofs++] = value; @@ -1424,6 +1430,12 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int case 0x3401: mxf_read_pixel_layout(pb, descriptor); break; + case 0x3406: + descriptor->component_max_ref = avio_rb32(pb); + break; + case 0x3407: + descriptor->component_min_ref = avio_rb32(pb); + break; default: /* Private uid used by SONY C0023S01.mxf */ if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) { @@ -2511,19 +2523,38 @@ static int mxf_add_metadata_stream(MXFContext *mxf, MXFTrack *track) static enum AVColorRange mxf_get_color_range(MXFContext *mxf, MXFDescriptor *descriptor) { - if (descriptor->black_ref_level || descriptor->white_ref_level || descriptor->color_range) { + unsigned int depth, black_ref_level, white_ref_level; + + // The red channel component depth value of the + // RGBALayout array is used as component_depth indicator + // for the pc/tv level detection in case of RGB content + // and their RGBA Descriptors instead of CDCI entries. + + if (descriptor->red_component_depth) { // RGBA Descriptor + depth = descriptor->red_component_depth; + black_ref_level = descriptor->component_min_ref; + white_ref_level = descriptor->component_max_ref; + } else { // CDCI Descriptor + depth = descriptor->component_depth; + black_ref_level = descriptor->black_ref_level; + white_ref_level = descriptor->white_ref_level; + } + + if (black_ref_level || white_ref_level) { /* CDCI range metadata */ - if (!descriptor->component_depth) + if (!depth) return AVCOL_RANGE_UNSPECIFIED; - if (descriptor->black_ref_level == 0 && descriptor->component_depth < 31 && - descriptor->white_ref_level == ((1<component_depth) - 1) && - (descriptor->color_range == (1<component_depth) || - descriptor->color_range == ((1<component_depth) - 1))) + if (black_ref_level == 0 && depth < 31 && + white_ref_level == ((1 << depth) - 1) && + (descriptor->red_component_depth || + descriptor->color_range == (1 << descriptor->component_depth) || + descriptor->color_range == ((1 << descriptor->component_depth) - 1))) return AVCOL_RANGE_JPEG; - if (descriptor->component_depth >= 8 && descriptor->component_depth < 31 && - descriptor->black_ref_level == (1 <<(descriptor->component_depth - 4)) && - descriptor->white_ref_level == (235<<(descriptor->component_depth - 8)) && - descriptor->color_range == ((14<<(descriptor->component_depth - 4)) + 1)) + if (depth >= 8 && depth < 31 && + black_ref_level == (1 << (depth - 4)) && + white_ref_level == (235 << (depth - 8)) && + ( descriptor->red_component_depth || + descriptor->color_range == ((14 << (descriptor->component_depth - 4))) + 1)) return AVCOL_RANGE_MPEG; avpriv_request_sample(mxf->fc, "Unrecognized CDCI color range (color diff range %d, b %d, w %d, depth %d)", descriptor->color_range, descriptor->black_ref_level, diff --git a/tests/ref/fate/mxf-probe-j2k b/tests/ref/fate/mxf-probe-j2k index f1dadf4..6287980 100644 --- a/tests/ref/fate/mxf-probe-j2k +++ b/tests/ref/fate/mxf-probe-j2k @@ -16,7 +16,7 @@ sample_aspect_ratio=1:1 display_aspect_ratio=16:9 pix_fmt=rgb48 level=-99 -color_range=unknown +color_range=pc color_space=unknown color_transfer=bt709 color_primaries=bt709