3 * Copyright (c) 2007 Bobby Bingham
5 * This file is part of FFmpeg.
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.
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.
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
22 #ifndef AVFILTER_AVFILTER_H
23 #define AVFILTER_AVFILTER_H
32 * @defgroup lavfi Libavfilter
38 #include "libavutil/avutil.h"
39 #include "libavutil/dict.h"
40 #include "libavutil/frame.h"
41 #include "libavutil/log.h"
42 #include "libavutil/samplefmt.h"
43 #include "libavutil/pixfmt.h"
44 #include "libavutil/rational.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);
63 typedef struct AVFilterContext AVFilterContext;
64 typedef struct AVFilterLink AVFilterLink;
65 typedef struct AVFilterPad AVFilterPad;
66 typedef struct AVFilterFormats AVFilterFormats;
68 #if FF_API_AVFILTERBUFFER
70 * A reference-counted buffer data type used by the filter system. Filters
71 * should not store pointers to this structure directly, but instead use the
72 * AVFilterBufferRef structure below.
74 typedef struct AVFilterBuffer {
75 uint8_t *data[8]; ///< buffer data for each plane/channel
78 * pointers to the data planes/channels.
80 * For video, this should simply point to data[].
82 * For planar audio, each channel has a separate data pointer, and
83 * linesize[0] contains the size of each channel buffer.
84 * For packed audio, there is just one data pointer, and linesize[0]
85 * contains the total size of the buffer for all channels.
87 * Note: Both data and extended_data will always be set, but for planar
88 * audio with more channels that can fit in data, extended_data must be used
89 * in order to access all channels.
91 uint8_t **extended_data;
92 int linesize[8]; ///< number of bytes per line
94 /** private data to be used by a custom free function */
97 * A pointer to the function to deallocate this buffer if the default
98 * function is not sufficient. This could, for example, add the memory
99 * back into a memory pool to be reused later without the overhead of
100 * reallocating it from scratch.
102 void (*free)(struct AVFilterBuffer *buf);
104 int format; ///< media format
105 int w, h; ///< width and height of the allocated buffer
106 unsigned refcount; ///< number of references to this buffer
109 #define AV_PERM_READ 0x01 ///< can read from the buffer
110 #define AV_PERM_WRITE 0x02 ///< can write to the buffer
111 #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
112 #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
113 #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
114 #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
115 #define AV_PERM_ALIGN 0x40 ///< the buffer must be aligned
117 #define AVFILTER_ALIGN 16 //not part of ABI
120 * Audio specific properties in a reference to an AVFilterBuffer. Since
121 * AVFilterBufferRef is common to different media formats, audio specific
122 * per reference properties must be separated out.
124 typedef struct AVFilterBufferRefAudioProps {
125 uint64_t channel_layout; ///< channel layout of audio buffer
126 int nb_samples; ///< number of audio samples per channel
127 int sample_rate; ///< audio buffer sample rate
128 int channels; ///< number of channels (do not access directly)
129 } AVFilterBufferRefAudioProps;
132 * Video specific properties in a reference to an AVFilterBuffer. Since
133 * AVFilterBufferRef is common to different media formats, video specific
134 * per reference properties must be separated out.
136 typedef struct AVFilterBufferRefVideoProps {
137 int w; ///< image width
138 int h; ///< image height
139 AVRational sample_aspect_ratio; ///< sample aspect ratio
140 int interlaced; ///< is frame interlaced
141 int top_field_first; ///< field order
142 enum AVPictureType pict_type; ///< picture type of the frame
143 int key_frame; ///< 1 -> keyframe, 0-> not
144 int qp_table_linesize; ///< qp_table stride
145 int qp_table_size; ///< qp_table size
146 int8_t *qp_table; ///< array of Quantization Parameters
147 } AVFilterBufferRefVideoProps;
150 * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
151 * a buffer to, for example, crop image without any memcpy, the buffer origin
152 * and dimensions are per-reference properties. Linesize is also useful for
153 * image flipping, frame to field filters, etc, and so is also per-reference.
155 * TODO: add anything necessary for frame reordering
157 typedef struct AVFilterBufferRef {
158 AVFilterBuffer *buf; ///< the buffer that this is a reference to
159 uint8_t *data[8]; ///< picture/audio data for each plane
161 * pointers to the data planes/channels.
163 * For video, this should simply point to data[].
165 * For planar audio, each channel has a separate data pointer, and
166 * linesize[0] contains the size of each channel buffer.
167 * For packed audio, there is just one data pointer, and linesize[0]
168 * contains the total size of the buffer for all channels.
170 * Note: Both data and extended_data will always be set, but for planar
171 * audio with more channels that can fit in data, extended_data must be used
172 * in order to access all channels.
174 uint8_t **extended_data;
175 int linesize[8]; ///< number of bytes per line
177 AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
178 AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
181 * presentation timestamp. The time unit may change during
182 * filtering, as it is specified in the link and the filter code
183 * may need to rescale the PTS accordingly.
186 int64_t pos; ///< byte position in stream, -1 if unknown
188 int format; ///< media format
190 int perms; ///< permissions, see the AV_PERM_* flags
192 enum AVMediaType type; ///< media type of buffer data
194 AVDictionary *metadata; ///< dictionary containing metadata key=value tags
198 * Copy properties of src to dst, without copying the actual data
201 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
204 * Add a new reference to a buffer.
206 * @param ref an existing reference to the buffer
207 * @param pmask a bitmask containing the allowable permissions in the new
209 * @return a new reference to the buffer with the same properties as the
210 * old, excluding any permissions denied by pmask
213 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
216 * Remove a reference to a buffer. If this is the last reference to the
217 * buffer, the buffer itself is also automatically freed.
219 * @param ref reference to the buffer, may be NULL
221 * @note it is recommended to use avfilter_unref_bufferp() instead of this
225 void avfilter_unref_buffer(AVFilterBufferRef *ref);
228 * Remove a reference to a buffer and set the pointer to NULL.
229 * If this is the last reference to the buffer, the buffer itself
230 * is also automatically freed.
232 * @param ref pointer to the buffer reference
235 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
239 * Get the number of channels of a buffer reference.
242 int avfilter_ref_get_channels(AVFilterBufferRef *ref);
244 #if FF_API_AVFILTERPAD_PUBLIC
246 * A filter pad used for either input or output.
248 * See doc/filter_design.txt for details on how to implement the methods.
250 * @warning this struct might be removed from public API.
251 * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
252 * to access the name and type fields; there should be no need to access
253 * any other fields from outside of libavfilter.
257 * Pad name. The name is unique among inputs and among outputs, but an
258 * input may have the same name as an output. This may be NULL if this
259 * pad has no need to ever be referenced by name.
266 enum AVMediaType type;
270 * Minimum required permissions on incoming buffers. Any buffer with
271 * insufficient permissions will be automatically copied by the filter
272 * system to a new buffer which provides the needed access permissions.
275 * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
276 * link must have at least these permissions; this fact is checked by
277 * asserts. It can be used to optimize buffer allocation.
279 attribute_deprecated int min_perms;
283 * Permissions which are not accepted on incoming buffers. Any buffer
284 * which has any of these permissions set will be automatically copied
285 * by the filter system to a new buffer which does not have those
286 * permissions. This can be used to easily disallow buffers with
290 * Permissions which are automatically removed on outgoing buffers. It
291 * can be used to optimize buffer allocation.
293 attribute_deprecated int rej_perms;
298 int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
301 * Callback function to get a video buffer. If NULL, the filter system will
302 * use ff_default_get_video_buffer().
304 * Input video pads only.
306 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
309 * Callback function to get an audio buffer. If NULL, the filter system will
310 * use ff_default_get_audio_buffer().
312 * Input audio pads only.
314 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
319 int (*end_frame)(AVFilterLink *link);
324 int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
327 * Filtering callback. This is where a filter receives a frame with
328 * audio/video data and should do its processing.
332 * @return >= 0 on success, a negative AVERROR on error. This function
333 * must ensure that frame is properly unreferenced on error if it
334 * hasn't been passed on to another filter.
336 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
339 * Frame poll callback. This returns the number of immediately available
340 * samples. It should return a positive value if the next request_frame()
341 * is guaranteed to return one frame (with no delay).
343 * Defaults to just calling the source poll_frame() method.
347 int (*poll_frame)(AVFilterLink *link);
350 * Frame request callback. A call to this should result in at least one
351 * frame being output over the given link. This should return zero on
352 * success, and another value on error.
353 * See ff_request_frame() for the error codes with a specific
358 int (*request_frame)(AVFilterLink *link);
361 * Link configuration callback.
363 * For output pads, this should set the following link properties:
364 * video: width, height, sample_aspect_ratio, time_base
365 * audio: sample_rate.
367 * This should NOT set properties such as format, channel_layout, etc which
368 * are negotiated between filters by the filter system using the
369 * query_formats() callback before this function is called.
371 * For input pads, this should check the properties of the link, and update
372 * the filter's internal state as necessary.
374 * For both input and output pads, this should return zero on success,
375 * and another value on error.
377 int (*config_props)(AVFilterLink *link);
380 * The filter expects a fifo to be inserted on its input link,
381 * typically because it has a delay.
390 * Passthrough filtering callback.
392 * If a filter supports timeline editing (in case
393 * AVFILTER_FLAG_SUPPORT_TIMELINE is enabled) then it can implement a
394 * custom passthrough callback to update its local context (for example to
395 * keep a frame reference, or simply send the filter to a custom outlink).
396 * The filter must not do any change to the frame in this callback.
400 int (*passthrough_filter_frame)(AVFilterLink *link, AVFrame *frame);
405 * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
406 * AVFilter.inputs/outputs).
408 int avfilter_pad_count(const AVFilterPad *pads);
411 * Get the name of an AVFilterPad.
413 * @param pads an array of AVFilterPads
414 * @param pad_idx index of the pad in the array it; is the caller's
415 * responsibility to ensure the index is valid
417 * @return name of the pad_idx'th pad in pads
419 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
422 * Get the type of an AVFilterPad.
424 * @param pads an array of AVFilterPads
425 * @param pad_idx index of the pad in the array; it is the caller's
426 * responsibility to ensure the index is valid
428 * @return type of the pad_idx'th pad in pads
430 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
433 * The number of the filter inputs is not determined just by AVFilter.inputs.
434 * The filter might add additional inputs during initialization depending on the
435 * options supplied to it.
437 #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
439 * The number of the filter outputs is not determined just by AVFilter.outputs.
440 * The filter might add additional outputs during initialization depending on
441 * the options supplied to it.
443 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
445 * Some filters support a generic "enable" expression option that can be used
446 * to enable or disable a filter in the timeline. Filters supporting this
447 * option have this flag set.
449 #define AVFILTER_FLAG_SUPPORT_TIMELINE (1 << 16)
452 * Filter definition. This defines the pads a filter contains, and all the
453 * callback functions used to interact with the filter.
455 typedef struct AVFilter {
456 const char *name; ///< filter name
459 * A description for the filter. You should use the
460 * NULL_IF_CONFIG_SMALL() macro to define it.
462 const char *description;
464 const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
465 const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
468 * A class for the private data, used to access filter private
471 const AVClass *priv_class;
474 * A combination of AVFILTER_FLAG_*
478 /*****************************************************************
479 * All fields below this line are not part of the public API. They
480 * may not be used outside of libavfilter and can be changed and
482 * New public fields should be added right above.
483 *****************************************************************
487 * Filter initialization function. Called when all the options have been
490 int (*init)(AVFilterContext *ctx);
493 * Should be set instead of init by the filters that want to pass a
494 * dictionary of AVOptions to nested contexts that are allocated in
497 int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
500 * Filter uninitialization function. Should deallocate any memory held
501 * by the filter, release any buffer references, etc. This does not need
502 * to deallocate the AVFilterContext->priv memory itself.
504 void (*uninit)(AVFilterContext *ctx);
507 * Queries formats/layouts supported by the filter and its pads, and sets
508 * the in_formats/in_chlayouts for links connected to its output pads,
509 * and out_formats/out_chlayouts for links connected to its input pads.
511 * @return zero on success, a negative value corresponding to an
512 * AVERROR code otherwise
514 int (*query_formats)(AVFilterContext *);
516 int priv_size; ///< size of private data to allocate for the filter
518 struct AVFilter *next;
521 * Make the filter instance process a command.
523 * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
524 * @param arg the argument for the command
525 * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported.
526 * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
527 * time consuming then a filter should treat it like an unsupported command
529 * @returns >=0 on success otherwise an error code.
530 * AVERROR(ENOSYS) on unsupported commands
532 int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
535 * Filter initialization function, alternative to the init()
536 * callback. Args contains the user-supplied parameters, opaque is
537 * used for providing binary data.
539 int (*init_opaque)(AVFilterContext *ctx, void *opaque);
542 /** An instance of a filter */
543 struct AVFilterContext {
544 const AVClass *av_class; ///< needed for av_log() and filters common options
546 const AVFilter *filter; ///< the AVFilter of which this is an instance
548 char *name; ///< name of this filter instance
550 AVFilterPad *input_pads; ///< array of input pads
551 AVFilterLink **inputs; ///< array of pointers to input links
553 unsigned input_count; ///< @deprecated use nb_inputs
555 unsigned nb_inputs; ///< number of input pads
557 AVFilterPad *output_pads; ///< array of output pads
558 AVFilterLink **outputs; ///< array of pointers to output links
560 unsigned output_count; ///< @deprecated use nb_outputs
562 unsigned nb_outputs; ///< number of output pads
564 void *priv; ///< private data for use by the filter
566 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
568 struct AVFilterCommand *command_queue;
570 char *enable_str; ///< enable expression string
571 void *enable; ///< parsed expression (AVExpr*)
572 double *var_values; ///< variable values for the enable expression
576 * A link between two filters. This contains pointers to the source and
577 * destination filters between which this link exists, and the indexes of
578 * the pads involved. In addition, this link also contains the parameters
579 * which have been negotiated and agreed upon between the filter, such as
580 * image dimensions, format, etc.
582 struct AVFilterLink {
583 AVFilterContext *src; ///< source filter
584 AVFilterPad *srcpad; ///< output pad on the source filter
586 AVFilterContext *dst; ///< dest filter
587 AVFilterPad *dstpad; ///< input pad on the dest filter
589 enum AVMediaType type; ///< filter media type
591 /* These parameters apply only to video */
592 int w; ///< agreed upon image width
593 int h; ///< agreed upon image height
594 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
595 /* These parameters apply only to audio */
596 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
597 int sample_rate; ///< samples per second
599 int format; ///< agreed upon media format
602 * Define the time base used by the PTS of the frames/samples
603 * which will pass through this link.
604 * During the configuration stage, each filter is supposed to
605 * change only the output timebase, while the timebase of the
606 * input link is assumed to be an unchangeable property.
608 AVRational time_base;
610 /*****************************************************************
611 * All fields below this line are not part of the public API. They
612 * may not be used outside of libavfilter and can be changed and
614 * New public fields should be added right above.
615 *****************************************************************
618 * Lists of formats and channel layouts supported by the input and output
619 * filters respectively. These lists are used for negotiating the format
620 * to actually be used, which will be loaded into the format and
621 * channel_layout members, above, when chosen.
624 AVFilterFormats *in_formats;
625 AVFilterFormats *out_formats;
628 * Lists of channel layouts and sample rates used for automatic
631 AVFilterFormats *in_samplerates;
632 AVFilterFormats *out_samplerates;
633 struct AVFilterChannelLayouts *in_channel_layouts;
634 struct AVFilterChannelLayouts *out_channel_layouts;
637 * Audio only, the destination filter sets this to a non-zero value to
638 * request that buffers with the given number of samples should be sent to
639 * it. AVFilterPad.needs_fifo must also be set on the corresponding input
641 * Last buffer before EOF will be padded with silence.
645 /** stage of the initialization of the link properties (dimensions, etc) */
647 AVLINK_UNINIT = 0, ///< not started
648 AVLINK_STARTINIT, ///< started, but incomplete
649 AVLINK_INIT ///< complete
652 struct AVFilterPool *pool;
655 * Graph the filter belongs to.
657 struct AVFilterGraph *graph;
660 * Current timestamp of the link, as defined by the most recent
661 * frame(s), in AV_TIME_BASE units.
666 * Index in the age array.
671 * Frame rate of the stream on the link, or 1/0 if unknown;
672 * if left to 0/0, will be automatically be copied from the first input
673 * of the source filter if it exists.
675 * Sources should set it to the best estimation of the real frame rate.
676 * Filters should update it if necessary depending on their function.
677 * Sinks can use it to set a default output frame rate.
678 * It is similar to the r_frame_rate field in AVStream.
680 AVRational frame_rate;
683 * Buffer partially filled with samples to achieve a fixed/minimum size.
685 AVFrame *partial_buf;
688 * Size of the partial buffer to allocate.
689 * Must be between min_samples and max_samples.
691 int partial_buf_size;
694 * Minimum number of samples to filter at once. If filter_frame() is
695 * called with fewer samples, it will accumulate them in partial_buf.
696 * This field and the related ones must not be changed after filtering
698 * If 0, all related fields are ignored.
703 * Maximum number of samples to filter at once. If filter_frame() is
704 * called with more samples, it will split them.
709 * The buffer reference currently being received across the link by the
710 * destination filter. This is used internally by the filter system to
711 * allow automatic copying of buffers which do not have sufficient
712 * permissions for the destination. This should not be accessed directly
715 AVFilterBufferRef *cur_buf_copy;
718 * True if the link is closed.
719 * If set, all attemps of start_frame, filter_frame or request_frame
720 * will fail with AVERROR_EOF, and if necessary the reference will be
722 * If request_frame returns AVERROR_EOF, this flag is set on the
723 * corresponding link.
724 * It can be set also be set by either the source or the destination
730 * Number of channels.
735 * True if a frame is being requested on the link.
736 * Used internally by the framework.
738 unsigned frame_requested;
741 * Link processing flags.
746 * Number of past frames sent through the link.
752 * Link two filters together.
754 * @param src the source filter
755 * @param srcpad index of the output pad on the source filter
756 * @param dst the destination filter
757 * @param dstpad index of the input pad on the destination filter
758 * @return zero on success
760 int avfilter_link(AVFilterContext *src, unsigned srcpad,
761 AVFilterContext *dst, unsigned dstpad);
764 * Free the link in *link, and set its pointer to NULL.
766 void avfilter_link_free(AVFilterLink **link);
769 * Get the number of channels of a link.
771 int avfilter_link_get_channels(AVFilterLink *link);
774 * Set the closed field of a link.
776 void avfilter_link_set_closed(AVFilterLink *link, int closed);
779 * Negotiate the media format, dimensions, etc of all inputs to a filter.
781 * @param filter the filter to negotiate the properties for its inputs
782 * @return zero on successful negotiation
784 int avfilter_config_links(AVFilterContext *filter);
786 #if FF_API_AVFILTERBUFFER
788 * Create a buffer reference wrapped around an already allocated image
791 * @param data pointers to the planes of the image to reference
792 * @param linesize linesizes for the planes of the image to reference
793 * @param perms the required access permissions
794 * @param w the width of the image specified by the data and linesize arrays
795 * @param h the height of the image specified by the data and linesize arrays
796 * @param format the pixel format of the image specified by the data and linesize arrays
800 avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
801 int w, int h, enum AVPixelFormat format);
804 * Create an audio buffer reference wrapped around an already
805 * allocated samples buffer.
807 * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
808 * that can handle unknown channel layouts.
810 * @param data pointers to the samples plane buffers
811 * @param linesize linesize for the samples plane buffers
812 * @param perms the required access permissions
813 * @param nb_samples number of samples per channel
814 * @param sample_fmt the format of each sample in the buffer to allocate
815 * @param channel_layout the channel layout of the buffer
818 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
822 enum AVSampleFormat sample_fmt,
823 uint64_t channel_layout);
825 * Create an audio buffer reference wrapped around an already
826 * allocated samples buffer.
828 * @param data pointers to the samples plane buffers
829 * @param linesize linesize for the samples plane buffers
830 * @param perms the required access permissions
831 * @param nb_samples number of samples per channel
832 * @param sample_fmt the format of each sample in the buffer to allocate
833 * @param channels the number of channels of the buffer
834 * @param channel_layout the channel layout of the buffer,
835 * must be either 0 or consistent with channels
838 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
842 enum AVSampleFormat sample_fmt,
844 uint64_t channel_layout);
849 #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
850 #define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
853 * Make the filter instance process a command.
854 * It is recommended to use avfilter_graph_send_command().
856 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
858 /** Initialize the filter system. Register all builtin filters. */
859 void avfilter_register_all(void);
861 #if FF_API_OLD_FILTER_REGISTER
862 /** Uninitialize the filter system. Unregister all filters. */
864 void avfilter_uninit(void);
868 * Register a filter. This is only needed if you plan to use
869 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
870 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
873 * @param filter the filter to register
874 * @return 0 if the registration was successful, a negative value
877 int avfilter_register(AVFilter *filter);
880 * Get a filter definition matching the given name.
882 * @param name the filter name to find
883 * @return the filter definition, if any matching one is registered.
884 * NULL if none found.
886 AVFilter *avfilter_get_by_name(const char *name);
889 * Iterate over all registered filters.
890 * @return If prev is non-NULL, next registered filter after prev or NULL if
891 * prev is the last filter. If prev is NULL, return the first registered filter.
893 const AVFilter *avfilter_next(const AVFilter *prev);
895 #if FF_API_OLD_FILTER_REGISTER
897 * If filter is NULL, returns a pointer to the first registered filter pointer,
898 * if filter is non-NULL, returns the next pointer after filter.
899 * If the returned pointer points to NULL, the last registered filter
900 * was already reached.
901 * @deprecated use avfilter_next()
904 AVFilter **av_filter_next(AVFilter **filter);
907 #if FF_API_AVFILTER_OPEN
909 * Create a filter instance.
911 * @param filter_ctx put here a pointer to the created filter context
912 * on success, NULL on failure
913 * @param filter the filter to create an instance of
914 * @param inst_name Name to give to the new instance. Can be NULL for none.
915 * @return >= 0 in case of success, a negative error code otherwise
916 * @deprecated use avfilter_graph_alloc_filter() instead
919 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
923 #if FF_API_AVFILTER_INIT_FILTER
925 * Initialize a filter.
927 * @param filter the filter to initialize
928 * @param args A string of parameters to use when initializing the filter.
929 * The format and meaning of this string varies by filter.
930 * @param opaque Any extra non-string data needed by the filter. The meaning
931 * of this parameter varies by filter.
932 * @return zero on success
935 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
939 * Initialize a filter with the supplied parameters.
941 * @param ctx uninitialized filter context to initialize
942 * @param args Options to initialize the filter with. This must be a
943 * ':'-separated list of options in the 'key=value' form.
944 * May be NULL if the options have been set directly using the
945 * AVOptions API or there are no options that need to be set.
946 * @return 0 on success, a negative AVERROR on failure
948 int avfilter_init_str(AVFilterContext *ctx, const char *args);
951 * Initialize a filter with the supplied dictionary of options.
953 * @param ctx uninitialized filter context to initialize
954 * @param options An AVDictionary filled with options for this filter. On
955 * return this parameter will be destroyed and replaced with
956 * a dict containing options that were not found. This dictionary
957 * must be freed by the caller.
958 * May be NULL, then this function is equivalent to
959 * avfilter_init_str() with the second parameter set to NULL.
960 * @return 0 on success, a negative AVERROR on failure
962 * @note This function and avfilter_init_str() do essentially the same thing,
963 * the difference is in manner in which the options are passed. It is up to the
964 * calling code to choose whichever is more preferable. The two functions also
965 * behave differently when some of the provided options are not declared as
966 * supported by the filter. In such a case, avfilter_init_str() will fail, but
967 * this function will leave those extra options in the options AVDictionary and
970 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
973 * Free a filter context. This will also remove the filter from its
974 * filtergraph's list of filters.
976 * @param filter the filter to free
978 void avfilter_free(AVFilterContext *filter);
981 * Insert a filter in the middle of an existing link.
983 * @param link the link into which the filter should be inserted
984 * @param filt the filter to be inserted
985 * @param filt_srcpad_idx the input pad on the filter to connect
986 * @param filt_dstpad_idx the output pad on the filter to connect
987 * @return zero on success
989 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
990 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
992 #if FF_API_AVFILTERBUFFER
994 * Copy the frame properties of src to dst, without copying the actual
997 * @return 0 on success, a negative number on error.
1000 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
1003 * Copy the frame properties and data pointers of src to dst, without copying
1006 * @return 0 on success, a negative number on error.
1008 attribute_deprecated
1009 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
1013 * @return AVClass for AVFilterContext.
1015 * @see av_opt_find().
1017 const AVClass *avfilter_get_class(void);
1019 typedef struct AVFilterGraph {
1020 const AVClass *av_class;
1021 #if FF_API_FOO_COUNT
1022 attribute_deprecated
1023 unsigned filter_count_unused;
1025 AVFilterContext **filters;
1026 #if !FF_API_FOO_COUNT
1027 unsigned nb_filters;
1030 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
1031 char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
1032 #if FF_API_FOO_COUNT
1033 unsigned nb_filters;
1035 char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
1040 * The following fields are for internal use only.
1041 * Their type, offset, number and semantic can change without notice.
1044 AVFilterLink **sink_links;
1045 int sink_links_count;
1047 unsigned disable_auto_convert;
1051 * Allocate a filter graph.
1053 AVFilterGraph *avfilter_graph_alloc(void);
1056 * Create a new filter instance in a filter graph.
1058 * @param graph graph in which the new filter will be used
1059 * @param filter the filter to create an instance of
1060 * @param name Name to give to the new instance (will be copied to
1061 * AVFilterContext.name). This may be used by the caller to identify
1062 * different filters, libavfilter itself assigns no semantics to
1063 * this parameter. May be NULL.
1065 * @return the context of the newly created filter instance (note that it is
1066 * also retrievable directly through AVFilterGraph.filters or with
1067 * avfilter_graph_get_filter()) on success or NULL or failure.
1069 AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
1070 const AVFilter *filter,
1074 * Get a filter instance with name name from graph.
1076 * @return the pointer to the found filter instance or NULL if it
1079 AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
1081 #if FF_API_AVFILTER_OPEN
1083 * Add an existing filter instance to a filter graph.
1085 * @param graphctx the filter graph
1086 * @param filter the filter to be added
1088 * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
1091 attribute_deprecated
1092 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
1096 * Create and add a filter instance into an existing graph.
1097 * The filter instance is created from the filter filt and inited
1098 * with the parameters args and opaque.
1100 * In case of success put in *filt_ctx the pointer to the created
1101 * filter instance, otherwise set *filt_ctx to NULL.
1103 * @param name the instance name to give to the created filter instance
1104 * @param graph_ctx the filter graph
1105 * @return a negative AVERROR error code in case of failure, a non
1106 * negative value otherwise
1108 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
1109 const char *name, const char *args, void *opaque,
1110 AVFilterGraph *graph_ctx);
1113 * Enable or disable automatic format conversion inside the graph.
1115 * Note that format conversion can still happen inside explicitly inserted
1116 * scale and aresample filters.
1118 * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
1120 void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags);
1123 AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
1124 AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
1128 * Check validity and configure all the links and formats in the graph.
1130 * @param graphctx the filter graph
1131 * @param log_ctx context used for logging
1132 * @return 0 in case of success, a negative AVERROR code otherwise
1134 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
1137 * Free a graph, destroy its links, and set *graph to NULL.
1138 * If *graph is NULL, do nothing.
1140 void avfilter_graph_free(AVFilterGraph **graph);
1143 * A linked-list of the inputs/outputs of the filter chain.
1145 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
1146 * where it is used to communicate open (unlinked) inputs and outputs from and
1148 * This struct specifies, per each not connected pad contained in the graph, the
1149 * filter context and the pad index required for establishing a link.
1151 typedef struct AVFilterInOut {
1152 /** unique name for this input/output in the list */
1155 /** filter context associated to this input/output */
1156 AVFilterContext *filter_ctx;
1158 /** index of the filt_ctx pad to use for linking */
1161 /** next input/input in the list, NULL if this is the last */
1162 struct AVFilterInOut *next;
1166 * Allocate a single AVFilterInOut entry.
1167 * Must be freed with avfilter_inout_free().
1168 * @return allocated AVFilterInOut on success, NULL on failure.
1170 AVFilterInOut *avfilter_inout_alloc(void);
1173 * Free the supplied list of AVFilterInOut and set *inout to NULL.
1174 * If *inout is NULL, do nothing.
1176 void avfilter_inout_free(AVFilterInOut **inout);
1179 * Add a graph described by a string to a graph.
1181 * @param graph the filter graph where to link the parsed graph context
1182 * @param filters string to be parsed
1183 * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
1184 * If non-NULL, *inputs is updated to contain the list of open inputs
1185 * after the parsing, should be freed with avfilter_inout_free().
1186 * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
1187 * If non-NULL, *outputs is updated to contain the list of open outputs
1188 * after the parsing, should be freed with avfilter_inout_free().
1189 * @return non negative on success, a negative AVERROR code on error
1191 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
1192 AVFilterInOut **inputs, AVFilterInOut **outputs,
1196 * Add a graph described by a string to a graph.
1198 * @param[in] graph the filter graph where to link the parsed graph context
1199 * @param[in] filters string to be parsed
1200 * @param[out] inputs a linked list of all free (unlinked) inputs of the
1201 * parsed graph will be returned here. It is to be freed
1202 * by the caller using avfilter_inout_free().
1203 * @param[out] outputs a linked list of all free (unlinked) outputs of the
1204 * parsed graph will be returned here. It is to be freed by the
1205 * caller using avfilter_inout_free().
1206 * @return zero on success, a negative AVERROR code on error
1208 * @note the difference between avfilter_graph_parse2() and
1209 * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
1210 * the lists of inputs and outputs, which therefore must be known before calling
1211 * the function. On the other hand, avfilter_graph_parse2() \em returns the
1212 * inputs and outputs that are left unlinked after parsing the graph and the
1213 * caller then deals with them. Another difference is that in
1214 * avfilter_graph_parse(), the inputs parameter describes inputs of the
1215 * <em>already existing</em> part of the graph; i.e. from the point of view of
1216 * the newly created part, they are outputs. Similarly the outputs parameter
1217 * describes outputs of the already existing filters, which are provided as
1218 * inputs to the parsed filters.
1219 * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
1220 * whatsoever to already existing parts of the graph and the inputs parameter
1221 * will on return contain inputs of the newly parsed part of the graph.
1222 * Analogously the outputs parameter will contain outputs of the newly created
1225 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1226 AVFilterInOut **inputs,
1227 AVFilterInOut **outputs);
1230 * Send a command to one or more filter instances.
1232 * @param graph the filter graph
1233 * @param target the filter(s) to which the command should be sent
1234 * "all" sends to all filters
1235 * otherwise it can be a filter or filter instance name
1236 * which will send the command to all matching filters.
1237 * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
1238 * @param arg the argument for the command
1239 * @param res a buffer with size res_size where the filter(s) can return a response.
1241 * @returns >=0 on success otherwise an error code.
1242 * AVERROR(ENOSYS) on unsupported commands
1244 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
1247 * Queue a command for one or more filter instances.
1249 * @param graph the filter graph
1250 * @param target the filter(s) to which the command should be sent
1251 * "all" sends to all filters
1252 * otherwise it can be a filter or filter instance name
1253 * which will send the command to all matching filters.
1254 * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only
1255 * @param arg the argument for the command
1256 * @param ts time at which the command should be sent to the filter
1258 * @note As this executes commands after this function returns, no return code
1259 * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
1261 int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
1265 * Dump a graph into a human-readable string representation.
1267 * @param graph the graph to dump
1268 * @param options formatting options; currently ignored
1269 * @return a string, or NULL in case of memory allocation failure;
1270 * the string must be freed using av_free
1272 char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
1275 * Request a frame on the oldest sink link.
1277 * If the request returns AVERROR_EOF, try the next.
1279 * Note that this function is not meant to be the sole scheduling mechanism
1280 * of a filtergraph, only a convenience function to help drain a filtergraph
1281 * in a balanced way under normal circumstances.
1283 * Also note that AVERROR_EOF does not mean that frames did not arrive on
1284 * some of the sinks during the process.
1285 * When there are multiple sink links, in case the requested link
1286 * returns an EOF, this may cause a filter to flush pending frames
1287 * which are sent to another sink link, although unrequested.
1289 * @return the return value of ff_request_frame(),
1290 * or AVERROR_EOF if all links returned AVERROR_EOF
1292 int avfilter_graph_request_oldest(AVFilterGraph *graph);
1297 #endif /* AVFILTER_AVFILTER_H */