From 444cf3fca8dab2da9b95cc36920667f76d0f796c Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 22 Oct 2021 09:34:51 +0200 Subject: [PATCH] avfilter/vf_bilateral: add direct aka writable frame support --- libavfilter/vf_bilateral.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libavfilter/vf_bilateral.c b/libavfilter/vf_bilateral.c index 8fe341f70d..b236efe6c3 100644 --- a/libavfilter/vf_bilateral.c +++ b/libavfilter/vf_bilateral.c @@ -297,18 +297,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out; - out = ff_get_video_buffer(outlink, outlink->w, outlink->h); - if (!out) { - av_frame_free(&in); - return AVERROR(ENOMEM); + if (av_frame_is_writable(in)) { + out = in; + } else { + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + av_frame_free(&in); + return AVERROR(ENOMEM); + } + av_frame_copy_props(out, in); } - av_frame_copy_props(out, in); for (int plane = 0; plane < s->nb_planes; plane++) { if (!(s->planes & (1 << plane))) { - av_image_copy_plane(out->data[plane], out->linesize[plane], - in->data[plane], in->linesize[plane], - s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]); + if (out != in) + av_image_copy_plane(out->data[plane], out->linesize[plane], + in->data[plane], in->linesize[plane], + s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]); continue; } @@ -322,7 +327,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) in->linesize[plane] / 2, out->linesize[plane] / 2); } - av_frame_free(&in); + if (out != in) + av_frame_free(&in); return ff_filter_frame(outlink, out); }