[FFmpeg-devel] [PATCH] lavfi/asplit: move asplit code to vf_split.c, and make it supports N outputs
Clément Bœsch
ubitux at gmail.com
Sat May 19 01:12:06 CEST 2012
On Sat, May 19, 2012 at 12:50:05AM +0200, Stefano Sabatini wrote:
> The move allows to share the init code already used by split.
> ---
> doc/filters.texi | 16 +++++++++----
> libavfilter/Makefile | 2 +-
> libavfilter/af_asplit.c | 56 -----------------------------------------------
> libavfilter/vf_split.c | 32 ++++++++++++++++++++++++++-
> 4 files changed, 43 insertions(+), 63 deletions(-)
> delete mode 100644 libavfilter/af_asplit.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 06374fc..467fb4a 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -304,16 +304,22 @@ expressed in the form "[@var{c0} @var{c1} @var{c2} @var{c3} @var{c4} @var{c5}
>
> @section asplit
>
> -Pass on the input audio to two outputs. Both outputs are identical to
> -the input audio.
> +Pass on the input audio to N outputs. Both outputs are identical to
> +the input audio. The number of outputs is specified as argument to the
> +filter, default value is 2.
>
> For example:
> @example
> -[in] asplit[out0], showaudio[out1]
> +[in] asplit[out0][out1]
nit: maybe some consistent spacing? "[in] asplit [out0][out1]" (or no
space at all).
> @end example
>
> -will create two separate outputs from the same input, one cropped and
> -one padded.
> +will create two separate outputs from the same input.
> +
> +To create 3 or more outputs, you need to specify the number of
> +outputs, like in:
> + at example
> +[in] asplit=3[out0][out1][out2]
ditto
> + at end example
>
> @section astreamsync
>
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 1f9d411..3992322 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -49,7 +49,7 @@ OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o
> OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
> OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o
> OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o
> -OBJS-$(CONFIG_ASPLIT_FILTER) += af_asplit.o
> +OBJS-$(CONFIG_ASPLIT_FILTER) += vf_split.o
> OBJS-$(CONFIG_ASTREAMSYNC_FILTER) += af_astreamsync.o
> OBJS-$(CONFIG_ASYNCTS_FILTER) += af_asyncts.o
> OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
> diff --git a/libavfilter/af_asplit.c b/libavfilter/af_asplit.c
> deleted file mode 100644
> index f63a29e..0000000
> --- a/libavfilter/af_asplit.c
> +++ /dev/null
> @@ -1,56 +0,0 @@
> -/*
> - * Copyright (c) 2011 Stefano Sabatini
> - *
> - * 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
> - * audio splitter
> - */
> -
> -#include "avfilter.h"
> -#include "audio.h"
> -
> -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
> -{
> - ff_filter_samples(inlink->dst->outputs[0],
> - avfilter_ref_buffer(insamples, ~AV_PERM_WRITE));
> - ff_filter_samples(inlink->dst->outputs[1],
> - avfilter_ref_buffer(insamples, ~AV_PERM_WRITE));
> - avfilter_unref_buffer(insamples);
> -}
> -
> -AVFilter avfilter_af_asplit = {
> - .name = "asplit",
> - .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to two outputs."),
> -
> - .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 = "output1",
> - .type = AVMEDIA_TYPE_AUDIO, },
> - { .name = "output2",
> - .type = AVMEDIA_TYPE_AUDIO, },
> - { .name = NULL}
> - },
> -};
> diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c
> index e7e2dee..172781d 100644
> --- a/libavfilter/vf_split.c
> +++ b/libavfilter/vf_split.c
> @@ -24,6 +24,7 @@
> */
>
> #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 = !strcmp(ctx->name, "split") ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
> pad.name = av_strdup(name);
>
> avfilter_insert_outpad(ctx, i, &pad);
> @@ -106,3 +107,32 @@ 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 }},
> +};
I may be dreaming, but isn't it possible to use the "split" filter as
audio or video depending on the input by adding an audio input in
avfilter_vf_split.inputs?
If not then LGTM.
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120519/b2426796/attachment.asc>
More information about the ffmpeg-devel
mailing list