diff mbox series

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

Message ID 99e5c1195224849c756451093270048a5c7037c6.1666689226.git.ffmpegagent@gmail.com
State New
Headers show
Series Subtitle Filtering 2022 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Aman Karmani Oct. 25, 2022, 9:13 a.m. UTC
From: softworkz <softworkz@hotmail.com>

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 configure                |  2 +-
 libavfilter/Makefile     |  2 ++
 libavfilter/allfilters.c |  2 ++
 libavfilter/sf_snull.c   | 61 ++++++++++++++++++++++++++++++++++++++++
 libavfilter/trim.c       | 60 ++++++++++++++++++++++++++++++++++++++-
 5 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/sf_snull.c
diff mbox series

Patch

diff --git a/configure b/configure
index 3703aa216b..3d830be10f 100755
--- a/configure
+++ b/configure
@@ -3842,7 +3842,7 @@  avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vaapi
 # programs
 ffmpeg_deps="avcodec avfilter avformat threads"
 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 c6dfa517e8..4e5d33a43f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -591,7 +591,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 8779141aad..9c84347659 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -579,7 +579,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..815436cfff
--- /dev/null
+++ b/libavfilter/sf_snull.c
@@ -0,0 +1,61 @@ 
+/*
+ * 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 int sconfig_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
+
+    outlink->format = inlink->format;
+
+    return 0;
+}
+
+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,
+        .config_props = sconfig_output,
+    },
+};
+
+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
+