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 9EE1A46162 for ; Mon, 8 May 2023 13:32:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACFC468C038; Mon, 8 May 2023 16:32:14 +0300 (EEST) Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3E9DB680105 for ; Mon, 8 May 2023 16:32:08 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id 8EE57A06EF for ; Mon, 8 May 2023 15:32:07 +0200 (CEST) Received: from smtp03.mail.de (smtp03.bt.mail.de [10.0.121.213]) by postfix03.mail.de (Postfix) with ESMTP id 758E38014D for ; Mon, 8 May 2023 15:32:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1683552727; bh=DyTK2yO5V+2PGJPeoo/QpAGYZEF84IWT2oOmkoRsafk=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=LO+dSJA8pwiFJR/wm/cdgzzKDIX2NuLIOfQFpXxo4CkKrk11KU5mzQSPRGx+D/Vwt CUzKKYz9cEfgpruooF9173SsE9sxXuACKuIqB8fLQRdV8K01nCWWpq9d983ff10Hfc YSjsseQFj6qb63/e1Kuekoi/oC3VrmtccTI196tN9pnFg9UX98MFMH+/NFaMQkoBLX 66HnFPzXaizZNW559E+ehChRY1Kd1B0BCpVRcxeuo/iUOdbtYRYaK7K6Ha38iJtclq Z6vKlKs2MHRV5yISJ9c4PxJ7UH7rgFTLdnE/rEGpqh1whr3Abj1jAdLxNqCO2Qcm6i m8UlMXkk4hXAg== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtp03.mail.de (Postfix) with ESMTPSA id 470C0A0358 for ; Mon, 8 May 2023 15:32:05 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 May 2023 15:32:05 +0200 Message-Id: <20230508133205.19247-1-thilo.borgmann@mail.de> MIME-Version: 1.0 X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3628 X-purgate-ID: 154282::1683552727-4E7FA647-32D2482F/0/0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping 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: This allows for decimating large similar portions of a video while preserving small ones. --- libavfilter/vf_mpdecimate.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c index 71f673cb64..d1e046fc32 100644 --- a/libavfilter/vf_mpdecimate.c +++ b/libavfilter/vf_mpdecimate.c @@ -46,6 +46,9 @@ typedef struct DecimateContext { int drop_count; ///< if positive: number of frames sequentially dropped ///< if negative: number of sequential frames which were not dropped + int max_keep_count; ///< number of similar frames to ignore before to start dropping them + int keep_count; ///< number of similar frames already ignored + int hsub, vsub; ///< chroma subsampling values AVFrame *ref; ///< reference picture av_pixelutils_sad_fn sad; ///< sum of absolute difference function @@ -57,6 +60,8 @@ typedef struct DecimateContext { static const AVOption mpdecimate_options[] = { { "max", "set the maximum number of consecutive dropped frames (positive), or the minimum interval between dropped frames (negative)", OFFSET(max_drop_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS }, + { "keep", "set the number of similar consecutive frames to be kept before starting to drop similar frames", + OFFSET(max_keep_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS }, { "hi", "set high dropping threshold", OFFSET(hi), AV_OPT_TYPE_INT, {.i64=64*12}, INT_MIN, INT_MAX, FLAGS }, { "lo", "set low dropping threshold", OFFSET(lo), AV_OPT_TYPE_INT, {.i64=64*5}, INT_MIN, INT_MAX, FLAGS }, { "frac", "set fraction dropping threshold", OFFSET(frac), AV_OPT_TYPE_FLOAT, {.dbl=0.33}, 0, 1, FLAGS }, @@ -112,6 +117,12 @@ static int decimate_frame(AVFilterContext *ctx, DecimateContext *decimate = ctx->priv; int plane; + if (decimate->max_keep_count > 0 && + decimate->keep_count > -1 && + decimate->keep_count < decimate->max_keep_count) { + decimate->keep_count++; + return 0; + } if (decimate->max_drop_count > 0 && decimate->drop_count >= decimate->max_drop_count) return 0; @@ -196,20 +207,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *cur) if (decimate->ref && decimate_frame(inlink->dst, cur, decimate->ref)) { decimate->drop_count = FFMAX(1, decimate->drop_count+1); + decimate->keep_count = -1; // do not keep any more frames until non-similar frames are detected } else { av_frame_free(&decimate->ref); decimate->ref = cur; decimate->drop_count = FFMIN(-1, decimate->drop_count-1); + if (decimate->keep_count < 0) // re-enable counting similiar frames to ignore before dropping + decimate->keep_count = 0; if ((ret = ff_filter_frame(outlink, av_frame_clone(cur))) < 0) return ret; } av_log(inlink->dst, AV_LOG_DEBUG, - "%s pts:%s pts_time:%s drop_count:%d\n", + "%s pts:%s pts_time:%s drop_count:%d keep_count:%d\n", decimate->drop_count > 0 ? "drop" : "keep", av_ts2str(cur->pts), av_ts2timestr(cur->pts, &inlink->time_base), - decimate->drop_count); + decimate->drop_count, + decimate->keep_count); if (decimate->drop_count > 0) av_frame_free(&cur); -- 2.37.1 (Apple Git-137.1) _______________________________________________ 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".