From: Niklas Haas via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avfilter/vf_libplacebo: two blending-related fixes (PR #20491)
Date: Thu, 11 Sep 2025 00:05:39 -0000
Message-ID: <175754914053.25.2176504532139457440@463a07221176> (raw)
PR #20491 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20491
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20491.patch
>From 71d4a88136e731bddf2673e13ed393efe9c2fdd5 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Thu, 11 Sep 2025 01:39:46 +0200
Subject: [PATCH 1/2] avfilter/vf_libplacebo: use temporary params struct for
per-pass params
Instead of directly mutating `opts->params`. Avoids any possible leak of
overriden params between invocations of this function, as well as the later
`pl_render_image` during the linear output pass.
---
libavfilter/vf_libplacebo.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 5e0a678ff2..8f30eb193b 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1038,12 +1038,7 @@ props_done:
}
/* Draw first frame opaque, others with blending */
- opts->params.blend_params = NULL;
-#if PL_API_VER >= 346
- opts->params.background = opts->params.border = PL_CLEAR_COLOR;
-#else
- opts->params.skip_target_clearing = false;
-#endif
+ struct pl_render_params tmp_params = opts->params;
for (int i = 0; i < s->nb_inputs; i++) {
LibplaceboInput *in = &s->inputs[i];
FilterLink *il = ff_filter_link(ctx->inputs[i]);
@@ -1053,17 +1048,17 @@ props_done:
pl_renderer_flush_cache(in->renderer);
continue;
}
- opts->params.skip_caching_single_frame = high_fps;
+ tmp_params.skip_caching_single_frame = high_fps;
update_crops(ctx, in, &target, target_pts);
- pl_render_image_mix(in->renderer, &in->mix, &target, &opts->params);
+ pl_render_image_mix(in->renderer, &in->mix, &target, &tmp_params);
/* Force straight output and set correct blend mode */
target.repr.alpha = PL_ALPHA_INDEPENDENT;
- opts->params.blend_params = &pl_alpha_overlay;
+ tmp_params.blend_params = &pl_alpha_overlay;
#if PL_API_VER >= 346
- opts->params.background = opts->params.border = PL_CLEAR_SKIP;
+ tmp_params.background = tmp_params.border = PL_CLEAR_SKIP;
#else
- opts->params.skip_target_clearing = true;
+ tmp_params.skip_target_clearing = true;
#endif
}
--
2.49.1
>From ba24b8bf6f6003901af92c83a442d49263cab9d3 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Thu, 11 Sep 2025 01:48:32 +0200
Subject: [PATCH 2/2] avfilter/vf_libplacebo: force premultiplied blending for
linear texture
Blending onto independent alpha framebuffers is not possible under the
constraints of the supported blend operators. While we could handle
blending premul-onto-premul, this would break if the base layer is YUV,
since premultiplied alpha does not survive the (nonlinear) YUV conversion.
Fortunately, blending independent-onto-premul is just as easy, and works in
all cases. So just force this mode when using a linear intermediate blend
texture, which is always RGBA.
---
libavfilter/vf_libplacebo.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 8f30eb193b..80d3b273bb 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1033,6 +1033,7 @@ props_done:
.color = orig_target.color,
.rotation = orig_target.rotation,
};
+ target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
target.color.transfer = PL_COLOR_TRC_LINEAR;
use_linear_compositor = true;
}
@@ -1052,7 +1053,8 @@ props_done:
update_crops(ctx, in, &target, target_pts);
pl_render_image_mix(in->renderer, &in->mix, &target, &tmp_params);
- /* Force straight output and set correct blend mode */
+ /* Force straight output and set correct blend operator. This is
+ * required to get correct blending onto YUV target buffers. */
target.repr.alpha = PL_ALPHA_INDEPENDENT;
tmp_params.blend_params = &pl_alpha_overlay;
#if PL_API_VER >= 346
@@ -1065,6 +1067,7 @@ props_done:
if (use_linear_compositor) {
/* Blit the linear intermediate image to the output frame */
target.crop = orig_target.crop = (struct pl_rect2df) {0};
+ target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
pl_render_image(s->linear_rr, &target, &orig_target, &opts->params);
target = orig_target;
} else if (!ref) {
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-11 0:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175754914053.25.2176504532139457440@463a07221176 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git