split.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Bobby Bingham
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 /**
22  * @file
23  * audio and video splitter
24  */
25 
26 #include <stdio.h>
27 
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 
32 #include "avfilter.h"
33 #include "audio.h"
34 #include "internal.h"
35 #include "video.h"
36 
37 typedef struct SplitContext {
38  const AVClass *class;
40 } SplitContext;
41 
42 static int split_init(AVFilterContext *ctx)
43 {
44  SplitContext *s = ctx->priv;
45  int i;
46 
47  for (i = 0; i < s->nb_outputs; i++) {
48  char name[32];
49  AVFilterPad pad = { 0 };
50 
51  snprintf(name, sizeof(name), "output%d", i);
52  pad.type = ctx->filter->inputs[0].type;
53  pad.name = av_strdup(name);
54 
55  ff_insert_outpad(ctx, i, &pad);
56  }
57 
58  return 0;
59 }
60 
61 static void split_uninit(AVFilterContext *ctx)
62 {
63  int i;
64 
65  for (i = 0; i < ctx->nb_outputs; i++)
66  av_freep(&ctx->output_pads[i].name);
67 }
68 
69 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
70 {
71  AVFilterContext *ctx = inlink->dst;
72  int i, ret = AVERROR_EOF;
73 
74  for (i = 0; i < ctx->nb_outputs; i++) {
75  AVFrame *buf_out;
76 
77  if (ctx->outputs[i]->closed)
78  continue;
79  buf_out = av_frame_clone(frame);
80  if (!buf_out) {
81  ret = AVERROR(ENOMEM);
82  break;
83  }
84 
85  ret = ff_filter_frame(ctx->outputs[i], buf_out);
86  if (ret < 0)
87  break;
88  }
89  av_frame_free(&frame);
90  return ret;
91 }
92 
93 #define OFFSET(x) offsetof(SplitContext, x)
94 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
95 static const AVOption options[] = {
96  { "outputs", "set number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, FLAGS },
97  { NULL },
98 };
99 
100 #define split_options options
102 
103 #define asplit_options options
104 AVFILTER_DEFINE_CLASS(asplit);
105 
107  {
108  .name = "default",
109  .type = AVMEDIA_TYPE_VIDEO,
110  .get_video_buffer = ff_null_get_video_buffer,
111  .filter_frame = filter_frame,
112  },
113  { NULL }
114 };
115 
117  .name = "split",
118  .description = NULL_IF_CONFIG_SMALL("Pass on the input video to N outputs."),
119 
120  .priv_size = sizeof(SplitContext),
121  .priv_class = &split_class,
122 
123  .init = split_init,
124  .uninit = split_uninit,
125 
126  .inputs = avfilter_vf_split_inputs,
127  .outputs = NULL,
128 
130 };
131 
133  {
134  .name = "default",
135  .type = AVMEDIA_TYPE_AUDIO,
136  .get_audio_buffer = ff_null_get_audio_buffer,
137  .filter_frame = filter_frame,
138  },
139  { NULL }
140 };
141 
143  .name = "asplit",
144  .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
145 
146  .priv_size = sizeof(SplitContext),
147  .priv_class = &asplit_class,
148 
149  .init = split_init,
150  .uninit = split_uninit,
151 
152  .inputs = avfilter_af_asplit_inputs,
153  .outputs = NULL,
154 
156 };
const char * name
Definition: avisynth_c.h:675
const char * s
Definition: avisynth_c.h:668
static int split_init(AVFilterContext *ctx)
Definition: split.c:42
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
AVOption.
Definition: opt.h:251
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
memory handling functions
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: split.c:69
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:35
enum AVMediaType type
AVFilterPad type.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
const char * name
Pad name.
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:538
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:334
AVOptions.
struct SplitContext SplitContext
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVFilter avfilter_vf_split
Definition: split.c:116
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:430
frame
Definition: stft.m:14
A filter pad used for either input or output.
#define FLAGS
Definition: split.c:94
unsigned nb_outputs
number of output pads
Definition: avfilter.h:543
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define OFFSET(x)
Definition: split.c:93
void * priv
private data for use by the filter
Definition: avfilter.h:545
static const AVFilterPad avfilter_af_asplit_inputs[]
Definition: split.c:132
common internal API header
ret
Definition: avfilter.c:821
static void ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Note except for filters that can have queued request_frame does not push and as a the filter_frame method will be called and do the work Legacy the filter_frame method was split
AVFrame * ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
get_audio_buffer() handler for filters which simply pass audio along
Definition: audio.c:36
const AVFilterPad * inputs
NULL terminated list of inputs. NULL if none.
Definition: avfilter.h:445
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:317
static const AVFilterPad avfilter_vf_split_inputs[]
Definition: split.c:106
NULL
Definition: eval.c:55
static void split_uninit(AVFilterContext *ctx)
Definition: split.c:61
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
AVFILTER_DEFINE_CLASS(split)
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
const char * name
filter name
Definition: avfilter.h:437
#define snprintf
Definition: snprintf.h:34
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static int flags
Definition: cpu.c:23
static const AVOption options[]
Definition: split.c:95
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
int nb_outputs
Definition: split.c:39
An instance of a filter.
Definition: avfilter.h:524
AVFilter avfilter_af_asplit
Definition: split.c:142
internal API functions
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:527