PR #22634 opened by nyanmisaka URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22634 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22634.patch
- avcodec/amfenc: update full range color support for AV1 encoder ``` Furthermore, the flags for H264/HEVC have been updated to those renamed in AMF 1.5.0+, instead of using the old ones that were already marked as deprecated: AMF_VIDEO_ENCODER_FULL_RANGE_COLOR -> AMF_VIDEO_ENCODER_OUTPUT_FULL_RANGE_COLOR AMF_VIDEO_ENCODER_HEVC_NOMINAL_RANGE -> AMF_VIDEO_ENCODER_HEVC_OUTPUT_FULL_RANGE_COLOR The macro content remains the same, therefore it will not cause regressions. ``` - avcodec/amfenc: use pixel desc to determine YUV input ``` Therefore, the YUV420P is now being taken into consideration. ``` Signed-off-by: nyanmisaka <[email protected]> >From d25a060ed8a3ae5948c4ccf626dbf5bf63e8e122 Mon Sep 17 00:00:00 2001 From: nyanmisaka <[email protected]> Date: Fri, 27 Mar 2026 13:56:06 +0800 Subject: [PATCH 1/2] avcodec/amfenc: update full range color support for AV1 encoder Furthermore, the flags for H264/HEVC have been updated to those renamed in AMF 1.5.0+, instead of using the old ones that were already marked as deprecated: AMF_VIDEO_ENCODER_FULL_RANGE_COLOR -> AMF_VIDEO_ENCODER_OUTPUT_FULL_RANGE_COLOR AMF_VIDEO_ENCODER_HEVC_NOMINAL_RANGE -> AMF_VIDEO_ENCODER_HEVC_OUTPUT_FULL_RANGE_COLOR The macro content remains the same, therefore it will not cause regressions. Signed-off-by: nyanmisaka <[email protected]> --- libavcodec/amfenc_av1.c | 4 ++-- libavcodec/amfenc_h264.c | 2 +- libavcodec/amfenc_hevc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index b57c76de27..6197fc96e2 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -262,7 +262,7 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile); // Color Range - // TODO + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_FULL_RANGE_COLOR, (avctx->color_range == AVCOL_RANGE_JPEG)); // Color Transfer Characteristics (AMF matches ISO/IEC) if(avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && (pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010)){ @@ -746,7 +746,7 @@ const FFCodec ff_av1_amf_encoder = { AV_CODEC_CAP_DR1, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, CODEC_PIXFMTS_ARRAY(ff_amf_pix_fmts), - .color_ranges = AVCOL_RANGE_MPEG, /* FIXME: implement tagging */ + .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, .p.wrapper_name = "amf", .hw_configs = ff_amfenc_hw_configs, }; diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c index b92b9af875..ff2fe31dd6 100644 --- a/libavcodec/amfenc_h264.c +++ b/libavcodec/amfenc_h264.c @@ -275,7 +275,7 @@ static av_cold int amf_encode_init_h264(AVCodecContext *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)); + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_OUTPUT_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 diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c index 01d6ea9b3d..7bd04d5dcf 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -257,7 +257,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *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)); + AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_FULL_RANGE_COLOR, (avctx->color_range == AVCOL_RANGE_JPEG)); // Color Transfer Characteristics (AMF matches ISO/IEC) if(avctx->color_trc != AVCOL_TRC_UNSPECIFIED && (pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010)){ -- 2.52.0 >From 95b91cfb994ca3b9faf2342b0ad0769ad254ec97 Mon Sep 17 00:00:00 2001 From: nyanmisaka <[email protected]> Date: Fri, 27 Mar 2026 14:11:23 +0800 Subject: [PATCH 2/2] avcodec/amfenc: use pixel desc to determine YUV input Therefore, the YUV420P is now being taken into consideration. Signed-off-by: nyanmisaka <[email protected]> --- libavcodec/amfenc_av1.c | 8 +++++--- libavcodec/amfenc_hevc.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index 6197fc96e2..9e2060d485 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -20,6 +20,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mem.h" #include "libavutil/opt.h" +#include "libavutil/pixdesc.h" #include "amfenc.h" #include "codec_internal.h" @@ -205,6 +206,7 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) amf_int64 bit_depth; amf_int64 color_profile; enum AVPixelFormat pix_fmt; + const AVPixFmtDescriptor *pix_desc; //for av1 alignment and crop uint32_t crop_right = 0; @@ -251,6 +253,7 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) // Color bit depth pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format : avctx->pix_fmt; + pix_desc = av_pix_fmt_desc_get(pix_fmt); bit_depth = ctx->bit_depth; if(bit_depth == AMF_COLOR_BIT_DEPTH_UNDEFINED){ bit_depth = pix_fmt == AV_PIX_FMT_P010 ? AMF_COLOR_BIT_DEPTH_10 : AMF_COLOR_BIT_DEPTH_8; @@ -265,7 +268,7 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_FULL_RANGE_COLOR, (avctx->color_range == AVCOL_RANGE_JPEG)); // Color Transfer Characteristics (AMF matches ISO/IEC) - if(avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && (pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010)){ + if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && !(pix_desc->flags & AV_PIX_FMT_FLAG_RGB)) { // if input is YUV, color_primaries are for VUI only // AMF VCN color conversion supports only specific output primaries BT2020 for 10-bit and BT709 for 8-bit // vpp_amf supports more @@ -273,8 +276,7 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) } // Color Primaries (AMF matches ISO/IEC) - if(avctx->color_primaries != AVCOL_PRI_UNSPECIFIED || pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010 ) - { + if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && !(pix_desc->flags & AV_PIX_FMT_FLAG_RGB)) { // AMF VCN color conversion supports only specific primaries BT2020 for 10-bit and BT709 for 8-bit // vpp_amf supports more AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, avctx->color_primaries); diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c index 7bd04d5dcf..9eadf87787 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -20,6 +20,7 @@ #include "libavutil/internal.h" #include "libavutil/mem.h" #include "libavutil/opt.h" +#include "libavutil/pixdesc.h" #include "amfenc.h" #include "codec_internal.h" #include <AMF/components/PreAnalysis.h> @@ -176,6 +177,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) amf_int64 bit_depth; amf_int64 color_profile; enum AVPixelFormat pix_fmt; + const AVPixFmtDescriptor *pix_desc; if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); @@ -245,7 +247,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) // Color bit depth pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format : avctx->pix_fmt; - + pix_desc = av_pix_fmt_desc_get(pix_fmt); bit_depth = ctx->bit_depth; if(bit_depth == AMF_COLOR_BIT_DEPTH_UNDEFINED){ bit_depth = pix_fmt == AV_PIX_FMT_P010 ? AMF_COLOR_BIT_DEPTH_10 : AMF_COLOR_BIT_DEPTH_8; @@ -260,7 +262,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_FULL_RANGE_COLOR, (avctx->color_range == AVCOL_RANGE_JPEG)); // Color Transfer Characteristics (AMF matches ISO/IEC) - if(avctx->color_trc != AVCOL_TRC_UNSPECIFIED && (pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010)){ + if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED && !(pix_desc->flags & AV_PIX_FMT_FLAG_RGB)) { // if input is YUV, color_trc is for VUI only - any value // AMF VCN color conversion supports only specific output transfer characteristic SMPTE2084 for 10-bit and BT709 for 8-bit // vpp_amf supports more @@ -268,7 +270,7 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) } // Color Primaries (AMF matches ISO/IEC) - if(avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && (pix_fmt == AV_PIX_FMT_NV12 || pix_fmt == AV_PIX_FMT_P010)){ + if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED && !(pix_desc->flags & AV_PIX_FMT_FLAG_RGB)) { // if input is YUV, color_primaries are for VUI only // AMF VCN color conversion supports only specific output primaries BT2020 for 10-bit and BT709 for 8-bit // vpp_amf supports more -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
