Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Jorge Estrada <jestrada.list@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_alphamerge: use refcounting for planar formats
Date: Thu, 7 Aug 2025 16:21:08 -0700
Message-ID: <CAHPA9KRf-_3on1ru1KhP6+xX-rt7xxMJmEA1GKA66qBoaGeOGw@mail.gmail.com> (raw)
In-Reply-To: <3dfd6642-9f52-4808-a25c-60807ddb18ef@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3339 bytes --]

Addressed and attached the updated patch. I sent my previous email
incorrectly. My bad.

On Thu, Aug 7, 2025 at 1:13 PM James Almer <jamrial@gmail.com> wrote:

> On 8/7/2025 4:58 PM, Jorge Estrada wrote:
> > Use reference plane when handling planar formats. Should address
> > https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20153
> >
> > Example:
> > ffmpeg -f lavfi -i "color=red:s=640x480:d=5,format=yuva420p" \
> >         -f lavfi -i
> "color=black:s=640x480:d=5,format=yuv420p,geq=lum='255*gt(150,hypot(X-W/2,Y-H/2))':a=0"
> \
> >         -f lavfi -i "color=blue:s=640x480:d=5,format=yuv420p" \
> >         -filter_complex
> "[0:v][1:v]alphamerge[merged_with_alpha];[2:v][merged_with_alpha]overlay" \
> >         -c:v libx264 \
> >         -y out.mp4
> > ---
> >   libavfilter/vf_alphamerge.c | 26 +++++++++++++++++++-------
> >   1 file changed, 19 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c
> > index f5779484a9..9f53806537 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,23 @@ 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);
> > +        }
> > +
>
> > +        av_buffer_unref(&main_buf->buf[A]);
> > +
> > +        main_buf->buf[A] = av_buffer_ref(alpha_plane_buf);
>
> av_buffer_replace()
>
> > +        if (!main_buf->buf[A]) {
> > +            av_log(ctx, AV_LOG_ERROR, "Failed to reference alpha plane
> buffer.\n");
> > +            return AVERROR(ENOMEM);
> > +        }
> > +
> > +        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 +224,4 @@ const FFFilter ff_vf_alphamerge = {
> >       FILTER_QUERY_FUNC2(query_formats),
> >       .uninit         = uninit,
> >       .activate       = activate,
> > -};
> > +};
> > \ No newline at end of file
> Please fix this.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>

[-- Attachment #2: 0001-avfilter-vf_alphamerge-use-refcounting-for-planar-fo.patch --]
[-- Type: application/octet-stream, Size: 2095 bytes --]

[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-08-07 23:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07 19:58 Jorge Estrada
2025-08-07 20:12 ` James Almer
2025-08-07 23:21   ` Jorge Estrada [this message]
2025-08-07 23:14 ` [FFmpeg-devel] use av_buffer_replace Jorge Estrada

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=CAHPA9KRf-_3on1ru1KhP6+xX-rt7xxMJmEA1GKA66qBoaGeOGw@mail.gmail.com \
    --to=jestrada.list@gmail.com \
    --cc=ffmpeg-devel@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