From patchwork Wed Aug 12 09:35:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Mallon X-Patchwork-Id: 21603 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 5035A448161 for ; Wed, 12 Aug 2020 12:35:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1493E68B20E; Wed, 12 Aug 2020 12:35:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f226.google.com (mail-pf1-f226.google.com [209.85.210.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 775D968A345 for ; Wed, 12 Aug 2020 12:35:40 +0300 (EEST) Received: by mail-pf1-f226.google.com with SMTP id f193so719187pfa.12 for ; Wed, 12 Aug 2020 02:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codex.online; s=google; h=from:mime-version:subject:message-id:date:to; bh=4AXJx1MbKHLKUS+1nvF6zbVG6qrQ24sSQTvgWkbXLgw=; b=NXW+8NlfRuyooFuXTJXbX4nbo7h5r2M6CvYl+2Iu0fsNv11NVKDSXiTwMCAUATzpTV YCkdqn3/k28wNaP0UFoudYHlQPGvNRRmFzO+7QQg8B2f3/+3iTpI+pMCV+MG0z22zlfE kFle8PiVpN16HsUyu0aLuW+C38Q/Y2MKq+Fs8= 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:message-id:date:to; bh=4AXJx1MbKHLKUS+1nvF6zbVG6qrQ24sSQTvgWkbXLgw=; b=Xh+iB8vX7f3b+0O7FaAEvT0efBbgbQ4dU7D6WPVg8j/J4NXDFFueSvlt0+K5198B4G 6cDwG3tHfgTRQqfZrElIIQjEgnOmj+8Kb16+2m7P4KzOFJyYk68V8gM3+yiw/7PtEbos jv980ark3hc7st38Spw/1vhfZ5q2+GILyywWHJhz7ZHTNktnFttYRtUn07HX/gSZ7IQn yTi3S/q0VoRqSoU9kgD6PCvPtHDUdgSbrPBjayOHDlszl2KD+gxskoH40aykLP41MoG/ ayZ/lwEueV50c4eNCoGBEOLCiVcoJcEJD65fiueTD9OvnjmgfELcGANsVqOak/sn4jYf UhfQ== X-Gm-Message-State: AOAM530IqHZVAbMfFrFr/jVIaQ0buqTtVi5hVtsqb15GzGKvDUf3jHA9 Jvq89OtksaSHtwGSbYrpsT9oorRmSTv2d0MMGKun4bd678NwmQ== X-Google-Smtp-Source: ABdhPJy29j578WrkjWDMlD1Gpj4/+wsKy7MDrqHbq1dFEd7WIFuDAuVU8em89ZWfYrbEHMdRa4D5uaw5qh2u X-Received: by 2002:a63:db18:: with SMTP id e24mr4154796pgg.192.1597224938510; Wed, 12 Aug 2020 02:35:38 -0700 (PDT) Received: from us3.smtp.exclaimer.net (us3.smtp.exclaimer.net. [23.100.16.236]) by smtp-relay.gmail.com with ESMTPS id np15sm164737pjb.16.2020.08.12.02.35.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2020 02:35:38 -0700 (PDT) X-Relaying-Domain: pixsystem.com Received: from mail-wr1-f69.google.com (209.85.221.69) by us3.smtp.exclaimer.net (23.100.16.236) with Exclaimer Signature Manager ESMTP Proxy us3.smtp.exclaimer.net (tlsversion=TLS12, tlscipher=TLS_ECDHE_WITH_AES256_SHA1); Wed, 12 Aug 2020 09:35:38 +0000 X-ExclaimerHostedSignatures-MessageProcessed: true X-ExclaimerProxyLatency: 8444795 X-ExclaimerImprintLatency: 2128877 X-ExclaimerImprintAction: e80a6e01afb64054a819114bddf07562 Received: by mail-wr1-f69.google.com with SMTP id w1so687541wro.4 for ; Wed, 12 Aug 2020 02:35:37 -0700 (PDT) X-Received: by 2002:a1c:7fd3:: with SMTP id a202mr7600425wmd.67.1597224936210; Wed, 12 Aug 2020 02:35:36 -0700 (PDT) X-Received: by 2002:a1c:7fd3:: with SMTP id a202mr7600408wmd.67.1597224936015; Wed, 12 Aug 2020 02:35:36 -0700 (PDT) Received: from ?IPv6:2a01:4b00:8571:3800:40f8:ddf2:24e:8b9? ([2a01:4b00:8571:3800:40f8:ddf2:24e:8b9]) by smtp.gmail.com with ESMTPSA id w132sm3023212wma.32.2020.08.12.02.35.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2020 02:35:35 -0700 (PDT) From: Harry Mallon Mime-Version: 1.0 Message-Id: Date: Wed, 12 Aug 2020 10:35:34 +0100 To: ffmpeg-devel@ffmpeg.org X-Mailer: Apple Mail (2.3608.120.23.2.1) X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] 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" Thanks to Tomas for reviewing these MXF patches. Here is another. FFMPEG already writes out the three range tags. This just reads them in. Best, Harry From c49f77d1e887d8c84752df11213dcf5afa8f761e Mon Sep 17 00:00:00 2001 From: Harry Mallon Date: Wed, 12 Aug 2020 10:26:23 +0100 Subject: [PATCH] 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index fa9dcab658..9d2563239e 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -201,6 +201,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; @@ -1230,6 +1233,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; @@ -2557,6 +2569,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) 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; + if (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->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; + } if (descriptor->mastering) { ret = av_stream_add_side_data(st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, (uint8_t *)descriptor->mastering,