3 * Copyright (c) 2007 Bobby Bingham
5 * This file is part of Libav.
7 * Libav 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.
12 * Libav 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef AVFILTER_AVFILTER_H
23 #define AVFILTER_AVFILTER_H
28 * Main libavfilter public API header
32 * @defgroup lavfi Libavfilter - graph-based frame editing library
36 #include "libavutil/avutil.h"
37 #include "libavutil/frame.h"
38 #include "libavutil/log.h"
39 #include "libavutil/samplefmt.h"
40 #include "libavutil/pixfmt.h"
41 #include "libavutil/rational.h"
42 #include "libavcodec/avcodec.h"
46 #include "libavfilter/version.h"
49 * Return the LIBAVFILTER_VERSION_INT constant.
51 unsigned avfilter_version(void);
54 * Return the libavfilter build-time configuration.
56 const char *avfilter_configuration(void);
59 * Return the libavfilter license.
61 const char *avfilter_license(void);
64 typedef struct AVFilterContext AVFilterContext;
65 typedef struct AVFilterLink AVFilterLink;
66 typedef struct AVFilterPad AVFilterPad;
67 typedef struct AVFilterFormats AVFilterFormats;
69 #if FF_API_AVFILTERBUFFER
71 * A reference-counted buffer data type used by the filter system. Filters
72 * should not store pointers to this structure directly, but instead use the
73 * AVFilterBufferRef structure below.
75 typedef struct AVFilterBuffer {
76 uint8_t *data[8]; ///< buffer data for each plane/channel
79 * pointers to the data planes/channels.
81 * For video, this should simply point to data[].
83 * For planar audio, each channel has a separate data pointer, and
84 * linesize[0] contains the size of each channel buffer.
85 * For packed audio, there is just one data pointer, and linesize[0]
86 * contains the total size of the buffer for all channels.
88 * Note: Both data and extended_data will always be set, but for planar
89 * audio with more channels that can fit in data, extended_data must be used
90 * in order to access all channels.
92 uint8_t **extended_data;
93 int linesize[8]; ///< number of bytes per line
95 /** private data to be used by a custom free function */
98 * A pointer to the function to deallocate this buffer if the default
99 * function is not sufficient. This could, for example, add the memory
100 * back into a memory pool to be reused later without the overhead of
101 * reallocating it from scratch.
103 void (*free)(struct AVFilterBuffer *buf);
105 int format; ///< media format
106 int w, h; ///< width and height of the allocated buffer
107 unsigned refcount; ///< number of references to this buffer
110 #define AV_PERM_READ 0x01 ///< can read from the buffer
111 #define AV_PERM_WRITE 0x02 ///< can write to the buffer
112 #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
113 #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
114 #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
115 #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
118 * Audio specific properties in a reference to an AVFilterBuffer. Since
119 * AVFilterBufferRef is common to different media formats, audio specific
120 * per reference properties must be separated out.
122 typedef struct AVFilterBufferRefAudioProps {
123 uint64_t channel_layout; ///< channel layout of audio buffer
124 int nb_samples; ///< number of audio samples
125 int sample_rate; ///< audio buffer sample rate
126 int planar; ///< audio buffer - planar or packed
127 } AVFilterBufferRefAudioProps;
130 * Video specific properties in a reference to an AVFilterBuffer. Since
131 * AVFilterBufferRef is common to different media formats, video specific
132 * per reference properties must be separated out.
134 typedef struct AVFilterBufferRefVideoProps {
135 int w; ///< image width
136 int h; ///< image height
137 AVRational pixel_aspect; ///< pixel aspect ratio
138 int interlaced; ///< is frame interlaced
139 int top_field_first; ///< field order
140 enum AVPictureType pict_type; ///< picture type of the frame
141 int key_frame; ///< 1 -> keyframe, 0-> not
142 } AVFilterBufferRefVideoProps;
145 * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
146 * a buffer to, for example, crop image without any memcpy, the buffer origin
147 * and dimensions are per-reference properties. Linesize is also useful for
148 * image flipping, frame to field filters, etc, and so is also per-reference.
150 * TODO: add anything necessary for frame reordering
152 typedef struct AVFilterBufferRef {
153 AVFilterBuffer *buf; ///< the buffer that this is a reference to
154 uint8_t *data[8]; ///< picture/audio data for each plane
156 * pointers to the data planes/channels.
158 * For video, this should simply point to data[].
160 * For planar audio, each channel has a separate data pointer, and
161 * linesize[0] contains the size of each channel buffer.
162 * For packed audio, there is just one data pointer, and linesize[0]
163 * contains the total size of the buffer for all channels.
165 * Note: Both data and extended_data will always be set, but for planar
166 * audio with more channels that can fit in data, extended_data must be used
167 * in order to access all channels.
169 uint8_t **extended_data;
170 int linesize[8]; ///< number of bytes per line
172 AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
173 AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
176 * presentation timestamp. The time unit may change during
177 * filtering, as it is specified in the link and the filter code
178 * may need to rescale the PTS accordingly.
181 int64_t pos; ///< byte position in stream, -1 if unknown
183 int format; ///< media format
185 int perms; ///< permissions, see the AV_PERM_* flags
187 enum AVMediaType type; ///< media type of buffer data
191 * Copy properties of src to dst, without copying the actual data
194 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
197 * Add a new reference to a buffer.
199 * @param ref an existing reference to the buffer
200 * @param pmask a bitmask containing the allowable permissions in the new
202 * @return a new reference to the buffer with the same properties as the
203 * old, excluding any permissions denied by pmask
206 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
209 * Remove a reference to a buffer. If this is the last reference to the
210 * buffer, the buffer itself is also automatically freed.
212 * @param ref reference to the buffer, may be NULL
214 * @note it is recommended to use avfilter_unref_bufferp() instead of this
218 void avfilter_unref_buffer(AVFilterBufferRef *ref);
221 * Remove a reference to a buffer and set the pointer to NULL.
222 * If this is the last reference to the buffer, the buffer itself
223 * is also automatically freed.
225 * @param ref pointer to the buffer reference
228 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
231 #if FF_API_AVFILTERPAD_PUBLIC
233 * A filter pad used for either input or output.
235 * @warning this struct will be removed from public API.
236 * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
237 * to access the name and type fields; there should be no need to access
238 * any other fields from outside of libavfilter.
242 * Pad name. The name is unique among inputs and among outputs, but an
243 * input may have the same name as an output. This may be NULL if this
244 * pad has no need to ever be referenced by name.
251 enum AVMediaType type;
254 * Minimum required permissions on incoming buffers. Any buffer with
255 * insufficient permissions will be automatically copied by the filter
256 * system to a new buffer which provides the needed access permissions.
260 attribute_deprecated int min_perms;
263 * Permissions which are not accepted on incoming buffers. Any buffer
264 * which has any of these permissions set will be automatically copied
265 * by the filter system to a new buffer which does not have those
266 * permissions. This can be used to easily disallow buffers with
271 attribute_deprecated int rej_perms;
276 int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
279 * Callback function to get a video buffer. If NULL, the filter system will
280 * use avfilter_default_get_video_buffer().
282 * Input video pads only.
284 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
287 * Callback function to get an audio buffer. If NULL, the filter system will
288 * use avfilter_default_get_audio_buffer().
290 * Input audio pads only.
292 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
297 int (*end_frame)(AVFilterLink *link);
302 int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
305 * Filtering callback. This is where a filter receives a frame with
306 * audio/video data and should do its processing.
310 * @return >= 0 on success, a negative AVERROR on error. This function
311 * must ensure that samplesref is properly unreferenced on error if it
312 * hasn't been passed on to another filter.
314 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
317 * Frame poll callback. This returns the number of immediately available
318 * samples. It should return a positive value if the next request_frame()
319 * is guaranteed to return one frame (with no delay).
321 * Defaults to just calling the source poll_frame() method.
325 int (*poll_frame)(AVFilterLink *link);
328 * Frame request callback. A call to this should result in at least one
329 * frame being output over the given link. This should return zero on
330 * success, and another value on error.
334 int (*request_frame)(AVFilterLink *link);
337 * Link configuration callback.
339 * For output pads, this should set the link properties such as
340 * width/height. This should NOT set the format property - that is
341 * negotiated between filters by the filter system using the
342 * query_formats() callback before this function is called.
344 * For input pads, this should check the properties of the link, and update
345 * the filter's internal state as necessary.
347 * For both input and output filters, this should return zero on success,
348 * and another value on error.
350 int (*config_props)(AVFilterLink *link);
353 * The filter expects a fifo to be inserted on its input link,
354 * typically because it has a delay.
365 * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
366 * AVFilter.inputs/outputs).
368 int avfilter_pad_count(const AVFilterPad *pads);
371 * Get the name of an AVFilterPad.
373 * @param pads an array of AVFilterPads
374 * @param pad_idx index of the pad in the array it; is the caller's
375 * responsibility to ensure the index is valid
377 * @return name of the pad_idx'th pad in pads
379 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
382 * Get the type of an AVFilterPad.
384 * @param pads an array of AVFilterPads
385 * @param pad_idx index of the pad in the array; it is the caller's
386 * responsibility to ensure the index is valid
388 * @return type of the pad_idx'th pad in pads
390 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
393 * The number of the filter inputs is not determined just by AVFilter.inputs.
394 * The filter might add additional inputs during initialization depending on the
395 * options supplied to it.
397 #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
399 * The number of the filter outputs is not determined just by AVFilter.outputs.
400 * The filter might add additional outputs during initialization depending on
401 * the options supplied to it.
403 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
406 * Filter definition. This defines the pads a filter contains, and all the
407 * callback functions used to interact with the filter.
409 typedef struct AVFilter {
410 const char *name; ///< filter name
413 * A description for the filter. You should use the
414 * NULL_IF_CONFIG_SMALL() macro to define it.
416 const char *description;
418 const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
419 const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
422 * A class for the private data, used to access filter private
425 const AVClass *priv_class;
428 * A combination of AVFILTER_FLAG_*
432 /*****************************************************************
433 * All fields below this line are not part of the public API. They
434 * may not be used outside of libavfilter and can be changed and
436 * New public fields should be added right above.
437 *****************************************************************
441 * Filter initialization function. Called when all the options have been
444 int (*init)(AVFilterContext *ctx);
447 * Should be set instead of init by the filters that want to pass a
448 * dictionary of AVOptions to nested contexts that are allocated in
451 int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
454 * Filter uninitialization function. Should deallocate any memory held
455 * by the filter, release any buffer references, etc. This does not need
456 * to deallocate the AVFilterContext->priv memory itself.
458 void (*uninit)(AVFilterContext *ctx);
461 * Queries formats supported by the filter and its pads, and sets the
462 * in_formats for links connected to its output pads, and out_formats
463 * for links connected to its input pads.
465 * @return zero on success, a negative value corresponding to an
466 * AVERROR code otherwise
468 int (*query_formats)(AVFilterContext *);
470 int priv_size; ///< size of private data to allocate for the filter
472 struct AVFilter *next;
475 /** An instance of a filter */
476 struct AVFilterContext {
477 const AVClass *av_class; ///< needed for av_log()
479 const AVFilter *filter; ///< the AVFilter of which this is an instance
481 char *name; ///< name of this filter instance
483 AVFilterPad *input_pads; ///< array of input pads
484 AVFilterLink **inputs; ///< array of pointers to input links
486 unsigned input_count; ///< @deprecated use nb_inputs
488 unsigned nb_inputs; ///< number of input pads
490 AVFilterPad *output_pads; ///< array of output pads
491 AVFilterLink **outputs; ///< array of pointers to output links
493 unsigned output_count; ///< @deprecated use nb_outputs
495 unsigned nb_outputs; ///< number of output pads
497 void *priv; ///< private data for use by the filter
499 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
503 * A link between two filters. This contains pointers to the source and
504 * destination filters between which this link exists, and the indexes of
505 * the pads involved. In addition, this link also contains the parameters
506 * which have been negotiated and agreed upon between the filter, such as
507 * image dimensions, format, etc.
509 struct AVFilterLink {
510 AVFilterContext *src; ///< source filter
511 AVFilterPad *srcpad; ///< output pad on the source filter
513 AVFilterContext *dst; ///< dest filter
514 AVFilterPad *dstpad; ///< input pad on the dest filter
516 enum AVMediaType type; ///< filter media type
518 /* These parameters apply only to video */
519 int w; ///< agreed upon image width
520 int h; ///< agreed upon image height
521 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
522 /* These two parameters apply only to audio */
523 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
524 int sample_rate; ///< samples per second
526 int format; ///< agreed upon media format
529 * Define the time base used by the PTS of the frames/samples
530 * which will pass through this link.
531 * During the configuration stage, each filter is supposed to
532 * change only the output timebase, while the timebase of the
533 * input link is assumed to be an unchangeable property.
535 AVRational time_base;
537 /*****************************************************************
538 * All fields below this line are not part of the public API. They
539 * may not be used outside of libavfilter and can be changed and
541 * New public fields should be added right above.
542 *****************************************************************
545 * Lists of formats supported by the input and output filters respectively.
546 * These lists are used for negotiating the format to actually be used,
547 * which will be loaded into the format member, above, when chosen.
549 AVFilterFormats *in_formats;
550 AVFilterFormats *out_formats;
553 * Lists of channel layouts and sample rates used for automatic
556 AVFilterFormats *in_samplerates;
557 AVFilterFormats *out_samplerates;
558 struct AVFilterChannelLayouts *in_channel_layouts;
559 struct AVFilterChannelLayouts *out_channel_layouts;
562 * Audio only, the destination filter sets this to a non-zero value to
563 * request that buffers with the given number of samples should be sent to
564 * it. AVFilterPad.needs_fifo must also be set on the corresponding input
566 * Last buffer before EOF will be padded with silence.
570 /** stage of the initialization of the link properties (dimensions, etc) */
572 AVLINK_UNINIT = 0, ///< not started
573 AVLINK_STARTINIT, ///< started, but incomplete
574 AVLINK_INIT ///< complete
579 * Link two filters together.
581 * @param src the source filter
582 * @param srcpad index of the output pad on the source filter
583 * @param dst the destination filter
584 * @param dstpad index of the input pad on the destination filter
585 * @return zero on success
587 int avfilter_link(AVFilterContext *src, unsigned srcpad,
588 AVFilterContext *dst, unsigned dstpad);
591 * Negotiate the media format, dimensions, etc of all inputs to a filter.
593 * @param filter the filter to negotiate the properties for its inputs
594 * @return zero on successful negotiation
596 int avfilter_config_links(AVFilterContext *filter);
598 #if FF_API_AVFILTERBUFFER
600 * Create a buffer reference wrapped around an already allocated image
603 * @param data pointers to the planes of the image to reference
604 * @param linesize linesizes for the planes of the image to reference
605 * @param perms the required access permissions
606 * @param w the width of the image specified by the data and linesize arrays
607 * @param h the height of the image specified by the data and linesize arrays
608 * @param format the pixel format of the image specified by the data and linesize arrays
612 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
613 int w, int h, enum AVPixelFormat format);
616 * Create an audio buffer reference wrapped around an already
617 * allocated samples buffer.
619 * @param data pointers to the samples plane buffers
620 * @param linesize linesize for the samples plane buffers
621 * @param perms the required access permissions
622 * @param nb_samples number of samples per channel
623 * @param sample_fmt the format of each sample in the buffer to allocate
624 * @param channel_layout the channel layout of the buffer
627 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
631 enum AVSampleFormat sample_fmt,
632 uint64_t channel_layout);
635 /** Initialize the filter system. Register all builtin filters. */
636 void avfilter_register_all(void);
638 #if FF_API_OLD_FILTER_REGISTER
639 /** Uninitialize the filter system. Unregister all filters. */
641 void avfilter_uninit(void);
645 * Register a filter. This is only needed if you plan to use
646 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
647 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
650 * @param filter the filter to register
651 * @return 0 if the registration was succesfull, a negative value
654 int avfilter_register(AVFilter *filter);
657 * Get a filter definition matching the given name.
659 * @param name the filter name to find
660 * @return the filter definition, if any matching one is registered.
661 * NULL if none found.
663 AVFilter *avfilter_get_by_name(const char *name);
666 * Iterate over all registered filters.
667 * @return If prev is non-NULL, next registered filter after prev or NULL if
668 * prev is the last filter. If prev is NULL, return the first registered filter.
670 const AVFilter *avfilter_next(const AVFilter *prev);
672 #if FF_API_OLD_FILTER_REGISTER
674 * If filter is NULL, returns a pointer to the first registered filter pointer,
675 * if filter is non-NULL, returns the next pointer after filter.
676 * If the returned pointer points to NULL, the last registered filter
677 * was already reached.
678 * @deprecated use avfilter_next()
681 AVFilter **av_filter_next(AVFilter **filter);
684 #if FF_API_AVFILTER_OPEN
686 * Create a filter instance.
688 * @param filter_ctx put here a pointer to the created filter context
689 * on success, NULL on failure
690 * @param filter the filter to create an instance of
691 * @param inst_name Name to give to the new instance. Can be NULL for none.
692 * @return >= 0 in case of success, a negative error code otherwise
693 * @deprecated use avfilter_graph_alloc_filter() instead
696 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
700 #if FF_API_AVFILTER_INIT_FILTER
702 * Initialize a filter.
704 * @param filter the filter to initialize
705 * @param args A string of parameters to use when initializing the filter.
706 * The format and meaning of this string varies by filter.
707 * @param opaque Any extra non-string data needed by the filter. The meaning
708 * of this parameter varies by filter.
709 * @return zero on success
712 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
716 * Initialize a filter with the supplied parameters.
718 * @param ctx uninitialized filter context to initialize
719 * @param args Options to initialize the filter with. This must be a
720 * ':'-separated list of options in the 'key=value' form.
721 * May be NULL if the options have been set directly using the
722 * AVOptions API or there are no options that need to be set.
723 * @return 0 on success, a negative AVERROR on failure
725 int avfilter_init_str(AVFilterContext *ctx, const char *args);
728 * Initialize a filter with the supplied dictionary of options.
730 * @param ctx uninitialized filter context to initialize
731 * @param options An AVDictionary filled with options for this filter. On
732 * return this parameter will be destroyed and replaced with
733 * a dict containing options that were not found. This dictionary
734 * must be freed by the caller.
735 * May be NULL, then this function is equivalent to
736 * avfilter_init_str() with the second parameter set to NULL.
737 * @return 0 on success, a negative AVERROR on failure
739 * @note This function and avfilter_init_str() do essentially the same thing,
740 * the difference is in manner in which the options are passed. It is up to the
741 * calling code to choose whichever is more preferable. The two functions also
742 * behave differently when some of the provided options are not declared as
743 * supported by the filter. In such a case, avfilter_init_str() will fail, but
744 * this function will leave those extra options in the options AVDictionary and
747 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
750 * Free a filter context. This will also remove the filter from its
751 * filtergraph's list of filters.
753 * @param filter the filter to free
755 void avfilter_free(AVFilterContext *filter);
758 * Insert a filter in the middle of an existing link.
760 * @param link the link into which the filter should be inserted
761 * @param filt the filter to be inserted
762 * @param filt_srcpad_idx the input pad on the filter to connect
763 * @param filt_dstpad_idx the output pad on the filter to connect
764 * @return zero on success
766 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
767 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
769 #if FF_API_AVFILTERBUFFER
771 * Copy the frame properties of src to dst, without copying the actual
774 * @return 0 on success, a negative number on error.
777 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
780 * Copy the frame properties and data pointers of src to dst, without copying
783 * @return 0 on success, a negative number on error.
786 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
790 * @return AVClass for AVFilterContext.
792 * @see av_opt_find().
794 const AVClass *avfilter_get_class(void);
796 typedef struct AVFilterGraph {
797 const AVClass *av_class;
800 unsigned filter_count;
802 AVFilterContext **filters;
803 #if !FF_API_FOO_COUNT
807 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
808 char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
815 * Allocate a filter graph.
817 AVFilterGraph *avfilter_graph_alloc(void);
820 * Create a new filter instance in a filter graph.
822 * @param graph graph in which the new filter will be used
823 * @param filter the filter to create an instance of
824 * @param name Name to give to the new instance (will be copied to
825 * AVFilterContext.name). This may be used by the caller to identify
826 * different filters, libavfilter itself assigns no semantics to
827 * this parameter. May be NULL.
829 * @return the context of the newly created filter instance (note that it is
830 * also retrievable directly through AVFilterGraph.filters or with
831 * avfilter_graph_get_filter()) on success or NULL or failure.
833 AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
834 const AVFilter *filter,
838 * Get a filter instance with name name from graph.
840 * @return the pointer to the found filter instance or NULL if it
843 AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
845 #if FF_API_AVFILTER_OPEN
847 * Add an existing filter instance to a filter graph.
849 * @param graphctx the filter graph
850 * @param filter the filter to be added
852 * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
856 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
860 * Create and add a filter instance into an existing graph.
861 * The filter instance is created from the filter filt and inited
862 * with the parameters args and opaque.
864 * In case of success put in *filt_ctx the pointer to the created
865 * filter instance, otherwise set *filt_ctx to NULL.
867 * @param name the instance name to give to the created filter instance
868 * @param graph_ctx the filter graph
869 * @return a negative AVERROR error code in case of failure, a non
870 * negative value otherwise
872 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
873 const char *name, const char *args, void *opaque,
874 AVFilterGraph *graph_ctx);
877 * Check validity and configure all the links and formats in the graph.
879 * @param graphctx the filter graph
880 * @param log_ctx context used for logging
881 * @return 0 in case of success, a negative AVERROR code otherwise
883 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
886 * Free a graph, destroy its links, and set *graph to NULL.
887 * If *graph is NULL, do nothing.
889 void avfilter_graph_free(AVFilterGraph **graph);
892 * A linked-list of the inputs/outputs of the filter chain.
894 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
895 * where it is used to communicate open (unlinked) inputs and outputs from and
897 * This struct specifies, per each not connected pad contained in the graph, the
898 * filter context and the pad index required for establishing a link.
900 typedef struct AVFilterInOut {
901 /** unique name for this input/output in the list */
904 /** filter context associated to this input/output */
905 AVFilterContext *filter_ctx;
907 /** index of the filt_ctx pad to use for linking */
910 /** next input/input in the list, NULL if this is the last */
911 struct AVFilterInOut *next;
915 * Allocate a single AVFilterInOut entry.
916 * Must be freed with avfilter_inout_free().
917 * @return allocated AVFilterInOut on success, NULL on failure.
919 AVFilterInOut *avfilter_inout_alloc(void);
922 * Free the supplied list of AVFilterInOut and set *inout to NULL.
923 * If *inout is NULL, do nothing.
925 void avfilter_inout_free(AVFilterInOut **inout);
928 * Add a graph described by a string to a graph.
930 * @param graph the filter graph where to link the parsed graph context
931 * @param filters string to be parsed
932 * @param inputs linked list to the inputs of the graph
933 * @param outputs linked list to the outputs of the graph
934 * @return zero on success, a negative AVERROR code on error
936 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
937 AVFilterInOut *inputs, AVFilterInOut *outputs,
941 * Add a graph described by a string to a graph.
943 * @param[in] graph the filter graph where to link the parsed graph context
944 * @param[in] filters string to be parsed
945 * @param[out] inputs a linked list of all free (unlinked) inputs of the
946 * parsed graph will be returned here. It is to be freed
947 * by the caller using avfilter_inout_free().
948 * @param[out] outputs a linked list of all free (unlinked) outputs of the
949 * parsed graph will be returned here. It is to be freed by the
950 * caller using avfilter_inout_free().
951 * @return zero on success, a negative AVERROR code on error
953 * @note the difference between avfilter_graph_parse2() and
954 * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
955 * the lists of inputs and outputs, which therefore must be known before calling
956 * the function. On the other hand, avfilter_graph_parse2() \em returns the
957 * inputs and outputs that are left unlinked after parsing the graph and the
958 * caller then deals with them. Another difference is that in
959 * avfilter_graph_parse(), the inputs parameter describes inputs of the
960 * <em>already existing</em> part of the graph; i.e. from the point of view of
961 * the newly created part, they are outputs. Similarly the outputs parameter
962 * describes outputs of the already existing filters, which are provided as
963 * inputs to the parsed filters.
964 * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
965 * whatsoever to already existing parts of the graph and the inputs parameter
966 * will on return contain inputs of the newly parsed part of the graph.
967 * Analogously the outputs parameter will contain outputs of the newly created
970 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
971 AVFilterInOut **inputs,
972 AVFilterInOut **outputs);
978 #endif /* AVFILTER_AVFILTER_H */