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 93BDB45DF2 for ; Tue, 11 Apr 2023 21:22:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B6E9968BC61; Wed, 12 Apr 2023 00:21:21 +0300 (EEST) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E39CF68BC86 for ; Wed, 12 Apr 2023 00:21:06 +0300 (EEST) Received: by mail-lj1-f176.google.com with SMTP id b33so5571436ljf.2 for ; Tue, 11 Apr 2023 14:21:06 -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=DqouW/mttYpdnVj1KFNE7/ofplabP1dm2S0Ys9Iegfs=; b=fsJ754jn95C0OcRB5NJAAgP2z9NHnG1bp59rH1Pqn5POmc6ZpmN4nGf4LxQD+JsZL4 aJRlYcFLiu7al6nCZBXX1qlrTpbU/Q/8oWLPSUlzOsWxFwKzXEgptd4/Cn1ib8a2GnlD 1tMJcvEEHTRR22dA6knCaGDoK6A7SyKFvbW+MbMTyoqfhAl96hpdWoh6OVPi+t82xsPE HO18nvs0hd50HPKD0Y6IM/Co10dcS7iwsnneNPRhNcvHr9jsTNoNBiUe/PpoVNVP6sfr s1O7nbNgdITGO/WPju3K8zSjOmVf2hVwuDAIHU6iHj3oXEGX2m7mPw17IyNJVuvCCsmX Hfvg== 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=DqouW/mttYpdnVj1KFNE7/ofplabP1dm2S0Ys9Iegfs=; b=oREaw+Pnltmzipij4M5Zty8Vdu/aaoeTa42he545hRYTSH/iM1KpqUKrxLG4F+njrx yLxVyB8fKJ7+1guZy27FFDLDIxbKUtgT6sEtEFAYkoRndSAydXnWW3U+6vkSOwuJBQyG fx5RQ7hjARdngfNPCKLtZFTpIAeiItvvIiCb3hIlfZgw5sJCHKYfSXt3GLDDo1dLdfHB 98MyhOrXZdt8hxgJbEX/PetCPey7cPLNpnWveAgIsq3i6bfSoIxNXFRbzuypl5BrbR5g kADKM0vZeajL30xIYZoIvCFJozCfvcCr6gMaxxU/MIFo75nhOvfr+9M8vqdkNrKiwtOY 41jA== X-Gm-Message-State: AAQBX9eFusrsyPKA85GpTR/4DeTOWZ2+TuTskCJdDf5lo0dS5alGTmoP UyIVIhmz8fWAtL52tBzHo96XFZKpmIY= X-Google-Smtp-Source: AKy350ZStzzoDSpd/O41rCbQnZE9klOZJ5Af4U2djpBVvRJp76zvXHTdGVR4L9QhNKXfJ2cD3U13RA== X-Received: by 2002:a2e:8909:0:b0:2a7:98f8:fc4f with SMTP id d9-20020a2e8909000000b002a798f8fc4fmr210323lji.53.1681248066002; 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.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 14:21:05 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 00:20:51 +0300 Message-Id: <20230411212052.159889-12-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 11/12] avcodec/libx264: 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: Both of these two structures were first available with X264_BUILD 163, so make relevant functionality conditional on the version being at least such. Keep handle_side_data available in all cases as this way X264_init does not require additional version based conditions within it. --- libavcodec/libx264.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index cfdd422236..94f93e4559 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -25,6 +25,7 @@ #include "libavutil/eval.h" #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "libavutil/stereo3d.h" @@ -755,6 +756,82 @@ static int convert_pix_fmt(enum AVPixelFormat pix_fmt) return AVERROR(EINVAL);\ } +#if X264_BUILD >= 163 +static void handle_mdcv(x264_param_t *params, + const AVMasteringDisplayMetadata *mdcv) +{ + int *points[][2] = { + { + ¶ms->mastering_display.i_red_x, + ¶ms->mastering_display.i_red_y + }, + { + ¶ms->mastering_display.i_green_x, + ¶ms->mastering_display.i_green_y + }, + { + ¶ms->mastering_display.i_blue_x, + ¶ms->mastering_display.i_blue_y + }, + }; + + if (!mdcv->has_primaries && !mdcv->has_luminance) + return; + + params->mastering_display.b_mastering_display = 1; + + if (!mdcv->has_primaries) + goto skip_primaries; + + for (int i = 0; i < 3; i++) { + const AVRational *src = mdcv->display_primaries[i]; + int *dst[2] = { points[i][0], points[i][1] }; + + *dst[0] = av_rescale_q(1, src[0], (AVRational){ 1, 50000 }); + *dst[1] = av_rescale_q(1, src[1], (AVRational){ 1, 50000 }); + } + + params->mastering_display.i_white_x = + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }); + params->mastering_display.i_white_y = + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }); + +skip_primaries: + if (!mdcv->has_luminance) + return; + + params->mastering_display.i_display_max = + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }); + params->mastering_display.i_display_min = + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 }); +} +#endif // X264_BUILD >= 163 + +static void handle_side_data(AVCodecContext *avctx, x264_param_t *params) +{ +#if X264_BUILD >= 163 + 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->content_light_level.i_max_cll = cll->MaxCLL; + params->content_light_level.i_max_fall = cll->MaxFALL; + + params->content_light_level.b_cll = 1; + } + + if (mdcv_sd) { + handle_mdcv(params, (AVMasteringDisplayMetadata *)mdcv_sd->data); + } +#endif // X264_BUILD >= 163 +} + static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; @@ -1049,6 +1126,8 @@ static av_cold int X264_init(AVCodecContext *avctx) if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1; + handle_side_data(avctx, &x4->params); + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; -- 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".