From patchwork Tue Mar 14 23:05:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rapha=C3=ABl_Zumer?= X-Patchwork-Id: 40677 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp2972416pzb; Tue, 14 Mar 2023 16:05:48 -0700 (PDT) X-Google-Smtp-Source: AK7set+ex9KVQ57jRSEImdx6l+wNmmIXowbQYFmOZegvNVPlQ42CUNRH6KcfluiL2A6TvTjbqfah X-Received: by 2002:a05:6402:1b07:b0:4ad:738b:6706 with SMTP id by7-20020a0564021b0700b004ad738b6706mr1047253edb.2.1678835148166; Tue, 14 Mar 2023 16:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678835148; cv=none; d=google.com; s=arc-20160816; b=tC1wJmw+/9XKNjuFjIjjlisUgLmOa+z3WRGBY1+ocHZkbtskKB5FF3/hpJBRB2N3ZG jev+FEL8k9Nu62ypLLNXqRmQdPBlqb5GDrPah3qVCFx8nkosK/ehRzK3r6MhBIZLqvJ4 yEbsQWAXt0LuNuNJZ93B1kT24dWbtbCuBLqYtwqK0qwLLeULFXht0/ctcipOoMDRO6W4 LlcoGKbKbecwefsTLK6qc6p4yhqd3R5nmEyg2WMepPaSCcRTSJZbwFdFCHWr5cAgcT3s KUKP1ff/s/WM/0F7eh9Nb1GduGieOVRUTuip77EEopTf+yplP3r04t1vl93Elcb834NJ UVaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:to:from:user-agent:mime-version :date:message-id:dkim-signature:delivered-to; bh=m9C5sfceNBZqP2O62SKgB83y741UdnfK20KuNKquHtw=; b=wOkaTH0/h8+KwCccK8pP+zdPkuF69tzjnAGIG4GGH5oFb/f2JbgqeJdIhx3ibxZ8zS 0mdjIKkS1Ce7UsvmspGgZ2Gr/lPPj7sGyJdip6DPSnm/MheegnpR8XS5zFRbmJbgmBs/ LwabO+gB00Y6QKmmIh5McSLgvy7i5Y97WEwzzYXWzaGBuZQcSmEIlb8FtmQd5T7Z11Fj 342LHE7W5Rc1IZqZNydMohSwoi3Fdo8QSl9wMcdk3FI40aXiP/HuEvi8HDKgtGTZknOQ s6jlUEDhZAbXBOZFznSEx6nq18MJkVT4tTWiQIr63b3b2D4nDv5oA+czGssAu4AeJAXE JwCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@vimeo.com header.s=google header.b=dRE2u1ye; 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=QUARANTINE dis=NONE) header.from=vimeo.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n1-20020aa7c781000000b004fcbc158671si638907eds.378.2023.03.14.16.05.47; Tue, 14 Mar 2023 16:05:48 -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=@vimeo.com header.s=google header.b=dRE2u1ye; 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=QUARANTINE dis=NONE) header.from=vimeo.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 116A768BE50; Wed, 15 Mar 2023 01:05:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BF9068BD6B for ; Wed, 15 Mar 2023 01:05:38 +0200 (EET) Received: by mail-qv1-f50.google.com with SMTP id bo10so13887473qvb.12 for ; Tue, 14 Mar 2023 16:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vimeo.com; s=google; t=1678835137; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=NxmqgGcAa535aqTF9U3Sb8G5q7qdeylyBxMvHoRfnqs=; b=dRE2u1ye8mtJxueMASJJJ4NsWr4KuzDIpY5H9sJQjio2m1naeRTSoMtfy1jSpM6h8r 6uJyIKKyE6i5ffkGxu31Xepyw8MjkRR9UeeGYn7UPRG/R2VE46ylLRnVJWML+LKGc7HN 4Z6T3A4515RqSqM7WAhvQKdQAuE8iBwmb2Kjo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678835137; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NxmqgGcAa535aqTF9U3Sb8G5q7qdeylyBxMvHoRfnqs=; b=oRt5Fk5xaFojCcbtq1gRXydpARLagZR3gfTnhYAPeWWUruVPUgedW3Nm0XQ+Lsc4vT 6/q0Kmf+jBzvEcb4n1jUNxclwf6al4Nk1JB79rUcilUPMtju6SztgJUbWs8Pz4FAWRVe vC5PQUY0dVcemLJBprO+4NCjK/tOl2F0SDy5Jkypi+cAlIMNqqzTKPz253mb3EC1vGUj Wz/vPDDp4Oltl7JYWgO89rdcSYjViDYPjAF41Tz3354aGeJgordF6doRfKFCGP5NeTKR UANC+zcBLzxOojpw0aUlk4yixmo4av0MdgSidf3W+h1WqH/rygumhNntX+l9p7IK5kQa GuaA== X-Gm-Message-State: AO0yUKWfdryjsOFMLc5ajcUOXA1UyWhMQYGYyTLRM1BAt7qhRnTkOjsH IeBTiKNho0a2RIb30ExP2o8ZIcIygLzDdtoxuaFoiA== X-Received: by 2002:a05:622a:18c:b0:3bf:a760:cb5 with SMTP id s12-20020a05622a018c00b003bfa7600cb5mr35433070qtw.4.1678835136751; Tue, 14 Mar 2023 16:05:36 -0700 (PDT) Received: from ?IPV6:2600:4041:6c:7000:1f01:20c:8ba9:815b? ([2600:4041:6c:7000:1f01:20c:8ba9:815b]) by smtp.gmail.com with ESMTPSA id x9-20020ac87a89000000b003a530a32f67sm2575643qtr.65.2023.03.14.16.05.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Mar 2023 16:05:36 -0700 (PDT) Message-ID: <4944f0c6-a902-6a2f-ba71-08bf9b716ae5@vimeo.com> Date: Tue, 14 Mar 2023 19:05:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 From: =?utf-8?q?Rapha=C3=ABl_Zumer?= To: ffmpeg-devel@ffmpeg.org Content-Language: en-US, fr-FR Subject: [FFmpeg-devel] [PATCH v7 2/2] avutil: add HDR10+ dynamic metadata serialization function X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: vu+lbNjOm6E4 Co-authored-by: Mohammad Izadi Signed-off-by: Raphaƫl Zumer --- doc/APIchanges | 5 ++ libavutil/hdr_dynamic_metadata.c | 148 +++++++++++++++++++++++++++++++ libavutil/hdr_dynamic_metadata.h | 13 +++ libavutil/version.h | 2 +- 4 files changed, 167 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 14737223cb..3a61d61931 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,11 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-03-13 - xxxxxxxxxx - lavu 58.4.100 - hdr_dynamic_metadata.h + Add av_dynamic_hdr_plus_from_t35() and av_dynamic_hdr_plus_to_t35() + functions to convert between raw T.35 payloads containing dynamic + HDR10+ metadata and their parsed representations as AVDynamicHDRPlus. + 2023-03-02 - xxxxxxxxxx - lavc 60.6.100 - avcodec.h Add FF_PROFILE_EAC3_DDP_ATMOS, FF_PROFILE_TRUEHD_ATMOS, FF_PROFILE_DTS_HD_MA_X and FF_PROFILE_DTS_HD_MA_X_IMAX. diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c index 5ed903f475..b26eafc5f2 100644 --- a/libavutil/hdr_dynamic_metadata.c +++ b/libavutil/hdr_dynamic_metadata.c @@ -20,6 +20,7 @@ #include "hdr_dynamic_metadata.h" #include "mem.h" +#include "libavcodec/defs.h" #include "libavcodec/get_bits.h" #include "libavcodec/put_bits.h" @@ -230,3 +231,150 @@ int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data, return 0; } + +int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size) +{ + uint8_t *buf; + size_t size_bits, size_bytes; + PutBitContext pbc, *pb = &pbc; + + if (!s || !data) + return AVERROR(EINVAL); + + /** + * Buffer size per CTA-861-H p.253-254: + * 48 header bits (excluded from the serialized payload) + * 8 bits for application_mode + * 2 bits for num_windows + * 153 bits for window geometry, for each window above 1 + * 27 bits for targeted_system_display_maximum_luminance + * 1-2511 bits for targeted system display peak luminance information + * 82-442 bits per window for pixel distribution information + * 1-2511 bits for mastering display peak luminance information + * 1-179 bits per window for tonemapping information + * 1-7 bits per window for color saturation mapping information + * Total: 123-7249 bits, excluding trimmed header bits + */ + size_bits = 8; + + size_bits += 2; + + for (int w = 1; w < s->num_windows; w++) + size_bits += 153; + + size_bits += 27; + + size_bits += 1; + if (s->targeted_system_display_actual_peak_luminance_flag) + size_bits += 10 + + s->num_rows_targeted_system_display_actual_peak_luminance * + s->num_cols_targeted_system_display_actual_peak_luminance * 4; + + for (int w = 0; w < s->num_windows; w++) + size_bits += 72 + s->params[w].num_distribution_maxrgb_percentiles * 24 + 10; + + size_bits += 1; + if (s->mastering_display_actual_peak_luminance_flag) + size_bits += 10 + + s->num_rows_mastering_display_actual_peak_luminance * + s->num_cols_mastering_display_actual_peak_luminance * 4; + + for (int w = 0; w < s->num_windows; w++) { + size_bits += 1; + if (s->params[w].tone_mapping_flag) + size_bits += 28 + s->params[w].num_bezier_curve_anchors * 10; + + size_bits += 1; + if (s->params[w].color_saturation_mapping_flag) + size_bits += 6; + } + + size_bytes = (size_bits + 7) / 8; + + buf = av_malloc(size_bytes); + if (!buf) + return AVERROR(ENOMEM); + + init_put_bits(pb, buf, size_bytes); + + // application_mode is set to Application Version 1 + put_bits(pb, 8, 1); + + // Payload as per CTA-861-H p.253-254 + put_bits(pb, 2, s->num_windows); + + for (int w = 1; w < s->num_windows; w++) { + put_bits(pb, 16, s->params[w].window_upper_left_corner_x.num / s->params[w].window_upper_left_corner_x.den); + put_bits(pb, 16, s->params[w].window_upper_left_corner_y.num / s->params[w].window_upper_left_corner_y.den); + put_bits(pb, 16, s->params[w].window_lower_right_corner_x.num / s->params[w].window_lower_right_corner_x.den); + put_bits(pb, 16, s->params[w].window_lower_right_corner_y.num / s->params[w].window_lower_right_corner_y.den); + put_bits(pb, 16, s->params[w].center_of_ellipse_x); + put_bits(pb, 16, s->params[w].center_of_ellipse_y); + put_bits(pb, 8, s->params[w].rotation_angle); + put_bits(pb, 16, s->params[w].semimajor_axis_internal_ellipse); + put_bits(pb, 16, s->params[w].semimajor_axis_external_ellipse); + put_bits(pb, 16, s->params[w].semiminor_axis_external_ellipse); + put_bits(pb, 1, s->params[w].overlap_process_option); + } + + put_bits(pb, 27, s->targeted_system_display_maximum_luminance.num * luminance_den / + s->targeted_system_display_maximum_luminance.den); + put_bits(pb, 1, s->targeted_system_display_actual_peak_luminance_flag); + if (s->targeted_system_display_actual_peak_luminance_flag) { + put_bits(pb, 5, s->num_rows_targeted_system_display_actual_peak_luminance); + put_bits(pb, 5, s->num_cols_targeted_system_display_actual_peak_luminance); + for (int i = 0; i < s->num_rows_targeted_system_display_actual_peak_luminance; i++) { + for (int j = 0; j < s->num_cols_targeted_system_display_actual_peak_luminance; j++) + put_bits(pb, 4, s->targeted_system_display_actual_peak_luminance[i][j].num * peak_luminance_den / + s->targeted_system_display_actual_peak_luminance[i][j].den); + } + } + + for (int w = 0; w < s->num_windows; w++) { + for (int i = 0; i < 3; i++) + put_bits(pb, 17, s->params[w].maxscl[i].num * rgb_den / s->params[w].maxscl[i].den); + put_bits(pb, 17, s->params[w].average_maxrgb.num * rgb_den / s->params[w].average_maxrgb.den); + put_bits(pb, 4, s->params[w].num_distribution_maxrgb_percentiles); + for (int i = 0; i < s->params[w].num_distribution_maxrgb_percentiles; i++) { + put_bits(pb, 7, s->params[w].distribution_maxrgb[i].percentage); + put_bits(pb, 17, s->params[w].distribution_maxrgb[i].percentile.num * rgb_den / + s->params[w].distribution_maxrgb[i].percentile.den); + } + put_bits(pb, 10, s->params[w].fraction_bright_pixels.num * fraction_pixel_den / + s->params[w].fraction_bright_pixels.den); + } + + put_bits(pb, 1, s->mastering_display_actual_peak_luminance_flag); + if (s->mastering_display_actual_peak_luminance_flag) { + put_bits(pb, 5, s->num_rows_mastering_display_actual_peak_luminance); + put_bits(pb, 5, s->num_cols_mastering_display_actual_peak_luminance); + for (int i = 0; i < s->num_rows_mastering_display_actual_peak_luminance; i++) { + for (int j = 0; j < s->num_cols_mastering_display_actual_peak_luminance; j++) + put_bits(pb, 4, s->mastering_display_actual_peak_luminance[i][j].num * peak_luminance_den / + s->mastering_display_actual_peak_luminance[i][j].den); + } + } + + for (int w = 0; w < s->num_windows; w++) { + put_bits(pb, 1, s->params[w].tone_mapping_flag); + if (s->params[w].tone_mapping_flag) { + put_bits(pb, 12, s->params[w].knee_point_x.num * knee_point_den / s->params[w].knee_point_x.den); + put_bits(pb, 12, s->params[w].knee_point_y.num * knee_point_den / s->params[w].knee_point_y.den); + put_bits(pb, 4, s->params[w].num_bezier_curve_anchors); + for (int i = 0; i < s->params[w].num_bezier_curve_anchors; i++) + put_bits(pb, 10, s->params[w].bezier_curve_anchors[i].num * bezier_anchor_den / + s->params[w].bezier_curve_anchors[i].den); + put_bits(pb, 1, s->params[w].color_saturation_mapping_flag); + if (s->params[w].color_saturation_mapping_flag) + put_bits(pb, 6, s->params[w].color_saturation_weight.num * saturation_weight_den / + s->params[w].color_saturation_weight.den); + } + } + + flush_put_bits(pb); + + *data = buf; + if (size) + *size = size_bytes; + return 0; +} diff --git a/libavutil/hdr_dynamic_metadata.h b/libavutil/hdr_dynamic_metadata.h index faa4f46b0b..ea6e629577 100644 --- a/libavutil/hdr_dynamic_metadata.h +++ b/libavutil/hdr_dynamic_metadata.h @@ -21,6 +21,7 @@ #ifndef AVUTIL_HDR_DYNAMIC_METADATA_H #define AVUTIL_HDR_DYNAMIC_METADATA_H +#include "buffer.h" #include "frame.h" #include "rational.h" @@ -353,4 +354,16 @@ AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame); int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data, size_t size); +/** + * Serialize dynamic HDR10+ metadata to a user data registered ITU-T T.35 buffer, + * excluding the first 48 bytes of the header, and beginning with the application mode. + * @param s A pointer containing the decoded AVDynamicHDRPlus structure. + * @param data A pointer to a byte buffer to be allocated and filled + * with the serialized metadata. + * @param size A pointer to a size to be set to the returned buffer's size (optional). + * + * @return 0 if succeed. Otherwise, returns the appropriate AVERROR. + */ +int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size); + #endif /* AVUTIL_HDR_DYNAMIC_METADATA_H */ diff --git a/libavutil/version.h b/libavutil/version.h index 900b798971..7635672985 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 58 -#define LIBAVUTIL_VERSION_MINOR 3 +#define LIBAVUTIL_VERSION_MINOR 4 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \