Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats
@ 2025-08-09  2:06 Jorge Estrada
  2025-08-09 17:51 ` Nicolas George
  0 siblings, 1 reply; 2+ messages in thread
From: Jorge Estrada @ 2025-08-09  2:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Jorge Estrada

As recommended by Nicholas George. Uses refcounting for planar formats similar to this change for alphamerge
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250807195800.77462-1-jestrada.list@gmail.com/
---
 libavfilter/vf_extractplanes.c | 41 +++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/libavfilter/vf_extractplanes.c b/libavfilter/vf_extractplanes.c
index 99e37ba04a..cc64d96e1c 100644
--- a/libavfilter/vf_extractplanes.c
+++ b/libavfilter/vf_extractplanes.c
@@ -307,25 +307,46 @@ static int extract_plane(AVFilterLink *outlink, AVFrame *frame)
     const int idx = s->map[FF_OUTLINK_IDX(outlink)];
     AVFrame *out;
 
-    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-    if (!out)
-        return AVERROR(ENOMEM);
-    av_frame_copy_props(out, frame);
-    if (idx == 3 /* alpha */)
-        out->color_range = AVCOL_RANGE_JPEG;
-
     if (s->is_packed) {
+        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+        if (!out)
+            return AVERROR(ENOMEM);
+
         extract_from_packed(out->data[0], out->linesize[0],
                             frame->data[0], frame->linesize[0],
                             outlink->w, outlink->h,
                             s->depth,
                             s->step, idx);
     } else {
-        av_image_copy_plane(out->data[0], out->linesize[0],
-                            frame->data[idx], frame->linesize[idx],
-                            s->linesize[idx], outlink->h);
+        out = av_frame_alloc();
+        if (!out)
+            return AVERROR(ENOMEM);
+
+        AVBufferRef *source_plane_buf = av_frame_get_plane_buffer(frame, idx);
+        if (!source_plane_buf) {
+            av_frame_free(&out);
+            av_log(ctx, AV_LOG_ERROR, "Could not get buffer for source plane %d.\n", idx);
+            return AVERROR(EINVAL);
+        }
+
+        out->format = outlink->format;
+        out->width  = outlink->w;
+        out->height = outlink->h;
+
+        out->buf[0] = av_buffer_ref(source_plane_buf);
+        if (!out->buf[0]) {
+            av_frame_free(&out);
+            return AVERROR(ENOMEM);
+        }
+
+        out->data[0]     = frame->data[idx];
+        out->linesize[0] = frame->linesize[idx];
     }
 
+    av_frame_copy_props(out, frame);
+    if (idx == 3 /* alpha */)
+        out->color_range = AVCOL_RANGE_JPEG;
+
     return ff_filter_frame(outlink, out);
 }
 
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats
  2025-08-09  2:06 [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats Jorge Estrada
@ 2025-08-09 17:51 ` Nicolas George
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas George @ 2025-08-09 17:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Jorge Estrada (HE12025-08-08):
> As recommended by Nicholas George. Uses refcounting for planar formats similar to this change for alphamerge

I'd prefer the first sentence to be left out. And if not, then please
fix the typo in my name ;)

> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250807195800.77462-1-jestrada.list@gmail.com/
> ---
>  libavfilter/vf_extractplanes.c | 41 +++++++++++++++++++++++++---------
>  1 file changed, 31 insertions(+), 10 deletions(-)

Apart from that, LGTM, assuming it was tested.

Thanks.

Regards,

-- 
  Nicolas George
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-09 17:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-09  2:06 [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats Jorge Estrada
2025-08-09 17:51 ` Nicolas George

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