* [FFmpeg-devel] [PATCH] avfilter/vf_extractplanes: use refcounting for planar formats
@ 2025-08-09 2:06 Jorge Estrada
0 siblings, 0 replies; only message 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/
---
| 41 +++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 10 deletions(-)
--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] only message in thread
only message in thread, other threads:[~2025-08-09 2:07 UTC | newest]
Thread overview: (only message) (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
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