26 #include "libavutil/avstring.h"
27 #include "libavutil/mem.h"
30 #define WHITESPACES " \n\t"
44 "Cannot create the link %s:%d -> %s:%d\n",
68 "Bad (empty?) label found in the following: \"%s\".\n", start);
72 if (*(*buf)++ !=
']') {
74 "Mismatched '[' found in the following: \"%s\".\n", start);
95 const char *filt_name,
const char *
args,
void *log_ctx)
99 char *tmp_args = NULL;
102 snprintf(inst_name,
sizeof(inst_name),
"Parsed_%s_%d", filt_name, index);
108 "No such filter: '%s'\n", filt_name);
115 "Error creating filter '%s'\n", filt_name);
119 if (!strcmp(filt_name,
"scale") && args && !strstr(args,
"flags") &&
131 "Error initializing filter '%s'", filt_name);
158 int index,
void *log_ctx)
169 ret =
create_filter(filt_ctx, graph, index, name, opts, log_ctx);
194 while (*links && (!(*links)->name || strcmp((*links)->name, label)))
195 links = &((*links)->next);
209 element->
next = *inouts;
215 while (*inouts && (*inouts)->
next)
216 inouts = &((*inouts)->next);
221 (*inouts)->
next = *element;
231 for (pad = 0; pad < filt_ctx->
nb_inputs; pad++) {
235 *curr_inputs = (*curr_inputs)->
next;
255 "Too many inputs specified for the \"%s\" filter.\n",
279 while (**buf ==
'[') {
308 *curr_inputs = parsed_inputs;
319 while (**buf ==
'[') {
330 "No output pad can be associated to link label '%s'.\n", name);
334 *curr_inputs = (*curr_inputs)->
next;
363 char *p = strchr(*buf,
';');
365 if (strncmp(*buf,
"sws_flags=", 10))
391 AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
402 if ((
ret =
parse_inputs(&filters, &curr_inputs, &open_outputs, graph)) < 0)
411 if ((
ret =
parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
418 if (chr ==
';' && curr_inputs)
421 }
while (chr ==
',' || chr ==
';');
425 "Unable to parse graph description substring: \"%s\"\n",
434 *inputs = open_inputs;
435 *outputs = open_outputs;
452 #if HAVE_INCOMPATIBLE_LIBAV_ABI || !FF_API_OLD_GRAPH_PARSE
464 if (inputs && !inputs->
name)
466 for (cur = inputs; cur; cur = cur->
next) {
469 "Not enough inputs specified for the \"%s\" filter.\n",
484 if (outputs && !outputs->name)
486 for (cur = outputs; cur; cur = cur->
next) {
489 "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
527 int index = 0, ret = 0;
531 AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL;
532 AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
539 const char *filterchain =
filters;
542 if ((ret =
parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
545 if ((ret =
parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
548 if (filter->
nb_inputs == 1 && !curr_inputs && !index) {
550 const char *tmp =
"[in]";
551 if ((ret =
parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)
558 if ((ret =
parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
565 if (chr ==
';' && curr_inputs) {
567 "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
573 }
while (chr ==
',' || chr ==
';');
577 "Unable to parse graph description substring: \"%s\"\n",
585 const char *tmp =
"[out]";
586 if ((ret =
parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,
593 if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
595 if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
void avfilter_free(AVFilterContext *filter)
Free a filter context.
const char * name
Filter name.
static const AVFilterPad outputs[]
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
AVFilterContext * filter_ctx
filter context associated to this input/output
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
static av_cold int end(AVCodecContext *avctx)
static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element)
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
static const vf_info_t *const filters[]
static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, AVFilterInOut **open_outputs, void *log_ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static AVFilterInOut * extract_inout(const char *label, AVFilterInOut **links)
unsigned nb_outputs
number of output pads
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned nb_inputs
number of input pads
const AVFilter * filter
the AVFilter of which this is an instance
char * name
unique name for this input/output in the list
size_t char * av_asprintf(const char *fmt,...) av_printf_format(1
Print arguments following specified format into a large enough auto allocated buffer.
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
Main libavfilter public API header.
A linked-list of the inputs/outputs of the filter chain.
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
static int parse_sws_flags(const char **buf, AVFilterGraph *graph)
static void append_inout(AVFilterInOut **inouts, AVFilterInOut **element)
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, void *log_ctx)
Add a graph described by a string to a graph.
static const AVFilterPad inputs[]
int pad_idx
index of the filt_ctx pad to use for linking
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph, int index, void *log_ctx)
Parse a string of the form FILTER_NAME[=PARAMS], and create a corresponding filter instance which is ...
static const int8_t filt[NUMTAPS]
static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, AVFilterInOut **open_inputs, AVFilterInOut **open_outputs, void *log_ctx)
static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index, const char *filt_name, const char *args, void *log_ctx)
Create an instance of a filter, initialize and insert it in the filtergraph in *ctx.
AVFilterContext ** filters
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
static int link_filter(AVFilterContext *src, int srcpad, AVFilterContext *dst, int dstpad, void *log_ctx)
Link two filters together.
static char * parse_link_name(const char **buf, void *log_ctx)
Parse the name of a link, which has the format "[linkname]".
static int link_filter_inouts(AVFilterContext *filt_ctx, AVFilterInOut **curr_inputs, AVFilterInOut **open_inputs, void *log_ctx)
int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
Add a graph described by a string to a graph.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...