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 80AA040158 for ; Thu, 3 Nov 2022 13:14:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A9C3668BF86; Thu, 3 Nov 2022 15:14:00 +0200 (EET) Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DACC768BF02 for ; Thu, 3 Nov 2022 15:13:53 +0200 (EET) Received: by mail-ua1-f42.google.com with SMTP id e26so879188uaa.7 for ; Thu, 03 Nov 2022 06:13:53 -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=X9cSX3+2lxqGhDgVH/Ilo9CtznVSQ2GjkcBIJBCZv/Q=; b=lyAr2JSKKv0PsKvmk7yL3yJOeGJQe4c5ykBGVSaGzyVmdvAsQEVsV+tD1bOFWMZuLe BmfFLNYCKCW7UHg6XxthCHQt5uleRxxQeiM92nF90Xo2G4uRODlyCMLFtjhcX3NvKgUA zJUq7+WWcSDEfnLt9p/LGTdWXDNzCs5Vd3P9bgQnxKrHZJ1tKw5ZPnUCYqBvPt3kCt7m 8Lith+1PiNB1NFIq28zJ06sWstgL1WjZHo7Bv6kQ/bcYnydnJNlZPnlYU4g1gYMXf4De OwraLtQitP6bobhk1+xgppbsu8eJuidTNgDud0tthobKYGXCKaF6HRRfko2s1OZvYXvK 3XjA== 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=X9cSX3+2lxqGhDgVH/Ilo9CtznVSQ2GjkcBIJBCZv/Q=; b=T9Ovm++VEP+k30GL6ytvfa+LuXP/ut/3fWQdT+peMWgaqC7EWAFx6TTaeTIVV8RleD e+egWF27Wgp/f9aEb/kXGNXlN107m1uzKvfBL+BVrj6uvgGDuuWBg4TRCian3mHGtsxT XMBntH5GA4phTBJpTmHikw6ZvWWKr7G8cC32kP4r6nRBiNu0SNREYIZb/XHceTEMS0DO fDTQUHRwudt36796oHqRjGs3P5LZ+RaL0Nqa+iNek86C6tvsPW83Eli+BIZPXtmMZ0nO gPEJRMPHRH3niR7lDbSDHrm6iDOXi40pND5nLCoa2baRSqaBUogYQrymXXeAE6xUUGfm x+Ag== X-Gm-Message-State: ACrzQf0HZ9fxfH0ACvUHaLs6EiaYCD+URd/GY/6hmSXyCEZHKe+StFvN yp0W6ScyvlaSBNjHv9GqdG/xCIM/l/bvDEwkp312n6Wn X-Google-Smtp-Source: AMsMyM7zkNSEsYLxlMylKqTKpURXH3MCpt5kZgUC08GyeZ2kE3ZpQA8BB2wnuFSC6LtkOHdS8b+zz54d82wAz6ixCAc= X-Received: by 2002:ab0:29d8:0:b0:40a:c9:9ff7 with SMTP id i24-20020ab029d8000000b0040a00c99ff7mr7189287uaq.41.1667481232243; Thu, 03 Nov 2022 06:13:52 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:612c:612:b0:314:ac6a:1eb7 with HTTP; Thu, 3 Nov 2022 06:13:50 -0700 (PDT) In-Reply-To: References: From: Paul B Mahol Date: Thu, 3 Nov 2022 14:13:50 +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/3/22, Andreas Rheinhardt wrote: > Paul B Mahol: >> 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. >> > > But in case this branch here is executed, the av_frame_clone() makes > frame non-writable, so it needs to be made writable again. Than will use copy frame. > >>> (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". > > _______________________________________________ > 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".