From 955cf563c8694128c1f5e76be3d60cc0674d1409 Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Fri, 6 Mar 2026 22:37:37 +0100 Subject: [PATCH] swscale/tests/swscale: always allocate frame in scale_legacy() Legacy swscale may overwrite the pixel formats in the context (see handle_formats() in libswscale/utils.c). This may lead to an issue where, when sws_frame_start() allocates a new frame, it uses the wrong pixel format. Instead of fixing the issue in swscale, just make sure dst is always allocated prior to calling the legacy scaler. Sponsored-by: Sovereign Tech Fund Signed-off-by: Ramiro Polla --- libswscale/tests/swscale.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index 8001f0d105..d85dcda726 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -224,14 +224,20 @@ static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode, sws_legacy->dither = mode.dither; sws_legacy->threads = opts.threads; + av_frame_unref(dst); + dst->width = sws_legacy->dst_w; + dst->height = sws_legacy->dst_h; + dst->format = sws_legacy->dst_format; + ret = av_frame_get_buffer(dst, 0); + if (ret < 0) + goto error; + if ((ret = sws_init_context(sws_legacy, NULL, NULL)) < 0) goto error; int64_t time = av_gettime_relative(); - for (int i = 0; ret >= 0 && i < opts.iters; i++) { - unref_buffers(dst); + for (int i = 0; ret >= 0 && i < opts.iters; i++) ret = sws_scale_frame(sws_legacy, dst, src); - } *out_time = av_gettime_relative() - time; error: