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 404FD4011A for ; Thu, 3 Nov 2022 07:43:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8822668BED3; Thu, 3 Nov 2022 09:43:50 +0200 (EET) Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1829268BDF4 for ; Thu, 3 Nov 2022 09:43:44 +0200 (EET) Received: by mail-vs1-f52.google.com with SMTP id l190so1110835vsc.10 for ; Thu, 03 Nov 2022 00:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=GI7hJGHMjTe+FZysSPyuvOp0/qjfZgu9wgzqusbc7U4=; b=pmFAt3YDFKZk6PxffFermcDKlwhWr6HtZHh7Fr2l+QFv5btouNFq8s5Z0FUlpCoZHV WvVGqroZJeJoHMCHFAzyJXpRVHbA+Iv3JVKCOy50F3BjHRi26ouyV/Y69qWheBYMa5Zw lKQpkrAI5zVu6ZhEmI2rxcgCTBKWd4aMhpYjirbAlMuxT6exjy7mbExWoL5WgaRWtNir HIxxQ1K/KlJZSN0V0i0Ibf/AlHoTNU8x7hlTlZANvKBNF0xjgZfkFhyFu130wHGGxj9S UWW+JVtUdIRV5n1eT/sILbKQN8KghTnMay4o6LkENH3f9sT7aOSYFZv1uKYA3Ik85kNB dAsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GI7hJGHMjTe+FZysSPyuvOp0/qjfZgu9wgzqusbc7U4=; b=VVvQjD9/IQUat1YedqqJQsTo/I28K9jQNG+H6q8xXTjIRMlTQhK+ElXYtJJuLTsb6L 6r4T9Jedukqp+U6vKpXrWbQTixGu4fAXJoyk24I1JY3dGWAZ9qPrIma87MldPPMiJJPa ayPHT86lMz/+H1fJM9Dc4pJocGb6uveKblVOlGzzwOlbr75scvGtDwdHaL8gZz2quBHI BUUeVOxYbY/8DN+FfO8mePY7UnIA6ncOaLZVm+M9jIWu95rgf3ju0W4fsjCPPJ9uqYuv MXqkZNkZhE5HJiVY3YI2EhVA7sf7LQpgWulSw6xEBF62HjjiarBNjKBQgn0NsrHqK6+8 2kBQ== X-Gm-Message-State: ACrzQf0FCleqrJ+X6f6rkl+PKyGKKil6J0SaEpLrdU0IKhABt18FVFn8 s8AncLNsbI3+ZJlu5VhdvgfzXpQ/NRS37lr+odFhGlFs X-Google-Smtp-Source: AMsMyM4eknC49LchivcKWuDxWE8D54ufj2SXfc7pdfo+vUkwoxrBp6KMy8fHJVEqPp9WqlhkNdktrSrMElckvdgFREA= X-Received: by 2002:a05:6102:ac3:b0:3ac:e685:eded with SMTP id m3-20020a0561020ac300b003ace685ededmr12321224vsh.61.1667461422356; Thu, 03 Nov 2022 00:43:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:612c:612:b0:314:ac6a:1eb7 with HTTP; Thu, 3 Nov 2022 00:43:41 -0700 (PDT) In-Reply-To: References: From: Paul B Mahol Date: Thu, 3 Nov 2022 08:43:41 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avfilter: add backgroundkey 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 11/2/22, Andreas Rheinhardt wrote: > 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). > This is invalid, input pad receives always writable frames as there is flag. > (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". > _______________________________________________ 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".