From patchwork Fri Mar 31 16:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 40961 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp852449pzb; Fri, 31 Mar 2023 09:24:12 -0700 (PDT) X-Google-Smtp-Source: AKy350akVzvqtgIXnnEPKzbBnnjLUwwdjRLOc9nfOiSChL6WhhgJo2hxTjYvd+F9OEIUuWYtne7i X-Received: by 2002:aa7:cb9a:0:b0:4f9:f45e:c8b3 with SMTP id r26-20020aa7cb9a000000b004f9f45ec8b3mr28434016edt.27.1680279852786; Fri, 31 Mar 2023 09:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680279852; cv=none; d=google.com; s=arc-20160816; b=SVEaydlHNxhTxnhwGzHfCAIdM/HrIb4Uxr+rpBj0gIvsQdWlJeihFy4xM5SslhfgBG RlGAIIHXZKWkgqWME5OHy/oKueMzU7aZ07rAOyuh9tlfzOXv3ULf5vjqrMATkK4RVEIm rE3blFmQaV6Oz6s9DSaJzqbR7Ziz8BD2VhzZOjLvarL5wrDcqIlrjhF3q9+7Dpcnyl8D 7XmCAkcK1k60lhnHDDOFZmhu0r00TJ+0dGA1r/UjWgl/DuiI4/bSe+x37+hbLMqacaaM UBsMfNjyie5KsHhM/8U7wQAFZFacDjoQ9XTW51IaRKba7xjGX0Nsf8v5zm8RmSknkeD7 VS2w== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=3715mchB74CoFmNF4o7+W3OQGj6vqtr312cMcRHKvLQ=; b=TALiuXsEIueFilnR90cSMolElbvFRQkGpHduLi/pIei+lxV4wJ/Ht+V/DFAbsRsSBK 4tqiPQ0rkw+5g3JJJHAFJ53cZraxq4OoX7lQvEIV5KY+ii5iwR9Dfpvhu82BT8r3CrJ8 +KRMGw/4ax91wZK+XwIV2rmF8dJi2fzmC4jqOhn4ERxz5UTpgwf961IKzBURW1HeoT7t EjWm7xiQSTble/Ha50vFLMy8h9h1xyI54fMp0b4RVnMO61gpsMxxcSHdWBvGngrB9cp+ PZenGe2u6xYmQhnahr1dqnLDPmIiMvxWneGmBbmAk9T9Jw338ipnJWK2HkDPnE0+GJAF gaSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=MZuNwukh; 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 s15-20020a056402164f00b004fd2aaa62d0si114124edx.242.2023.03.31.09.24.12; Fri, 31 Mar 2023 09:24:12 -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=20210112 header.b=MZuNwukh; 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 86F8A68C369; Fri, 31 Mar 2023 19:22:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 95B5668C2F9 for ; Fri, 31 Mar 2023 19:22:19 +0300 (EEST) Received: by mail-lj1-f172.google.com with SMTP id o20so20695591ljp.3 for ; Fri, 31 Mar 2023 09:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680279739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8pMTtc/dk40m7irEIMLDQHOM308NHXgmb5xwIXgCYGM=; b=MZuNwukheIeOea9abrzrmch7ML7BwHkESczrkrm1KYPCl5Z5oC/5ZfPRX9zXuLG2AI qI/ozzi8W+132i9bWHdKLnGzxpXohAVcEi5tBnOJOzM8576dQrQ9P4z5tnhB8PkwaM0w sYAl80i9Vr6k0IXqeoMvbzI95nWLZpybyYZw/D0xhehtVYwYFnBCWuPPZ38dfYh5rvJ8 pEeApyRvcZ4XNaVIv2jKO3R2mzL5qS6PqGZKdO3iFh/zAAmE65k1CV0MWHciAx+RgMNt OfkNqsj/iZDnaphsrSrOdOLxncmXrz8pwnJXlP9IyJ1SF4dXVa9a7r+aUJcG/rSmEJql sHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680279739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8pMTtc/dk40m7irEIMLDQHOM308NHXgmb5xwIXgCYGM=; b=wxUriVAlJwAeUZt4G7KRo/Lu391c3W1DtxzrYJLV1VXsVl1EuGZs6Pk5OJ/7wzIrV+ h71on1a4dAy06yef88EE2b4ByRp+4TSSCu6wjPFeUUp2FNSbnuvS5DLtEESFbugHZq9W Vdal+zRR6Bvhs/tdAsmnGNTWxRsIsTzM6mkmSQnBz2xOA0uYp8Sxz5W6pUm6f4TEMvAj RK+n3v0bo5cXpse2nn5CU3lfCN3FwrMuakJwYhnYLH+NgbYi91diRUb8s+XmfJr7TSS+ QQTvwu4LAun23JJ98U48/98h54BaqE15Gfb4Y7a1gVlqfw7IpbBZbMvLOeviTfAkJruU Fp3g== X-Gm-Message-State: AAQBX9cEe51rLgbXugCS72S1+PTYtwStaX4w1R7i3KN9uw9Bk36YojQn K0E4jGtUdCHmMYNAp/elOIjMdXg6ksA= X-Received: by 2002:a2e:961a:0:b0:298:700b:e4a8 with SMTP id v26-20020a2e961a000000b00298700be4a8mr8628817ljh.27.1680279739025; Fri, 31 Mar 2023 09:22:19 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id n20-20020a2e8794000000b0029573844d03sm411483lji.109.2023.03.31.09.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 09:22:18 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 Mar 2023 19:22:05 +0300 Message-Id: <20230331162205.428735-13-jeebjp@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331162205.428735-1-jeebjp@gmail.com> References: <20230331162205.428735-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 12/12] avcodec/libx265: add support for writing out CLL and MDCV 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: Rzc/RX3UbcCm The newer of these two are the separate integers for content light level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea , with X265_BUILD 75. As we already require X265_BUILD of at least 89, no further conditions are required. --- libavcodec/libx265.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 420d0953af..4378c04996 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -28,9 +28,11 @@ #include #include "libavutil/avassert.h" +#include "libavutil/bprint.h" #include "libavutil/buffer.h" #include "libavutil/internal.h" #include "libavutil/common.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" @@ -179,6 +181,79 @@ static av_cold int libx265_param_parse_int(AVCodecContext *avctx, return 0; } +static int handle_mdcv(AVCodecContext *avctx, const x265_api *api, + x265_param *params, + const AVMasteringDisplayMetadata *mdcv) +{ + int ret = AVERROR_BUG; + static const char *option = "master-display"; + AVBPrint buf; + av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); + + // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u) + av_bprintf( + &buf, + "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")" + "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")", + av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }), + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 })); + + if (!av_bprint_is_complete(&buf)) { + ret = AVERROR(ENOMEM); + goto end; + } + + if (api->param_parse(params, option, buf.str) == + X265_PARAM_BAD_VALUE) { + av_log(avctx, AV_LOG_ERROR, + "Invalid value \"%s\" for param \"%s\".\n", + buf.str, option); + ret = AVERROR(EINVAL); + goto end; + } + + ret = 0; + +end: + av_bprint_finalize(&buf, NULL); + + return ret; +} + +static int handle_side_data(AVCodecContext *avctx, const x265_api *api, + x265_param *params) +{ + const AVFrameSideDataSet set = avctx->side_data_set; + const AVFrameSideData *cll_sd = + av_get_side_data_from_set(set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_get_side_data_from_set(set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->maxCLL = cll->MaxCLL; + params->maxFALL = cll->MaxFALL; + } + + if (mdcv_sd) { + int ret = handle_mdcv(avctx, api, params, (AVMasteringDisplayMetadata *)mdcv_sd->data); + if (ret < 0) + return ret; + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; @@ -333,6 +408,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) return AVERROR_BUG; } + ret = handle_side_data(avctx, ctx->api, ctx->params); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n", + av_err2str(ret)); + return ret; + } + if (ctx->crf >= 0) { char crf[6];