From patchwork Thu Aug 20 13:58:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Mallon X-Patchwork-Id: 21769 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4D23544B85F for ; Thu, 20 Aug 2020 16:59:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 243B568B6EB; Thu, 20 Aug 2020 16:59:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22F5B68B69A for ; Thu, 20 Aug 2020 16:59:09 +0300 (EEST) Received: by mail-wr1-f51.google.com with SMTP id r4so2109784wrx.9 for ; Thu, 20 Aug 2020 06:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codex.online; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BhmDVx+iuNq39e6v/N9mUNTOcUe8fSN95jjqe9DBlrk=; b=V5Lc5QUslVrn9WxFgFlQir9iFl0QfjEFtKNm+cxdbElwqNKBHhRyPpXvRxI0j/8dWG lP0SPedPgVm+B6a3k+RnfzeiiVku1XUjIHs6F3OtuatDEsNGVrMeEtucUIy0L1ltgkPg JUZkPGqVTrfU3nI5CAz/aDbEM5LFxzPMvvVZo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BhmDVx+iuNq39e6v/N9mUNTOcUe8fSN95jjqe9DBlrk=; b=jKB49un7J6A/63iVmi9YjR+yrpud8W1c2gs6LggfeK3QLBAzi8HHJpKn/x5SwHB2wR 6D11rn6swYx1tkGAKDnF6vHtrlxwb9UHnylV9PcB3qI5EBXo80KbHxTXlIDwDEexzIO9 8DxzkjPc0Vtv00r4kuGQ6qs0i0UtUFA8A2Ci1GzerUfKyg5JDYbZpN4MnaXUvWxXLa/g DOJLQorKDdWygaeq0wMYbkMtRMXL3deHJy+rNHDFR3U+J1boBi3Daau9A6SOrWM8TS8Z 1aDBIpa3DzpQT/3LQbLjIjuA2PKcz9oqOBfHTtYkHlQ1jGMnREOpZU3XWcCflzDvetnl xACg== X-Gm-Message-State: AOAM5337lu82OQtMiaXPML+1zVENvmBPbUGWzUj02Czq46d8pLC0nR2G 9houA8PYrUvn4HNphSr3WGRbsgmHfHkIvQ== X-Google-Smtp-Source: ABdhPJxrEsWZEHKdXAilJN5kEJ5u49cw/4WnSY9mNAoRzUxsM1/ZdUK21j6KRsNyNluV0D70NJ/HQw== X-Received: by 2002:a5d:4802:: with SMTP id l2mr3211169wrq.183.1597931948990; Thu, 20 Aug 2020 06:59:08 -0700 (PDT) Received: from localhost ([2a01:4b00:8571:3800:7c6a:d69c:56a4:3d6]) by smtp.gmail.com with ESMTPSA id t25sm4181872wmj.18.2020.08.20.06.59.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2020 06:59:08 -0700 (PDT) From: Harry Mallon To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Aug 2020 14:58:52 +0100 Message-Id: <20200820135853.96869-1-harry.mallon@codex.online> X-Mailer: git-send-email 2.28.0 In-Reply-To: <0730D7D7-22C1-465B-8242-40C3E78659CB@codex.online> References: <0730D7D7-22C1-465B-8242-40C3E78659CB@codex.online> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/2] avformat/mxfdec: Read video range from CDCIEssenceDescriptor X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" * Capture black_ref, white_ref and color_range and recognise full and narrow range. Signed-off-by: Harry Mallon --- libavformat/mxfdec.c | 37 ++++++++++++++++++++++++++++++++++ tests/ref/fate/mxf-probe-dnxhd | 2 +- tests/ref/fate/mxf-probe-dv25 | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 4b56984b77..7e1686f0df 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -199,6 +199,9 @@ typedef struct MXFDescriptor { int bits_per_sample; int64_t duration; /* ContainerDuration optional property */ unsigned int component_depth; + unsigned int black_ref_level; + unsigned int white_ref_level; + unsigned int color_range; unsigned int horiz_subsampling; unsigned int vert_subsampling; UID *sub_descriptors_refs; @@ -1222,6 +1225,15 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int case 0x3302: descriptor->horiz_subsampling = avio_rb32(pb); break; + case 0x3304: + descriptor->black_ref_level = avio_rb32(pb); + break; + case 0x3305: + descriptor->white_ref_level = avio_rb32(pb); + break; + case 0x3306: + descriptor->color_range = avio_rb32(pb); + break; case 0x3308: descriptor->vert_subsampling = avio_rb32(pb); break; @@ -2157,6 +2169,30 @@ static int mxf_add_metadata_stream(MXFContext *mxf, MXFTrack *track) return 0; } +static enum AVColorRange mxf_get_color_range(MXFContext *mxf, MXFDescriptor *descriptor) +{ + if (descriptor->black_ref_level || descriptor->white_ref_level || descriptor->color_range) { + /* CDCI range metadata */ + if (!descriptor->component_depth) + return AVCOL_RANGE_UNSPECIFIED; + if (descriptor->black_ref_level == 0 && + descriptor->white_ref_level == ((1<component_depth) - 1) && + (descriptor->color_range == (1<component_depth) || + descriptor->color_range == ((1<component_depth) - 1))) + return AVCOL_RANGE_JPEG; + if (descriptor->component_depth >= 8 && + 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)) + 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, + descriptor->white_ref_level, descriptor->component_depth); + } + + return AVCOL_RANGE_UNSPECIFIED; +} + static int mxf_parse_structural_metadata(MXFContext *mxf) { MXFPackage *material_package = NULL; @@ -2492,6 +2528,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) st->display_aspect_ratio = descriptor->aspect_ratio; + st->codecpar->color_range = mxf_get_color_range(mxf, descriptor); st->codecpar->color_primaries = mxf_get_codec_ul(ff_mxf_color_primaries_uls, &descriptor->color_primaries_ul)->id; st->codecpar->color_trc = mxf_get_codec_ul(ff_mxf_color_trc_uls, &descriptor->color_trc_ul)->id; st->codecpar->color_space = mxf_get_codec_ul(ff_mxf_color_space_uls, &descriptor->color_space_ul)->id; diff --git a/tests/ref/fate/mxf-probe-dnxhd b/tests/ref/fate/mxf-probe-dnxhd index 012d3ea1d9..5a6221b1d5 100644 --- a/tests/ref/fate/mxf-probe-dnxhd +++ b/tests/ref/fate/mxf-probe-dnxhd @@ -124,7 +124,7 @@ sample_aspect_ratio=1:1 display_aspect_ratio=4:3 pix_fmt=yuv422p level=-99 -color_range=unknown +color_range=tv color_space=bt709 color_transfer=bt709 color_primaries=bt709 diff --git a/tests/ref/fate/mxf-probe-dv25 b/tests/ref/fate/mxf-probe-dv25 index 810f145f41..ffd26c4dfd 100644 --- a/tests/ref/fate/mxf-probe-dv25 +++ b/tests/ref/fate/mxf-probe-dv25 @@ -16,7 +16,7 @@ sample_aspect_ratio=16:15 display_aspect_ratio=4:3 pix_fmt=yuv420p level=-99 -color_range=unknown +color_range=tv color_space=unknown color_transfer=bt470m color_primaries=unknown From patchwork Thu Aug 20 13:58:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Mallon X-Patchwork-Id: 21770 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5440244B85F for ; Thu, 20 Aug 2020 16:59:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 40CC5687FCF; Thu, 20 Aug 2020 16:59:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51EFE6808B2 for ; Thu, 20 Aug 2020 16:59:27 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id a15so2102266wrh.10 for ; Thu, 20 Aug 2020 06:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codex.online; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4Xa8d+2fh1bCOnmXJFsHyeyNQwGVj9FwAnkX/U3QGD8=; b=bG9FVWrZOGHCC67BcxU3RNDXTk5jDQHRF3OdGqNZP6eOj/i62lWyd5/Ki/ty+swrrr c8wfJfxw8wqKff0VG9Yk3SIhlnuTgzmjsE01chEA6TMVAOwTFIN85yBllfdCduLmtHIa wDxyQd1eRq6oQRxvE04IpZg5BVenpQQvGkt+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Xa8d+2fh1bCOnmXJFsHyeyNQwGVj9FwAnkX/U3QGD8=; b=Xa4/5hBVbdRBElsX+7w4mhW7W2Et44b0ubXK1j+oiqXowkoy4N9iYSRrnXy3Vux9Wp WpXdvgJ60SY4TI0qsZN3BKC0OZcwEGVeqPkvQK1v45ZL2JtBi7G1N7h8FucFrvZuk3Va ZBjZopT77C9WutGv0CvIkyJxo6c2B++Hf5hlvNjL2DlpUXq+n58uOlZMnSpWlE1TUm66 ambV/+QuonbCj/olx/MEaACK1VGx0Rxab2tAFQbxqseWohmUatz2WEjAF2g9izmYTdQR syQUV6ksdr8ZuBPVhGS8+i0oq4YY6oaoN88bLX1UwB3UYaedGCOey8o/q+3b4WMnkLqo fbzw== X-Gm-Message-State: AOAM5326tjgkweYjUW78VrycrTL695tH09zLo6WHdBkTgUTCG8EJJjpl RZc0+OPkN/c8OayT5BpMYIN2CdbA7f7yHA== X-Google-Smtp-Source: ABdhPJzqzdy91rGpLelUO7e6NQR+9GX22S9n+1PY2W2t0dn/be75YNr91UqC6IlxNUotk2SmRpOgjQ== X-Received: by 2002:adf:dfc8:: with SMTP id q8mr3200357wrn.231.1597931966535; Thu, 20 Aug 2020 06:59:26 -0700 (PDT) Received: from localhost ([2a01:4b00:8571:3800:7c6a:d69c:56a4:3d6]) by smtp.gmail.com with ESMTPSA id u6sm3920146wrn.95.2020.08.20.06.59.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2020 06:59:26 -0700 (PDT) From: Harry Mallon To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Aug 2020 14:58:53 +0100 Message-Id: <20200820135853.96869-2-harry.mallon@codex.online> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820135853.96869-1-harry.mallon@codex.online> References: <0730D7D7-22C1-465B-8242-40C3E78659CB@codex.online> <20200820135853.96869-1-harry.mallon@codex.online> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 2/2] libavformat/mxfenc: color_range should be inclusive X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" MXF CDCI color range was being set to (1<component_depth) - 1 for full range but it should be (1<component_depth) is 0 is a valid value. Signed-off-by: Harry Mallon --- libavformat/mxfenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index a38fa6b983..e495b5ba0e 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1160,7 +1160,7 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED) { int black = 0, white = (1<component_depth) - 1, - color = (1<component_depth) - 1; + color = (1<component_depth); if (st->codecpar->color_range == AVCOL_RANGE_MPEG) { black = 1 << (sc->component_depth - 4); white = 235 << (sc->component_depth - 8);