From patchwork Tue Aug 3 00:12:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 29208 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp2011593ioh; Mon, 2 Aug 2021 17:13:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+IuuRYD670T9WsCVKa4Z/TGxvz6KYoXCtXSVKipAJriaNyJx5NzQwPDFPAGZSGGnKRcBH X-Received: by 2002:a17:906:3495:: with SMTP id g21mr18137947ejb.359.1627949597070; Mon, 02 Aug 2021 17:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627949597; cv=none; d=google.com; s=arc-20160816; b=OST2aHEqVaZV1G4PA/ganZhLMSIRMbar3sKS7gkcAJwY2lb9q+iJJxCbXpYmGaJ9nu nky/DIki9oTSgwuPp2vynWwEAtPh6CX4J5C8KpuKfAlfKoHLLHrK6V6NLWbvtKNCdoNR 2KCqiwCgaAh58MCp8UiooDBU94A7o2zeE8/U6UWR4/GLLhD1rIM9V67nt/WFow9VF8Vq SjUGdfRvn1kQ7OC6FDd9OQqa3vP33/6IKy/pjLxBfaiHLL7K8koxsIhLKVYz6Jelt96r tnLKc7IyHchT2yQi2sZXBbhx61nhmD/hJIp/DYlEwvMZKtBrdFiMlDkk5P1zz4UrrdWF WNng== 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:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=z8pl5NwoTN2pZSC4Q8GCsc9Bn8llpTCds2RIjFi7w/k=; b=IvCAcEPdw/eczYxPgWcYYCcma9ztETpbljZqyVAP3T8x2t2oeYMnenumTi1GdfYOjB pQNCdvf48Q75Hp1+lIboqSYOUrspAVD+196Ejy68HFNwVnhEjmR0OGYoi/BULQbDcmKV IvSgfaMXohdFEJHWTagexWfewSajzSeQpv6qZQrxEXpAqVOm0RzOKLOxY8/NRibwE9Mr Rso3JXXxlQ3xsdYB+ylbB14vxSXksfVhSt4nOjp4uI0KW1WzI5OdD7hX6GfG7toeKjHa qT9y4WHQo3OrfY1HRVTVsQBOfzTwgKS3FR4/KCn4FVTNVtydy0M/GlwZdMOdUsIKe8AG 4kjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=M2KrWCZ7; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e1si11011318eji.452.2021.08.02.17.13.16; Mon, 02 Aug 2021 17:13:17 -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=@gmail.com header.s=20161025 header.b=M2KrWCZ7; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7EF9A68806D; Tue, 3 Aug 2021 03:13:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D261680212 for ; Tue, 3 Aug 2021 03:13:05 +0300 (EEST) Received: by mail-pj1-f42.google.com with SMTP id j1so27434419pjv.3 for ; Mon, 02 Aug 2021 17:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=+rEZ3IKeM2wvU7bxS8JVoq0TBYwP/HB6gBt3/csnMEo=; b=M2KrWCZ7PlEyT1tVO5WJ+OLX+bhRvbmPpa3vlkqA1gGeAwQlGKj0KJ3/zVVXk9Z/1t WGwFqfUcHVGzcwZ0VVyYmr5GaV5aUtGk3QkuUoVLyC5YaELCQpM+ta7ZPltiYdjBUskM k/NXEO8r3Hru6lYRLnbRxbaFYH4Cmo60lulZfBMOWNqb0jz3jKTj7hgYsLbPRqFvtdD2 mVBBaUQccDTwar8ocESxDyQLebEgMCwSks+9YjnGoHN/acURY+I4SxKM32wrIwJrO2r9 K5Bp+bYaGm7D4cS22+esVmxx56rMA6EnakXnm0n6EbPDChcLW+aaBkCJ8NByWOabVkp0 Kt5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=+rEZ3IKeM2wvU7bxS8JVoq0TBYwP/HB6gBt3/csnMEo=; b=JUS1DaOpchcdMTH1ouvgfhHs92tEsBYnqZlfS3k9pC5CfpyMN/bfp9RZMZrY4VBe0g bapEmOD9RfD7w16RJ9nAnHD5YgWh1Ayc33kBGxkpLr1foesKt10Yw0tQTWwcVybarnTn 3EfOlomGU1rnBKHxUHe+cn9SeFeccmwPf0uBPwKTNhEG7Mub6g8Ob/LWrEtmf2DLoiyQ sC7XAtWe1cScgAD8zCQDcVbvvmmCeBQKC4Tzz9K39/AopDt99n3ZzmZyJTFQuoANzEgA XNCTZBf1J0+Vj04pNgSMCch8Xt1Te809W7z8Yyt8p8cMFwNrdPruLNnTXxUmSEiBr0G9 UyYw== X-Gm-Message-State: AOAM5309FJpFjfIPFuDW/ALjgPM11aIHrhAp8kfj+R5+VSV9C+ObSL6W 8S306TtOhcU3QOj5XcGAdhokYbn5vtZsRA== X-Received: by 2002:a17:902:864c:b029:10d:8c9e:5f56 with SMTP id y12-20020a170902864cb029010d8c9e5f56mr16154949plt.8.1627949582877; Mon, 02 Aug 2021 17:13:02 -0700 (PDT) Received: from localhost.localdomain ([191.84.227.130]) by smtp.gmail.com with ESMTPSA id e12sm14832545pgv.51.2021.08.02.17.13.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 17:13:02 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Aug 2021 21:12:29 -0300 Message-Id: <20210803001231.2346-1-jamrial@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] cbs_h265: add support for Film Grain Characteristics SEI message 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: cTom6WMHFkKt Signed-off-by: James Almer --- libavcodec/cbs_h2645.c | 6 +++ libavcodec/cbs_h265.h | 21 +++++++++ libavcodec/cbs_h265_syntax_template.c | 65 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 61c1e13cf7..3396c059c9 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1610,6 +1610,12 @@ static const SEIMessageTypeDescriptor cbs_sei_h265_types[] = { sizeof(H265RawSEIRecoveryPoint), SEI_MESSAGE_RW(h265, sei_recovery_point), }, + { + SEI_TYPE_FILM_GRAIN_CHARACTERISTICS, + 1, 0, + sizeof(H265RawFilmGrainCharacteristics), + SEI_MESSAGE_RW(h265, film_grain_characteristics), + }, { SEI_TYPE_DISPLAY_ORIENTATION, 1, 0, diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index f7753f1206..f7cbd4970d 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -594,6 +594,27 @@ typedef struct H265RawSEIRecoveryPoint { uint8_t broken_link_flag; } H265RawSEIRecoveryPoint; +typedef struct H265RawFilmGrainCharacteristics { + uint8_t film_grain_characteristics_cancel_flag; + uint8_t film_grain_model_id; + uint8_t separate_colour_description_present_flag; + uint8_t film_grain_bit_depth_luma_minus8; + uint8_t film_grain_bit_depth_chroma_minus8; + uint8_t film_grain_full_range_flag; + uint8_t film_grain_colour_primaries; + uint8_t film_grain_transfer_characteristics; + uint8_t film_grain_matrix_coeffs; + uint8_t blending_mode_id; + uint8_t log2_scale_factor; + uint8_t comp_model_present_flag[3]; + uint8_t num_intensity_intervals_minus1[3]; + uint8_t num_model_values_minus1[3]; + uint8_t intensity_interval_lower_bound[3][256]; + uint8_t intensity_interval_upper_bound[3][256]; + int16_t comp_model_value[3][256][6]; + uint8_t film_grain_characteristics_persistence_flag; +} H265RawFilmGrainCharacteristics; + typedef struct H265RawSEIDisplayOrientation { uint8_t display_orientation_cancel_flag; uint8_t hor_flip; diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index 5d216aad36..67bc77f975 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -1844,6 +1844,71 @@ static int FUNC(sei_recovery_point) return 0; } +static int FUNC(film_grain_characteristics)(CodedBitstreamContext *ctx, RWContext *rw, + H265RawFilmGrainCharacteristics *current, + SEIMessageState *state) +{ + CodedBitstreamH265Context *h265 = ctx->priv_data; + const H265RawSPS *sps = h265->active_sps; + int err, c, i, j; + + HEADER("Film Grain Characteristics"); + + flag(film_grain_characteristics_cancel_flag); + if (!current->film_grain_characteristics_cancel_flag) { + int filmGrainBitDepth[3]; + + u(2, film_grain_model_id, 0, 1); + flag(separate_colour_description_present_flag); + if (current->separate_colour_description_present_flag) { + ub(3, film_grain_bit_depth_luma_minus8); + ub(3, film_grain_bit_depth_chroma_minus8); + flag(film_grain_full_range_flag); + ub(8, film_grain_colour_primaries); + ub(8, film_grain_transfer_characteristics); + ub(8, film_grain_matrix_coeffs); + } else { + if (!sps) { + av_log(ctx->log_ctx, AV_LOG_ERROR, + "No active SPS for film_grain_characteristics.\n"); + return AVERROR_INVALIDDATA; + } + infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8); + infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8); + infer(film_grain_full_range_flag, sps->vui.video_full_range_flag); + infer(film_grain_colour_primaries, sps->vui.colour_primaries); + infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics); + infer(film_grain_matrix_coeffs, sps->vui.matrix_coefficients); + } + + filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8; + filmGrainBitDepth[1] = + filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8; + + u(2, blending_mode_id, 0, 1); + ub(4, log2_scale_factor); + for (c = 0; c < 3; c++) + flags(comp_model_present_flag[c], 1, c); + for (c = 0; c < 3; c++) { + if (current->comp_model_present_flag[c]) { + ubs(8, num_intensity_intervals_minus1[c], 1, c); + us(3, num_model_values_minus1[c], 0, 5, 1, c); + for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) { + ubs(8, intensity_interval_lower_bound[c][i], 2, c, i); + ubs(8, intensity_interval_upper_bound[c][i], 2, c, i); + for (j = 0; j <= current->num_model_values_minus1[c]; j++) + ses(comp_model_value[c][i][j], 0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), + ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), + 3, c, i, j); + } + } + } + flag(film_grain_characteristics_persistence_flag); + } + + return 0; +} + static int FUNC(sei_display_orientation) (CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIDisplayOrientation *current, SEIMessageState *sei)