Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avfilter: add backgroundkey video filter
Date: Wed, 2 Nov 2022 22:02:08 +0100
Message-ID: <GV1P250MB0737EBB765C03EB2F566BC2D8F399@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAPYw7P5ycbcFubw6f9Sq7hHvvKfpE+PS8kgSGXkB=afhM_tiOA@mail.gmail.com>

Paul B Mahol:
> +static int filter_frame(AVFilterLink *link, AVFrame *frame)
> +{
> +    AVFilterContext *avctx = link->dst;
> +    BackgroundkeyContext *s = avctx->priv;
> +    int64_t sum = 0;
> +    int ret;
> +
> +    if (!s->background) {
> +        s->background = av_frame_clone(frame);
> +        if (!s->background)
> +            return AVERROR(ENOMEM);
> +        av_frame_make_writable(s->background);

You are never writing to the background frame, so there is no point in
making it writable; what you actually want to achieve here is making
frame writable again and to achieve this you should make frame, not
background writable (and of course you should check said call).

(Actually, you never

> +    }
> +
> +    if (ret = ff_filter_execute(avctx, s->do_slice, frame, NULL,
> +                                FFMIN(frame->height, s->nb_threads)))
> +        return ret;
> +
> +    for (int n = 0; n < s->nb_threads; n++)
> +        sum += s->sums[n];
> +    if (s->max_sum * s->threshold < sum) {
> +        av_frame_free(&s->background);
> +        s->background = av_frame_clone(frame);
> +        if (!s->background)
> +            return AVERROR(ENOMEM);
> +        av_frame_make_writable(s->background);

Given that you never write to background, there is no need to make it
writable. This time, there is also no need to make frame writable (the
next filter in the chain may not need a writable frame anyway), so just
remove this.
And the av_frame_free+av_frame_clone can become an
av_frame_unref+av_frame_ref (this will necessitate modifying the check
above to not only check for to existence of s->background).

> +    }
> +
> +    return ff_filter_frame(avctx->outputs[0], frame);
> +}

_______________________________________________
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:[~2022-11-02 21:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 14:34 Paul B Mahol
2022-11-02 16:22 ` Paul B Mahol
2022-11-02 21:02   ` Andreas Rheinhardt [this message]
2022-11-03  7:43     ` Paul B Mahol
2022-11-03 12:49       ` Andreas Rheinhardt
2022-11-03 13:13         ` Paul B Mahol
2022-11-04  7:36           ` Paul B Mahol
2022-11-04 19:34   ` Paul B Mahol

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=GV1P250MB0737EBB765C03EB2F566BC2D8F399@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.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