2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * audio and video splitter
29 static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
31 int i, nb_outputs = 2;
34 nb_outputs = strtol(args, NULL, 0);
35 if (nb_outputs <= 0) {
36 av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
38 return AVERROR(EINVAL);
42 for (i = 0; i < nb_outputs; i++) {
44 AVFilterPad pad = { 0 };
46 snprintf(name, sizeof(name), "output%d", i);
47 pad.type = ctx->filter->inputs[0].type;
48 pad.name = av_strdup(name);
50 avfilter_insert_outpad(ctx, i, &pad);
56 static void split_uninit(AVFilterContext *ctx)
60 for (i = 0; i < ctx->output_count; i++)
61 av_freep(&ctx->output_pads[i].name);
64 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
66 AVFilterContext *ctx = inlink->dst;
69 for (i = 0; i < ctx->output_count; i++)
70 avfilter_start_frame(ctx->outputs[i],
71 avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
74 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
76 AVFilterContext *ctx = inlink->dst;
79 for (i = 0; i < ctx->output_count; i++)
80 avfilter_draw_slice(ctx->outputs[i], y, h, slice_dir);
83 static void end_frame(AVFilterLink *inlink)
85 AVFilterContext *ctx = inlink->dst;
88 for (i = 0; i < ctx->output_count; i++)
89 avfilter_end_frame(ctx->outputs[i]);
91 avfilter_unref_buffer(inlink->cur_buf);
94 AVFilter avfilter_vf_split = {
96 .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
99 .uninit = split_uninit,
101 .inputs = (AVFilterPad[]) {{ .name = "default",
102 .type = AVMEDIA_TYPE_VIDEO,
103 .get_video_buffer= avfilter_null_get_video_buffer,
104 .start_frame = start_frame,
105 .draw_slice = draw_slice,
106 .end_frame = end_frame, },
108 .outputs = (AVFilterPad[]) {{ .name = NULL}},
111 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
113 AVFilterContext *ctx = inlink->dst;
116 for (i = 0; i < ctx->output_count; i++)
117 ff_filter_samples(inlink->dst->outputs[i],
118 avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
121 AVFilter avfilter_af_asplit = {
123 .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
126 .uninit = split_uninit,
128 .inputs = (const AVFilterPad[]) {{ .name = "default",
129 .type = AVMEDIA_TYPE_AUDIO,
130 .get_audio_buffer = ff_null_get_audio_buffer,
131 .filter_samples = filter_samples },
133 .outputs = (const AVFilterPad[]) {{ .name = NULL }},