FFmpeg
avfilter.h
Go to the documentation of this file.
1 /*
2  * filter layer
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVFILTER_AVFILTER_H
23 #define AVFILTER_AVFILTER_H
24 
38 #include <stddef.h>
39 
40 #include "libavutil/attributes.h"
41 #include "libavutil/avutil.h"
42 #include "libavutil/buffer.h"
43 #include "libavutil/dict.h"
44 #include "libavutil/frame.h"
45 #include "libavutil/log.h"
46 #include "libavutil/samplefmt.h"
47 #include "libavutil/pixfmt.h"
48 #include "libavutil/rational.h"
49 
50 #include "libavfilter/version.h"
51 
55 unsigned avfilter_version(void);
56 
60 const char *avfilter_configuration(void);
61 
65 const char *avfilter_license(void);
66 
67 typedef struct AVFilterContext AVFilterContext;
68 typedef struct AVFilterLink AVFilterLink;
69 typedef struct AVFilterPad AVFilterPad;
70 typedef struct AVFilterFormats AVFilterFormats;
71 
76 int avfilter_pad_count(const AVFilterPad *pads);
77 
87 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
88 
98 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
99 
105 #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
106 
111 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
112 
116 #define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
117 
125 #define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC (1 << 16)
126 
133 #define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL (1 << 17)
134 
138 #define AVFILTER_FLAG_SUPPORT_TIMELINE (AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL)
139 
144 typedef struct AVFilter {
148  const char *name;
149 
155  const char *description;
156 
173 
183 
187  int flags;
188 
189  /*****************************************************************
190  * All fields below this line are not part of the public API. They
191  * may not be used outside of libavfilter and can be changed and
192  * removed at will.
193  * New public fields should be added right above.
194  *****************************************************************
195  */
196 
210  int (*preinit)(AVFilterContext *ctx);
211 
233  int (*init)(AVFilterContext *ctx);
234 
246  int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
247 
258  void (*uninit)(AVFilterContext *ctx);
259 
283 
284  int priv_size;
285 
287 
292  struct AVFilter *next;
293 
306  int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
307 
313  int (*init_opaque)(AVFilterContext *ctx, void *opaque);
314 
327  int (*activate)(AVFilterContext *ctx);
328 } AVFilter;
329 
333 #define AVFILTER_THREAD_SLICE (1 << 0)
334 
335 typedef struct AVFilterInternal AVFilterInternal;
336 
339  const AVClass *av_class;
340 
341  const AVFilter *filter;
342 
343  char *name;
344 
347  unsigned nb_inputs;
348 
351  unsigned nb_outputs;
352 
353  void *priv;
354 
356 
374 
378  AVFilterInternal *internal;
379 
380  struct AVFilterCommand *command_queue;
381 
382  char *enable_str;
383  void *enable;
384  double *var_values;
386 
395 
402 
408  unsigned ready;
409 
425 };
426 
439 struct AVFilterLink {
442 
445 
446  enum AVMediaType type;
447 
448  /* These parameters apply only to video */
449  int w;
450  int h;
452  /* These parameters apply only to audio */
453  uint64_t channel_layout;
455 
456  int format;
457 
466 
467  /*****************************************************************
468  * All fields below this line are not part of the public API. They
469  * may not be used outside of libavfilter and can be changed and
470  * removed at will.
471  * New public fields should be added right above.
472  *****************************************************************
473  */
482  AVFilterFormats *out_formats;
483 
489  AVFilterFormats *out_samplerates;
490  struct AVFilterChannelLayouts *in_channel_layouts;
491  struct AVFilterChannelLayouts *out_channel_layouts;
492 
501 
503  enum {
504  AVLINK_UNINIT = 0,
506  AVLINK_INIT
507  } init_state;
508 
513 
518  int64_t current_pts;
519 
524  int64_t current_pts_us;
525 
530 
543 
548 
554 
563 
569 
573  int channels;
574 
578  unsigned flags;
579 
583  int64_t frame_count_in, frame_count_out;
584 
588  void *frame_pool;
589 
596 
602 
603 #ifndef FF_INTERNAL_FIELDS
604 
610  char reserved[0xF000];
611 
612 #else /* FF_INTERNAL_FIELDS */
613 
617  FFFrameQueue fifo;
618 
624  int frame_blocked_in;
625 
631  int status_in;
632 
636  int64_t status_in_pts;
637 
643  int status_out;
644 
645 #endif /* FF_INTERNAL_FIELDS */
646 
647 };
648 
658 int avfilter_link(AVFilterContext *src, unsigned srcpad,
659  AVFilterContext *dst, unsigned dstpad);
660 
664 void avfilter_link_free(AVFilterLink **link);
665 
666 #if FF_API_FILTER_GET_SET
667 
671 attribute_deprecated
672 int avfilter_link_get_channels(AVFilterLink *link);
673 #endif
674 
680 attribute_deprecated
681 void avfilter_link_set_closed(AVFilterLink *link, int closed);
682 
690 
691 #define AVFILTER_CMD_FLAG_ONE 1
692 #define AVFILTER_CMD_FLAG_FAST 2
693 
694 
698 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
699 
709 const AVFilter *av_filter_iterate(void **opaque);
710 
711 #if FF_API_NEXT
712 
713 attribute_deprecated
714 void avfilter_register_all(void);
715 
726 attribute_deprecated
727 int avfilter_register(AVFilter *filter);
728 
734 attribute_deprecated
735 const AVFilter *avfilter_next(const AVFilter *prev);
736 #endif
737 
745 const AVFilter *avfilter_get_by_name(const char *name);
746 
747 
758 int avfilter_init_str(AVFilterContext *ctx, const char *args);
759 
780 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
781 
788 void avfilter_free(AVFilterContext *filter);
789 
800  unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
801 
807 const AVClass *avfilter_get_class(void);
808 
810 
823 typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
824 
838  void *arg, int *ret, int nb_jobs);
839 
840 typedef struct AVFilterGraph {
841  const AVClass *av_class;
842  AVFilterContext **filters;
843  unsigned nb_filters;
844 
846 #if FF_API_LAVR_OPTS
847  attribute_deprecated char *resample_lavr_opts;
848 #endif
849 
863 
870 
875 
881  void *opaque;
882 
896 
898 
907  int sink_links_count;
908 
909  unsigned disable_auto_convert;
910 } AVFilterGraph;
911 
918 
934  const AVFilter *filter,
935  const char *name);
936 
946 
960 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
961  const char *name, const char *args, void *opaque,
962  AVFilterGraph *graph_ctx);
963 
973 
974 enum {
977 };
978 
986 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
987 
992 void avfilter_graph_free(AVFilterGraph **graph);
993 
1003 typedef struct AVFilterInOut {
1005  char *name;
1006 
1009 
1011  int pad_idx;
1012 
1015 } AVFilterInOut;
1016 
1023 
1028 void avfilter_inout_free(AVFilterInOut **inout);
1029 
1048 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
1050  void *log_ctx);
1051 
1069 int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
1071  void *log_ctx);
1072 
1095 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1098 
1114 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
1115 
1131 int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
1132 
1133 
1142 char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
1143 
1163 
1168 #endif /* AVFILTER_AVFILTER_H */
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
Definition: avfiltergraph.c:165
double * var_values
variable values for the enable expression
Definition: avfilter.h:384
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts)
Queue a command for one or more filter instances.
Definition: avfiltergraph.c:1316
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:862
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:760
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:83
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
Definition: avfiltergraph.c:1266
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:203
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1014
Queue of AVFrame pointers.
Definition: framequeue.h:53
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:1039
Definition: internal.h:148
Libavfilter version macros.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:120
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in...
Definition: avfilter.h:394
Convenience header that includes libavutil&#39;s core.
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: avfilter.h:327
all automatic conversions enabled
Definition: avfilter.h:975
int thread_type
Type of multithreading being allowed/used.
Definition: avfilter.h:373
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
Definition: avfilter.h:258
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
Macro definitions for various function/variable attributes.
int nb_threads
Max number of threads allowed in this filter instance.
Definition: avfilter.h:401
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:845
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:355
int(* init_dict)(AVFilterContext *ctx, AVDictionary **options)
Should be set instead of init by the filters that want to pass a dictionary of AVOptions to nested co...
Definition: avfilter.h:246
int priv_size
size of private data to allocate for the filter
Definition: avfilter.h:284
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
char * name
name of this filter instance
Definition: avfilter.h:343
Public dictionary API.
avfilter_execute_func * execute
This callback may be set by the caller immediately after allocating the graph and before adding any f...
Definition: avfilter.h:895
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:135
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:349
const char * avfilter_license(void)
Return the libavfilter license.
Definition: avfilter.c:88
unsigned ready
Ready status of the filter.
Definition: avfilter.h:408
int( avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
A function executing multiple jobs, possibly in parallel.
Definition: avfilter.h:837
int flags
A combination of AVFILTER_FLAG_*.
Definition: avfilter.h:187
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
Definition: avfiltergraph.c:142
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:869
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:277
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, const char *name)
Get a filter instance identified by instance name from graph.
Definition: avfiltergraph.c:290
int(* preinit)(AVFilterContext *ctx)
Filter pre-initialization function.
Definition: avfilter.h:210
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
Definition: graphparser.c:407
int extra_hw_frames
Sets the number of extra hardware frames which the filter will allocate on its output links for use i...
Definition: avfilter.h:424
A filter pad used for either input or output.
Definition: internal.h:54
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
Definition: dict.c:30
unsigned nb_outputs
number of output pads
Definition: avfilter.h:351
unsigned avfilter_version(void)
Return the LIBAVFILTER_VERSION_INT constant.
Definition: avfilter.c:77
struct AVFilterInOut AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
void * priv
private data for use by the filter
Definition: avfilter.h:353
char * enable_str
enable expression string
Definition: avfilter.h:382
AVFilterLink ** sink_links
Private fields.
Definition: avfilter.h:906
reference-counted frame API
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:428
attribute_deprecated void avfilter_link_set_closed(AVFilterLink *link, int closed)
Set the closed field of a link.
Definition: avfilter.c:235
unsigned nb_inputs
number of input pads
Definition: avfilter.h:347
int(* init)(AVFilterContext *ctx)
Filter initialization function.
Definition: avfilter.h:233
Definition: internal.h:154
int flags_internal
Additional flags for avfilter internal use only.
Definition: avfilter.h:286
Definition: avfilter.h:840
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1008
int( avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A function pointer passed to the AVFilterGraph::execute callback to be executed multiple times...
Definition: avfilter.h:823
A list of supported channel layouts.
Definition: formats.h:85
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:924
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:164
struct AVFilter AVFilter
Filter definition.
const AVClass * avfilter_get_class(void)
Definition: avfilter.c:1620
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1003
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
Insert a filter in the middle of an existing link.
Definition: avfilter.c:240
const AVClass * priv_class
A class for the private data, used to declare filter private AVOptions.
Definition: avfilter.h:182
int(* process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags)
Make the filter instance process a command.
Definition: avfilter.h:306
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
Definition: avfiltergraph.c:1396
int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
Make the filter instance process a command.
Definition: avfilter.c:557
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.
Definition: graphparser.c:475
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1011
Rational number (pair of numerator and denominator).
Definition: rational.h:58
const AVFilter * av_filter_iterate(void **opaque)
Iterate over all registered filters.
Definition: allfilters.c:417
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:282
struct AVFilter * next
Used by the filter registration system.
Definition: avfilter.h:292
AVMediaType
Definition: avutil.h:199
refcounted data buffer API
const char * name
Filter name.
Definition: avfilter.h:148
const char * avfilter_configuration(void)
Return the libavfilter build-time configuration.
Definition: avfilter.c:83
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:1034
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
Definition: internal.h:38
char * name
unique name for this input/output in the list
Definition: avfilter.h:1005
int(* init_opaque)(AVFilterContext *ctx, void *opaque)
Filter initialization function, alternative to the init() callback.
Definition: avfilter.h:313
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
Definition: avfilter.c:887
A reference to a data buffer.
Definition: buffer.h:81
void * opaque
Opaque user data.
Definition: avfilter.h:881
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
Definition: graphparser.c:198
Utilties for rational number calculation.
char * avfilter_graph_dump(AVFilterGraph *graph, const char *options)
Dump a graph into a human-readable string representation.
Definition: graphdump.c:154
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
Send a command to one or more filter instances.
Definition: avfiltergraph.c:1286
char * aresample_swr_opts
swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions ...
Definition: avfilter.h:897
pixel format definitions
const char * description
A description of the filter.
Definition: avfilter.h:155
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
Definition: avfiltergraph.c:170
void * enable
parsed expression (AVExpr*)
Definition: avfilter.h:383
const AVClass * av_class
needed for av_log() and filters common options
Definition: avfilter.h:339
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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.
Definition: graphparser.c:538
An instance of a filter.
Definition: avfilter.h:338
int avfilter_pad_count(const AVFilterPad *pads)
Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
Definition: avfilter.c:578
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:172
all automatic conversions disabled
Definition: avfilter.h:976
void avfilter_link_free(AVFilterLink **link)
Free the link in *link, and set its pointer to NULL.
Definition: avfilter.c:174
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341