[FFmpeg-devel] [PATCH] avfilter/vf_alphamerge: use refcounting for planar formats
Nicolas George
george at nsup.org
Sat Aug 9 20:46:58 EEST 2025
Jorge Estrada (HE12025-08-07):
> From b413b7f8a966c2cf77c8703b5f68e8ea492d930a Mon Sep 17 00:00:00 2001
> From: Jorge Estrada <jestrada.list at gmail.com>
> Date: Thu, 7 Aug 2025 12:55:19 -0700
> Subject: use av_buffer_replace
>
> Addressed. Uses av_buffer_replace now
>
> ---
> libavfilter/vf_alphamerge.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c
> index f5779484a9..69c0dd04ea 100644
> --- a/libavfilter/vf_alphamerge.c
> +++ b/libavfilter/vf_alphamerge.c
> @@ -28,12 +28,12 @@
> #include "libavutil/imgutils.h"
> #include "libavutil/opt.h"
> #include "libavutil/pixfmt.h"
> +#include "libavutil/frame.h"
> #include "avfilter.h"
> #include "drawutils.h"
> #include "formats.h"
> #include "filters.h"
> #include "framesync.h"
> -#include "video.h"
>
> enum { Y, U, V, A };
>
> @@ -78,11 +78,21 @@ static int do_alphamerge(FFFrameSync *fs)
> }
> }
> } else {
> - const int main_linesize = main_buf->linesize[A];
> - const int alpha_linesize = alpha_buf->linesize[Y];
> - av_image_copy_plane(main_buf->data[A], main_linesize,
> - alpha_buf->data[Y], alpha_linesize,
> - FFMIN(main_linesize, alpha_linesize), alpha_buf->height);
> + AVBufferRef *alpha_plane_buf = av_frame_get_plane_buffer(alpha_buf, Y);
> +
> + if (!alpha_plane_buf) {
> + av_log(ctx, AV_LOG_ERROR, "Could not get buffer for alpha plane.\n");
> + return AVERROR(EINVAL);
That should probably be AVERROR_BUG.
> + }
> +
> + ret = av_buffer_replace(&main_buf->buf[A], alpha_plane_buf);
> + if (ret < 0) {
> + av_log(ctx, AV_LOG_ERROR, "Failed to replace alpha plane buffer.\n");
> + return ret;
> + }
> +
> + main_buf->data[A] = alpha_buf->data[Y];
> + main_buf->linesize[A] = alpha_buf->linesize[Y];
> }
>
> return ff_filter_frame(ctx->outputs[0], main_buf);
> @@ -212,4 +222,4 @@ const FFFilter ff_vf_alphamerge = {
> FILTER_QUERY_FUNC2(query_formats),
> .uninit = uninit,
> .activate = activate,
> -};
> +};
> \ No newline at end of file
You really need to fix you editor to not have it remove the final
newline.
I am assuming that you of course tested it on a few cases and ran FATE.
If so, apart from the details above, LGTM. Thanks for your efforts.
Regards,
--
Nicolas George
More information about the ffmpeg-devel
mailing list