From patchwork Mon Apr 15 09:04:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 48064 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1713378pzb; Mon, 15 Apr 2024 02:04:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZ2c5iFXnXjyf6FO3fq8zvAGnxUrIxtLVcfKV48Ot5M1YIoWihJSGEHjfIi4cMlQaqrYw+6UFVWwAXSkCP2qvk+LrisawZXj5Djw== X-Google-Smtp-Source: AGHT+IGAXYZbp+ZNRQNsUNRDqTsTIG6wTgDojDP4a9IsvIxtpSel41dHXn0+/f5ScoSgD9OO6Tdg X-Received: by 2002:a50:d553:0:b0:56e:2c34:cfec with SMTP id f19-20020a50d553000000b0056e2c34cfecmr5832341edj.7.1713171895806; Mon, 15 Apr 2024 02:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713171895; cv=none; d=google.com; s=arc-20160816; b=DcVbv0taCstOitVGcemPYqU5trhF9+ShC5HDcQt2ErmL4NG4HOYdr2e39GvVp8wIyF AWajF7jrL1JM5wjffILNtIkKBySvCwzWEe7fy54+ueN5hMreq67rieCPMMr3JrjYaRkL 23dQwvTvR/zs2kSnUQ5l/+MHR4aWbmThrJgAyFY5CjhUTwkPsWcethTtz+3TYZKUf0fS h12CP/tn1voS+aT8ak/5qBt9a6ipPUpuH52d4rAew/FIijd6DBuWixpNCKk0ma/DadyU 9EGxfP6vGyBl9mQgFkFZrB63yiRvvwdygvKSTvLt0iPDqzf0CKMYRU5Ulngy+IgggVNH uPeQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=Wd1hbNttG4ZEt7z7h0H5bdHp95H9Qpamyc6TdUGjGbA=; fh=RtB4DVs0FDmf9Hvrn87VH/goAyWr8bjY4Nman67RuSk=; b=U+3gBD+sCDXeTTkr6ggPwkr/AnkjhAHWBmL00W6oMoZHRIKVJPSb5DzonP7qTrTpix YcqcP9JMD/XFLC0bGava11EAcG5x4EY5jagBxiXFtKNAO7XOUMXZ9M7kPXWmP1k2Y8xE gSoCJRpEgqPwhhO1yvr2jUssHMmL/PQd/QiR1yTD/UiBynbwywRru5FPB0uScrnm/qMg 65YJ8xc5sCRArbCG7S59quD249cT0nAKlytUX3Tbm8WcGWJFZoJzuJa7L4pP6KRfBivM At9i0ZrH0P2nQ92WVsqLFsc18s7GSZzja+LJIOq1+Uccrwk8c0I5KHjxFXy94M8cnGPD 3V6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="awM6x/5q"; 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 f13-20020a0564021e8d00b0056e5c6a72d0si4460083edf.614.2024.04.15.02.04.55; Mon, 15 Apr 2024 02:04:55 -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="awM6x/5q"; 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 C2D4F68D284; Mon, 15 Apr 2024 12:04:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1ADF968D284 for ; Mon, 15 Apr 2024 12:04:46 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2da68af6c6fso11942041fa.3 for ; Mon, 15 Apr 2024 02:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713171884; x=1713776684; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sXZq4k4eAGtuImwnuonwx+7NRFA5YO1FmITR4mxfm2w=; b=awM6x/5qAXzdcss18N/oSA45nqjmEb9DtnRNcnEogzV7p+fGIeJo6nIPHgV6BHWvo5 dL+AwW2t5mNx6KrzZdD1tDNvYxun4aX7pAuqpLPtGiwXHZUU4PfX9cioCpdpu5n/exa1 gZdPWOJNoXQxw+IlKg+nEhpjhdjnQ/gLyOz7EGfBnqJqs77n/VHN6e1i6n8Kwu/UsE1l VydxuxIb/CmrJe0ac0IAyLtIp4eNuU3KD7+khbZ/w3Ax2HFVDGdAleYuvMRDR2rt/4HF cy6SaAAAytbZ+PBjzSBpEEGOOBBtf0kL+jHlSePnRdZzYQ2dm+3TJZib9VjVl3RFkujf 6nDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713171884; x=1713776684; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sXZq4k4eAGtuImwnuonwx+7NRFA5YO1FmITR4mxfm2w=; b=YG5c+iGn52r2KbSyQ/5jCyHMrsb3ta4ww1wql6qy66Yz2S0S1/D0CF8iBbufvLyl1/ WRL0kzy+jj4rvLBiXPMBklnD3i/SFQrCa1qCNmttK9dBBTVjoAgMsYUMrJCMrxN5i1OI heBc2828dUNQJi+z3b4B+iIMFShMruLgYbVo9padjuKxnFcipWE8EJQ0foRANYZZDVih 7Zvqy3t/v9Mw1W65hsR4llTfUbZK3ghba4okUDp+nQvDESDfeghFpEkxdM/ZRdYY4i34 4zyQIKSYdFBis2I5Gw0IIcsSVKXOf4HTjwRbvrnjzI02JP8IsPjHoA3SYljSeEhYSdkQ Mrog== X-Gm-Message-State: AOJu0YwzvaMn6MbNTI3C2eX3UM1xX2VRmRHCw4BGbB8gKaoNCIrXMYYM pPWMG32duPshQ3AkXJTlc7vTv/8AK9COfXkh4MYyL+H2KVHvQF7EJ2Bofg== X-Received: by 2002:a2e:be1a:0:b0:2d4:54f2:c409 with SMTP id z26-20020a2ebe1a000000b002d454f2c409mr8002150ljq.38.1713171883684; Mon, 15 Apr 2024 02:04:43 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.133.126]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b004181c91d1dcsm9283139wmb.18.2024.04.15.02.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:04:43 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 11:04:07 +0200 Message-ID: <20240415090410.1138-1-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/amfenc: Fixes the color information in the output. 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: Evgeny Pavlov , Michael Fabian 'Xaymar' Dirks Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dIbnsTIxsWt6 From: Michael Fabian 'Xaymar' Dirks added 10 bit support for amf hevc. before: command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i test_10bit_file.mkv -an -c:v h264_amf res.dx11_hw_h264.mkv output - Format of input frames context (p010le) is not supported by AMF. command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv output - Format of input frames context (p010le) is not supported by AMF. after: command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i test_10bit_file -an -c:v h264_amf res.dx11_hw_h264.mkv output - 10-bit input video is not supported by AMF H264 encoder command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv output - 10bit file v2 - lost line returned in ff_amf_pix_fmts v3 - fixes after review v4 - extract duplicated code, fix incorrect processing of 10-bit input for h264 v5 - non-functional changes after review Co-authored-by: Evgeny Pavlov --- libavcodec/amfenc.c | 37 +++++++++++++++++++++++++++++++++++++ libavcodec/amfenc.h | 3 +++ libavcodec/amfenc_h264.c | 24 ++++++++++++++++++++---- libavcodec/amfenc_hevc.c | 26 +++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 061859f85c..0bd15dd812 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -60,6 +60,7 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = { #if CONFIG_DXVA2 AV_PIX_FMT_DXVA2_VLD, #endif + AV_PIX_FMT_P010, AV_PIX_FMT_NONE }; @@ -72,6 +73,7 @@ static const FormatMap format_map[] = { { AV_PIX_FMT_NONE, AMF_SURFACE_UNKNOWN }, { AV_PIX_FMT_NV12, AMF_SURFACE_NV12 }, + { AV_PIX_FMT_P010, AMF_SURFACE_P010 }, { AV_PIX_FMT_BGR0, AMF_SURFACE_BGRA }, { AV_PIX_FMT_RGB0, AMF_SURFACE_RGBA }, { AV_PIX_FMT_GRAY8, AMF_SURFACE_GRAY8 }, @@ -785,6 +787,41 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) return ret; } +int ff_amf_get_color_profile(AVCodecContext *avctx) +{ + amf_int64 color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN; + if (avctx->color_range == AVCOL_RANGE_JPEG) { + /// Color Space for Full (JPEG) Range + switch (avctx->colorspace) { + case AVCOL_SPC_SMPTE170M: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601; + break; + case AVCOL_SPC_BT709: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709; + break; + case AVCOL_SPC_BT2020_NCL: + case AVCOL_SPC_BT2020_CL: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020; + break; + } + } else { + /// Color Space for Limited (MPEG) range + switch (avctx->colorspace) { + case AVCOL_SPC_SMPTE170M: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601; + break; + case AVCOL_SPC_BT709: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709; + break; + case AVCOL_SPC_BT2020_NCL: + case AVCOL_SPC_BT2020_CL: + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020; + break; + } + } + return color_profile; +} + const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[] = { #if CONFIG_D3D11VA HW_CONFIG_ENCODER_FRAMES(D3D11, D3D11VA), diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h index 2dbd378ef8..62736ef579 100644 --- a/libavcodec/amfenc.h +++ b/libavcodec/amfenc.h @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -170,6 +171,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt); */ extern const enum AVPixelFormat ff_amf_pix_fmts[]; +int ff_amf_get_color_profile(AVCodecContext *avctx); + /** * Error handling helper */ diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c index bd544d12df..f785e091c9 100644 --- a/libavcodec/amfenc_h264.c +++ b/libavcodec/amfenc_h264.c @@ -199,6 +199,8 @@ static av_cold int amf_encode_init_h264(AVCodecContext *avctx) AMFRate framerate; AMFSize framesize = AMFConstructSize(avctx->width, avctx->height); int deblocking_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0; + amf_int64 color_profile; + enum AVPixelFormat pix_fmt; if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); @@ -262,10 +264,24 @@ FF_ENABLE_DEPRECATION_WARNINGS AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, AMF_VIDEO_ENCODER_ASPECT_RATIO, ratio); } - /// Color Range (Partial/TV/MPEG or Full/PC/JPEG) - if (avctx->color_range == AVCOL_RANGE_JPEG) { - AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, 1); - } + color_profile = ff_amf_get_color_profile(avctx); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_COLOR_PROFILE, color_profile); + + /// Color Range (Support for older Drivers) + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, !!(avctx->color_range == AVCOL_RANGE_JPEG)); + + /// Color Depth + pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format + : avctx->pix_fmt; + + // 10 bit input video is not supported by AMF H264 encoder + AMF_RETURN_IF_FALSE(ctx, pix_fmt != AV_PIX_FMT_P010, AVERROR_INVALIDDATA, "10-bit input video is not supported by AMF H264 encoder\n"); + + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_COLOR_BIT_DEPTH, AMF_COLOR_BIT_DEPTH_8); + /// Color Transfer Characteristics (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc); + /// Color Primaries (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); // autodetect rate control method if (ctx->rate_control_mode == AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_UNKNOWN) { diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c index 352564a301..8c6401c646 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -34,8 +34,9 @@ static const AVOption options[] = { { "high_quality", "high quality trancoding", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_HIGH_QUALITY }, 0, 0, VE, "usage" }, { "lowlatency_high_quality","low latency yet high quality trancoding", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY_HIGH_QUALITY }, 0, 0, VE, "usage" }, - { "profile", "Set the profile (default main)", OFFSET(profile), AV_OPT_TYPE_INT,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN }, AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN, AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN, VE, "profile" }, + { "profile", "Set the profile (default main)", OFFSET(profile), AV_OPT_TYPE_INT,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN }, AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN, AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10, VE, "profile" }, { "main", "", 0, AV_OPT_TYPE_CONST,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN }, 0, 0, VE, "profile" }, + { "main10", "", 0, AV_OPT_TYPE_CONST,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10 }, 0, 0, VE, "profile" }, { "profile_tier", "Set the profile tier (default main)", OFFSET(tier), AV_OPT_TYPE_INT,{ .i64 = AMF_VIDEO_ENCODER_HEVC_TIER_MAIN }, AMF_VIDEO_ENCODER_HEVC_TIER_MAIN, AMF_VIDEO_ENCODER_HEVC_TIER_HIGH, VE, "tier" }, { "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_TIER_MAIN }, 0, 0, VE, "tier" }, @@ -160,6 +161,9 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) AMFRate framerate; AMFSize framesize = AMFConstructSize(avctx->width, avctx->height); int deblocking_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0; + amf_int64 color_depth; + amf_int64 color_profile; + enum AVPixelFormat pix_fmt; if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); @@ -187,6 +191,9 @@ FF_ENABLE_DEPRECATION_WARNINGS case AV_PROFILE_HEVC_MAIN: profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN; break; + case AV_PROFILE_HEVC_MAIN_10: + profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10; + break; default: break; } @@ -215,6 +222,23 @@ FF_ENABLE_DEPRECATION_WARNINGS AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ASPECT_RATIO, ratio); } + color_profile = ff_amf_get_color_profile(avctx); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PROFILE, color_profile); + /// Color Range (Support for older Drivers) + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NOMINAL_RANGE, !!(avctx->color_range == AVCOL_RANGE_JPEG)); + /// Color Depth + color_depth = AMF_COLOR_BIT_DEPTH_8; + pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format + : avctx->pix_fmt; + if (pix_fmt == AV_PIX_FMT_P010) { + color_depth = AMF_COLOR_BIT_DEPTH_10; + } + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_COLOR_BIT_DEPTH, color_depth); + /// Color Transfer Characteristics (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc); + /// Color Primaries (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); + // Picture control properties AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NUM_GOPS_PER_IDR, ctx->gops_per_idr); AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_GOP_SIZE, avctx->gop_size); From patchwork Mon Apr 15 09:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 48065 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1713469pzb; Mon, 15 Apr 2024 02:05:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXKcpF3YJ9nqSN4G2dE8W4s3fThFSrWZgllRYbuPxTP2Wr9aynFv0sWFwY4Yg6+dvq6V38xve4OP1NXF6vTT0ogN4qdXePlA+dC0Q== X-Google-Smtp-Source: AGHT+IFZagYh041mJkDEfJ6VgCRYx/0jrf44UEdG98HsyNZu/E/mlR4eNYyxWWfpYiPNquXgGlzA X-Received: by 2002:a17:906:5fc2:b0:a51:ae51:5206 with SMTP id k2-20020a1709065fc200b00a51ae515206mr4937866ejv.42.1713171906712; Mon, 15 Apr 2024 02:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713171906; cv=none; d=google.com; s=arc-20160816; b=gb8SlV4bDyTGttVg9peRdJgOD50nZhSFuV3ny/mPdU/auRt+H28gNRYvV16fdmTXJ3 MvOBfuEFGC+HMQKCD6JDy+ZFa9SYxVqH9oUB520wfaxeznmKtscnD1FAYNIo2mSzRs0J WjglQEB4sAGOaelnVHxi17+y5oA8nvbk7BwkqC3OuSuePvkbkaM3u/mTONQkxgDAO77Y MBPrZ8qQD+OPVFLvmIO1tYpMrbclapF9LhrC7nZ3vOIpIsDp/ZfOIUd7rE0hjHzThBjm 8ILHEl7uyDB/A/s9mh33uBEzDu/5fwXoIPE5POe78MdM7/WxFK94GlyG5XjGgYEaM/Wh HxCg== 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=1DFZdSaIXljhFjfBLKI2GwbitBoQC/791Ky1EvxsguU=; fh=s4NEqlgyeQvuJ9M2FER/qIrd96lZ1v/frktaqQpFGmg=; b=b+Fk/uAP/A4xfume2XmxjSPrazfAyC5iQP4iebzN02a1vwXakYNr6pd/LmF0+JoZ9n tQsIZKsbp4zPV+3Ow0jb9U0QU+67ISPWvPd363tx+YJkOmk0rwDV2RjexoRabtE2l6fZ 5jWY9dDFZ0PnMRGu4gjBg+BGYfZmHhXmfFFDxnK+cfiwArfni1WkyecWCMsqmGbHgkF/ X9L0ah18FUsy61M005e1+/Yv9oW/kgmy9BTtATsA/tDE30Dup7OQ+7YNkpDIJ4w6rhdv hPr50w669tXRIh3aBLqpDL3ooPed6WANz6ujfoPwpWkuCn0mXRgbByK7b6qetfM/SdQq AVXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=IaFNhH9H; 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 qk30-20020a1709077f9e00b00a4e256a82ccsi4587372ejc.232.2024.04.15.02.05.06; Mon, 15 Apr 2024 02:05:06 -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=IaFNhH9H; 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 D260468D3DE; Mon, 15 Apr 2024 12:05:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A512468D3BE for ; Mon, 15 Apr 2024 12:04:55 +0300 (EEST) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a450bedffdfso354992066b.3 for ; Mon, 15 Apr 2024 02:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713171895; x=1713776695; 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=HcNco338gbhERxqFBR0RbryTDtAseuSjaMuiWA73MjI=; b=IaFNhH9HOdkvJKDmQwev709THYEsMS4CY8q/+SichnxTUw1qKjc4h5TbThc0xSIdqC 0nDyTqwoR3FF+SJA5poXu4Ss0P75p8as2gAcV7POMwwUH8zLZ1eNFhP4RmL4gPX4qvLP gqaWFbRks44P+9auyu0AT92xUn4xW8ve1aMrnVc+DeGxd+TXuCwCzYvsUAxZytXSacu2 FBEz0a0zgB9D6Y6+nKf2FBHKZL+isdbGB+ug/0quuvHPt5146CcyQn6JvLSULivMNJQB Fjk9LmwGOmMJnNYKDUNiEZEsCADdZBRzyBafAqc+62bnyLGRq4XG+d56CcsRB3E+ZHV7 oN4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713171895; x=1713776695; 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=HcNco338gbhERxqFBR0RbryTDtAseuSjaMuiWA73MjI=; b=I4HG+6ZmopdZVRpxLZ5Lf1Z+txbREH4q6Kz5267Q4eJ9Gh22RaB9uagslO64JYSu7x LwVHnGQCCEdS1jGg5r0NVbhLriTcc2d2bgegd1+0h+KRG9po4AWTlr497DB0uTmJU4d3 qq2b0WD/SHSdZbSaLsPoY0RF8vgM0aEkBPv1lHojSkFD+eCVDC8PUnihiZqzXaXR1iD7 tIX9bSiNW320JJdTGZHVemoCdgtr4X0NZND76oDHhOHAFZJKck74UFE63F26+mw38VK2 3KMvzkXi1oQyKCJol3DWwk8q+RyGNLrGs4yaWEYIk+ZWcnIyUgRtZ9kkCI7i+kDsHRUM ztOA== X-Gm-Message-State: AOJu0YxDBg9O4gmz9nlEG7e/dAsXq2HUHZ559M22tfpeLf7jqEndB56C ncFsC8mBknFNmqxJBrL7YmYKLYJcHq4pJX4jt9rEKNcO9V+VCqEF5sDxYA== X-Received: by 2002:a17:906:3b11:b0:a52:4fc6:2d6a with SMTP id g17-20020a1709063b1100b00a524fc62d6amr3096509ejf.32.1713171894474; Mon, 15 Apr 2024 02:04:54 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.133.126]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b004181c91d1dcsm9283139wmb.18.2024.04.15.02.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:04:54 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 11:04:08 +0200 Message-ID: <20240415090410.1138-2-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240415090410.1138-1-Primeadvice@gmail.com> References: <20240415090410.1138-1-Primeadvice@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] 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: aLL03k3mNP7Z 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); From patchwork Mon Apr 15 09:04:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 48066 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1713552pzb; Mon, 15 Apr 2024 02:05:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUUBalYahsXNVrqfjDk5hiJD771a07iMtB5E9bkPw0d/2MyiV/juN3oUIkotOon66Bfk9EsvC4O5/pFYTgiDTTM6L7OOcQKVaLyaQ== X-Google-Smtp-Source: AGHT+IGkf8N+i1yzVTGM5aJUqiaQFyU0yRcHMJtdfEaL0yOwUy0ANHIO61pQxXKlFmGHj/1VeB7u X-Received: by 2002:a50:a455:0:b0:56d:fc89:ecf8 with SMTP id v21-20020a50a455000000b0056dfc89ecf8mr7742137edb.10.1713171915847; Mon, 15 Apr 2024 02:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713171915; cv=none; d=google.com; s=arc-20160816; b=TALJg3aLglnXM+dTmUrh8t2fiqx9WijLUM4qdR0mWZpeLR5DTvI4jdT5u4qlasjInq Bd27QnW9JUwVhxk9icucaRRLfn9K7Olk5uPljBRwfoBqYaURROq4WBCWeZh3k7AdiEkf PjeEyo7l0OZK+Sk9TO0bHt56X/hIPJkNZNJRFIGK+1WGDfJGRdX1Jy0YerVAVaMXtj6M rwZXc73kWJOrIxa5C+RXOKI9auTd6Acq8eubK1owDPLcA1UVotsvAAblPA/hDy6v6YMK ApDhhy18ZUzX2vNQt6xNFTWp8N7ONMwSjQLFAk08PCWXHORcpsJqMmlUwg90N1kHahs7 3xUw== 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=aRDQuPW8pFGD+bUhkrkcx4L+/dIVHzjBPw25djRvQ6Y=; fh=GFMLWjWsOMgBmoPKQLjFbTnXINkN4pkSjsZqwDcYLuI=; b=vgRortsRwAKglqRpgCbdJtFC2tYU1l+8bBI7hi1yFqXgsnVihJJnBnHNRZde+rfxkf ZsWt5cI9npPinXUcfup4W29IAF01HW1qCVfbK5f2L08AWodg0FqomY7GGpLv7kqeuM4q MbisqBG2x0T+FbCaGXdSLQP+yUDJDmPh61OUscEts5/FDppP+kzbhWMtdjXCY0L8rm+n WPpPFTm0TSWpxEdRcfKs89HM/uhrc82QGDNDzWA4P54YTXozeE5LBmrCJsc9tFkoiE7M ANCwEgFmU19vBmE6PbtR9zg98tGcMjLHD0DhC9ZrxVZZ4th/5kaXpYyOZ/2WfBYzZZay Hyng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=Ip67tZOs; 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 d8-20020a056402400800b005700374d478si2912261eda.641.2024.04.15.02.05.15; Mon, 15 Apr 2024 02:05:15 -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=Ip67tZOs; 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 D4B1968D31F; Mon, 15 Apr 2024 12:05:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7281368D3A3 for ; Mon, 15 Apr 2024 12:04:57 +0300 (EEST) Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2da01cb187cso53085141fa.0 for ; Mon, 15 Apr 2024 02:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713171896; x=1713776696; 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=g2+vXeqmRr60G684vQhUPsi0OYrJlWpEomR/2OzMm7c=; b=Ip67tZOsh5gvTJ8gFzfC/YjSpcirBNocLkxlcGo6/verVl8EJVGtk1ay0sLMyIdw6w lMoWkKhItOTpdRggqk0B32EtywLdKpH81bVEB9ZLU/vvm3v4g5cPlVNhm+2vsvqL8CTS oNK9tC09qnVnLTm5p62y8eX+tjoZlNypaHre0XKKz8cs3asXMfWPljqZn0rn1rqx3Tsc MuQxd/sd2fGXFj48igxoFxH7fITxoWR2mWBJPzgJRnDNoJUWEbWaIwaBSFZcl1PPtJ7J U6e2awwloM7oB09a1b+MMwhKmI8FjSDZFHgOG8h7P5AQ9wlEhHrdvhKBfuS+1ZxsOx7B ZePQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713171896; x=1713776696; 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=g2+vXeqmRr60G684vQhUPsi0OYrJlWpEomR/2OzMm7c=; b=p67RQlunoicXyrTa8nK3Jx4pXgwPKk6I36Hz7Y7vtSglnC3DhjnvJNQ/FALb8ZzbFt tbgECSIHdkbb3kAgE3NJLz5IH0JZ3YS074dmDUMGCejMfPnS3B3pdwIOtmOH6JJIbPok cUkl02Tl5xQI707Y1YU3DfVKFoQnXf/jHG9ETEUzpd6O+IvUbsJcCv9S6pSE7TFqoJbD kOI/QZoFYoWL6BYYyVvhw6M4QwrkrcK94AnjpFWtM/NyNA9pgQpiqSkuS6OQzNaLGpAN mXQ5gDY6J95Oq3lTJgDYzSe8yaEUuTDRcXbA4YybBmde2JmT7+SBFjIgtLJxdirK9A7p FU/g== X-Gm-Message-State: AOJu0YxLM4iGDn6SFFWP0KeI5GIj3qjrr4FCJfvf8uCrB/a9oCx48Gm3 9Tw2Ww1xF4QZVSwzsNcjJGEjGORM3Zbf5YellJ1Uizo6+7qGRNyKdyU1HEM6 X-Received: by 2002:a2e:a718:0:b0:2d8:687d:b22 with SMTP id s24-20020a2ea718000000b002d8687d0b22mr7294903lje.20.1713171896134; Mon, 15 Apr 2024 02:04:56 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.133.126]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b004181c91d1dcsm9283139wmb.18.2024.04.15.02.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:04:55 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 11:04:09 +0200 Message-ID: <20240415090410.1138-3-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240415090410.1138-1-Primeadvice@gmail.com> References: <20240415090410.1138-1-Primeadvice@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/amfenc: add 10 bit encoding in av1_amf 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: Evgeny Pavlov , Dmitrii Ovchinnikov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aNDVEcf/7vKk From: Evgeny Pavlov v2: refactored after review Signed-off-by: Evgeny Pavlov Co-authored-by: Dmitrii Ovchinnikov --- libavcodec/amfenc.c | 2 ++ libavcodec/amfenc_av1.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 068bb53002..f1b76bd6aa 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -826,6 +826,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) 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; + case AV_CODEC_ID_AV1: + AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break; } hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer); } diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index 8f13aea29e..634eeea48f 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -165,6 +165,9 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) AMFGuid guid; AMFRate framerate; AMFSize framesize = AMFConstructSize(avctx->width, avctx->height); + amf_int64 color_depth; + amf_int64 color_profile; + enum AVPixelFormat pix_fmt; @@ -203,6 +206,25 @@ FF_ENABLE_DEPRECATION_WARNINGS } AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_PROFILE, profile); + /// Color profile + color_profile = ff_amf_get_color_profile(avctx); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile); + + /// Color Depth + pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format + : avctx->pix_fmt; + color_depth = AMF_COLOR_BIT_DEPTH_8; + if (pix_fmt == AV_PIX_FMT_P010) { + color_depth = AMF_COLOR_BIT_DEPTH_10; + } + + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_COLOR_BIT_DEPTH, color_depth); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile); + /// Color Transfer Characteristics (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc); + /// Color Primaries (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); + profile_level = avctx->level; if (profile_level == AV_LEVEL_UNKNOWN) { profile_level = ctx->level; From patchwork Mon Apr 15 09:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 48067 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1713683pzb; Mon, 15 Apr 2024 02:05:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX8xEuIeqLE5mAjHC19xfsyuIM3Hm4393eQEBkE9esPMTh5zTsjb2SEdB7a2XE7+sEmPUjFewMbXqR2M712u8pZyqKKx5/SeprOrA== X-Google-Smtp-Source: AGHT+IG0cOuYtqJ5owxEVnpkb0F8Q8FRRiRcO3xr8oDypN//uc+vkEG0fm8hYQD+FSnDOLqRwmYD X-Received: by 2002:a05:651c:c1:b0:2d8:fc50:4281 with SMTP id 1-20020a05651c00c100b002d8fc504281mr3423772ljr.22.1713171928048; Mon, 15 Apr 2024 02:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713171928; cv=none; d=google.com; s=arc-20160816; b=Z4rXcnV8EfAk3LpCgOhH4z8QwwUO7PVzQKJiFAXNThiNkqCFZfnCzVFbNHpsxV8oeb 4R8c93JJxNphepObqAwQUUPEjAiSO/kgK1GntC9iWZ+glgnNj+AWzmHLpcjn8ovjHGUV GEjf8cAE7/NHzt137vvDE7w/q+TTUsu4ZrZPsHGXQwx11kWNVGGekwoQXhW2Ty/esfLM wv7t2XcENbjWnXktGOgzRZ56uOmMcVOgGKud29PMn3Svx15rLMFepxhCd21hT/wunyjQ arrqfM5O8z/VyvzIcfswcJda+FCa+ZyU4tMsOp7Xo/TGJ/1mKvist4m0pEzSdHOmEYwu 5erQ== 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=rKqfFyVmhH01mIr+cPnvEFCL+mi30GdfJY5/9Gp7gmY=; fh=OWLPUf18s9dlUQuxhl6xLimy4NybloePU6lVbhxT1Ck=; b=PC//zPqcLIcP8LVLOzT7bNbs7BJF+8Phvts3fee6SLgSxpBFHLqkCEGGYYhAiwcApl RVt9oE8J8NtNOMxacT9OlPieqNz4hfmuUW4tzvR+uYf265aySq39dgcb7sYQUCzSmtiY 39WA27svFyBAcvmVku5b83ivGYGIV4tppIr/bxYEDooq5Nu3IWWK9ZDuXgDBLO1A6BFr Nd06IxVAD+nZxrzMmoBDBo3rwhHyvfX17+UR8I41gqsI8e6YQWlJcdjtVVJQE6zvNR6s x/EiFVw7WOFKBo6Og77ge/zuPbKivokgUmkOOU4NBZYC4vng3O4T+K96Zp+C2U5gMoP+ qw+A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=aM4IweAQ; 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 o6-20020a2e9b46000000b002da1f07ae1asi1682645ljj.38.2024.04.15.02.05.27; Mon, 15 Apr 2024 02:05:28 -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=aM4IweAQ; 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 EDF0D68D40C; Mon, 15 Apr 2024 12:05:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1B47C68D34D for ; Mon, 15 Apr 2024 12:04:59 +0300 (EEST) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4167fce0a41so20996255e9.0 for ; Mon, 15 Apr 2024 02:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713171898; x=1713776698; 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=tGbnz3gUycUoGNbZmfz1SppeIPPLxIh+3147G/3mJc4=; b=aM4IweAQ4m0qW09a3i4R7zSf4edv2iQQHSNqMjqocrxBzpdQHUyloILFiXjyrYjNuy 0j2PyHHSvVW0OySB1RLfCnyTLaSLcEX7ozGMpr+/PG4p64gCZJApNN82gxrfF9QN282A uDafycmn0Pt2YsUkrMLgV/2Denrmtt7OSYoeLZO/Fo9U7b08gokv6LEmxwCd9i6gLAFf poYTB9MYyNgbMr+TyDRZor83XqnquQ8SjmLmYM+xzr0inW9AZPKTcBQpBsUDH/rt1rJ5 fXDCxFP2ucv687YNntU97OxJWs9rgm44cbcUse+PkPIeqV7jw1s6C1+GEcbmqYM88Vdp mgyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713171898; x=1713776698; 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=tGbnz3gUycUoGNbZmfz1SppeIPPLxIh+3147G/3mJc4=; b=HXfrhidqFE0XUrkzqROa0/gdi920Vxa4QJ33cHrPZPsEpTFgRceCoPJZN/a0Rzi6QE k5QZuiR76LrOuF2d89KWL+UDgC0a3jSPqFkHI++XJxGi4kOTdiAbn1RarBZPrpu7mtEv 8sXMsmKnLlLD+BUxGAy3IqE4PB264yS0QukG8cKbK7RZbuLMtA6lD85oeRLZFfWG+Zos SLJu+RmimLsSbFXhTGV3v17YGvhaWczILjuJpzUI7Zam7tYiDaHlIiYu4aCMbQ5ZwG47 2E21trVYrSpIgEIeLApkmH6sGSZCwI1ckHeIaF+vNVK8GU+H63X15dzMosthx1ZcDGf6 egnA== X-Gm-Message-State: AOJu0YxQu/iWHMqDSstJJw6QewGp4yEL75vrGNevvatynSReuvjHeqMH zhYU45knYzUAERhR1B8o6vI+5oHDRG3otgN9pL1DCBLgqVJMEgQ3c3CQn1pA X-Received: by 2002:a7b:ca49:0:b0:418:c6a:1765 with SMTP id m9-20020a7bca49000000b004180c6a1765mr6500267wml.16.1713171897900; Mon, 15 Apr 2024 02:04:57 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.133.126]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b004181c91d1dcsm9283139wmb.18.2024.04.15.02.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:04:57 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 11:04:10 +0200 Message-ID: <20240415090410.1138-4-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240415090410.1138-1-Primeadvice@gmail.com> References: <20240415090410.1138-1-Primeadvice@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/amfenc: GPU driver version check 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: Araz Iusubov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SnecffOOlHYa Implemented gpu driver check. 10-bit patch works incorrectly on driver version lower than 23.30. --- libavcodec/amfenc_av1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index 634eeea48f..7463251529 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -215,6 +215,7 @@ FF_ENABLE_DEPRECATION_WARNINGS : avctx->pix_fmt; color_depth = AMF_COLOR_BIT_DEPTH_8; if (pix_fmt == AV_PIX_FMT_P010) { + AMF_RETURN_IF_FALSE(ctx, ctx->version >= AMF_MAKE_FULL_VERSION(1, 4, 32, 0), AVERROR_UNKNOWN, "HEVC 10-bit encoder is not supported by AMD GPU drivers versions lower than 23.30.\n"); color_depth = AMF_COLOR_BIT_DEPTH_10; }