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-devel@ffmpeg.org
Cc: Jorge Estrada <jestrada.list@gmail.com>
Subject: [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats
Date: Fri,  8 Aug 2025 19:06:24 -0700
Message-ID: <20250809020624.87270-1-jestrada.list@gmail.com> (raw)

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

                 reply	other threads:[~2025-08-09  2:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250809020624.87270-1-jestrada.list@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