From patchwork Wed May 10 13:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 41570 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp3867876pzb; Wed, 10 May 2023 06:56:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ilWnLjnPlELrA83SzHwacWL77IeUPWDJlkeTdfl5uFpKxTtOHd5W+0EPxYouLPWcUQsoS X-Received: by 2002:a17:907:6da0:b0:96a:4409:ef96 with SMTP id sb32-20020a1709076da000b0096a4409ef96mr523511ejc.77.1683726984344; Wed, 10 May 2023 06:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683726984; cv=none; d=google.com; s=arc-20160816; b=e81WBdRL9bDN3mrbkCZkUEMy3NH+uC0vQCluOUubt8UbxMPEhcdVccsLu6MZGIG4l2 EZvhm5H+rVsGTLAiuxiGG8SUtNKI42YbAEbs5idRCD09geAxWHjYLQ2GX8vqzhM3XAGZ SI8fodShKfaO/8HRnu2HK1LkGp4pFzF/xkfaxzfCwJpJX+8i2tsfqBTUmcuWEf3FxJWJ 3D0ltdjt40caUwDwCqWADuXlDnPrUg1tVeodbdQv6QLQx9Lczwknl40fVJGyEvCzyrHV ov1/CZXN78VG7xN4BSJYX9YyZe0iiDLb/Nz6KiLfjdmRiNbqUTYSGGZhc6b4D4sCjY6V BHHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=307kUyDzXVmmLIkDGMoADRqSWbOp9xQUAoiUyOzLmgA=; b=ogsKW/1NpoPM+87/0yj4mKJ9Fgxg7SQqQIpyl/AXeL7rs8P5XxUHuJiOek2sp+NvPQ G5wW7Gp2zCSgrqzXhlETlzQVxx2Dt34x/wnBiqW0nN6V1/4zdsAb+/T6n/xLUxYu5lt2 2EO/DEcFkpgyePQb893NaTf5ogrJIlPIAPGWpGC5WubXxhzX4s3I3fiUCMbbfWfNDD77 A/vjMHQ+qICzTlmncBkV2MIeBpNdKQs4fScKoT4hn6a3iaZOyS1VUZ3DoGAivtaLJHA7 nvrkdlikR8DzwoR+wk9RmMBLK1ZrYllG1GtZB4NYEh05K0JNzhmNbZbHKZqwI+HQumhw v2qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=HvX4F37R; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b22-20020a1709062b5600b0096651724240si3135322ejg.286.2023.05.10.06.56.24; Wed, 10 May 2023 06:56:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=HvX4F37R; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA62868C19B; Wed, 10 May 2023 16:55:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B98968C170 for ; Wed, 10 May 2023 16:55:22 +0300 (EEST) Received: from localhost (217-74-0-168.hsi.r-kom.net [217.74.0.168]) by haasn.dev (Postfix) with ESMTPSA id 568DE4AA43; Wed, 10 May 2023 15:55:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1683726918; bh=KN4fsxd7kygArHsiO75slviY5jotxqXTUsdtoc+2nDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HvX4F37RvE4wRuyemvVYnh9KZLNsbe6HwMOLkPJk4M8VqQ2adg2BlmnbEZQQiUAFi aqqGSLCzuWTEbbldwqRg7/BFtMM4TBNQ2GmfKpEluRVKCsrP87b91xchImsBUxPWhB cgA5MB4WJc+wHiKWs5pHeImTWkbBMAYZtBE+2YKo= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 May 2023 15:55:09 +0200 Message-Id: <20230510135509.4074-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510135509.4074-1-ffmpeg@haasn.xyz> References: <20230510135509.4074-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] lavfi/vf_libplacebo: add frame_mixer option 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sQ+agQhagof2 From: Niklas Haas 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 --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 },