[FFmpeg-devel] [PATCH] lavfi: add framestep filter

Stefano Sabatini stefasab at gmail.com
Thu Aug 16 19:07:06 CEST 2012


This filter is a simple wrapper around select, meant as a replacement for
mp=framestep.
---
 doc/filters.texi         |   15 +++++++++++++
 libavfilter/Makefile     |    1 +
 libavfilter/allfilters.c |    1 +
 libavfilter/vf_select.c  |   50 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f4c895a..390b3f6 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2057,6 +2057,21 @@ Desired output framerate.
 
 @end table
 
+ at section framestep
+
+Select one frame every N.
+
+This filter accepts in input a string representing a positive
+integer. Default argument is @code{1}.
+
+Note that this filter is equivalent to:
+ at example
+select='not(mod(n\, at var{STEP}))'
+ at end example
+
+where @var{STEP} is the value specified as argument to
+ at code{framestep}.
+
 @anchor{frei0r}
 @section frei0r
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index a73f593..2387ce7 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -94,6 +94,7 @@ OBJS-$(CONFIG_FADE_FILTER)                   += vf_fade.o
 OBJS-$(CONFIG_FIELDORDER_FILTER)             += vf_fieldorder.o
 OBJS-$(CONFIG_FIFO_FILTER)                   += fifo.o
 OBJS-$(CONFIG_FORMAT_FILTER)                 += vf_format.o
+OBJS-$(CONFIG_FRAMESTEP_FILTER)              += vf_select.o
 OBJS-$(CONFIG_FPS_FILTER)                    += vf_fps.o
 OBJS-$(CONFIG_FREI0R_FILTER)                 += vf_frei0r.o
 OBJS-$(CONFIG_GRADFUN_FILTER)                += vf_gradfun.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 7b66452..eef5f5e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -86,6 +86,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER (FIFO,        fifo,        vf);
     REGISTER_FILTER (FORMAT,      format,      vf);
     REGISTER_FILTER (FPS,         fps,         vf);
+    REGISTER_FILTER (FRAMESTEP,   framestep,   vf);
     REGISTER_FILTER (FREI0R,      frei0r,      vf);
     REGISTER_FILTER (GRADFUN,     gradfun,     vf);
     REGISTER_FILTER (HFLIP,       hflip,       vf);
diff --git a/libavfilter/vf_select.c b/libavfilter/vf_select.c
index db1b038..69c1e4b 100644
--- a/libavfilter/vf_select.c
+++ b/libavfilter/vf_select.c
@@ -404,6 +404,54 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
+#if CONFIG_FRAMESTEP_FILTER
+
+static av_cold int framestep_init(AVFilterContext *ctx, const char *args)
+{
+    char args1[256];
+    char *tailptr;
+    long int n = 1;
+
+    if (args) {
+        n = strtol(args, &tailptr, 10);
+        if (*tailptr || n <= 0) {
+            av_log(ctx, AV_LOG_ERROR,
+                   "Invalid argument '%s', must be a positive integer\n", args);
+            return AVERROR(EINVAL);
+        }
+    }
+    snprintf(args1, sizeof(args1), "not(mod(n,%ld))", n);
+    return init(ctx, args1);
+}
+
+AVFilter avfilter_vf_framestep = {
+    .name      = "framestep",
+    .description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
+    .init      = framestep_init,
+    .uninit    = uninit,
+    .query_formats = query_formats,
+
+    .priv_size = sizeof(SelectContext),
+
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .config_props     = config_input,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .end_frame        = end_frame },
+                                        { .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .poll_frame       = poll_frame,
+                                          .request_frame    = request_frame, },
+                                        { .name = NULL}},
+};
+
+#endif /* CONFIG_FRAMESTEP_FILTER */
+
+#if CONFIG_SELECT_FILTER
+
 AVFilter avfilter_vf_select = {
     .name      = "select",
     .description = NULL_IF_CONFIG_SMALL("Select frames to pass in output."),
@@ -427,3 +475,5 @@ AVFilter avfilter_vf_select = {
                                           .request_frame    = request_frame, },
                                         { .name = NULL}},
 };
+
+#endif  /* CONFIG_SELECT_FILTER */
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list