lavfi: add an audio split filter
authorJustin Ruggles <justin.ruggles@gmail.com>
Mon, 21 May 2012 18:03:42 +0000 (14:03 -0400)
committerJustin Ruggles <justin.ruggles@gmail.com>
Mon, 21 May 2012 18:49:52 +0000 (14:49 -0400)
Based on current version of the asplit filter in FFmpeg written by
Stefano Sabatini and others.

Changelog
doc/filters.texi
libavfilter/Makefile
libavfilter/allfilters.c
libavfilter/split.c
libavfilter/version.h

index afde0e9..2da60b1 100644 (file)
--- 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:
index cda235f..ac78029 100644 (file)
@@ -137,6 +137,19 @@ aformat=sample_fmts\=u8\,s16:channel_layouts\=stereo
 
 Pass the audio source unchanged to the output.
 
+@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
+@example
+avconv -i INPUT -filter_complex asplit=5 OUTPUT
+@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.
index 1a436d2..8649222 100644 (file)
@@ -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
 
index b3e57fd..316fff1 100644 (file)
@@ -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);
 
index da6b3ff..83ad765 100644 (file)
 
 /**
  * @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 }},
+};
index f352f7b..f6497db 100644 (file)
@@ -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, \