[FFmpeg-devel] [PATCH 1/2] Add split filter.

Stefano Sabatini stefano.sabatini-lala
Sat Jul 31 02:07:12 CEST 2010


---
 doc/filters.texi         |   15 ++++++++++
 libavfilter/Makefile     |    1 +
 libavfilter/allfilters.c |    1 +
 libavfilter/vf_split.c   |   66 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 libavfilter/vf_split.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 7f0cb71..3ce60b3 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -164,6 +164,21 @@ not specified it will use the default value of 16.
 Adding this in the beginning of filter chains should make filtering
 faster due to better use of the memory cache.
 
+ at section split
+
+Pass on the input video to two outputs. Both outputs are perfectly
+identical to the input video.
+
+For example if you want to process the same input using two different
+filterchains, you can use the split filter to issue two different
+outputs.
+
+For example:
+ at example
+"split [splitout1][splitout2]; [splitout1] crop=0:0:100:100 [cropout]; [splitout2] pad=200:200:100:100 [padout]; 
+ at end example
+will create two separate outputs, one cropped and one padded.
+
 @section unsharp
 
 Sharpen or blur the input video.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index feef16c..b7d3ddb 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -24,6 +24,7 @@ OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
 OBJS-$(CONFIG_PIXELASPECT_FILTER)            += vf_aspect.o
 OBJS-$(CONFIG_SCALE_FILTER)                  += vf_scale.o
 OBJS-$(CONFIG_SLICIFY_FILTER)                += vf_slicify.o
+OBJS-$(CONFIG_SPLIT_FILTER)                  += vf_split.o
 OBJS-$(CONFIG_UNSHARP_FILTER)                += vf_unsharp.o
 OBJS-$(CONFIG_VFLIP_FILTER)                  += vf_vflip.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index e8bc771..3282a31 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -44,6 +44,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER (PIXELASPECT, pixelaspect, vf);
     REGISTER_FILTER (SCALE,       scale,       vf);
     REGISTER_FILTER (SLICIFY,     slicify,     vf);
+    REGISTER_FILTER (SPLIT,       split,       vf);
     REGISTER_FILTER (UNSHARP,     unsharp,     vf);
     REGISTER_FILTER (VFLIP,       vflip,       vf);
 
diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c
new file mode 100644
index 0000000..5643249
--- /dev/null
+++ b/libavfilter/vf_split.c
@@ -0,0 +1,66 @@
+/*
+ * copyright (c) 2007 Bobby Bingham
+ *
+ * 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
+ * Video splitter
+ */
+
+#include "avfilter.h"
+
+static void start_frame(AVFilterLink *inlink, AVFilterPicRef *picref)
+{
+    avfilter_start_frame(inlink->dst->outputs[0],
+                         avfilter_ref_pic(picref, ~AV_PERM_WRITE));
+    avfilter_start_frame(inlink->dst->outputs[1],
+                         avfilter_ref_pic(picref, ~AV_PERM_WRITE));
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+    avfilter_end_frame(inlink->dst->outputs[0]);
+    avfilter_end_frame(inlink->dst->outputs[1]);
+
+    avfilter_unref_pic(inlink->cur_pic);
+}
+
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+    avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir);
+}
+
+AVFilter avfilter_vf_split = {
+    .name      = "split",
+    .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AVMEDIA_TYPE_VIDEO,
+                                    .get_video_buffer= avfilter_null_get_video_buffer,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .end_frame       = end_frame, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "output1",
+                                    .type            = AVMEDIA_TYPE_VIDEO, },
+                                  { .name            = "output2",
+                                    .type            = AVMEDIA_TYPE_VIDEO, },
+                                  { .name = NULL}},
+};
-- 
1.7.0.4




More information about the ffmpeg-devel mailing list