diff mbox series

[FFmpeg-devel,3/3] lavfi/vf_libplacebo: update peak detection options

Message ID 20230515085943.31760-3-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/3] lavfi/vf_libplacebo: switch to new gamut mapping API | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas May 15, 2023, 8:59 a.m. UTC
From: Niklas Haas <git@haasn.dev>

Upstream peak detection lost one option and gained one option. Update
code and documentation as required.
---
 doc/filters.texi            |  9 +++++----
 libavfilter/vf_libplacebo.c | 11 +++++++++--
 2 files changed, 14 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 510aefc6c9..3cd978e751 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16320,10 +16320,11 @@  logarithmic scale between @code{0.0} and @code{100.0}. Default to @code{5.5}
 and @code{10.0}, respectively. Setting either to a negative value disables
 this functionality.
 
-@item overshoot
-Peak smoothing overshoot margin, between @code{0.0} and @code{1.0}. Provides a
-safety margin to prevent clipping as a result of peak smoothing. Defaults to
-@code{0.05}, corresponding to a margin of 5%.
+@item percentile
+Which percentile of the frame brightness histogram to use as the source peak
+for tone-mapping. Defaults to @code{99.995}, a fairly conservative value.
+Setting this to @code{100.0} disables frame histogram measurement and instead
+uses the true peak brightness for tone-mapping.
 @end table
 
 @subsubsection Tone mapping
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 85e431402f..96822d0e57 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -242,7 +242,7 @@  typedef struct LibplaceboContext {
     float min_peak;
     float scene_low;
     float scene_high;
-    float overshoot;
+    float percentile;
 
     /* pl_color_map_params */
     struct pl_color_map_params color_map_params;
@@ -263,6 +263,7 @@  typedef struct LibplaceboContext {
     int intent;
     int tonemapping_mode;
     float crosstalk;
+    float overshoot;
 #endif
 
     /* pl_dither_params */
@@ -408,7 +409,12 @@  static int update_settings(AVFilterContext *ctx)
         .minimum_peak = s->min_peak,
         .scene_threshold_low = s->scene_low,
         .scene_threshold_high = s->scene_high,
+#if PL_API_VER >= 263
+        .percentile = s->percentile,
+#endif
+#if FF_API_LIBPLACEBO_OPTS && PL_API_VER < 256
         .overshoot_margin = s->overshoot,
+#endif
     );
 
     s->color_map_params = *pl_color_map_params(
@@ -1194,7 +1200,7 @@  static const AVOption libplacebo_options[] = {
     { "minimum_peak", "Peak detection minimum peak", OFFSET(min_peak), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 100.0, DYNAMIC },
     { "scene_threshold_low", "Scene change low threshold", OFFSET(scene_low), AV_OPT_TYPE_FLOAT, {.dbl = 5.5}, -1.0, 100.0, DYNAMIC },
     { "scene_threshold_high", "Scene change high threshold", OFFSET(scene_high), AV_OPT_TYPE_FLOAT, {.dbl = 10.0}, -1.0, 100.0, DYNAMIC },
-    { "overshoot", "Tone-mapping overshoot margin", OFFSET(overshoot), AV_OPT_TYPE_FLOAT, {.dbl = 0.05}, 0.0, 1.0, DYNAMIC },
+    { "percentile", "Peak detection percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl = 99.995}, 0.0, 100.0, DYNAMIC },
 
     { "gamut_mode", "Gamut-mapping mode", OFFSET(gamut_mode), AV_OPT_TYPE_INT, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, GAMUT_MAP_COUNT - 1, DYNAMIC, "gamut_mode" },
         { "clip", "Hard-clip (RGB per-channel)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_CLIP}, 0, 0, STATIC, "gamut_mode" },
@@ -1244,6 +1250,7 @@  static const AVOption libplacebo_options[] = {
         { "hybrid", "Hybrid of Luma/RGB", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, STATIC, "tonemap_mode" },
         { "luma", "Luminance", 0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, STATIC, "tonemap_mode" },
     { "tonemapping_crosstalk", "Crosstalk factor for tone-mapping", OFFSET(crosstalk), AV_OPT_TYPE_FLOAT, {.dbl = 0.04}, 0.0, 0.30, DYNAMIC | AV_OPT_FLAG_DEPRECATED },
+    { "overshoot", "Tone-mapping overshoot margin", OFFSET(overshoot), AV_OPT_TYPE_FLOAT, {.dbl = 0.05}, 0.0, 1.0, DYNAMIC | AV_OPT_FLAG_DEPRECATED },
 #endif
 
     { "dithering", "Dither method to use", OFFSET(dithering), AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1, DYNAMIC, "dither" },