From patchwork Wed Feb 1 12:42:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran O Leary X-Patchwork-Id: 2399 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2419839vsb; Wed, 1 Feb 2017 04:49:54 -0800 (PST) X-Received: by 10.223.163.199 with SMTP id m7mr2429906wrb.63.1485953394821; Wed, 01 Feb 2017 04:49:54 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t81si21183368wme.38.2017.02.01.04.49.54; Wed, 01 Feb 2017 04:49:54 -0800 (PST) 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=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 457E3687EE4; Wed, 1 Feb 2017 14:49:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f176.google.com (mail-qt0-f176.google.com [209.85.216.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CF8D680CF8 for ; Wed, 1 Feb 2017 14:49:42 +0200 (EET) Received: by mail-qt0-f176.google.com with SMTP id w20so193602309qtb.1 for ; Wed, 01 Feb 2017 04:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=dUQno42Its8/R5HXa7fYNPD2A3Omohjz14OzM2GUAWU=; b=RShjAZG848/ao5TNg8B+QA26kRvFnbFm9TFjsjBTM33+KpE2hSVEPuV+FGONACL35y UsdhoWlgVQplozRFuArAK0EcJwW/IY9W8a5n5uX8wrqqHCm9K2TbI0sEKySOZ9M5KFtq 0v4wZ3YV3oIIWUXZfQswjdo4Y/Bs8Cqg35W+oe+B/TF2KxSanj/wPbQc8KA5ZEw72eER WwJ6nuDo3hajRFlQAlOFYAgtRnx1xzaLsr1tT/cRqlJx4qVVp03GRa2fUL3EOwiWug/x lBnMW4JAdkqiJ5DBMKxbuStVJUqV6HaKGynH5/5L/viRFEbJiClOsbR3QCv0qNEOoo0Y ArvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=dUQno42Its8/R5HXa7fYNPD2A3Omohjz14OzM2GUAWU=; b=Ba2MM2ceLRawo1ggrjYgpXvwnZB6+q07FWjRh1yCfNxBGMS2v+GABzNIFP+ycRJNAN PnfBsSelYtAnqjWUEsbAdp1OUsyAeRkY5Zipy/JRVlckNJYg1vUpUuKLK4GplTjWsroL nF/Yv/J4yPF0N3AZdwOgX3/mlsKAeQVgbvXnK+u3TZkfBl0qO4lm9FgtHzj4VUp4qb0i DD6PlIfIG+phBqGUlYUHqemnpDI1WLnCj5hhX88XbrXts27fWoRjraSdDz3CB4+vQPA4 Y+iIRy8wl5RDn64OaUVAMC7ib3KTYnsXSwUe8WLLX07tncDMiMP4enQHpUGt8ZmY/Q+f Uy7A== X-Gm-Message-State: AIkVDXJF53F93XDY3eDEZ7cnBqqCI5QX5/xOrqlOXGBiNjgu0IiEcho0octKqqpwVG++QEyq8x1ugREQQhM8ug== X-Received: by 10.200.35.150 with SMTP id q22mr2556844qtq.237.1485952970686; Wed, 01 Feb 2017 04:42:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.55.113.70 with HTTP; Wed, 1 Feb 2017 04:42:50 -0800 (PST) From: Kieran O Leary Date: Wed, 1 Feb 2017 12:42:50 +0000 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] avcodec/dpxenc: support colour metadata in DPX encoder, fixes ticket #6023 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: Vittorio Giovara , "Murray, Kathleen" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hello, I'm cc'ing Vittorio as I don't think that he's subscribed to the list but he's contributed to dpxenc.c and recent colorspace filters. The same with Kate Murray from the Library of Congress who knows a lot more about DPX than me. Apologies if this is inappropriate. I mostly based this patch on other ffmpeg encoders, such as pncenc.c. I'm not really a C coder, I'm a moving image archivist who needs to be able to specify colour metadata in DPX for various workflows. Please excuse my ignorance/mistakes. This patch adds documentation and two command line options for the DPX encoder: -trc (Transfer Characteristics) and -clr (Colorimetric Specification), which set colour metadata values in a DPX file. Currently these are hardcoded to always be 2, aka Linear. Ticket #6023 is related to this, but there have also been many mailing list posts about this issue: https://ffmpeg.org/pipermail/ffmpeg-user/2015-March/025630.html https://ffmpeg.org/pipermail/ffmpeg-user/2015-December/029456.html I've kept the default values as 2 (Linear) as this is what was originally in dpxenc, but I'm not sure of the value of this really. I think that there's more value in a default of 0 (User-defined) which would just leave the values unspecified. Or perhaps no value at all! The initial default of 2 for colorimetric was potentially useless as 2 is listed as 'Not applicable' for colorimetric specification in SMPTE 268M-2003. The values for each of these options are the integers listed in the SMPTE standards doc: https://web.archive.org/web/20050706060025/http://www.smpte.org/smpte_store/standards/pdf/s268m.pdf Initially I just had one argument that set the Transfer Characteristic and Colorimetric Specification to the same value, but perhaps some use cases could require that these values be different? I'm not sure if they ever would. I have never seen real world files that suggest this but I can edit this if it seems weird. Some of the values from 0-12 are listed as 'Not applicable' for the colorimetric specification, but I didn't know how to specify just those numbers (0-1, 4-10) in the patch. Perhaps it's OK to leave it as is, otherwise hopefully someone can point me to similar code that I can learn from. Again, apologies for my ignorance. I'm attaching the patch and pasting it here too: From 8ae63b8301e6822686a7885202938fd6e4cba6f2 Mon Sep 17 00:00:00 2001 From: Kieran O'Leary Date: Wed, 1 Feb 2017 12:06:38 +0000 Subject: [PATCH] avcodec/dpxenc: support colour metadata in DPX encoder, fixes ticket #6023 --- doc/encoders.texi | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/dpxenc.c | 25 ++++++++++++++--- 2 files changed, 99 insertions(+), 3 deletions(-) s->bits_per_component == 12) ? 1 : 0); /* packing method */ @@ -275,7 +280,20 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, return 0; } +#define OFFSET(x) offsetof(DPXContext, x) +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + {"trc", "Transfer Characteristics", OFFSET(transfer_characteristic), AV_OPT_TYPE_INT, {.i64 = 2}, 0, 12, VE }, + {"clr", "Colorimetric Specification", OFFSET(colorimetric_specification), AV_OPT_TYPE_INT, {.i64 = 2}, 0, 12, VE }, + { NULL}, +}; +static const AVClass dpxenc_class = { + .class_name = "DPX encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; AVCodec ff_dpx_encoder = { .name = "dpx", .long_name = NULL_IF_CONFIG_SMALL("DPX (Digital Picture Exchange) image"), @@ -293,4 +311,5 @@ AVCodec ff_dpx_encoder = { AV_PIX_FMT_GBRP10LE, AV_PIX_FMT_GBRP10BE, AV_PIX_FMT_GBRP12LE, AV_PIX_FMT_GBRP12BE, AV_PIX_FMT_NONE}, -}; + .priv_class = &dpxenc_class, +}; \ No newline at end of file diff --git a/doc/encoders.texi b/doc/encoders.texi index 8137465..d3d8eb2 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1269,6 +1269,83 @@ disabled A description of some of the currently available video encoders follows. +@section dpx + +DPX image encoder. + +@subsection Options + +@table @option +@item trc @var{integer} +Set the transfer characteristics as listed in Table 5A in SMPTE 268M-2003: + +@table @samp +@item 0 +User Defined +@item 1 +Printing Density +@item 2 +Linear +@item 3 +Logarithmic [to be defined by SMPTE I23 Technology Committee, sub-group on “Transfer Characteristics”] +@item 4 +Unspecified Video +@item 5 +SMPTE 274M +@item 6 +ITU-R 709-4 +@item 7 +ITU-R 601-5 system B or G (625) +@item 8 +ITU-R 601-5 system M (525) +@item 9 +Composite video (NTSC); see SMPTE 170M +@item 10 +Composite video (PAL); see ITU-R 624-4 +@item 11 +Z (depth) – linear +@item 12 +Z (depth) – homogeneous (distance to screen and angle of view must also be specified in user-defined section) +@end table + +Default value is @var{2}. + +@item clr @var{integer} +Set the Colorimetric Specification as listed in Table 5B in SMPTE 268M-2003: + +@table @samp +@item 0 +User Defined +@item 1 +Printing Density +@item 2 +Not applicable +@item 3 +Not Applicable +@item 4 +Unspecified Video +@item 5 +SMPTE 274M +@item 6 +ITU-R 709-4 +@item 7 +ITU-R 601-5 system B or G (625) +@item 8 +ITU-R 601-5 system M (525) +@item 9 +Composite video (NTSC); see SMPTE 170M +@item 10 +Composite video (PAL); see ITU-R 624-4 +@item 11 +Not applicable +@item 12 +Not applicable +@end table + +Default value is @var{2}. + +@end table + @section Hap Vidvox Hap video encoder. diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c index a596033..3b0e890 100644 --- a/libavcodec/dpxenc.c +++ b/libavcodec/dpxenc.c @@ -24,15 +24,20 @@ #include "libavutil/imgutils.h" #include "avcodec.h" #include "internal.h" +#include "libavutil/opt.h" typedef struct DPXContext { + AVClass *class; int big_endian; int bits_per_component; int num_components; int descriptor; int planar; + int transfer_characteristic; + int colorimetric_specification; } DPXContext; + static av_cold int encode_init(AVCodecContext *avctx) { DPXContext *s = avctx->priv_data; @@ -218,8 +223,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, write32(buf + 772, avctx->width); write32(buf + 776, avctx->height); buf[800] = s->descriptor; - buf[801] = 2; /* linear transfer */ - buf[802] = 2; /* linear colorimetric */ + buf[801] = s->transfer_characteristic; + buf[802] = s->colorimetric_specification; buf[803] = s->bits_per_component; write16(buf + 804, (s->bits_per_component == 10 ||