From e48d82211e62cb9199d722f7218cfccbd0c77741 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Sun, 3 Aug 2025 19:41:02 +0200 Subject: [PATCH 02/39] =?UTF-8?q?lavfi/vf=5Fstack:=20check=20alp=C4=A5a=20?= =?UTF-8?q?mode=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas George --- libavfilter/vf_stack.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index fa202ee0cc..981f644cd2 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -135,6 +135,7 @@ static av_cold int init(AVFilterContext *ctx) pad.name = av_asprintf("input%d", i); if (!pad.name) return AVERROR(ENOMEM); + pad.flags |= AVFILTERPAD_FLAG_ACCEPT_PREMULTIPLIED; if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0) return ret; @@ -166,6 +167,17 @@ static int process_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) return 0; } +static int check_premult_consistent(AVFrame * const *frames, unsigned nb_frames) +{ + unsigned m = 0, i; + for (i = 0; i < nb_frames; i++) { + m |= frames[i]->alpha_mode == AVALPHA_MODE_PREMULTIPLIED ? 2 : 1; + if (m == 3) + return 0; + } + return 1; +} + static int process_frame(FFFrameSync *fs) { AVFilterContext *ctx = fs->parent; @@ -179,6 +191,10 @@ static int process_frame(FFFrameSync *fs) if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0) return ret; } + if (!check_premult_consistent(in, s->nb_inputs)) { + av_log(ctx, AV_LOG_ERROR, "All frames must have the same alpha mode.\n"); + return AVERROR(EINVAL); + } out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) -- 2.47.2