00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avfilter.h"
00027
00028 static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
00029 {
00030 int i, nb_outputs = 2;
00031
00032 if (args) {
00033 nb_outputs = strtol(args, NULL, 0);
00034 if (nb_outputs <= 0) {
00035 av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
00036 nb_outputs);
00037 return AVERROR(EINVAL);
00038 }
00039 }
00040
00041 for (i = 0; i < nb_outputs; i++) {
00042 char name[32];
00043 AVFilterPad pad = { 0 };
00044
00045 snprintf(name, sizeof(name), "output%d", i);
00046 pad.type = AVMEDIA_TYPE_VIDEO;
00047 pad.name = av_strdup(name);
00048
00049 avfilter_insert_outpad(ctx, i, &pad);
00050 }
00051
00052 return 0;
00053 }
00054
00055 static void split_uninit(AVFilterContext *ctx)
00056 {
00057 int i;
00058
00059 for (i = 0; i < ctx->output_count; i++)
00060 av_freep(&ctx->output_pads[i].name);
00061 }
00062
00063 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
00064 {
00065 AVFilterContext *ctx = inlink->dst;
00066 int i;
00067
00068 for (i = 0; i < ctx->output_count; i++)
00069 avfilter_start_frame(ctx->outputs[i],
00070 avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
00071 }
00072
00073 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
00074 {
00075 AVFilterContext *ctx = inlink->dst;
00076 int i;
00077
00078 for (i = 0; i < ctx->output_count; i++)
00079 avfilter_draw_slice(ctx->outputs[i], y, h, slice_dir);
00080 }
00081
00082 static void end_frame(AVFilterLink *inlink)
00083 {
00084 AVFilterContext *ctx = inlink->dst;
00085 int i;
00086
00087 for (i = 0; i < ctx->output_count; i++)
00088 avfilter_end_frame(ctx->outputs[i]);
00089
00090 avfilter_unref_buffer(inlink->cur_buf);
00091 }
00092
00093 AVFilter avfilter_vf_split = {
00094 .name = "split",
00095 .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
00096
00097 .init = split_init,
00098 .uninit = split_uninit,
00099
00100 .inputs = (const AVFilterPad[]) {{ .name = "default",
00101 .type = AVMEDIA_TYPE_VIDEO,
00102 .get_video_buffer= avfilter_null_get_video_buffer,
00103 .start_frame = start_frame,
00104 .draw_slice = draw_slice,
00105 .end_frame = end_frame, },
00106 { .name = NULL}},
00107 .outputs = (AVFilterPad[]) {{ .name = NULL}},
00108 };