* [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
@ 2023-05-08 13:32 Thilo Borgmann
2023-05-08 13:43 ` Thilo Borgmann
0 siblings, 1 reply; 6+ messages in thread
From: Thilo Borgmann @ 2023-05-08 13:32 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
2023-05-08 13:32 [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping Thilo Borgmann
@ 2023-05-08 13:43 ` Thilo Borgmann
2023-05-08 13:58 ` Paul B Mahol
0 siblings, 1 reply; 6+ messages in thread
From: Thilo Borgmann @ 2023-05-08 13:43 UTC (permalink / raw)
To: ffmpeg-devel
Am 08.05.23 um 15:32 schrieb Thilo Borgmann:
> 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(-)
docs and micro bump in v2.
-Thilo
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
2023-05-08 13:43 ` Thilo Borgmann
@ 2023-05-08 13:58 ` Paul B Mahol
2023-05-08 18:06 ` Thilo Borgmann
0 siblings, 1 reply; 6+ messages in thread
From: Paul B Mahol @ 2023-05-08 13:58 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, May 8, 2023 at 3:43 PM Thilo Borgmann <thilo.borgmann@mail.de>
wrote:
> Am 08.05.23 um 15:32 schrieb Thilo Borgmann:
> > 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(-)
>
> docs and micro bump in v2.
>
Why is range for option allowed to go bellow 0 to INT_MIN?
> -Thilo
>
> _______________________________________________
> 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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
2023-05-08 13:58 ` Paul B Mahol
@ 2023-05-08 18:06 ` Thilo Borgmann
2023-05-08 18:55 ` Paul B Mahol
0 siblings, 1 reply; 6+ messages in thread
From: Thilo Borgmann @ 2023-05-08 18:06 UTC (permalink / raw)
To: ffmpeg-devel
Am 08.05.23 um 15:58 schrieb Paul B Mahol:
> On Mon, May 8, 2023 at 3:43 PM Thilo Borgmann <thilo.borgmann@mail.de>
> wrote:
>
>> Am 08.05.23 um 15:32 schrieb Thilo Borgmann:
>>> 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(-)
>>
>> docs and micro bump in v2.
>>
>
> Why is range for option allowed to go bellow 0 to INT_MIN?
Oh it shall allow for >= 0 from the user. Will fix the min/max values, anything else?
Thanks,
Thilo
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
2023-05-08 18:06 ` Thilo Borgmann
@ 2023-05-08 18:55 ` Paul B Mahol
2023-05-08 19:57 ` Thilo Borgmann
0 siblings, 1 reply; 6+ messages in thread
From: Paul B Mahol @ 2023-05-08 18:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, May 8, 2023 at 8:06 PM Thilo Borgmann <thilo.borgmann@mail.de>
wrote:
> Am 08.05.23 um 15:58 schrieb Paul B Mahol:
> > On Mon, May 8, 2023 at 3:43 PM Thilo Borgmann <thilo.borgmann@mail.de>
> > wrote:
> >
> >> Am 08.05.23 um 15:32 schrieb Thilo Borgmann:
> >>> 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(-)
> >>
> >> docs and micro bump in v2.
> >>
> >
> > Why is range for option allowed to go bellow 0 to INT_MIN?
>
> Oh it shall allow for >= 0 from the user. Will fix the min/max values,
> anything else?
>
Nope. Rest looks fine.
>
> Thanks,
> Thilo
> _______________________________________________
> 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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping
2023-05-08 18:55 ` Paul B Mahol
@ 2023-05-08 19:57 ` Thilo Borgmann
0 siblings, 0 replies; 6+ messages in thread
From: Thilo Borgmann @ 2023-05-08 19:57 UTC (permalink / raw)
To: ffmpeg-devel
Am 08.05.23 um 20:55 schrieb Paul B Mahol:
> On Mon, May 8, 2023 at 8:06 PM Thilo Borgmann <thilo.borgmann@mail.de>
> wrote:
>
>> Am 08.05.23 um 15:58 schrieb Paul B Mahol:
>>> On Mon, May 8, 2023 at 3:43 PM Thilo Borgmann <thilo.borgmann@mail.de>
>>> wrote:
>>>
>>>> Am 08.05.23 um 15:32 schrieb Thilo Borgmann:
>>>>> 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(-)
>>>>
>>>> docs and micro bump in v2.
>>>>
>>>
>>> Why is range for option allowed to go bellow 0 to INT_MIN?
>>
>> Oh it shall allow for >= 0 from the user. Will fix the min/max values,
>> anything else?
>>
>
> Nope. Rest looks fine.
Pushed including the min value fix.
Thanks,
Thilo
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-08 19:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08 13:32 [FFmpeg-devel] [PATCH] avfilter/vf_mpdecimate: Add option to keep the first N similar frames before dropping Thilo Borgmann
2023-05-08 13:43 ` Thilo Borgmann
2023-05-08 13:58 ` Paul B Mahol
2023-05-08 18:06 ` Thilo Borgmann
2023-05-08 18:55 ` Paul B Mahol
2023-05-08 19:57 ` Thilo Borgmann
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