[FFmpeg-devel] [PATCH v6 22/25] avfilter/snull, strim: Add snull and strim filters

softworkz ffmpegagent at gmail.com
Sun Jun 26 19:35:19 EEST 2022


From: softworkz <softworkz at hotmail.com>

Signed-off-by: softworkz <softworkz at hotmail.com>
---
 configure                |  2 +-
 libavfilter/Makefile     |  2 ++
 libavfilter/allfilters.c |  2 ++
 libavfilter/sf_snull.c   | 50 +++++++++++++++++++++++++++++++++
 libavfilter/trim.c       | 60 +++++++++++++++++++++++++++++++++++++++-
 5 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/sf_snull.c

diff --git a/configure b/configure
index f74077b439..285bdf958e 100755
--- a/configure
+++ b/configure
@@ -3817,7 +3817,7 @@ avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vaapi
 # programs
 ffmpeg_deps="avcodec avfilter avformat"
 ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
-               hflip_filter null_filter
+               snull_filter strim_filter hflip_filter null_filter
                transpose_filter trim_filter vflip_filter"
 ffmpeg_suggest="ole32 psapi shell32"
 ffplay_deps="avcodec avformat swscale swresample sdl2"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index adbc16a5a9..697eee57d2 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -581,7 +581,9 @@ OBJS-$(CONFIG_NULLSINK_FILTER)               += vsink_nullsink.o
 # subtitle filters
 OBJS-$(CONFIG_CENSOR_FILTER)                 += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)           += sf_textmod.o
+OBJS-$(CONFIG_SNULL_FILTER)                  += sf_snull.o
 OBJS-$(CONFIG_SPLITCC_FILTER)                += sf_splitcc.o
+OBJS-$(CONFIG_STRIM_FILTER)                  += trim.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)            += sf_stripstyles.o
 OBJS-$(CONFIG_SUBFEED_FILTER)                += sf_subfeed.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)               += sf_subscale.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 82297e9657..fa7bee3bd8 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -573,7 +573,9 @@ extern const AVFilter ff_avsrc_movie;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_snull;
 extern const AVFilter ff_sf_splitcc;
+extern const AVFilter ff_sf_strim;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_subscale;
diff --git a/libavfilter/sf_snull.c b/libavfilter/sf_snull.c
new file mode 100644
index 0000000000..064c8d5c3a
--- /dev/null
+++ b/libavfilter/sf_snull.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * null subtitle filter
+ */
+
+#include "avfilter.h"
+#include "internal.h"
+#include "libavutil/internal.h"
+
+static const AVFilterPad avfilter_sf_snull_inputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_SUBTITLE,
+    },
+};
+
+static const AVFilterPad avfilter_sf_snull_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_SUBTITLE,
+    },
+};
+
+const AVFilter ff_sf_snull = {
+    .name          = "snull",
+    .description   = NULL_IF_CONFIG_SMALL("Pass the source unchanged to the output."),
+    .flags         = AVFILTER_FLAG_METADATA_ONLY,
+    FILTER_INPUTS(avfilter_sf_snull_inputs),
+    FILTER_OUTPUTS(avfilter_sf_snull_outputs),
+};
diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index ee6e821cd2..a25366497b 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -83,7 +83,7 @@ static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     TrimContext       *s = ctx->priv;
-    AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
+    AVRational tb = (inlink->type != AVMEDIA_TYPE_AUDIO) ?
                      inlink->time_base : (AVRational){ 1, inlink->sample_rate };
 
     if (s->start_time != INT64_MAX) {
@@ -369,3 +369,61 @@ const AVFilter ff_af_atrim = {
     FILTER_OUTPUTS(atrim_outputs),
 };
 #endif // CONFIG_ATRIM_FILTER
+
+#if CONFIG_STRIM_FILTER
+
+static int sconfig_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
+
+    outlink->format = inlink->format;
+    outlink->w = inlink->w;
+    outlink->h = inlink->h;
+
+    return 0;
+}
+
+
+#define FLAGS (AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
+static const AVOption strim_options[] = {
+    COMMON_OPTS
+    { "start_frame", "Number of the first frame that should be passed "
+        "to the output",                                                 OFFSET(start_frame), AV_OPT_TYPE_INT64,  { .i64 = -1 },       -1, INT64_MAX, FLAGS },
+    { "end_frame",   "Number of the first frame that should be dropped "
+        "again",                                                         OFFSET(end_frame),   AV_OPT_TYPE_INT64,  { .i64 = INT64_MAX }, 0, INT64_MAX, FLAGS },
+    { NULL }
+};
+#undef FLAGS
+
+AVFILTER_DEFINE_CLASS(strim);
+
+static const AVFilterPad strim_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_SUBTITLE,
+        .filter_frame = trim_filter_frame,
+        .config_props = config_input,
+    },
+};
+
+static const AVFilterPad strim_outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_SUBTITLE,
+        .config_props = sconfig_output,
+    },
+};
+
+const AVFilter ff_sf_strim = {
+    .name        = "strim",
+    .description = NULL_IF_CONFIG_SMALL("Pick one continuous section from the input, drop the rest."),
+    .init        = init,
+    .priv_size   = sizeof(TrimContext),
+    .priv_class  = &strim_class,
+    .flags       = AVFILTER_FLAG_METADATA_ONLY,
+    FILTER_INPUTS(strim_inputs),
+    FILTER_OUTPUTS(strim_outputs),
+};
+#endif // CONFIG_STRIM_FILTER
+
-- 
ffmpeg-codebot



More information about the ffmpeg-devel mailing list