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 D350A42C2F for ; Wed, 12 Jan 2022 22:50:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C93CC68AE46; Thu, 13 Jan 2022 00:49:51 +0200 (EET) Received: from mail.xaymar.com (xaymar.com [95.217.118.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 801FD6899A7 for ; Thu, 13 Jan 2022 00:49:44 +0200 (EET) Received: from localhost.localdomain (unknown [IPv6:2a02:8106:c:6a00:ccbc:cf2c:5bb9:d3cf]) by mail.xaymar.com (Postfix) with ESMTPSA id AA39961341; Wed, 12 Jan 2022 23:49:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xaymar.com; s=2021; t=1642027783; bh=b/353aHdmaIO4F2oI1ltV0rxbVBJuKPzo2XyoI4pcUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EudoQXCpsaIjoKd8F22KG4SifWbUtqNfwyMI1XMhsfD4x6+nKMxUTQ+opsKGrdE+Y ZU1PbzpcYJsmPBhubdoNhrm7NRMKb8vcUkn9ARMNzX/vG+/GWPHYoBzumg8Hta/Xk+ notLU2ELYJGrwHQXnvz5v9rTEMJEP7+wTc/brNfH7rBpNELalxQ5fekYebzJSqMhRX ik4vyJmcp0K+fKV0HL98rK6wsSKDitI7nQB5Zhd+D5LG4DggGAYOK7I1WP0tFNTCBw rB3nPB9ois1u+DukU48/xNyWdthHNnl0BCYCe135lG9VWrRM2ufOmOLA2+eURMqiFs dey2dixmjUmGhnbuf9gGG4DhzkLm//PljzAwQBy6SXQzrsypexKHM1NPpQKJXcuMyQ sVUkTNlx2hFq5g+MbOY7G9gB0xOPian+4aUQQIwIJez/+SURmlqQ+Mdbex1yLr72Af O6xcKOWXnnec9+DI2XiuUKUZn3a3IYdgB8FkO/Y3B8KJmbyxt73OeZbYVLnVnBGhml W3U4flWqjsxFornNzLWPZ+XtGMjYRcXQ2+xalxkGG9NbAFXS3B9SXDNxRSXjQlDrFW TlgM1stSdwZCfNu5fL5vKvL5aoz08IyY7FICtoGPoputtTSjJ5/YYmyacC2bLtNF92 OShPaRBcww137QRrbIEw= From: Michael Fabian 'Xaymar' Dirks To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:49:21 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <96117e46dbb4032a02d92c178ea4cc979203a0d3.1642027745.git.michael.dirks@xaymar.com> References: <96117e46dbb4032a02d92c178ea4cc979203a0d3.1642027745.git.michael.dirks@xaymar.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avcodec/amfenc: Set all color metadata for 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: Michael Fabian 'Xaymar' Dirks 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: Fixes the color information in the output from the AMD encoder being wrong, which led to weird transcoding results. This problem appeared out of thin air, and I've been unable to tie it to a specific driver that supports my hardware. Unfortunately this requires AMF SDK version 1.4.23 or later, but it should still work fine on older drivers. Theoretical support for HDR encoding is also now possible, although the implementation is not complete. I have no clear idea on how to generate AMFs HDR metadata structure, or where to even take this information from. --- libavcodec/amfenc.h | 1 + libavcodec/amfenc_h264.c | 48 +++++++++++++++++++++++++++++++++++++- libavcodec/amfenc_hevc.c | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h index 358b2ef778..951e529362 100644 --- a/libavcodec/amfenc.h +++ b/libavcodec/amfenc.h @@ -21,6 +21,7 @@ #include +#include #include #include diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c index aeca99f7c6..009378e9f1 100644 --- a/libavcodec/amfenc_h264.c +++ b/libavcodec/amfenc_h264.c @@ -137,6 +137,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_depth; + amf_int64 color_profile; if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); @@ -194,10 +196,54 @@ static av_cold int amf_encode_init_h264(AVCodecContext *avctx) AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, AMF_VIDEO_ENCODER_ASPECT_RATIO, ratio); } - /// Color Range (Partial/TV/MPEG or Full/PC/JPEG) + // Color Metadata + /// Color Range (Support for older Drivers) if (avctx->color_range == AVCOL_RANGE_JPEG) { AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, 1); + } else { + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, 0); + } + /// Color Space & Depth + color_depth = AMF_COLOR_BIT_DEPTH_8; + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN; + switch (avctx->colorspace) { + case AVCOL_SPC_SMPTE170M: + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601; + } + break; + case AVCOL_SPC_BT709: + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709; + } + break; + case AVCOL_SPC_BT2020_NCL: + case AVCOL_SPC_BT2020_CL: + // !FIXME: Verify that this is correct on Hardware supporting it. + // !FIXME: Figure out how to decide on bit depth. + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020; + color_depth = AMF_COLOR_BIT_DEPTH_10; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020; + color_depth = AMF_COLOR_BIT_DEPTH_10; + } + break; } + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_COLOR_BIT_DEPTH, color_depth); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_COLOR_PROFILE, color_profile); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_COLOR_PROFILE, color_profile); + /// Color Transfer Characteristics (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc); + 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_INPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); + /// !TODO: AMF HDR Metadata generation // 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 79541b9b2f..900e1482b4 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -104,6 +104,8 @@ 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; if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); @@ -152,6 +154,54 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) AMFRatio ratio = AMFConstructRatio(avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ASPECT_RATIO, ratio); } + + // Color Metadata + /// Color Range (Support for older Drivers) + if (avctx->color_range == AVCOL_RANGE_JPEG) { + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NOMINAL_RANGE, 1); + } else { + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NOMINAL_RANGE, 0); + } + /// Color Space & Depth + color_depth = AMF_COLOR_BIT_DEPTH_8; + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN; + switch (avctx->colorspace) { + case AVCOL_SPC_SMPTE170M: + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601; + } + break; + case AVCOL_SPC_BT709: + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709; + } + break; + case AVCOL_SPC_BT2020_NCL: + case AVCOL_SPC_BT2020_CL: + // !FIXME: Verify that this is correct on Hardware supporting it. + // !FIXME: Figure out how to decide on bit depth. + if (avctx->color_range == AVCOL_RANGE_JPEG) { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020; + color_depth = AMF_COLOR_BIT_DEPTH_10; + } else { + color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020; + color_depth = AMF_COLOR_BIT_DEPTH_10; + } + break; + } + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_COLOR_BIT_DEPTH, color_depth); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_COLOR_PROFILE, color_profile); + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PROFILE, color_profile); + /// Color Transfer Characteristics (AMF matches ISO/IEC) + AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_TRANSFER_CHARACTERISTIC, (amf_int64)avctx->color_trc); + 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_INPUT_COLOR_PRIMARIES, (amf_int64)avctx->color_primaries); + 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); -- 2.34.1.windows.1 _______________________________________________ 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".