[libav-commits] lavfi: add an audio split filter

Justin Ruggles git at libav.org
Mon May 21 20:53:31 CEST 2012


Module: libav
Branch: master
Commit: afeb3590fc5ff01d43b1a1be9df8fac64431ff9e

Author:    Justin Ruggles <justin.ruggles at gmail.com>
Committer: Justin Ruggles <justin.ruggles at gmail.com>
Date:      Mon May 21 14:03:42 2012 -0400

lavfi: add an audio split filter

Based on current version of the asplit filter in FFmpeg written by
Stefano Sabatini and others.

---

 Changelog                |    1 +
 doc/filters.texi         |   13 +++++++++++++
 libavfilter/Makefile     |    1 +
 libavfilter/allfilters.c |    1 +
 libavfilter/split.c      |   30 ++++++++++++++++++++++++++++--
 libavfilter/version.h    |    2 +-
 6 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index afde0e9..2da60b1 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ version <next>:
 - add libavresample audio conversion library
 - audio filters support in libavfilter and avconv
 - add fps filter
+- audio split filter
 
 
 version 0.8:
diff --git a/doc/filters.texi b/doc/filters.texi
index cda235f..ac78029 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -137,6 +137,19 @@ aformat=sample_fmts\=u8\,s16:channel_layouts\=stereo
 
 Pass the audio source unchanged to the output.
 
+ at section asplit
+
+Split input audio into several identical outputs.
+
+The filter accepts a single parameter which specifies the number of outputs. If
+unspecified, it defaults to 2.
+
+For example
+ at example
+avconv -i INPUT -filter_complex asplit=5 OUTPUT
+ at end example
+will create 5 copies of the input audio.
+
 @section asyncts
 Synchronize audio data with timestamps by squeezing/stretching it and/or
 dropping samples/adding silence when needed.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1a436d2..8649222 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -27,6 +27,7 @@ OBJS = allfilters.o                                                     \
 
 OBJS-$(CONFIG_AFORMAT_FILTER)                += af_aformat.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
+OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
 OBJS-$(CONFIG_ASYNCTS_FILTER)                += af_asyncts.o
 OBJS-$(CONFIG_RESAMPLE_FILTER)               += af_resample.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b3e57fd..316fff1 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -36,6 +36,7 @@ void avfilter_register_all(void)
 
     REGISTER_FILTER (AFORMAT,     aformat,     af);
     REGISTER_FILTER (ANULL,       anull,       af);
+    REGISTER_FILTER (ASPLIT,      asplit,      af);
     REGISTER_FILTER (ASYNCTS,     asyncts,     af);
     REGISTER_FILTER (RESAMPLE,    resample,    af);
 
diff --git a/libavfilter/split.c b/libavfilter/split.c
index da6b3ff..83ad765 100644
--- a/libavfilter/split.c
+++ b/libavfilter/split.c
@@ -20,10 +20,11 @@
 
 /**
  * @file
- * Video splitter
+ * audio and video splitter
  */
 
 #include "avfilter.h"
+#include "audio.h"
 
 static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
 {
@@ -43,7 +44,7 @@ static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
         AVFilterPad pad = { 0 };
 
         snprintf(name, sizeof(name), "output%d", i);
-        pad.type = AVMEDIA_TYPE_VIDEO;
+        pad.type = ctx->filter->inputs[0].type;
         pad.name = av_strdup(name);
 
         avfilter_insert_outpad(ctx, i, &pad);
@@ -106,3 +107,28 @@ AVFilter avfilter_vf_split = {
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name = NULL}},
 };
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
+{
+    AVFilterContext *ctx = inlink->dst;
+    int i;
+
+    for (i = 0; i < ctx->output_count; i++)
+        ff_filter_samples(inlink->dst->outputs[i],
+                          avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
+}
+
+AVFilter avfilter_af_asplit = {
+    .name        = "asplit",
+    .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
+
+    .init   = split_init,
+    .uninit = split_uninit,
+
+    .inputs  = (const AVFilterPad[]) {{ .name             = "default",
+                                        .type             = AVMEDIA_TYPE_AUDIO,
+                                        .get_audio_buffer = ff_null_get_audio_buffer,
+                                        .filter_samples   = filter_samples },
+                                      { .name = NULL }},
+    .outputs = (const AVFilterPad[]) {{ .name = NULL }},
+};
diff --git a/libavfilter/version.h b/libavfilter/version.h
index f352f7b..f6497db 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  2
-#define LIBAVFILTER_VERSION_MINOR  18
+#define LIBAVFILTER_VERSION_MINOR  19
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \



More information about the libav-commits mailing list