diff mbox series

[FFmpeg-devel,6/6] lavfi/vf_libplacebo: add frame_mixer option

Message ID 20230510135509.4074-6-ffmpeg@haasn.xyz
State Accepted
Commit 30c71ef98e6b0d3b5d303388a81676a5bd963227
Headers show
Series [FFmpeg-devel,1/6] lavfi/vf_libplacebo: update render params on demand | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas May 10, 2023, 1:55 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Fairly straightforward. We just need to modify the scaler handling code
slightly to support looking at a different list of filter presets.
---
 doc/filters.texi            | 31 +++++++++++++++++++++++++++++++
 libavfilter/vf_libplacebo.c | 17 +++++++++++------
 2 files changed, 42 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 3e17ba1654..42ce313743 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16167,6 +16167,31 @@  Cubic BC spline with parameters recommended by Mitchell and Netravali. Very
 little ringing.
 @end table
 
+@item frame_mixer
+Controls the kernel used for mixing frames temporally. The default value is
+@code{none}, which disables frame mixing. For a full list of possible values,
+pass @code{help} to this option. The most important values are:
+@table @samp
+@item none
+Disables frame mixing, giving a result equivalent to "nearest neighbour"
+semantics.
+
+@item oversample
+Oversamples the input video to create a "Smooth Motion"-type effect: if an
+output frame would exactly fall on the transition between two video frames, it
+is blended according to the relative overlap. This is the recommended option
+whenever preserving the original subjective appearance is desired.
+
+@item mitchell_clamp
+Larger filter kernel that smoothly interpolates multiple frames in a manner
+designed to eliminate ringing and other artefacts as much as possible. This is
+the recommended option wherever maximum visual smoothness is desired.
+
+@item linear
+Linear blend/fade between frames. Especially useful for constructing e.g.
+slideshows.
+@end table
+
 @item lut_entries
 Configures the size of scaler LUTs, ranging from @code{1} to @code{256}. The
 default of @code{0} will pick libplacebo's internal default, typically
@@ -16524,6 +16549,12 @@  Rescale input to fit into standard 1080p, with high quality scaling:
 libplacebo=w=1920:h=1080:force_original_aspect_ratio=decrease:normalize_sar=true:upscaler=ewa_lanczos:downscaler=ewa_lanczos
 @end example
 
+@item
+Interpolate low FPS / VFR input to smoothed constant 60 fps output:
+@example
+libplacebo=fps=60:frame_mixer=mitchell_clamp
+@end example
+
 @item
 Convert input to standard sRGB JPEG:
 @example
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 2bec942358..9cbc1bac94 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -164,6 +164,7 @@  typedef struct LibplaceboContext {
     struct pl_render_params params;
     char *upscaler;
     char *downscaler;
+    char *frame_mixer;
     int lut_entries;
     float antiringing;
     int sigmoid;
@@ -285,17 +286,19 @@  static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
 
 static int find_scaler(AVFilterContext *avctx,
                        const struct pl_filter_config **opt,
-                       const char *name)
+                       const char *name, int frame_mixing)
 {
-    const struct pl_filter_preset *preset;
+    const struct pl_filter_preset *preset, *presets_avail;
+    presets_avail = frame_mixing ? pl_frame_mixers : pl_scale_filters;
+
     if (!strcmp(name, "help")) {
         av_log(avctx, AV_LOG_INFO, "Available scaler presets:\n");
-        for (preset = pl_scale_filters; preset->name; preset++)
+        for (preset = presets_avail; preset->name; preset++)
             av_log(avctx, AV_LOG_INFO, "    %s\n", preset->name);
         return AVERROR_EXIT;
     }
 
-    for (preset = pl_scale_filters; preset->name; preset++) {
+    for (preset = presets_avail; preset->name; preset++) {
         if (!strcmp(name, preset->name)) {
             *opt = preset->filter;
             return 0;
@@ -411,8 +414,9 @@  static int update_settings(AVFilterContext *ctx)
         .disable_fbos = s->disable_fbos,
     );
 
-    RET(find_scaler(ctx, &s->params.upscaler, s->upscaler));
-    RET(find_scaler(ctx, &s->params.downscaler, s->downscaler));
+    RET(find_scaler(ctx, &s->params.upscaler, s->upscaler, 0));
+    RET(find_scaler(ctx, &s->params.downscaler, s->downscaler, 0));
+    RET(find_scaler(ctx, &s->params.frame_mixer, s->frame_mixer, 1));
     return 0;
 
 fail:
@@ -1107,6 +1111,7 @@  static const AVOption libplacebo_options[] = {
 
     { "upscaler", "Upscaler function", OFFSET(upscaler), AV_OPT_TYPE_STRING, {.str = "spline36"}, .flags = DYNAMIC },
     { "downscaler", "Downscaler function", OFFSET(downscaler), AV_OPT_TYPE_STRING, {.str = "mitchell"}, .flags = DYNAMIC },
+    { "frame_mixer", "Frame mixing function", OFFSET(frame_mixer), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = DYNAMIC },
     { "lut_entries", "Number of scaler LUT entries", OFFSET(lut_entries), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 256, DYNAMIC },
     { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC },
     { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },