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 C0FDF401AF for ; Fri, 4 Nov 2022 07:36:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 96C4D68BF41; Fri, 4 Nov 2022 09:36:19 +0200 (EET) Received: from mail-vs1-f41.google.com (mail-vs1-f41.google.com [209.85.217.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 837BD68BF1B for ; Fri, 4 Nov 2022 09:36:13 +0200 (EET) Received: by mail-vs1-f41.google.com with SMTP id q127so3904459vsa.7 for ; Fri, 04 Nov 2022 00:36:13 -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=IgsmfalA/cZTU1D+cfW4Un0ECWAxaujH2zlaIQHcRpw=; b=Nf6Q8kdU7esUlBeeSeJV9B90cxiaZb+qQOwX/gyWT1VPjWlHWs6Lw+DtgVZG096lkk SGSOxGihu7a+ZZdbnFxrHGCv5Qs0cVb1jhPd+UBwAULqfaou6ihB5sVfwmZaAlMEz7k5 gWNM4NYYnVPy3zRKGj2iwqMl3WcT4pnnxPHvs7HLPXIM86/w/VXekz/1Kp0O4q9gjBUj X3pNcnMar8OZDWDfijhp6bpxYntchBBpJB1Ucmxc80yi5PoAaHxlQ4JsqNLHXbHQWbYf LQymDulFR3N7ageWL17S7nTOexEIztDFOdZqguQnh1ZIpI5OgiOJ4vwghxIRa1kvpWVd JlMQ== 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=IgsmfalA/cZTU1D+cfW4Un0ECWAxaujH2zlaIQHcRpw=; b=DbnM4tIFYZgdgkU00SeodjF6eAvDkTwqczd7m3kfQPVxCrhBlfB+86B7XOVsMkLd5Q 11ci5Vbe0mbzzMnYigUZDRjaeYJiNRvXv1Nhs+bRH5xfo6oaAUxIcLdmxo1H08FaR4sZ 1tzW3375tjXqBUQMcPgTr+w7s82gjJ19SFSMHZr/+1wwQfcHQTtcWL1n+449O1bCbD1v Mh/8Z5lWlWCV8+i2bXlBg8EsSfV28m7u7OSHWtVtzRI2hYlj9Cof1gAMs/16QPOy9Ugt qdy+gjCvXw0p2XdZRUyimM8nAv3xCnoyrQ8VJGcKM7Ebo34/k7rQi1mTrRaG0TJ+R6pX DPCw== X-Gm-Message-State: ACrzQf07BcqwK3kDZlNCJQvJiftm1RniJv08JBaVHjVV54R97IIbD7TQ P5ES11ke4cHiqg9i97As7Kfwr54awFZMJwEZ02lSpAo/ X-Google-Smtp-Source: AMsMyM48q/f3qpaWzeEgQTJlJ4Ouiqso4paRlnUuhMyKM1ftg7oo/HRcYmWTdg/xNSQgYKgYlyuHX4wRXdqoZTy9KXg= X-Received: by 2002:a05:6102:118:b0:3ad:2777:742 with SMTP id z24-20020a056102011800b003ad27770742mr9478456vsq.57.1667547371834; Fri, 04 Nov 2022 00:36:11 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:612c:612:b0:314:ac6a:1eb7 with HTTP; Fri, 4 Nov 2022 00:36:10 -0700 (PDT) In-Reply-To: References: From: Paul B Mahol Date: Fri, 4 Nov 2022 08:36:10 +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, Paul B Mahol wrote: > 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". >> > Will apply witjh av_copy_frame() solution. _______________________________________________ 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".