From patchwork Sat Sep 24 05:19:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Robertson X-Patchwork-Id: 696 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp926468vsd; Fri, 23 Sep 2016 22:19:39 -0700 (PDT) X-Received: by 10.194.134.161 with SMTP id pl1mr9509772wjb.81.1474694379713; Fri, 23 Sep 2016 22:19:39 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x17si6072717wma.104.2016.09.23.22.19.37; Fri, 23 Sep 2016 22:19:39 -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=@strobe-cc.20150623.gappssmtp.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E812689B33; Sat, 24 Sep 2016 08:19:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f68.google.com (mail-pa0-f68.google.com [209.85.220.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DDE3368997D for ; Sat, 24 Sep 2016 08:19:10 +0300 (EEST) Received: by mail-pa0-f68.google.com with SMTP id gg10so471482pac.2 for ; Fri, 23 Sep 2016 22:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=strobe-cc.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=/UrpdgojpDhpoje0vQUypz4iGgEX5SkTLuEHXVxqLtU=; b=XTO9UZPtlfMhr8OqSH/vSX7vzW0ro1ngILZSKA63PbAnnFdGJDVzUxLZ3YyWJ+MdBm nZyNYxBhO2WkI4bRXbOLcNsZHljCYCw9g/2A+wse8K9K6KF6jIAX7NKN9YFYMf4pGg5D zrZBRY1w7qC5MYKwD7uSjTfIipGwE20Cib9Um9nFtw+He5v/37td9ANDDhYdROZh43oB W/McvW4j91g4Zo/ZVCjwOvxSyLykNPCglrD4IFwqFEI4U48tBbRiZWhlutfQciyDkYyQ WW37mfpu+Rl1TDVl1aHc1H72X7ZeBAIppBWkbkJZBtR6OAy7afuQ1CzviLQsP3Je2ltm fBmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/UrpdgojpDhpoje0vQUypz4iGgEX5SkTLuEHXVxqLtU=; b=nHiR1NNCRI9pjVPAHZx/tleGk8TwH7Ud6zTMWQ2V6DunHaKV6qthZMrbi3LWKoIlAu qMFZpL8WGP4USLRsmHTaE9Tng/Gl9G/EbcHzcK24Zb79AdD1ut7UMWpknR+c9LFJWIE7 Zn7K0aON7WH3o8CyX3VyNqgJysA/AuWPKUP7uWed9InwgnorHt1gXVioQdESh4Xm7vk6 8lMrKWX42MLwN1dfeX+Sq5BcWMm64GPVkizFhCLdgZ51LAZFIaoWoxm2kEgye2p0vOwO d4LtY2YlTZnvbi2wroqhKqqPgncmEtnvxJZByjeL+JTE/x89PVJQbT3qZBFZb9LsGohO tadg== X-Gm-Message-State: AE9vXwPzTFeeE2gZKxmJjHhEsJnpVsqeZzusMWVkHIf/Qe5Vm2TUUEEifyer4EqKyuKYUA== X-Received: by 10.66.73.3 with SMTP id h3mr18593359pav.87.1474694365470; Fri, 23 Sep 2016 22:19:25 -0700 (PDT) Received: from strobe.sbo.corp.google.com ([100.106.156.15]) by smtp.gmail.com with ESMTPSA id ic2sm15093355pad.24.2016.09.23.22.19.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Sep 2016 22:19:24 -0700 (PDT) From: Steven Robertson To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Sep 2016 22:19:03 -0700 Message-Id: <1474694344-31167-1-git-send-email-steven@strobe.cc> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [FFmpeg-devel] [PATCH 1/2] [avformat/mxf] Add core colorimetry support to 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 Cc: Steven Robertson MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Steven Robertson --- libavformat/mxf.c | 33 +++++++++++++++++++++++++++++++++ libavformat/mxf.h | 3 +++ libavformat/mxfdec.c | 29 +++++++++++++++++++++++++++++ libavformat/mxfenc.c | 36 +++++++++++++++++++++++++++++++----- 4 files changed, 96 insertions(+), 5 deletions(-) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index e9c48e8..ea7c1db 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -84,6 +84,39 @@ 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_transfer_characteristics_uls[] = { + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00 }, 14, AVCOL_TRC_GAMMA22 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00 }, 14, AVCOL_TRC_BT709 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x03,0x00,0x00 }, 14, AVCOL_TRC_SMPTE240M }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x04,0x00,0x00 }, 14, AVCOL_TRC_BT709 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x05,0x00,0x00 }, 14, AVCOL_TRC_BT1361_ECG }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x01,0x06,0x00,0x00 }, 14, AVCOL_TRC_LINEAR }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x08,0x04,0x01,0x01,0x01,0x01,0x07,0x00,0x00 }, 14, AVCOL_TRC_SMPTEST428_1 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x08,0x00,0x00 }, 14, AVCOL_TRC_IEC61966_2_4 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0E,0x04,0x01,0x01,0x01,0x01,0x09,0x00,0x00 }, 14, AVCOL_TRC_BT2020_10 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x0A,0x00,0x00 }, 14, AVCOL_TRC_SMPTEST2084 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x01,0x0B,0x00,0x00 }, 14, AVCOL_TRC_ARIB_STD_B67 }, + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_TRC_RESERVED0 }, +}; + +const MXFCodecUL ff_mxf_coding_equations_uls[] = { + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x02,0x01,0x00,0x00 }, 14, AVCOL_SPC_BT470BG }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x02,0x02,0x00,0x00 }, 14, AVCOL_SPC_BT709 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x02,0x03,0x00,0x00 }, 14, AVCOL_SPC_SMPTE240M }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x04,0x00,0x00 }, 14, AVCOL_SPC_YCOCG }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x05,0x00,0x00 }, 14, AVCOL_SPC_RGB }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x02,0x06,0x00,0x00 }, 14, AVCOL_SPC_BT2020_NCL }, + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_SPC_UNSPECIFIED }, +}; + +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 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x02,0x00,0x00 }, 14, AVCOL_PRI_BT470M }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x06,0x04,0x01,0x01,0x01,0x03,0x03,0x00,0x00 }, 14, AVCOL_PRI_BT709 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x01,0x01,0x03,0x04,0x00,0x00 }, 14, AVCOL_PRI_BT2020 }, + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVCOL_PRI_RESERVED0 }, +}; + static const struct { enum AVPixelFormat pix_fmt; const char data[16]; diff --git a/libavformat/mxf.h b/libavformat/mxf.h index f3db1f9..1c9ca2a 100644 --- a/libavformat/mxf.h +++ b/libavformat/mxf.h @@ -79,6 +79,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_transfer_characteristics_uls[]; +extern const MXFCodecUL ff_mxf_coding_equations_uls[]; +extern const MXFCodecUL ff_mxf_color_primaries_uls[]; int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat *pix_fmt); const MXFSamplesPerFrame *ff_mxf_get_samples_per_frame(AVFormatContext *s, AVRational time_base); diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 1939761..d012e41 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -188,6 +188,9 @@ typedef struct MXFDescriptor { uint8_t *extradata; int extradata_size; enum AVPixelFormat pix_fmt; + UID color_trc_ul; + UID color_primaries_ul; + UID color_space_ul; } MXFDescriptor; typedef struct MXFIndexTableSegment { @@ -1000,9 +1003,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; @@ -1853,6 +1865,9 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) const MXFCodecUL *codec_ul = NULL; const MXFCodecUL *container_ul = NULL; const MXFCodecUL *pix_fmt_ul = NULL; + const MXFCodecUL *color_trc_ul = NULL; + const MXFCodecUL *color_primaries_ul = NULL; + const MXFCodecUL *color_space_ul = NULL; AVStream *st; AVTimecode tc; int flags; @@ -2085,6 +2100,20 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } } + + color_primaries_ul = mxf_get_codec_ul(ff_mxf_color_primaries_uls, + &descriptor->color_primaries_ul); + if (color_primaries_ul->uid[0]) + st->codecpar->color_primaries = color_primaries_ul->id; + color_space_ul = mxf_get_codec_ul(ff_mxf_coding_equations_uls, + &descriptor->color_space_ul); + if (color_space_ul->uid[0]) + st->codecpar->color_space = color_space_ul->id; + color_trc_ul = mxf_get_codec_ul(ff_mxf_transfer_characteristics_uls, + &descriptor->color_trc_ul); + if (color_trc_ul->uid[0]) + st->codecpar->color_trc = color_trc_ul->id; + st->need_parsing = AVSTREAM_PARSE_HEADERS; if (material_track->sequence->origin) { av_dict_set_int(&st->metadata, "material_track_origin", material_track->sequence->origin, 0); diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 7733ef8..eb77f3a 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -415,9 +415,12 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = { { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */ { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */ { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */ + { 0x3210, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x01,0x02,0x00}}, /* Transfer Characteristic */ { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* Presentation Y offset */ { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */ { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */ + { 0x321A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x03,0x01,0x00}}, /* Coding Equations */ + { 0x3219, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x04,0x01,0x02,0x01,0x01,0x06,0x01,0x00}}, /* Color Primaries */ { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */ { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */ // CDCI Picture Essence Descriptor @@ -576,11 +579,10 @@ static void mxf_free(AVFormatContext *s) } } -static const MXFCodecUL *mxf_get_data_definition_ul(int type) +static const MXFCodecUL *mxf_get_ul_by_id(const MXFCodecUL *uls, int id) { - const MXFCodecUL *uls = ff_mxf_data_definition_uls; while (uls->uid[0]) { - if (type == uls->id) + if (id == uls->id) break; uls++; } @@ -835,7 +837,7 @@ static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) if (st == mxf->timecode_track) avio_write(pb, smpte_12m_timecode_track_data_ul, 16); else { - const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codecpar->codec_type); + const MXFCodecUL *data_def_ul = mxf_get_ul_by_id(ff_mxf_data_definition_uls, st->codecpar->codec_type); avio_write(pb, data_def_ul->uid, 16); } @@ -1011,6 +1013,9 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke { MXFStreamContext *sc = st->priv_data; AVIOContext *pb = s->pb; + const MXFCodecUL* color_trc_ul; + const MXFCodecUL* color_primaries_ul; + const MXFCodecUL* color_space_ul; int stored_height = (st->codecpar->height+15)/16*16; int display_height; int f1, f2; @@ -1020,6 +1025,16 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke if (sc->signal_standard) desc_size += 5; + color_trc_ul = mxf_get_ul_by_id(ff_mxf_transfer_characteristics_uls, st->codecpar->color_trc); + if (color_trc_ul->uid[0]) + desc_size += 20; + color_primaries_ul = mxf_get_ul_by_id(ff_mxf_color_primaries_uls, st->codecpar->color_primaries); + if (color_primaries_ul->uid[0]) + desc_size += 20; + color_space_ul = mxf_get_ul_by_id(ff_mxf_coding_equations_uls, st->codecpar->color_space); + if (color_space_ul->uid[0]) + desc_size += 20; + mxf_write_generic_desc(s, st, key, desc_size); mxf_write_local_tag(pb, 4, 0x3203); @@ -1082,7 +1097,6 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke f1 *= 2; } - mxf_write_local_tag(pb, 16, 0x320D); avio_wb32(pb, 2); avio_wb32(pb, 4); @@ -1101,6 +1115,18 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke avio_w8(pb, sc->field_dominance); } + if (color_trc_ul->uid[0]) { + mxf_write_local_tag(pb, 16, 0x3210); + avio_write(pb, color_trc_ul->uid, 16); + } + if (color_primaries_ul->uid[0]) { + mxf_write_local_tag(pb, 16, 0x3219); + avio_write(pb, color_primaries_ul->uid, 16); + } + if (color_space_ul->uid[0]) { + mxf_write_local_tag(pb, 16, 0x321A); + avio_write(pb, color_space_ul->uid, 16); + } } static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)