PR #25456 opened by JuliusBairaktaris URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25456 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25456.patch
The AMF video converter tone maps HDR input to SDR output, but vpp_amf has no way to select the algorithm, so the runtime default is always used. - `avfilter/vf_vpp_amf: add a tonemap option`: copy, amd, linear, gamma, reinhard or bt2390. Leaving it unset keeps the runtime default, which is amd. HDR10 (BT.2020, PQ) 1080p to BT.709 NV12: leaving the option unset gives the same output as tonemap=amd, and copy, gamma, reinhard and bt2390 each change the output. On the current runtime, linear gives the same output as copy, bt2390 is far too dark, and input and output HDR metadata do not change any curve. I reported this as GPUOpen-LibrariesAndSDKs/AMF#628. The option passes the value through, so it follows runtime fixes. Tested on Windows 11, RX 9070 XT, driver 32.0.32015.7029, AMF runtime 1.5.3.0. Written with Claude Opus 5.5 in Claude Code; `Assisted-by` trailer on the commit. >From db1e1b459d78a6b9a87ddc448573f5e7d1453bda Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris <[email protected]> Date: Sun, 25 Oct 2026 16:36:29 +0100 Subject: [PATCH] avfilter/vf_vpp_amf: add a tonemap option The AMF video converter tone maps HDR input to SDR output, but vpp_amf has no way to select the algorithm, so the runtime default is always used. Add a tonemap option that sets AMF_VIDEO_CONVERTER_INPUT_TONEMAPPING. Leaving it unset keeps the runtime default. Tested on Windows 11, RX 9070 XT, driver 32.0.32015.7029, AMF runtime 1.5.3.0, with an HDR10 (BT.2020, PQ) clip converted to BT.709 NV12: leaving the option unset gives the same output as tonemap=amd, and copy, gamma, reinhard and bt2390 each change the output. linear gives the same output as copy, and bt2390 is much darker than BT.2390 should be; both are runtime issues, reported as GPUOpen-LibrariesAndSDKs/AMF#628. Assisted-by: Claude Opus 5.5 Signed-off-by: Julius Bairaktaris <[email protected]> --- doc/filters.texi | 23 +++++++++++++++++++++++ libavfilter/vf_amf_common.h | 1 + libavfilter/vf_vpp_amf.c | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 37f9123df49..e40a393abff 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -26350,6 +26350,29 @@ ARIB_STD_B67 @end table +@item tonemap +Tone mapping applied when HDR input is converted to SDR output. By default the +AMF runtime decides. +@table @samp +@item copy +Copy without tone mapping. + +@item amd +AMD tone mapping. + +@item linear +Linear. + +@item gamma +Gamma. + +@item reinhard +Reinhard. + +@item bt2390 +ITU-R BT.2390. +@end table + @item in_primaries Override input color primaries. diff --git a/libavfilter/vf_amf_common.h b/libavfilter/vf_amf_common.h index 9af3d2ddda9..94c78ffb4db 100644 --- a/libavfilter/vf_amf_common.h +++ b/libavfilter/vf_amf_common.h @@ -47,6 +47,7 @@ typedef struct AMFFilterContext { int out_color_range; int out_primaries; int out_trc; + int tonemapping; int fill; int fill_color; int keep_ratio; diff --git a/libavfilter/vf_vpp_amf.c b/libavfilter/vf_vpp_amf.c index 1369c400124..36771a17b8e 100644 --- a/libavfilter/vf_vpp_amf.c +++ b/libavfilter/vf_vpp_amf.c @@ -141,6 +141,11 @@ static int amf_filter_config_output(AVFilterLink *outlink) AMF_ASSIGN_PROPERTY_INT64(res, ctx->component, AMF_VIDEO_CONVERTER_INPUT_TRANSFER_CHARACTERISTIC, ctx->in_trc); } + if (ctx->tonemapping != AMF_VIDEO_CONVERTER_TONEMAPPING_UNDEFINED) { + AMF_ASSIGN_PROPERTY_INT64(res, ctx->component, AMF_VIDEO_CONVERTER_INPUT_TONEMAPPING, ctx->tonemapping); + AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "Failed to set tone mapping: %d\n", res); + } + sd = av_frame_side_data_get(inlink->side_data, inlink->nb_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); if (sd) { @@ -249,6 +254,14 @@ static const AVOption vpp_amf_options[] = { { "smpte428", "SMPTE428", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE428 }, 0, 0, FLAGS, "trc" }, { "arib-std-b67", "ARIB_STD_B67", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_COLOR_TRANSFER_CHARACTERISTIC_ARIB_STD_B67 }, 0, 0, FLAGS, "trc" }, + { "tonemap", "Tone mapping of HDR input to SDR output", OFFSET(tonemapping), AV_OPT_TYPE_INT, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_UNDEFINED }, AMF_VIDEO_CONVERTER_TONEMAPPING_UNDEFINED, AMF_VIDEO_CONVERTER_TONEMAPPING_2390, FLAGS, "tonemap" }, + { "copy", "Copy without tone mapping", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_COPY }, 0, 0, FLAGS, "tonemap" }, + { "amd", "AMD tone mapping", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_AMD }, 0, 0, FLAGS, "tonemap" }, + { "linear", "Linear", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_LINEAR }, 0, 0, FLAGS, "tonemap" }, + { "gamma", "Gamma", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_GAMMA }, 0, 0, FLAGS, "tonemap" }, + { "reinhard", "Reinhard", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_REINHARD }, 0, 0, FLAGS, "tonemap" }, + { "bt2390", "ITU-R BT.2390", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_CONVERTER_TONEMAPPING_2390 }, 0, 0, FLAGS, "tonemap" }, + { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, SCALE_FORCE_OAR_NB-1, FLAGS, "force_oar" }, { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_FORCE_OAR_DISABLE }, 0, 0, FLAGS, "force_oar" }, { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_FORCE_OAR_DECREASE }, 0, 0, FLAGS, "force_oar" }, -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
