From patchwork Thu Aug 13 10:04:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Mallon X-Patchwork-Id: 21626 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 E59E644A080 for ; Thu, 13 Aug 2020 13:05:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD46A68AE37; Thu, 13 Aug 2020 13:05:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f226.google.com (mail-pg1-f226.google.com [209.85.215.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0918A6880DC for ; Thu, 13 Aug 2020 13:04:57 +0300 (EEST) Received: by mail-pg1-f226.google.com with SMTP id t6so2583536pgq.1 for ; Thu, 13 Aug 2020 03:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codex.online; s=google; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=w4kD36U24fubE/vTDDT0VV/BDN7yQ9zzHYKHWXqdT8Q=; b=QSoBr4C0mptI97MeX52MSp5erqFPAsuu6gtoAatzXKPTEHt5cYFFUaXEUNjkOS6oGP ojn2Hsigyhfr8UsaH3IPSQKDHJhMD6fgYuyghO3g86zYQl2yYlCuHJ9xeAgwXxW1hbmi Wi/gubOpikTs4OI3D84DRYjFfVl8+TjxX06Ls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=w4kD36U24fubE/vTDDT0VV/BDN7yQ9zzHYKHWXqdT8Q=; b=hKcsMNkzmLOo7qWnWm2+6KXsNpBLPVlztaFvWC4t6KajP+IPmA5mfJuCbAczeRRSek lfRWfRx5PhfO/zfklDZx8xMdgiqThTd+QcpocUsW+uOPUbq9TjJ+6QmposPsD/6D3AIr KhvvXHWS7MH9sgY90eZEgQiil6NNhsJcEwV7g1hOyJf27bli1QpCsBtz59t+2fglJB3d ICLYZM0Ddy0fTySU8dWt4xKAmL1xdJeheqpfYdfAsmLdF1/Dvk6Jr6DeDu7FdfJz0e9s s+A3SDwDPzSU9kmRuzY6r7bApKZ/XRP7CKN8+xGKXWAOPIxgH7PUN34Qfnm77JsZamu0 rHeQ== X-Gm-Message-State: AOAM533h80Hx6knUOeY8aK3OO6DRdTJMnBTCkPEb0U1Q0TRBWBxVjRVI B/vs96ovnXO7WRBybjhh4ibjLSW92FQ9l8VA97JRLjkfgYvCdg== X-Google-Smtp-Source: ABdhPJy6PPF7NRAe4JYa25RvUQnG+E6DvFJgurkcAo8VB4bPWNIPdKp3V51qwfNG/cfjN47gbNLa2WSXDnOU X-Received: by 2002:a65:5849:: with SMTP id s9mr1367833pgr.145.1597313095633; Thu, 13 Aug 2020 03:04:55 -0700 (PDT) Received: from us2.smtp.exclaimer.net (us2.smtp.exclaimer.net. [104.209.35.28]) by smtp-relay.gmail.com with ESMTPS id cp14sm537583pjb.0.2020.08.13.03.04.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2020 03:04:55 -0700 (PDT) X-Relaying-Domain: pixsystem.com Received: from mail-wm1-f69.google.com (209.85.128.69) by us2.smtp.exclaimer.net (104.209.35.28) with Exclaimer Signature Manager ESMTP Proxy us2.smtp.exclaimer.net (tlsversion=TLS12, tlscipher=TLS_ECDHE_WITH_AES256_SHA1); Thu, 13 Aug 2020 10:04:54 +0000 X-ExclaimerHostedSignatures-MessageProcessed: true X-ExclaimerProxyLatency: 17817068 X-ExclaimerImprintLatency: 2889788 X-ExclaimerImprintAction: 44d73bb1438b484bbec8094ba6bd665f Received: by mail-wm1-f69.google.com with SMTP id h6so1780473wml.8 for ; Thu, 13 Aug 2020 03:04:53 -0700 (PDT) X-Received: by 2002:a1c:bcd6:: with SMTP id m205mr3541333wmf.47.1597313091725; Thu, 13 Aug 2020 03:04:51 -0700 (PDT) X-Received: by 2002:a1c:bcd6:: with SMTP id m205mr3541298wmf.47.1597313091385; Thu, 13 Aug 2020 03:04:51 -0700 (PDT) Received: from ?IPv6:2a01:4b00:8571:3800:39af:a8b7:34f8:18b9? ([2a01:4b00:8571:3800:39af:a8b7:34f8:18b9]) by smtp.gmail.com with ESMTPSA id 33sm9917347wri.16.2020.08.13.03.04.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2020 03:04:50 -0700 (PDT) From: Harry Mallon Mime-Version: 1.0 Date: Thu, 13 Aug 2020 11:04:50 +0100 References: To: FFmpeg development discussions and patches In-Reply-To: Message-Id: <0730D7D7-22C1-465B-8242-40C3E78659CB@codex.online> X-Mailer: Apple Mail (2.3608.120.23.2.1) X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH v4] avformat/mxfdec: Read video range from PictureDescriptor 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" Here is an updated patch (now hopefully going with correct email headers). From 5866d0dc5536a6ea3f6a899c3d09f19df083c16a Mon Sep 17 00:00:00 2001 From: Harry Mallon Date: Wed, 12 Aug 2020 10:26:23 +0100 Subject: [PATCH v4] avformat/mxfdec: Read video range from PictureDescriptor * Capture black_ref, white_ref and color_range and recognise full and narrow range. Signed-off-by: Harry Mallon --- libavformat/mxfdec.c | 29 +++++++++++++++++++++++++++++ tests/ref/fate/mxf-probe-dnxhd | 2 +- tests/ref/fate/mxf-probe-dv25 | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 4b56984b77..0831ad5768 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; @@ -2492,6 +2504,23 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) st->display_aspect_ratio = descriptor->aspect_ratio; + if (descriptor->component_depth && + descriptor->black_ref_level == 0 && + descriptor->white_ref_level == ((1<component_depth) - 1) && + descriptor->color_range == ((1<component_depth) - 1)) { + st->codecpar->color_range = AVCOL_RANGE_JPEG; + } + else 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)) { + st->codecpar->color_range = AVCOL_RANGE_MPEG; + } + else if (descriptor->black_ref_level || descriptor->white_ref_level || descriptor->color_range) { + avpriv_request_sample(mxf->fc, "Unrecognized color range (range %d, b %d, w %d, depth %d)", + descriptor->color_range, descriptor->black_ref_level, + descriptor->white_ref_level, descriptor->component_depth); + } 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