From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F3DEB45DDF for ; Tue, 11 Apr 2023 21:23:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C05168BD68; Wed, 12 Apr 2023 00:21:22 +0300 (EEST) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 381BF68BBEE for ; Wed, 12 Apr 2023 00:21:07 +0300 (EEST) Received: by mail-lj1-f170.google.com with SMTP id b33so5571444ljf.2 for ; Tue, 11 Apr 2023 14:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681248066; 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=+ipIT9V1vsRg5m0MHfrDn1IxbMgxY/ZOXaTvWd57QTk=; b=pD6jPxw7SZ3qfh+Pf+OAkdxdk+4rm/ehK5A6G9qlBsE+q54BDxCxBscO8tSWIp7beZ piYjuxjctSAqZ9ig4lG1Hg7Yul63BMiUoSxjabJUzMmzBTedjFX0Rik+Z7yd44WZC4N0 3INHTGw2FRa4rYgGayWmGloUbYsGH2qmMzRG/r0kApZ+cmhnExgq/zV7AI8k9E+pi0Xz JOKnbjYN09YhFNdeGvPX69U5YuZSqKI7lEAxDVbCSmX389FMj77i/NlzCGvtcSwACgLP e8c9tsK27Ihyxs1P/fQnu+u8CUMNlNSSNaE+xWTHPoeIgcn0ceAMV8yUk/mQvOmCtRDI XCmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681248066; 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=+ipIT9V1vsRg5m0MHfrDn1IxbMgxY/ZOXaTvWd57QTk=; b=MqbVOWL+LN/RVuyJkHI7Fv5MkYHkci59hVtin+sfAL4azLjGXzAMiwDnJAmOyl/T8u SPmxqoXKyN9y5niwUhTzDAw7Jh0dWf97F0VJ8z6YXAzrIHEku5JFjo2nEPlEMohDnAUB 4xEsnzQSMdqtR7pyU73S0uf8FPzo5P3bCYv8FGJaO2laNP42UppJ7RJ1oPEctULqUB3h c+EhqmoL56ELHpnhGBHKxNGahV5QwIzRIHZ57AyqWBfIk4IUo5oeiB8GlAeiny28iJyX rKQCj0NWw/4mVgWfRsU4uQX7hvzY54X3gk7O797nzlhj41WDat4xw23zmYxJv90TcSJl ZTVQ== X-Gm-Message-State: AAQBX9d8PVPFiQe2cRJIqG1uhmE0PiPifKpWzrLTv3AEJVvG1A89VEjI 0N44wWJQXZ6QxGnUmIr0Bwr+qHn85GM= X-Google-Smtp-Source: AKy350aCPMZsVECfiCJJcAxP41CZyPfnGyCAiYNeIIrqr23sYMp31xoQWb3ZFdentxDaJTWrgW11nw== X-Received: by 2002:a2e:994a:0:b0:29b:d488:fd87 with SMTP id r10-20020a2e994a000000b0029bd488fd87mr999920ljj.23.1681248066433; Tue, 11 Apr 2023 14:21:06 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id w21-20020a2e9995000000b002a7778bd271sm1195055lji.20.2023.04.11.14.21.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 14:21:06 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 00:20:52 +0300 Message-Id: <20230411212052.159889-13-jeebjp@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411212052.159889-1-jeebjp@gmail.com> References: <20230411212052.159889-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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]; -- 2.40.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".