lavfi: add an audio split filter

Based on current version of the asplit filter in FFmpeg written by
Stefano Sabatini and others.
This commit is contained in:
Justin Ruggles 2012-05-21 14:03:42 -04:00
parent cc30080b3f
commit afeb3590fc
6 changed files with 45 additions and 3 deletions

View File

@ -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:

View 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.

View 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

View 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);

View File

@ -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 }},
};

View 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, \