From patchwork Mon Apr 15 02:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 48060 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1583706pzb; Sun, 14 Apr 2024 19:08:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV6I6ktC+nFfOjawGB6O//MNeA0q2Pp2pZLXpT6LpUscNYpioQC9Nw94mH2vr8R35BAqXUKBJtQKYgJgo4CHbwid+QO7+ChjRYHzg== X-Google-Smtp-Source: AGHT+IEbOYphXMoIYG+3KweWHQActQc/7hENCRd8sRM5bTIjkcytUeU9kSgydrL9vcJ6ke+svp8D X-Received: by 2002:a05:6512:3da3:b0:516:c241:a912 with SMTP id k35-20020a0565123da300b00516c241a912mr7290084lfv.1.1713146913190; Sun, 14 Apr 2024 19:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713146913; cv=none; d=google.com; s=arc-20160816; b=q3tfSZqKAUoBNscjg1STjXRagrRE3zPXJso+gut/llC0B9TI1qBwTHBL47h5v2jF8a o9Tj/nP7Zc3/dcXbCAbPKRHb1i5mBGXQQQ0RoWSyymUswb5dfKUvXhmIbGyRWWzKCpnQ 2EQr5p4l/jB+erq/qzhiSre6uh7vgO11NV4GNRsXfuEZZGkcyxA88mX1ICuz2qqw+vkf D17PyFoVFlWUA9LV8oZRwNx12xpZbM15qYbVl9h7CEhJP5Ho2jZBQhxFYPNaCS3DC7gR GB6q+bSzZKrM7Atfi8ip+0AM+m7kxiLEGhIjlp6Tbr2QK92Kw+jV07WXJr40uLROXzny YfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=YrT+W5HRYC+I7nSY2ye+/6+N3GBiyjtgIStcaPFXJo8=; fh=1kpmTRI1sW42eNCnNMby7VLIISQBX6KJuVYxOEG0t2A=; b=wPHAlDpv5h1wZ4EKSQYRj1V3pwhJUap6j/zsQhEgV3gxHlz5yK9jbZxAPzEB4t5noA pUCijK6KmLNzbsEGHML/npA6kYFzY7REmVPN+Q9UNWnZbH0EOYLYoZH6BaodcVomDFGW yQ/nQgLlMn/qPu8zNA3z3Ckbs3C6+2bImM61+472qn9n3v/wnGGdRTw9unarpKfJn+X8 ZJML5N+IfMUGpD34MFwhGvhA5SF/GCnnvz23RawuqaiR8YF23Du+914LUa3wcqCWOKHX Tzhi5GmAR5kC8imSF8QvDucyFz14MdmZt2emcnNAc9C2lzINjLQjzXA9JH43C2Yppa2c NOOg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=QFSC3c55; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i25-20020a1709064ed900b00a523b0516cfsi2780590ejv.757.2024.04.14.19.08.32; Sun, 14 Apr 2024 19:08:33 -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=@intel.com header.s=Intel header.b=QFSC3c55; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 84DB168D3EB; Mon, 15 Apr 2024 05:08:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5548F68D3A5 for ; Mon, 15 Apr 2024 05:08:14 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713146900; x=1744682900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SUOQLmJxDXwiBu9ZtKMsVvAXEQSr75eHigWK12rwvgM=; b=QFSC3c55V5FQS/1rREIMqiHieqHRXtnd3wyEvP7s04En04Qf28Sg18mM Ay4bOMV+XXN7ari4jZEFfk/fgX2RDvel69X546Odor5WLbtfpwQLgYYAI Lo2W3o2JJ+eRLL6cjfAJILC7eXY2eWCtevAkBkn02L772QgY446YaMSL/ +eD/uEyx82GMWL5DwUdFAe6i5pkOGzbuKWz/tziF1j1ue02n8cRf6LdPN 0mHuWSclsNVGoqgHrJZkT1HvSMd9kWYcSe8dn30jlmnuhWiv4d6CjxnYu /RNLzZSM2J3pEbUmY5uLsMje4K+3O/LgABH/J+NI2VEv0Jbaxg13K/0ne A==; X-CSE-ConnectionGUID: IyxubGp+Rgq1eyrqd3QGDw== X-CSE-MsgGUID: 7Eqd5qDjSCqsUShCEKUbkw== X-IronPort-AV: E=McAfee;i="6600,9927,11044"; a="19943106" X-IronPort-AV: E=Sophos;i="6.07,202,1708416000"; d="scan'208";a="19943106" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2024 19:08:11 -0700 X-CSE-ConnectionGUID: 5COPdwRTR0OYun81T3Usew== X-CSE-MsgGUID: lA/DNQJlTWGwlKtJ/w/rTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,202,1708416000"; d="scan'208";a="26186630" Received: from unknown (HELO xhh-dg264.sh.intel.com) ([10.238.2.76]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2024 19:08:11 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 10:07:53 +0800 Message-Id: <20240415020754.674831-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240415020754.674831-1-haihao.xiang@intel.com> References: <20240415020754.674831-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/vaapi_encode_av1: Insert HDR_MDCV metadata if have 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 Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jL5T6QyQPhGW From: Haihao Xiang Only look for HDR_MDVC on key frame on the output. Signed-off-by: Haihao Xiang --- libavcodec/vaapi_encode_av1.c | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c index 4b417b05e7..4077d21202 100644 --- a/libavcodec/vaapi_encode_av1.c +++ b/libavcodec/vaapi_encode_av1.c @@ -23,6 +23,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/opt.h" +#include "libavutil/mastering_display_metadata.h" #include "cbs_av1.h" #include "put_bits.h" @@ -663,6 +664,51 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, priv->nb_mh = 0; + if (pic->type == PICTURE_TYPE_IDR) { + AVFrameSideData *sd = + av_frame_get_side_data(pic->input_image, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + if (sd) { + AVMasteringDisplayMetadata *mdm = + (AVMasteringDisplayMetadata *)sd->data; + if (mdm->has_primaries && mdm->has_luminance) { + AV1RawOBU *obu = &priv->mh[priv->nb_mh++]; + AV1RawMetadata *md = &obu->obu.metadata; + AV1RawMetadataHDRMDCV *mdcv = &md->metadata.hdr_mdcv; + const int chroma_den = 1 << 16; + const int max_luma_den = 1 << 8; + const int min_luma_den = 1 << 14; + + memset(obu, 0, sizeof(*obu)); + obu->header.obu_type = AV1_OBU_METADATA; + md->metadata_type = AV1_METADATA_TYPE_HDR_MDCV; + + for (i = 0; i < 3; i++) { + mdcv->primary_chromaticity_x[i] = + av_rescale(mdm->display_primaries[i][0].num, chroma_den, + mdm->display_primaries[i][0].den); + mdcv->primary_chromaticity_y[i] = + av_rescale(mdm->display_primaries[i][1].num, chroma_den, + mdm->display_primaries[i][1].den); + } + + mdcv->white_point_chromaticity_x = + av_rescale(mdm->white_point[0].num, chroma_den, + mdm->white_point[0].den); + mdcv->white_point_chromaticity_y = + av_rescale(mdm->white_point[1].num, chroma_den, + mdm->white_point[1].den); + + mdcv->luminance_max = + av_rescale(mdm->max_luminance.num, max_luma_den, + mdm->max_luminance.den); + mdcv->luminance_min = + av_rescale(mdm->min_luminance.num, min_luma_den, + mdm->min_luminance.den); + } + } + } + end: ff_cbs_fragment_reset(obu); return ret;