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 95BF5456B2 for ; Mon, 20 Mar 2023 23:36:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9369168C62C; Tue, 21 Mar 2023 01:34:35 +0200 (EET) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C82A68C5AC for ; Tue, 21 Mar 2023 01:34:21 +0200 (EET) Received: by mail-lf1-f51.google.com with SMTP id q16so6159726lfe.10 for ; Mon, 20 Mar 2023 16:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679355260; 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=SpAa/pjolt/eUYqhGtTYzdpdGq6gC/sLMVOV/jRTrsg=; b=Y46ozT5mdt/Y4ajZiJW6sOQSLXwGaDA+HU74HT+40Vt28sFnkHkpEVRLzVB84ah5k9 QuN18wHjNsckxA7WuaHjq6A+z6nd+MVVslc9wdsHvydo2f5akzuFhg2+33A95iTxYzBw Y2XFNbDr88MaSEY9GkaE/RUIpDbsj1W0J0hrEVHUZM+MOD8jkBH2Wmfwqm6MhgQvLr4G yxm2xZIhSd5H5ALpevEbtgcJXfsvEckesahhm72AL91VZJfwidNRouuxF2YrKMmeN766 nrCIwOse0S1yI+g9WkbPAQrMOmOnQ6SeuRFnlVIUxzJsf/Vhqw8KPbm//HTDMjr0vGUX oq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679355260; 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=SpAa/pjolt/eUYqhGtTYzdpdGq6gC/sLMVOV/jRTrsg=; b=UIO7TqoNWKdIqi5v+CVvArtcdptw/ou/0vReLwXTEMAxediFGEccldC2cJrqMuZYY0 738jw/BBh3UnVCMcA8gi/rYFTrGYo6rVOoDxzXjbLL0mvJKOJ53heIhg9ro8TnqNsDvI c1Xm3maGKW0Ol9Z2YklMRjspTlpLXWgVFWZk6P2xqhxyhyAUtKvFlAB+d8bWe7tv3VHx tuE0ebNAkvoiYhEXBWn5wnCNVqBm/NJtPXu0/8X1lshui/hxIayy3lQOTuzZv2vEB8G/ WcL5Z7uDkld25SHujZiP5+bAb3Z5hDGNr6zTbVgWwsmTUQISo0Vnp63Pmraslob/VZr9 sWEg== X-Gm-Message-State: AO0yUKWR/zU28wudnISfTaRLT2LSrMGf5LWvTrpF/pkgcmDooZUCQd88 Hk5xD8+YYnUPEO4+pQzKJvVgAXj14rY= X-Google-Smtp-Source: AK7set8Ws9DlaFiLyEplcXF9+bncgKG4p5FB4xfG1U7mEs3cns/6dCNtx9ZyQdho0ec5QUGU7NAWag== X-Received: by 2002:a19:740e:0:b0:4e8:49ff:8df8 with SMTP id v14-20020a19740e000000b004e849ff8df8mr202347lfe.61.1679355260657; Mon, 20 Mar 2023 16:34:20 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j19-20020a19f513000000b004e84b79de9bsm1900701lfb.254.2023.03.20.16.34.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 16:34:20 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Mar 2023 01:34:07 +0200 Message-Id: <20230320233408.134255-14-jeebjp@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230320233408.134255-1-jeebjp@gmail.com> References: <20230320233408.134255-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v0 13/14] 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 92828fabc3..83c870609a 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" @@ -737,6 +738,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->internal->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; @@ -1031,6 +1108,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.39.2 _______________________________________________ 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".