From patchwork Thu Jul 30 15:00:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Mallon X-Patchwork-Id: 21382 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 7C64044BBD9 for ; Thu, 30 Jul 2020 18:00:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68CA868B5F4; Thu, 30 Jul 2020 18:00:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f225.google.com (mail-oi1-f225.google.com [209.85.167.225]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 597FA68B4DA for ; Thu, 30 Jul 2020 18:00:34 +0300 (EEST) Received: by mail-oi1-f225.google.com with SMTP id h3so384481oie.11 for ; Thu, 30 Jul 2020 08:00:34 -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=ab1Wy3zkmm5Ar9eEbF8kHRbt3UE5bNibEd1OQ1y1ykA=; b=TjEwCuYDNUtBa44ARm3EDxfHue6q32kHRZwaHh/Mv5Xg3JdkB+rUz2U/ZIkrBrIaOv kWwh1GavnmH3ZivcnMiE3OIMSVKkIscdmuFkB6syo4DXbLzRKDiSdrOhCUhHGW4+YCpT FbGS2ja7xSp9miiiFl1MhilZbq5/S9knHmils= 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=ab1Wy3zkmm5Ar9eEbF8kHRbt3UE5bNibEd1OQ1y1ykA=; b=GdUeIeSTbgpm00pNYhN0MBQecTuudWtJq/pcXFv9wKvPhAkBU289Cz/z/0mcWPKBZO /QGndhJZVJUZUGmfidYt85dwaoa2iLUwmmLloT9FW74j/Jd8jK/5DXeSEZo7GwhsS1aR RArNEIaIS3LCcJhMNcmt1zKoqRSHQkmZ17VMH8SqZcGW8lpgLIVBOL90hLlAjL8Su0OD yglwckYwdoFTXrbqc4VzwNBACkdwHu9J7S9UsJtUqhy7nB/sU6ohAiHoz4LPVXcRY+Lo cxkiuRGlVrOX9GpQzlVKpzc6jhOO08lGUfUhKeqfLw86rmPW3ZwEbaKS5bPbIP/dwAcx Di5g== X-Gm-Message-State: AOAM531vifsvwmu/i8n+/b+C0PCYAzUXlVXVmCxx7+7hoNYYd69L1j+c Udnd3JEes34eEtzYzu2DiPjgGIXThjFHKfbdL23Po9aNLcpE1Q== X-Google-Smtp-Source: ABdhPJxpNuACYyE6op2j1W5wVFu2ZeWuhHjzekHls3RWmqUmc81ZBLkuQwzBWFbnlkkpN859ZqOtuq6bS4XL X-Received: by 2002:aca:3883:: with SMTP id f125mr11966513oia.27.1596121232589; Thu, 30 Jul 2020 08:00:32 -0700 (PDT) Received: from us3.smtp.exclaimer.net (us3.smtp.exclaimer.net. [23.100.16.236]) by smtp-relay.gmail.com with ESMTPS id n5sm718752oom.4.2020.07.30.08.00.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2020 08:00:32 -0700 (PDT) X-Relaying-Domain: pixsystem.com Received: from mail-wm1-f70.google.com (209.85.128.70) 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); Thu, 30 Jul 2020 15:00:32 +0000 X-ExclaimerHostedSignatures-MessageProcessed: true X-ExclaimerProxyLatency: 12068301 X-ExclaimerImprintLatency: 5035807 X-ExclaimerImprintAction: c7e02d91881840c4b42c34854fdc8265 Received: by mail-wm1-f70.google.com with SMTP id q15so2306795wmj.6 for ; Thu, 30 Jul 2020 08:00:31 -0700 (PDT) X-Received: by 2002:adf:97d3:: with SMTP id t19mr3009962wrb.138.1596121229821; Thu, 30 Jul 2020 08:00:29 -0700 (PDT) X-Received: by 2002:adf:97d3:: with SMTP id t19mr3009945wrb.138.1596121229524; Thu, 30 Jul 2020 08:00:29 -0700 (PDT) Received: from ?IPv6:2a01:4b00:8571:3800:54dc:edf6:5273:4b3f? ([2a01:4b00:8571:3800:54dc:edf6:5273:4b3f]) by smtp.gmail.com with ESMTPSA id f17sm11243085wme.14.2020.07.30.08.00.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2020 08:00:28 -0700 (PDT) From: Harry Mallon Mime-Version: 1.0 Message-Id: <5BCA187A-69EC-4E2A-9768-B400A35E8DB6@codex.online> Date: Thu, 30 Jul 2020 16:00:28 +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] avformat/mxfdec: Read color metadata from MXF 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" Hello, Sorry I wasn't able to send this with git-send-email, I'm trying again with patch inline. The following patch adds reading colour metadata (transfer, primaries and colour space) from standard MXF files. I wrote it without seeing the other patch but it turned out very similar to this one that was never merged https://patchwork.ffmpeg.org/project/ffmpeg/patch/1474694344-31167-1-git-send-email-steven@strobe.cc/ . Thanks. Harry From 3ff4c4187654e92a84ce165365e339995512c5be Mon Sep 17 00:00:00 2001 From: Harry Mallon Date: Mon, 27 Jul 2020 15:52:17 +0100 Subject: [PATCH 1/2] avformat/mxfdec: Read color metadata from MXF Reads color_primaries, color_trc and color_space from mxf headers. ULs are from https://registry.smpte-ra.org/ site. Signed-off-by: Harry Mallon --- libavformat/mxf.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ libavformat/mxf.h | 3 +++ libavformat/mxfdec.c | 15 ++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index 7d154ca9d3..e51fc48a84 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -86,6 +86,55 @@ const MXFCodecUL ff_mxf_codec_tag_uls[] = { { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, 0 }, }; +const MXFCodecUL ff_mxf_color_primaries_uls[] = { + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x01,0x00,0x00 }, 14, AVCOL_PRI_SMPTE170M }, /* SMPTE 170M */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x02,0x00,0x00 }, 14, AVCOL_PRI_BT470BG }, /* ITU-R BT.470 PAL */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x03,0x00,0x00 }, 14, AVCOL_PRI_BT709 }, /* ITU-R BT.709 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x04,0x00,0x00 }, 14, AVCOL_PRI_BT2020 }, /* ITU-R BT.2020 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x05,0x00,0x00 }, 14, AVCOL_PRI_SMPTE428 }, /* SMPTE-DC28 DCDM */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x06,0x00,0x00 }, 14, AVCOL_PRI_SMPTE432 }, /* P3D65 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x08,0x00,0x00 }, 14, AVCOL_PRI_SMPTE428 }, /* Cinema Mezzanine */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x0a,0x00,0x00 }, 14, AVCOL_PRI_SMPTE431 }, /* P3DCI */ + /* alternate mappings for encoding */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x01,0x00,0x00 }, 14, AVCOL_PRI_SMPTE240M }, /* = AVCOL_PRI_SMPTE170M */ + + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_PRI_UNSPECIFIED }, +}; + +const MXFCodecUL ff_mxf_color_trc_uls[] = { + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00 }, 14, AVCOL_TRC_GAMMA22 }, /* ITU-R BT.470 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00 }, 14, AVCOL_TRC_BT709 }, /* ITU-R BT.709 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x03,0x00,0x00 }, 14, AVCOL_TRC_SMPTE240M }, /* SMPTE 240M */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x04,0x00,0x00 }, 14, AVCOL_TRC_BT709 }, /* SMPTE 274/296M (must appear after ITU-R BT.709) */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x05,0x00,0x00 }, 14, AVCOL_TRC_BT1361_ECG }, /* ITU-R BT.1361 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x06,0x00,0x00 }, 14, AVCOL_TRC_LINEAR }, /* Linear */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x08,0x04,0x01,0x01,0x01,0x01,0x07,0x00,0x00 }, 14, AVCOL_TRC_SMPTE428 }, /* SMPTE-DC28 DCDM */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x08,0x00,0x00 }, 14, AVCOL_TRC_IEC61966_2_4 }, /* IEC 61966-2-4 xvYCC */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0E,0x04,0x01,0x01,0x01,0x01,0x09,0x00,0x00 }, 14, AVCOL_TRC_BT2020_10 }, /* ITU-R BT.2020 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x0A,0x00,0x00 }, 14, AVCOL_TRC_SMPTE2084 }, /* SMPTE ST 2084 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x0B,0x00,0x00 }, 14, AVCOL_TRC_ARIB_STD_B67 }, /* Hybrid Log-Gamma OETF */ + /* alternate mappings for encoding */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00 }, 14, AVCOL_TRC_GAMMA28 }, /* = AVCOL_TRC_GAMMA22 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00 }, 14, AVCOL_TRC_SMPTE170M }, /* = AVCOL_TRC_BT709 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0E,0x04,0x01,0x01,0x01,0x01,0x09,0x00,0x00 }, 14, AVCOL_TRC_BT2020_12 }, /* = AVCOL_TRC_BT2020_10 */ + + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_TRC_UNSPECIFIED }, +}; + +/* aka Coding Equations */ +const MXFCodecUL ff_mxf_color_space_uls[] = { + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x02,0x01,0x00,0x00 }, 14, AVCOL_SPC_BT470BG }, /* ITU-R BT.601 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x02,0x02,0x00,0x00 }, 14, AVCOL_SPC_BT709 }, /* ITU-R BT.709 */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x02,0x03,0x00,0x00 }, 14, AVCOL_SPC_SMPTE240M }, /* SMPTE 240M */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x04,0x00,0x00 }, 14, AVCOL_SPC_YCGCO }, /* YCgCo */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x05,0x00,0x00 }, 14, AVCOL_SPC_RGB }, /* GBR */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x06,0x00,0x00 }, 14, AVCOL_SPC_BT2020_NCL }, /* ITU-R BT.2020 Non-Constant Luminance */ + /* alternate mappings for encoding */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x02,0x03,0x00,0x00 }, 14, AVCOL_SPC_SMPTE170M }, /* = AVCOL_SPC_SMPTE240M */ + + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_SPC_UNSPECIFIED }, +}; + static const struct { enum AVPixelFormat pix_fmt; const char data[16]; diff --git a/libavformat/mxf.h b/libavformat/mxf.h index f2fff2781e..fc587f19f0 100644 --- a/libavformat/mxf.h +++ b/libavformat/mxf.h @@ -91,6 +91,9 @@ extern const MXFCodecUL ff_mxf_data_definition_uls[]; extern const MXFCodecUL ff_mxf_codec_uls[]; extern const MXFCodecUL ff_mxf_pixel_format_uls[]; extern const MXFCodecUL ff_mxf_codec_tag_uls[]; +extern const MXFCodecUL ff_mxf_color_primaries_uls[]; +extern const MXFCodecUL ff_mxf_color_trc_uls[]; +extern const MXFCodecUL ff_mxf_color_space_uls[]; int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat *pix_fmt); int ff_mxf_get_content_package_rate(AVRational time_base); diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index f0975f409e..4b56984b77 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -207,6 +207,9 @@ typedef struct MXFDescriptor { uint8_t *extradata; int extradata_size; enum AVPixelFormat pix_fmt; + UID color_primaries_ul; + UID color_trc_ul; + UID color_space_ul; } MXFDescriptor; typedef struct MXFIndexTableSegment { @@ -1201,9 +1204,18 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int descriptor->aspect_ratio.num = avio_rb32(pb); descriptor->aspect_ratio.den = avio_rb32(pb); break; + case 0x3210: + avio_read(pb, descriptor->color_trc_ul, 16); + break; case 0x3212: descriptor->field_dominance = avio_r8(pb); break; + case 0x3219: + avio_read(pb, descriptor->color_primaries_ul, 16); + break; + case 0x321A: + avio_read(pb, descriptor->color_space_ul, 16); + break; case 0x3301: descriptor->component_depth = avio_rb32(pb); break; @@ -2480,6 +2492,9 @@ 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_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; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul); /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */