From patchwork Mon Oct 23 13:46:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Pavlov X-Patchwork-Id: 44331 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1b28:b0:15d:8365:d4b8 with SMTP id ch40csp1422523pzb; Mon, 23 Oct 2023 06:54:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV7YWwUV4RDn8wFj5ObdJEmW9gp/D2HYABCgIead6JCcVm2qqHEzZmM4o//GIsNG1iFmPv X-Received: by 2002:a05:6402:5243:b0:53e:7fe:b856 with SMTP id t3-20020a056402524300b0053e07feb856mr7790403edd.15.1698069266553; Mon, 23 Oct 2023 06:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698069266; cv=none; d=google.com; s=arc-20160816; b=a9wKryZ/KhLgt+lzUTfTezZGuNkij+3NIMC9zZQiI9yGa8y5uXYd9SSX3wC8mmOLZG ZBFw3//eEeX7vU6fdLrN+g0gZ+kpF8X+W9TGJhoXMiS9SR68ZBZI32oBKqNRMzUXJz61 ttJLAM3/5pMlt9FLghWJaeQI4wNwEsKiBreHFPjOoLcW8xxq/gHa14s+tlIlcUEYeLnI FrPU/GAM2q8FrVmF51RoDwXASRGxOnXyXCVTd1Fg/6YigW0zZcRTF7sXq+mcY9nY2o4u ajvDkMrgeo5PLcvkSp75AvTFHUsS6iDtnv43jUqzFzi8yiu6b+W0NzpIWDOpwtU3N/ub cN8Q== 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=nQXLYHTU+pzuXnAClmiMA38bfEI/TvjQj+sU31BLIk4=; fh=s4NEqlgyeQvuJ9M2FER/qIrd96lZ1v/frktaqQpFGmg=; b=Ut0E5qHgT1cnTIA8+sO/Dh1amHy2TrCfkFJI6SDfZ1QqBYP4fTebQHZruJ1s/ZwzIu Sltq718Fm3h/QmT+Amzs8JL6Z1ON/3h06CE9in2dxT2676QqwHKYsa8uSB1Wfd1FDGKv +g8cvjRZf8jnk/esmbfxwjpNlqcjqMT60r0wbLP4TsOfB+vBxFesJpnQhnJXGNxW3y63 BMw0sMNKoxeCfLVQS2OZgiWgvrLPYL0lL201o7AEjaehhZPgZlcA1WZEH16dUhCQ+0f3 JY56Xz4yCwrgFZ0qN8fKPcLXJt0NMZhpexT2XGsvwOhHXbcCpLn2m2KJQkvDPflBvU/B xWVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=nU98cwU6; 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 b5-20020a509f05000000b0053e886e0d3esi3381608edf.26.2023.10.23.06.54.25; Mon, 23 Oct 2023 06:54:26 -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=20230601 header.b=nU98cwU6; 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 96E3B68CA4B; Mon, 23 Oct 2023 16:54:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CE6468C7B5 for ; Mon, 23 Oct 2023 16:54:16 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-32da7ac5c4fso2311934f8f.1 for ; Mon, 23 Oct 2023 06:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698069255; x=1698674055; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JX4G0I9AfulDVPsYmdrP3bDhk9RapAH7Dgp5Ckjk1xY=; b=nU98cwU6ig506n2DHe9c+BMwDARNb/fm+Y2MiJuuRuuiEyhAMH1VlSY4xT+JmqYQHj +YWKZG3LnFPVzYm+S9a4S5t/TEA8u+2Uy63y7rxLMyyYy8gotkMD3i7M4Nti81fIN6h2 WZY4e7+jqReZV0b5Ao9VnunkHWpgmX+AkUBrQFJ4cBIKmrRcUhfEJxVINKX5OgWyu9VE 4uqcSDuYrFYs7wBcO4iaHta9t/UdgzlglV/mAQDSPN8nfmmNoSvhqKH5CehbRd9Xf3xb jzkZj0LiCKGSG3SSxuEC3TYvXwKqv84sHXecMYcdg7FeChTWGkAYEixyKWxyjtgAH2Fe rreg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698069255; x=1698674055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JX4G0I9AfulDVPsYmdrP3bDhk9RapAH7Dgp5Ckjk1xY=; b=RFK1sAGkwrDuglWqwy5rSpprVtsn33R9FqHobnStdDMKff2MZ8KvygbfcSuioZN5q+ hOppICxUt8l9ThvnVWI8LAd4K1mq5QBzo6fv5KMZlT7k/TclxfsznrIo87WfGOOspY10 QIYHvmqhxi9YMZMptKd/EFkP/UPWdUNhXoJyQvD4Xi+YKZEGtue1QTOrsCBVOyt/J/rD tEDMq5Kmz94/2QW6lAjeIhNsYD+V9FCv1ZXMOceIGCyhxA7lKbyc6Nt5/srNivXbj33u wNOeKIEni3EmoCx6Sjh7H2ESF7HGz8jDU8/w5AxIfAPBSW+uLs2diYwVDqKQoBm60p8p T4nQ== X-Gm-Message-State: AOJu0YxJt+PqbsTuN/Ca3MLh7LRHlKZbvXHwgujQg4N+bB8ilDKaDXkm VToXSKUy5cfkO42tiLVLXarIKqqDoajFlSL5 X-Received: by 2002:adf:f4cf:0:b0:32d:a4c9:8ab4 with SMTP id h15-20020adff4cf000000b0032da4c98ab4mr6204379wrp.65.1698069255537; Mon, 23 Oct 2023 06:54:15 -0700 (PDT) Received: from MSDN-EVPAVLOV.amd.com (178-223-50-56.dynamic.isp.telekom.rs. [178.223.50.56]) by smtp.gmail.com with ESMTPSA id v3-20020adff683000000b0032d9523de65sm7746997wrp.48.2023.10.23.06.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 06:54:15 -0700 (PDT) From: Evgeny Pavlov To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Oct 2023 15:46:00 +0200 Message-ID: <20231023134753.17106-5-lucenticus@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009095340.41807-1-lucenticus@gmail.com> References: <20231009095340.41807-1-lucenticus@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH avcodec/amfenc: 10-bit support, v5, 2/3] avcodec/amfenc: HDR metadata. 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: nyanmisaka Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yyJWl0kgb2lw From: nyanmisaka v2: fixes for indentation --- libavcodec/amfenc.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 0bd15dd812..068bb53002 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -36,6 +36,57 @@ #include "amfenc.h" #include "encode.h" #include "internal.h" +#include "libavutil/mastering_display_metadata.h" + +static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, AMFHDRMetadata *hdrmeta) +{ + AVFrameSideData *sd_display; + AVFrameSideData *sd_light; + AVMasteringDisplayMetadata *display_meta; + AVContentLightMetadata *light_meta; + + sd_display = av_frame_get_side_data(frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + if (sd_display) { + display_meta = (AVMasteringDisplayMetadata *)sd_display->data; + if (display_meta->has_luminance) { + const unsigned int luma_den = 10000; + hdrmeta->maxMasteringLuminance = + (amf_uint32)(luma_den * av_q2d(display_meta->max_luminance)); + hdrmeta->minMasteringLuminance = + FFMIN((amf_uint32)(luma_den * av_q2d(display_meta->min_luminance)), hdrmeta->maxMasteringLuminance); + } + if (display_meta->has_primaries) { + const unsigned int chroma_den = 50000; + hdrmeta->redPrimary[0] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[0][0])), chroma_den); + hdrmeta->redPrimary[1] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[0][1])), chroma_den); + hdrmeta->greenPrimary[0] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[1][0])), chroma_den); + hdrmeta->greenPrimary[1] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[1][1])), chroma_den); + hdrmeta->bluePrimary[0] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[2][0])), chroma_den); + hdrmeta->bluePrimary[1] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->display_primaries[2][1])), chroma_den); + hdrmeta->whitePoint[0] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->white_point[0])), chroma_den); + hdrmeta->whitePoint[1] = + FFMIN((amf_uint16)(chroma_den * av_q2d(display_meta->white_point[1])), chroma_den); + } + + sd_light = av_frame_get_side_data(frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + if (sd_light) { + light_meta = (AVContentLightMetadata *)sd_light->data; + if (light_meta) { + hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->MaxCLL; + hdrmeta->maxFrameAverageLightLevel = (amf_uint16)light_meta->MaxFALL; + } + } + return 0; + } + return 1; +} #if CONFIG_D3D11VA #include @@ -683,6 +734,26 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer); } + // HDR10 metadata + if (frame->color_trc == AVCOL_TRC_SMPTE2084) { + AMFBuffer * hdrmeta_buffer = NULL; + res = ctx->context->pVtbl->AllocBuffer(ctx->context, AMF_MEMORY_HOST, sizeof(AMFHDRMetadata), &hdrmeta_buffer); + if (res == AMF_OK) { + AMFHDRMetadata * hdrmeta = (AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer); + if (amf_save_hdr_metadata(avctx, frame, hdrmeta) == 0) { + switch (avctx->codec->id) { + case AV_CODEC_ID_H264: + AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break; + case AV_CODEC_ID_HEVC: + AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break; + } + res = amf_set_property_buffer(surface, L"av_frame_hdrmeta", hdrmeta_buffer); + AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res); + } + hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer); + } + } + surface->pVtbl->SetPts(surface, frame->pts); AMF_ASSIGN_PROPERTY_INT64(res, surface, PTS_PROP, frame->pts); @@ -746,6 +817,18 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) } res_resubmit = AMF_OK; if (ctx->delayed_surface != NULL) { // try to resubmit frame + if (ctx->delayed_surface->pVtbl->HasProperty(ctx->delayed_surface, L"av_frame_hdrmeta")) { + AMFBuffer * hdrmeta_buffer = NULL; + res = amf_get_property_buffer((AMFData *)ctx->delayed_surface, L"av_frame_hdrmeta", &hdrmeta_buffer); + AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "GetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res); + switch (avctx->codec->id) { + case AV_CODEC_ID_H264: + AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break; + case AV_CODEC_ID_HEVC: + AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break; + } + hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer); + } res_resubmit = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, (AMFData*)ctx->delayed_surface); if (res_resubmit != AMF_INPUT_FULL) { int64_t pts = ctx->delayed_surface->pVtbl->GetPts(ctx->delayed_surface);