2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of FFmpeg.
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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
30 static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
32 int i, nb_outputs = 2;
35 nb_outputs = strtol(args, NULL, 0);
36 if (nb_outputs <= 0) {
37 av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
39 return AVERROR(EINVAL);
43 for (i = 0; i < nb_outputs; i++) {
45 AVFilterPad pad = { 0 };
47 snprintf(name, sizeof(name), "output%d", i);
48 pad.type = ctx->filter->inputs[0].type;
49 pad.name = av_strdup(name);
51 avfilter_insert_outpad(ctx, i, &pad);
57 static void split_uninit(AVFilterContext *ctx)
61 for (i = 0; i < ctx->output_count; i++)
62 av_freep(&ctx->output_pads[i].name);
65 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
67 AVFilterContext *ctx = inlink->dst;
70 for (i = 0; i < ctx->output_count; i++)
71 avfilter_start_frame(ctx->outputs[i],
72 avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
75 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
77 AVFilterContext *ctx = inlink->dst;
80 for (i = 0; i < ctx->output_count; i++)
81 avfilter_draw_slice(ctx->outputs[i], y, h, slice_dir);
84 static void end_frame(AVFilterLink *inlink)
86 AVFilterContext *ctx = inlink->dst;
89 for (i = 0; i < ctx->output_count; i++)
90 avfilter_end_frame(ctx->outputs[i]);
92 avfilter_unref_buffer(inlink->cur_buf);
95 AVFilter avfilter_vf_split = {
97 .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
100 .uninit = split_uninit,
102 .inputs = (const AVFilterPad[]) {{ .name = "default",
103 .type = AVMEDIA_TYPE_VIDEO,
104 .get_video_buffer= ff_null_get_video_buffer,
105 .start_frame = start_frame,
106 .draw_slice = draw_slice,
107 .end_frame = end_frame, },
109 .outputs = (AVFilterPad[]) {{ .name = NULL}},
112 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
114 AVFilterContext *ctx = inlink->dst;
117 for (i = 0; i < ctx->output_count; i++)
118 ff_filter_samples(inlink->dst->outputs[i],
119 avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
122 AVFilter avfilter_af_asplit = {
124 .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
127 .uninit = split_uninit,
129 .inputs = (const AVFilterPad[]) {{ .name = "default",
130 .type = AVMEDIA_TYPE_AUDIO,
131 .get_audio_buffer = ff_null_get_audio_buffer,
132 .filter_samples = filter_samples },
134 .outputs = (const AVFilterPad[]) {{ .name = NULL }},