From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C0D6E40F07 for ; Tue, 12 Apr 2022 17:17:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0F49C68B181; Tue, 12 Apr 2022 20:17:23 +0300 (EEST) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A06868B181 for ; Tue, 12 Apr 2022 20:17:16 +0300 (EEST) Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29]) (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 9174D20007 for ; Tue, 12 Apr 2022 17:17:15 +0000 (UTC) Date: Tue, 12 Apr 2022 19:17:14 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220412171714.GK2829255@pb2> References: <20220411172446.100543-1-onemda@gmail.com> MIME-Version: 1.0 In-Reply-To: <20220411172446.100543-1-onemda@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] avfilter: add feedback video filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============6035934253514299190==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6035934253514299190== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IUWISk5nRJsstxji" Content-Disposition: inline --IUWISk5nRJsstxji Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 11, 2022 at 07:24:46PM +0200, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > doc/filters.texi | 38 +++++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_feedback.c | 312 ++++++++++++++++++++++++++++++++++++++ > 4 files changed, 352 insertions(+) > create mode 100644 libavfilter/vf_feedback.c >=20 > diff --git a/doc/filters.texi b/doc/filters.texi > index 0300a4e2e3..de2b674ba2 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -12214,6 +12214,44 @@ fade=3Dt=3Din:st=3D5.5:d=3D0.5 > =20 > @end itemize > =20 > +@section feedback > +Apply feedback video filter. > + > +This filter pass cropped input frames to 2nd output. > +From there it can be filtered with other video filters. > +After filter receives frame from 2nd input, that frame > +is combined on top of original frame from 1st input and passed > +to 1st output. > + > +The typical usage is filter only part of frame. > + > +The filter accepts the following options: > +@table @option > +@item x > +@item y > +Set the top left crop position. > + > +@item w > +@item h > +Set the crop size. > +@end table > + > +@subsection Examples > + > +@itemize > +@item > +Blur only top left rectangular part of video frame size 100x100 with gbl= ur filter. > +@example > +[in][blurin]feedback=3Dx=3D0:y=3D0:w=3D100:h=3D100[out][blurout];[blurou= t]gblur=3D8[blurin] > +@end example > + > +@item > +Draw black box on top left part of video frame of size 100x100 with draw= box filter. > +@example > +[in][blurin]feedback=3Dx=3D0:y=3D0:w=3D100:h=3D100[out][blurout];[blurou= t]drawbox=3Dx=3D0:y=3D0:w=3D100:h=3D100:t=3D100[blurin] > +@end example > +@end itemize > + > @section fftdnoiz > Denoise frames using 3D FFT (frequency domain filtering). > =20 > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index d69bd59bb6..bdfdfdc04a 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -279,6 +279,7 @@ OBJS-$(CONFIG_ESTDIF_FILTER) +=3D vf_= estdif.o > OBJS-$(CONFIG_EXPOSURE_FILTER) +=3D vf_exposure.o > OBJS-$(CONFIG_EXTRACTPLANES_FILTER) +=3D vf_extractplanes.o > OBJS-$(CONFIG_FADE_FILTER) +=3D vf_fade.o > +OBJS-$(CONFIG_FEEDBACK_FILTER) +=3D vf_feedback.o > OBJS-$(CONFIG_FFTDNOIZ_FILTER) +=3D vf_fftdnoiz.o > OBJS-$(CONFIG_FFTFILT_FILTER) +=3D vf_fftfilt.o > OBJS-$(CONFIG_FIELD_FILTER) +=3D vf_field.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index abd1fe2367..44fac46521 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -261,6 +261,7 @@ extern const AVFilter ff_vf_estdif; > extern const AVFilter ff_vf_exposure; > extern const AVFilter ff_vf_extractplanes; > extern const AVFilter ff_vf_fade; > +extern const AVFilter ff_vf_feedback; > extern const AVFilter ff_vf_fftdnoiz; > extern const AVFilter ff_vf_fftfilt; > extern const AVFilter ff_vf_field; > diff --git a/libavfilter/vf_feedback.c b/libavfilter/vf_feedback.c > new file mode 100644 > index 0000000000..268aff0ebd > --- /dev/null > +++ b/libavfilter/vf_feedback.c > @@ -0,0 +1,312 @@ > +/* > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1= 301 USA > + */ > + > +/** > + * @file > + * feedback video filter > + */ > + > +#include "libavutil/fifo.h" > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > +#include "libavutil/internal.h" > +#include "avfilter.h" > +#include "filters.h" > +#include "internal.h" > +#include "video.h" > + > +typedef struct FeedbackContext { > + const AVClass *class; > + > + int x, y; > + int w, h; > + > + int max_step[4]; > + int hsub, vsub; > + > + AVFrame *feed; > + > + AVFifo *fifo; > +} FeedbackContext; > + > +static void adjust_pos(AVFilterContext *ctx, FeedbackContext *s) > +{ > + if (s->x + s->w > ctx->inputs[0]->w) > + s->x =3D ctx->inputs[0]->w - s->w; > + if (s->y + s->h > ctx->inputs[0]->h) > + s->y =3D ctx->inputs[0]->h - s->h; > +} > + > +static void adjust_parameters(AVFilterContext *ctx, FeedbackContext *s) > +{ > + if (s->x >=3D ctx->inputs[0]->w) > + s->x =3D 0; > + if (s->y >=3D ctx->inputs[0]->h) > + s->y =3D 0; > + > + if (s->w <=3D 0) > + s->w =3D ctx->inputs[0]->w - s->x; > + if (s->h <=3D 0) > + s->h =3D ctx->inputs[0]->h - s->y; > + > + if (s->w > ctx->inputs[0]->w) > + s->w =3D ctx->inputs[0]->w; > + if (s->h > ctx->inputs[0]->h) > + s->h =3D ctx->inputs[0]->h; > + > + adjust_pos(ctx, s); > +} > + > +static int config_input(AVFilterLink *inlink) > +{ > + AVFilterContext *ctx =3D inlink->dst; > + const AVPixFmtDescriptor *pix_desc =3D av_pix_fmt_desc_get(inlink->f= ormat); > + FeedbackContext *s =3D ctx->priv; > + > + s->hsub =3D pix_desc->log2_chroma_w; > + s->vsub =3D pix_desc->log2_chroma_h; > + > + av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); > + > + adjust_parameters(ctx, s); > + > + ctx->inputs[1]->w =3D s->w; > + ctx->inputs[1]->h =3D s->h; > + > + return 0; > +} > + > +static int config_output(AVFilterLink *outlink) > +{ > + AVFilterContext *ctx =3D outlink->src; > + FeedbackContext *s =3D ctx->priv; > + > + adjust_parameters(ctx, s); > + > + ctx->outputs[0]->w =3D ctx->inputs[0]->w; > + ctx->outputs[0]->h =3D ctx->inputs[0]->h; > + ctx->outputs[1]->w =3D s->w; > + ctx->outputs[1]->h =3D s->h; > + > + return 0; > +} > + > +static int query_formats(AVFilterContext *ctx) > +{ > + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, AV_PI= X_FMT_FLAG_BITSTREAM | > + AV_PI= X_FMT_FLAG_HWACCEL | > + AV_PI= X_FMT_FLAG_PAL)); > +} > + > +static int activate(AVFilterContext *ctx) > +{ > + FeedbackContext *s =3D ctx->priv; > + int status, ret; > + int64_t pts; > + > + adjust_pos(ctx, s); > + > + for (int i =3D 0; i < ctx->nb_outputs; i++) > + FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx); > + > + if (!s->feed) { > + ret =3D ff_inlink_consume_frame(ctx->inputs[1], &s->feed); > + if (ret < 0) > + return ret; > + } > + > + if (s->feed && av_fifo_can_read(s->fifo)) { > + AVFrame *src =3D s->feed; > + AVFrame *dst =3D NULL; > + > + av_fifo_read(s->fifo, &dst, 1); > + if (!dst) > + return AVERROR_BUG; > + putting a av_frame_make_writable(dst); here makes the output look quite a b= it less jittery so i think this filter corrupted the inputs frame thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Its not that you shouldnt use gotos but rather that you should write readable code and code with gotos often but not always is less readable --IUWISk5nRJsstxji Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYlW0FgAKCRBhHseHBAsP q2n4AJsFTb0nVquRXnSp495F4Ciu0wupkQCdFxcUk4IOnJAh3FbBplmQ0wlTTHk= =Z6C0 -----END PGP SIGNATURE----- --IUWISk5nRJsstxji-- --===============6035934253514299190== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============6035934253514299190==--