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 29D9B42AB2 for ; Tue, 12 Apr 2022 18:15:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9BB3468B395; Tue, 12 Apr 2022 21:15:53 +0300 (EEST) Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 780F068B2B5 for ; Tue, 12 Apr 2022 21:15:47 +0300 (EEST) Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-2ed65e63afcso51221947b3.9 for ; Tue, 12 Apr 2022 11:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=aJjGNEPSMkrV8kQNGKjguuxSrB40T2dCl3n6nxefdnA=; b=IDl/L0sNZz9DErrOsYBXIjrIpel/kolIRYoNHxWOCyRdds8K+BwmLfe6dTHx/i1unB VAyKgdC0ORPVkWGEzEfExFC5dvJKWz+jHLfrlHf6qc0Db7WE9jh4BpsDem/mXpOJmXkn ZpEFN1n4cwPhZjGZUCXOcD3PMKjIyErVz7NTVto5xNTm+/FLhtGSB5epY0f/bFTyOIkl Dhjxdst3wItgJrV1tgH/aDM8gdoyHmik1c3mebAUSrLM04O71lMN4gFBBHWcfkWUU7Ie iRxAb4WrECXWxGyLwyeKmmbOlmDd9IXHx2i1k5ZAv+VejfL7c2DlHYjnOkWeM+Ai35a9 4P1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=aJjGNEPSMkrV8kQNGKjguuxSrB40T2dCl3n6nxefdnA=; b=FvmvM999BdXUptXsmE0AIZd606gRq2uGGDxRYR6PHaZWPpcJoYMvk0AMnnWpQEbiDp 7k8GPiVG449vqTd0SLBTuEGUDXr7auk3BwlxDz9JutFelNKjZJvH1Bkal9rSavBvf6tl FcRlPjQOC9RgFz+hRKPx5aN1XUzqc31uSk7K5clgcHV3poNia2GcpnHWmisum8j7PSDF CwlK0/Y4T4boYxwNm5rF1Cfs24i+erritlTcM4w1d1AABoOWe3Gcs7f9aEZMHRFOAPWK I297SoyXIKY4OxC40WEe6t8UCcbBhTvJN4kdzEsp+RFNo6/3mgUSBeR1eESF7/F0m6Ss vv4g== X-Gm-Message-State: AOAM531TDYpM8m4tfCftf3bKJfOxoEXMord+6/RhV9Kt0KPSI63Pspax agPZsTjiTS0pCEmR0j4sGJq6lry0orVr2Ff2DeKw0Zhd X-Google-Smtp-Source: ABdhPJyDbCuDhTf/eCalF6DAOc5pnH5NaQDJTNZ5Fc/FfHN8H7ZdDyPmXL3qvZs7GWzCY0bZnN+EjKXZ8FueE/1mueU= X-Received: by 2002:a0d:e2c6:0:b0:2ec:279b:c170 with SMTP id l189-20020a0de2c6000000b002ec279bc170mr9649329ywe.302.1649787346118; Tue, 12 Apr 2022 11:15:46 -0700 (PDT) MIME-Version: 1.0 References: <20220411172446.100543-1-onemda@gmail.com> <20220412171714.GK2829255@pb2> In-Reply-To: <20220412171714.GK2829255@pb2> From: Paul B Mahol Date: Tue, 12 Apr 2022 20:18:02 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, Apr 12, 2022 at 7:17 PM Michael Niedermayer wrote: > 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 > > > > 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=t=in:st=5.5:d=0.5 > > > > @end itemize > > > > +@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 > gblur filter. > > +@example > > > +[in][blurin]feedback=x=0:y=0:w=100:h=100[out][blurout];[blurout]gblur=8[blurin] > > +@end example > > + > > +@item > > +Draw black box on top left part of video frame of size 100x100 with > drawbox filter. > > +@example > > > +[in][blurin]feedback=x=0:y=0:w=100:h=100[out][blurout];[blurout]drawbox=x=0:y=0:w=100:h=100:t=100[blurin] > > +@end example > > +@end itemize > > + > > @section fftdnoiz > > Denoise frames using 3D FFT (frequency domain filtering). > > > > 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) += > vf_estdif.o > > OBJS-$(CONFIG_EXPOSURE_FILTER) += vf_exposure.o > > OBJS-$(CONFIG_EXTRACTPLANES_FILTER) += vf_extractplanes.o > > OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o > > +OBJS-$(CONFIG_FEEDBACK_FILTER) += vf_feedback.o > > OBJS-$(CONFIG_FFTDNOIZ_FILTER) += vf_fftdnoiz.o > > OBJS-$(CONFIG_FFTFILT_FILTER) += vf_fftfilt.o > > OBJS-$(CONFIG_FIELD_FILTER) += 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-1301 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 = ctx->inputs[0]->w - s->w; > > + if (s->y + s->h > ctx->inputs[0]->h) > > + s->y = ctx->inputs[0]->h - s->h; > > +} > > + > > +static void adjust_parameters(AVFilterContext *ctx, FeedbackContext *s) > > +{ > > + if (s->x >= ctx->inputs[0]->w) > > + s->x = 0; > > + if (s->y >= ctx->inputs[0]->h) > > + s->y = 0; > > + > > + if (s->w <= 0) > > + s->w = ctx->inputs[0]->w - s->x; > > + if (s->h <= 0) > > + s->h = ctx->inputs[0]->h - s->y; > > + > > + if (s->w > ctx->inputs[0]->w) > > + s->w = ctx->inputs[0]->w; > > + if (s->h > ctx->inputs[0]->h) > > + s->h = ctx->inputs[0]->h; > > + > > + adjust_pos(ctx, s); > > +} > > + > > +static int config_input(AVFilterLink *inlink) > > +{ > > + AVFilterContext *ctx = inlink->dst; > > + const AVPixFmtDescriptor *pix_desc = > av_pix_fmt_desc_get(inlink->format); > > + FeedbackContext *s = ctx->priv; > > + > > + s->hsub = pix_desc->log2_chroma_w; > > + s->vsub = pix_desc->log2_chroma_h; > > + > > + av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); > > + > > + adjust_parameters(ctx, s); > > + > > + ctx->inputs[1]->w = s->w; > > + ctx->inputs[1]->h = s->h; > > + > > + return 0; > > +} > > + > > +static int config_output(AVFilterLink *outlink) > > +{ > > + AVFilterContext *ctx = outlink->src; > > + FeedbackContext *s = ctx->priv; > > + > > + adjust_parameters(ctx, s); > > + > > + ctx->outputs[0]->w = ctx->inputs[0]->w; > > + ctx->outputs[0]->h = ctx->inputs[0]->h; > > + ctx->outputs[1]->w = s->w; > > + ctx->outputs[1]->h = s->h; > > + > > + return 0; > > +} > > + > > +static int query_formats(AVFilterContext *ctx) > > +{ > > + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, > AV_PIX_FMT_FLAG_BITSTREAM | > > + > AV_PIX_FMT_FLAG_HWACCEL | > > + > AV_PIX_FMT_FLAG_PAL)); > > +} > > + > > +static int activate(AVFilterContext *ctx) > > +{ > > + FeedbackContext *s = ctx->priv; > > + int status, ret; > > + int64_t pts; > > + > > + adjust_pos(ctx, s); > > + > > + for (int i = 0; i < ctx->nb_outputs; i++) > > + FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx); > > + > > + if (!s->feed) { > > + ret = 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 = s->feed; > > + AVFrame *dst = 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 > bit > less jittery so i think this filter corrupted the inputs frame > Fixed locally. Thanks. I always forgot that frames can be read only. > > thx > > > [...] > -- > 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 > _______________________________________________ > 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". > _______________________________________________ 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".