FFmpeg 6.1.7
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
25/**
26 * @file
27 * @ingroup lavfi
28 * Main libavfilter public API header
29 */
30
31/**
32 * @defgroup lavfi libavfilter
33 * Graph-based frame editing library.
34 *
35 * @{
36 */
37
38#include <stddef.h>
39
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
51#ifndef HAVE_AV_CONFIG_H
52/* When included as part of the ffmpeg build, only include the major version
53 * to avoid unnecessary rebuilds. When included externally, keep including
54 * the full version information. */
55#include "libavfilter/version.h"
56#endif
57
58/**
59 * Return the LIBAVFILTER_VERSION_INT constant.
60 */
61unsigned avfilter_version(void);
62
63/**
64 * Return the libavfilter build-time configuration.
65 */
66const char *avfilter_configuration(void);
67
68/**
69 * Return the libavfilter license.
70 */
71const char *avfilter_license(void);
72
73typedef struct AVFilterContext AVFilterContext;
74typedef struct AVFilterLink AVFilterLink;
75typedef struct AVFilterPad AVFilterPad;
78
79/**
80 * Get the name of an AVFilterPad.
81 *
82 * @param pads an array of AVFilterPads
83 * @param pad_idx index of the pad in the array; it is the caller's
84 * responsibility to ensure the index is valid
85 *
86 * @return name of the pad_idx'th pad in pads
87 */
88const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
89
90/**
91 * Get the type of an AVFilterPad.
92 *
93 * @param pads an array of AVFilterPads
94 * @param pad_idx index of the pad in the array; it is the caller's
95 * responsibility to ensure the index is valid
96 *
97 * @return type of the pad_idx'th pad in pads
98 */
99enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
100
101/**
102 * The number of the filter inputs is not determined just by AVFilter.inputs.
103 * The filter might add additional inputs during initialization depending on the
104 * options supplied to it.
105 */
106#define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
107/**
108 * The number of the filter outputs is not determined just by AVFilter.outputs.
109 * The filter might add additional outputs during initialization depending on
110 * the options supplied to it.
111 */
112#define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
113/**
114 * The filter supports multithreading by splitting frames into multiple parts
115 * and processing them concurrently.
116 */
117#define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
118/**
119 * The filter is a "metadata" filter - it does not modify the frame data in any
120 * way. It may only affect the metadata (i.e. those fields copied by
121 * av_frame_copy_props()).
122 *
123 * More precisely, this means:
124 * - video: the data of any frame output by the filter must be exactly equal to
125 * some frame that is received on one of its inputs. Furthermore, all frames
126 * produced on a given output must correspond to frames received on the same
127 * input and their order must be unchanged. Note that the filter may still
128 * drop or duplicate the frames.
129 * - audio: the data produced by the filter on any of its outputs (viewed e.g.
130 * as an array of interleaved samples) must be exactly equal to the data
131 * received by the filter on one of its inputs.
132 */
133#define AVFILTER_FLAG_METADATA_ONLY (1 << 3)
134
135/**
136 * The filter can create hardware frames using AVFilterContext.hw_device_ctx.
137 */
138#define AVFILTER_FLAG_HWDEVICE (1 << 4)
139/**
140 * Some filters support a generic "enable" expression option that can be used
141 * to enable or disable a filter in the timeline. Filters supporting this
142 * option have this flag set. When the enable expression is false, the default
143 * no-op filter_frame() function is called in place of the filter_frame()
144 * callback defined on each input pad, thus the frame is passed unchanged to
145 * the next filters.
146 */
147#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC (1 << 16)
148/**
149 * Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will
150 * have its filter_frame() callback(s) called as usual even when the enable
151 * expression is false. The filter will disable filtering within the
152 * filter_frame() callback(s) itself, for example executing code depending on
153 * the AVFilterContext->is_disabled value.
154 */
155#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL (1 << 17)
156/**
157 * Handy mask to test whether the filter supports or no the timeline feature
158 * (internally or generically).
159 */
160#define AVFILTER_FLAG_SUPPORT_TIMELINE (AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL)
161
162/**
163 * Filter definition. This defines the pads a filter contains, and all the
164 * callback functions used to interact with the filter.
165 */
166typedef struct AVFilter {
167 /**
168 * Filter name. Must be non-NULL and unique among filters.
169 */
170 const char *name;
171
172 /**
173 * A description of the filter. May be NULL.
174 *
175 * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
176 */
177 const char *description;
178
179 /**
180 * List of static inputs.
181 *
182 * NULL if there are no (static) inputs. Instances of filters with
183 * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
184 * this list.
185 */
187
188 /**
189 * List of static outputs.
190 *
191 * NULL if there are no (static) outputs. Instances of filters with
192 * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
193 * this list.
194 */
196
197 /**
198 * A class for the private data, used to declare filter private AVOptions.
199 * This field is NULL for filters that do not declare any options.
200 *
201 * If this field is non-NULL, the first member of the filter private data
202 * must be a pointer to AVClass, which will be set by libavfilter generic
203 * code to this class.
204 */
206
207 /**
208 * A combination of AVFILTER_FLAG_*
209 */
210 int flags;
211
212 /*****************************************************************
213 * All fields below this line are not part of the public API. They
214 * may not be used outside of libavfilter and can be changed and
215 * removed at will.
216 * New public fields should be added right above.
217 *****************************************************************
218 */
219
220 /**
221 * The number of entries in the list of inputs.
222 */
223 uint8_t nb_inputs;
224
225 /**
226 * The number of entries in the list of outputs.
227 */
228 uint8_t nb_outputs;
229
230 /**
231 * This field determines the state of the formats union.
232 * It is an enum FilterFormatsState value.
233 */
235
236 /**
237 * Filter pre-initialization function
238 *
239 * This callback will be called immediately after the filter context is
240 * allocated, to allow allocating and initing sub-objects.
241 *
242 * If this callback is not NULL, the uninit callback will be called on
243 * allocation failure.
244 *
245 * @return 0 on success,
246 * AVERROR code on failure (but the code will be
247 * dropped and treated as ENOMEM by the calling code)
248 */
250
251 /**
252 * Filter initialization function.
253 *
254 * This callback will be called only once during the filter lifetime, after
255 * all the options have been set, but before links between filters are
256 * established and format negotiation is done.
257 *
258 * Basic filter initialization should be done here. Filters with dynamic
259 * inputs and/or outputs should create those inputs/outputs here based on
260 * provided options. No more changes to this filter's inputs/outputs can be
261 * done after this callback.
262 *
263 * This callback must not assume that the filter links exist or frame
264 * parameters are known.
265 *
266 * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
267 * initialization fails, so this callback does not have to clean up on
268 * failure.
269 *
270 * @return 0 on success, a negative AVERROR on failure
271 */
272 int (*init)(AVFilterContext *ctx);
273
274 /**
275 * Filter uninitialization function.
276 *
277 * Called only once right before the filter is freed. Should deallocate any
278 * memory held by the filter, release any buffer references, etc. It does
279 * not need to deallocate the AVFilterContext.priv memory itself.
280 *
281 * This callback may be called even if @ref AVFilter.init "init" was not
282 * called or failed, so it must be prepared to handle such a situation.
283 */
284 void (*uninit)(AVFilterContext *ctx);
285
286 /**
287 * The state of the following union is determined by formats_state.
288 * See the documentation of enum FilterFormatsState in internal.h.
289 */
290 union {
291 /**
292 * Query formats supported by the filter on its inputs and outputs.
293 *
294 * This callback is called after the filter is initialized (so the inputs
295 * and outputs are fixed), shortly before the format negotiation. This
296 * callback may be called more than once.
297 *
298 * This callback must set ::AVFilterLink's
299 * @ref AVFilterFormatsConfig.formats "outcfg.formats"
300 * on every input link and
301 * @ref AVFilterFormatsConfig.formats "incfg.formats"
302 * on every output link to a list of pixel/sample formats that the filter
303 * supports on that link.
304 * For audio links, this filter must also set
305 * @ref AVFilterFormatsConfig.samplerates "incfg.samplerates"
306 * /
307 * @ref AVFilterFormatsConfig.samplerates "outcfg.samplerates"
308 * and @ref AVFilterFormatsConfig.channel_layouts "incfg.channel_layouts"
309 * /
310 * @ref AVFilterFormatsConfig.channel_layouts "outcfg.channel_layouts"
311 * analogously.
312 *
313 * This callback must never be NULL if the union is in this state.
314 *
315 * @return zero on success, a negative value corresponding to an
316 * AVERROR code otherwise
317 */
319 /**
320 * A pointer to an array of admissible pixel formats delimited
321 * by AV_PIX_FMT_NONE. The generic code will use this list
322 * to indicate that this filter supports each of these pixel formats,
323 * provided that all inputs and outputs use the same pixel format.
324 *
325 * This list must never be NULL if the union is in this state.
326 * The type of all inputs and outputs of filters using this must
327 * be AVMEDIA_TYPE_VIDEO.
328 */
330 /**
331 * Analogous to pixels, but delimited by AV_SAMPLE_FMT_NONE
332 * and restricted to filters that only have AVMEDIA_TYPE_AUDIO
333 * inputs and outputs.
334 *
335 * In addition to that the generic code will mark all inputs
336 * and all outputs as supporting all sample rates and every
337 * channel count and channel layout, as long as all inputs
338 * and outputs use the same sample rate and channel count/layout.
339 */
341 /**
342 * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
343 */
345 /**
346 * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
347 */
350
351 int priv_size; ///< size of private data to allocate for the filter
352
353 int flags_internal; ///< Additional flags for avfilter internal use only.
354
355 /**
356 * Make the filter instance process a command.
357 *
358 * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
359 * @param arg the argument for the command
360 * @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.
361 * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
362 * time consuming then a filter should treat it like an unsupported command
363 *
364 * @returns >=0 on success otherwise an error code.
365 * AVERROR(ENOSYS) on unsupported commands
366 */
367 int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
368
369 /**
370 * Filter activation function.
371 *
372 * Called when any processing is needed from the filter, instead of any
373 * filter_frame and request_frame on pads.
374 *
375 * The function must examine inlinks and outlinks and perform a single
376 * step of processing. If there is nothing to do, the function must do
377 * nothing and not return an error. If more steps are or may be
378 * possible, it must use ff_filter_set_ready() to schedule another
379 * activation.
380 */
382} AVFilter;
383
384/**
385 * Get the number of elements in an AVFilter's inputs or outputs array.
386 */
387unsigned avfilter_filter_pad_count(const AVFilter *filter, int is_output);
388
389/**
390 * Process multiple parts of the frame concurrently.
391 */
392#define AVFILTER_THREAD_SLICE (1 << 0)
393
395
396/** An instance of a filter */
398 const AVClass *av_class; ///< needed for av_log() and filters common options
399
400 const AVFilter *filter; ///< the AVFilter of which this is an instance
401
402 char *name; ///< name of this filter instance
403
404 AVFilterPad *input_pads; ///< array of input pads
405 AVFilterLink **inputs; ///< array of pointers to input links
406 unsigned nb_inputs; ///< number of input pads
407
408 AVFilterPad *output_pads; ///< array of output pads
409 AVFilterLink **outputs; ///< array of pointers to output links
410 unsigned nb_outputs; ///< number of output pads
411
412 void *priv; ///< private data for use by the filter
413
414 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
415
416 /**
417 * Type of multithreading being allowed/used. A combination of
418 * AVFILTER_THREAD_* flags.
419 *
420 * May be set by the caller before initializing the filter to forbid some
421 * or all kinds of multithreading for this filter. The default is allowing
422 * everything.
423 *
424 * When the filter is initialized, this field is combined using bit AND with
425 * AVFilterGraph.thread_type to get the final mask used for determining
426 * allowed threading types. I.e. a threading type needs to be set in both
427 * to be allowed.
428 *
429 * After the filter is initialized, libavfilter sets this field to the
430 * threading type that is actually used (0 for no multithreading).
431 */
433
434 /**
435 * An opaque struct for libavfilter internal use.
436 */
438
439 struct AVFilterCommand *command_queue;
440
441 char *enable_str; ///< enable expression string
442 void *enable; ///< parsed expression (AVExpr*)
443 double *var_values; ///< variable values for the enable expression
444 int is_disabled; ///< the enabled state from the last expression evaluation
445
446 /**
447 * For filters which will create hardware frames, sets the device the
448 * filter should create them in. All other filters will ignore this field:
449 * in particular, a filter which consumes or processes hardware frames will
450 * instead use the hw_frames_ctx field in AVFilterLink to carry the
451 * hardware context information.
452 *
453 * May be set by the caller on filters flagged with AVFILTER_FLAG_HWDEVICE
454 * before initializing the filter with avfilter_init_str() or
455 * avfilter_init_dict().
456 */
458
459 /**
460 * Max number of threads allowed in this filter instance.
461 * If <= 0, its value is ignored.
462 * Overrides global number of threads set per filter graph.
463 */
465
466 /**
467 * Ready status of the filter.
468 * A non-0 value means that the filter needs activating;
469 * a higher value suggests a more urgent activation.
470 */
471 unsigned ready;
472
473 /**
474 * Sets the number of extra hardware frames which the filter will
475 * allocate on its output links for use in following filters or by
476 * the caller.
477 *
478 * Some hardware filters require all frames that they will use for
479 * output to be defined in advance before filtering starts. For such
480 * filters, any hardware frame pools used for output must therefore be
481 * of fixed size. The extra frames set here are on top of any number
482 * that the filter needs internally in order to operate normally.
483 *
484 * This field must be set before the graph containing this filter is
485 * configured.
486 */
488};
489
490/**
491 * Lists of formats / etc. supported by an end of a link.
492 *
493 * This structure is directly part of AVFilterLink, in two copies:
494 * one for the source filter, one for the destination filter.
495
496 * These lists are used for negotiating the format to actually be used,
497 * which will be loaded into the format and channel_layout members of
498 * AVFilterLink, when chosen.
499 */
500typedef struct AVFilterFormatsConfig {
501
502 /**
503 * List of supported formats (pixel or sample).
504 */
506
507 /**
508 * Lists of supported sample rates, only for audio.
509 */
511
512 /**
513 * Lists of supported channel layouts, only for audio.
514 */
516
518
519/**
520 * A link between two filters. This contains pointers to the source and
521 * destination filters between which this link exists, and the indexes of
522 * the pads involved. In addition, this link also contains the parameters
523 * which have been negotiated and agreed upon between the filter, such as
524 * image dimensions, format, etc.
525 *
526 * Applications must not normally access the link structure directly.
527 * Use the buffersrc and buffersink API instead.
528 * In the future, access to the header may be reserved for filters
529 * implementation.
530 */
532 AVFilterContext *src; ///< source filter
533 AVFilterPad *srcpad; ///< output pad on the source filter
534
535 AVFilterContext *dst; ///< dest filter
536 AVFilterPad *dstpad; ///< input pad on the dest filter
537
538 enum AVMediaType type; ///< filter media type
539
540 /* These parameters apply only to video */
541 int w; ///< agreed upon image width
542 int h; ///< agreed upon image height
543 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
544 /* These parameters apply only to audio */
545#if FF_API_OLD_CHANNEL_LAYOUT
546 /**
547 * channel layout of current buffer (see libavutil/channel_layout.h)
548 * @deprecated use ch_layout
549 */
551 uint64_t channel_layout;
552#endif
553 int sample_rate; ///< samples per second
554
555 int format; ///< agreed upon media format
556
557 /**
558 * Define the time base used by the PTS of the frames/samples
559 * which will pass through this link.
560 * During the configuration stage, each filter is supposed to
561 * change only the output timebase, while the timebase of the
562 * input link is assumed to be an unchangeable property.
563 */
565
566 AVChannelLayout ch_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
567
568 /*****************************************************************
569 * All fields below this line are not part of the public API. They
570 * may not be used outside of libavfilter and can be changed and
571 * removed at will.
572 * New public fields should be added right above.
573 *****************************************************************
574 */
575
576 /**
577 * Lists of supported formats / etc. supported by the input filter.
578 */
580
581 /**
582 * Lists of supported formats / etc. supported by the output filter.
583 */
585
586 /** stage of the initialization of the link properties (dimensions, etc) */
587 enum {
588 AVLINK_UNINIT = 0, ///< not started
589 AVLINK_STARTINIT, ///< started, but incomplete
590 AVLINK_INIT ///< complete
592
593 /**
594 * Graph the filter belongs to.
595 */
597
598 /**
599 * Current timestamp of the link, as defined by the most recent
600 * frame(s), in link time_base units.
601 */
602 int64_t current_pts;
603
604 /**
605 * Current timestamp of the link, as defined by the most recent
606 * frame(s), in AV_TIME_BASE units.
607 */
609
610 /**
611 * Index in the age array.
612 */
614
615 /**
616 * Frame rate of the stream on the link, or 1/0 if unknown or variable;
617 * if left to 0/0, will be automatically copied from the first input
618 * of the source filter if it exists.
619 *
620 * Sources should set it to the best estimation of the real frame rate.
621 * If the source frame rate is unknown or variable, set this to 1/0.
622 * Filters should update it if necessary depending on their function.
623 * Sinks can use it to set a default output frame rate.
624 * It is similar to the r_frame_rate field in AVStream.
625 */
627
628 /**
629 * Minimum number of samples to filter at once. If filter_frame() is
630 * called with fewer samples, it will accumulate them in fifo.
631 * This field and the related ones must not be changed after filtering
632 * has started.
633 * If 0, all related fields are ignored.
634 */
636
637 /**
638 * Maximum number of samples to filter at once. If filter_frame() is
639 * called with more samples, it will split them.
640 */
642
643 /**
644 * Number of past frames sent through the link.
645 */
647
648 /**
649 * Number of past samples sent through the link.
650 */
652
653 /**
654 * A pointer to a FFFramePool struct.
655 */
657
658 /**
659 * True if a frame is currently wanted on the output of this filter.
660 * Set when ff_request_frame() is called by the output,
661 * cleared when a frame is filtered.
662 */
664
665 /**
666 * For hwaccel pixel formats, this should be a reference to the
667 * AVHWFramesContext describing the frames.
668 */
670
671#ifndef FF_INTERNAL_FIELDS
672
673 /**
674 * Internal structure members.
675 * The fields below this limit are internal for libavfilter's use
676 * and must in no way be accessed by applications.
677 */
678 char reserved[0xF000];
679
680#else /* FF_INTERNAL_FIELDS */
681
682 /**
683 * Queue of frames waiting to be filtered.
684 */
685 FFFrameQueue fifo;
686
687 /**
688 * Format and size of the video frames the link was configured with.
689 */
690 int cfg_format, cfg_w, cfg_h;
691
692 /**
693 * If set, the source filter can not generate a frame as is.
694 * The goal is to avoid repeatedly calling the request_frame() method on
695 * the same link.
696 */
697 int frame_blocked_in;
698
699 /**
700 * Link input status.
701 * If not zero, all attempts of filter_frame will fail with the
702 * corresponding code.
703 */
704 int status_in;
705
706 /**
707 * Timestamp of the input status change.
708 */
709 int64_t status_in_pts;
710
711 /**
712 * Link output status.
713 * If not zero, all attempts of request_frame will fail with the
714 * corresponding code.
715 */
716 int status_out;
717
718#endif /* FF_INTERNAL_FIELDS */
719
720};
721
722/**
723 * Link two filters together.
724 *
725 * @param src the source filter
726 * @param srcpad index of the output pad on the source filter
727 * @param dst the destination filter
728 * @param dstpad index of the input pad on the destination filter
729 * @return zero on success
730 */
731int avfilter_link(AVFilterContext *src, unsigned srcpad,
732 AVFilterContext *dst, unsigned dstpad);
733
734/**
735 * Free the link in *link, and set its pointer to NULL.
736 */
738
739/**
740 * Negotiate the media format, dimensions, etc of all inputs to a filter.
741 *
742 * @param filter the filter to negotiate the properties for its inputs
743 * @return zero on successful negotiation
744 */
746
747#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
748#define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
749
750/**
751 * Make the filter instance process a command.
752 * It is recommended to use avfilter_graph_send_command().
753 */
754int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
755
756/**
757 * Iterate over all registered filters.
758 *
759 * @param opaque a pointer where libavfilter will store the iteration state. Must
760 * point to NULL to start the iteration.
761 *
762 * @return the next registered filter or NULL when the iteration is
763 * finished
764 */
766
767/**
768 * Get a filter definition matching the given name.
769 *
770 * @param name the filter name to find
771 * @return the filter definition, if any matching one is registered.
772 * NULL if none found.
773 */
774const AVFilter *avfilter_get_by_name(const char *name);
775
776
777/**
778 * Initialize a filter with the supplied parameters.
779 *
780 * @param ctx uninitialized filter context to initialize
781 * @param args Options to initialize the filter with. This must be a
782 * ':'-separated list of options in the 'key=value' form.
783 * May be NULL if the options have been set directly using the
784 * AVOptions API or there are no options that need to be set.
785 * @return 0 on success, a negative AVERROR on failure
786 */
787int avfilter_init_str(AVFilterContext *ctx, const char *args);
788
789/**
790 * Initialize a filter with the supplied dictionary of options.
791 *
792 * @param ctx uninitialized filter context to initialize
793 * @param options An AVDictionary filled with options for this filter. On
794 * return this parameter will be destroyed and replaced with
795 * a dict containing options that were not found. This dictionary
796 * must be freed by the caller.
797 * May be NULL, then this function is equivalent to
798 * avfilter_init_str() with the second parameter set to NULL.
799 * @return 0 on success, a negative AVERROR on failure
800 *
801 * @note This function and avfilter_init_str() do essentially the same thing,
802 * the difference is in manner in which the options are passed. It is up to the
803 * calling code to choose whichever is more preferable. The two functions also
804 * behave differently when some of the provided options are not declared as
805 * supported by the filter. In such a case, avfilter_init_str() will fail, but
806 * this function will leave those extra options in the options AVDictionary and
807 * continue as usual.
808 */
810
811/**
812 * Free a filter context. This will also remove the filter from its
813 * filtergraph's list of filters.
814 *
815 * @param filter the filter to free
816 */
818
819/**
820 * Insert a filter in the middle of an existing link.
821 *
822 * @param link the link into which the filter should be inserted
823 * @param filt the filter to be inserted
824 * @param filt_srcpad_idx the input pad on the filter to connect
825 * @param filt_dstpad_idx the output pad on the filter to connect
826 * @return zero on success
827 */
829 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
830
831/**
832 * @return AVClass for AVFilterContext.
833 *
834 * @see av_opt_find().
835 */
837
839
840/**
841 * A function pointer passed to the @ref AVFilterGraph.execute callback to be
842 * executed multiple times, possibly in parallel.
843 *
844 * @param ctx the filter context the job belongs to
845 * @param arg an opaque parameter passed through from @ref
846 * AVFilterGraph.execute
847 * @param jobnr the index of the job being executed
848 * @param nb_jobs the total number of jobs
849 *
850 * @return 0 on success, a negative AVERROR on error
851 */
852typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
853
854/**
855 * A function executing multiple jobs, possibly in parallel.
856 *
857 * @param ctx the filter context to which the jobs belong
858 * @param func the function to be called multiple times
859 * @param arg the argument to be passed to func
860 * @param ret a nb_jobs-sized array to be filled with return values from each
861 * invocation of func
862 * @param nb_jobs the number of jobs to execute
863 *
864 * @return 0 on success, a negative AVERROR on error
865 */
867 void *arg, int *ret, int nb_jobs);
868
869typedef struct AVFilterGraph {
872 unsigned nb_filters;
873
874 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
875
876 /**
877 * Type of multithreading allowed for filters in this graph. A combination
878 * of AVFILTER_THREAD_* flags.
879 *
880 * May be set by the caller at any point, the setting will apply to all
881 * filters initialized after that. The default is allowing everything.
882 *
883 * When a filter in this graph is initialized, this field is combined using
884 * bit AND with AVFilterContext.thread_type to get the final mask used for
885 * determining allowed threading types. I.e. a threading type needs to be
886 * set in both to be allowed.
887 */
889
890 /**
891 * Maximum number of threads used by filters in this graph. May be set by
892 * the caller before adding any filters to the filtergraph. Zero (the
893 * default) means that the number of threads is determined automatically.
894 */
896
897 /**
898 * Opaque object for libavfilter internal use.
899 */
901
902 /**
903 * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
904 * be used from callbacks like @ref AVFilterGraph.execute.
905 * Libavfilter will not touch this field in any way.
906 */
907 void *opaque;
908
909 /**
910 * This callback may be set by the caller immediately after allocating the
911 * graph and before adding any filters to it, to provide a custom
912 * multithreading implementation.
913 *
914 * If set, filters with slice threading capability will call this callback
915 * to execute multiple jobs in parallel.
916 *
917 * If this field is left unset, libavfilter will use its internal
918 * implementation, which may or may not be multithreaded depending on the
919 * platform and build options.
920 */
922
923 char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
924
925 /**
926 * Private fields
927 *
928 * The following fields are for internal use only.
929 * Their type, offset, number and semantic can change without notice.
930 */
931
934
937
938/**
939 * Allocate a filter graph.
940 *
941 * @return the allocated filter graph on success or NULL.
942 */
944
945/**
946 * Create a new filter instance in a filter graph.
947 *
948 * @param graph graph in which the new filter will be used
949 * @param filter the filter to create an instance of
950 * @param name Name to give to the new instance (will be copied to
951 * AVFilterContext.name). This may be used by the caller to identify
952 * different filters, libavfilter itself assigns no semantics to
953 * this parameter. May be NULL.
954 *
955 * @return the context of the newly created filter instance (note that it is
956 * also retrievable directly through AVFilterGraph.filters or with
957 * avfilter_graph_get_filter()) on success or NULL on failure.
958 */
960 const AVFilter *filter,
961 const char *name);
962
963/**
964 * Get a filter instance identified by instance name from graph.
965 *
966 * @param graph filter graph to search through.
967 * @param name filter instance name (should be unique in the graph).
968 * @return the pointer to the found filter instance or NULL if it
969 * cannot be found.
970 */
972
973/**
974 * Create and add a filter instance into an existing graph.
975 * The filter instance is created from the filter filt and inited
976 * with the parameter args. opaque is currently ignored.
977 *
978 * In case of success put in *filt_ctx the pointer to the created
979 * filter instance, otherwise set *filt_ctx to NULL.
980 *
981 * @param name the instance name to give to the created filter instance
982 * @param graph_ctx the filter graph
983 * @return a negative AVERROR error code in case of failure, a non
984 * negative value otherwise
985 */
987 const char *name, const char *args, void *opaque,
988 AVFilterGraph *graph_ctx);
989
990/**
991 * Enable or disable automatic format conversion inside the graph.
992 *
993 * Note that format conversion can still happen inside explicitly inserted
994 * scale and aresample filters.
995 *
996 * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
997 */
999
1000enum {
1001 AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
1002 AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
1003};
1004
1005/**
1006 * Check validity and configure all the links and formats in the graph.
1007 *
1008 * @param graphctx the filter graph
1009 * @param log_ctx context used for logging
1010 * @return >= 0 in case of success, a negative AVERROR code otherwise
1011 */
1012int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
1013
1014/**
1015 * Free a graph, destroy its links, and set *graph to NULL.
1016 * If *graph is NULL, do nothing.
1017 */
1019
1020/**
1021 * A linked-list of the inputs/outputs of the filter chain.
1022 *
1023 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
1024 * where it is used to communicate open (unlinked) inputs and outputs from and
1025 * to the caller.
1026 * This struct specifies, per each not connected pad contained in the graph, the
1027 * filter context and the pad index required for establishing a link.
1028 */
1029typedef struct AVFilterInOut {
1030 /** unique name for this input/output in the list */
1031 char *name;
1032
1033 /** filter context associated to this input/output */
1035
1036 /** index of the filt_ctx pad to use for linking */
1038
1039 /** next input/input in the list, NULL if this is the last */
1042
1043/**
1044 * Allocate a single AVFilterInOut entry.
1045 * Must be freed with avfilter_inout_free().
1046 * @return allocated AVFilterInOut on success, NULL on failure.
1047 */
1049
1050/**
1051 * Free the supplied list of AVFilterInOut and set *inout to NULL.
1052 * If *inout is NULL, do nothing.
1053 */
1055
1056/**
1057 * Add a graph described by a string to a graph.
1058 *
1059 * @note The caller must provide the lists of inputs and outputs,
1060 * which therefore must be known before calling the function.
1061 *
1062 * @note The inputs parameter describes inputs of the already existing
1063 * part of the graph; i.e. from the point of view of the newly created
1064 * part, they are outputs. Similarly the outputs parameter describes
1065 * outputs of the already existing filters, which are provided as
1066 * inputs to the parsed filters.
1067 *
1068 * @param graph the filter graph where to link the parsed graph context
1069 * @param filters string to be parsed
1070 * @param inputs linked list to the inputs of the graph
1071 * @param outputs linked list to the outputs of the graph
1072 * @return zero on success, a negative AVERROR code on error
1073 */
1074int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
1075 AVFilterInOut *inputs, AVFilterInOut *outputs,
1076 void *log_ctx);
1077
1078/**
1079 * Add a graph described by a string to a graph.
1080 *
1081 * In the graph filters description, if the input label of the first
1082 * filter is not specified, "in" is assumed; if the output label of
1083 * the last filter is not specified, "out" is assumed.
1084 *
1085 * @param graph the filter graph where to link the parsed graph context
1086 * @param filters string to be parsed
1087 * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
1088 * If non-NULL, *inputs is updated to contain the list of open inputs
1089 * after the parsing, should be freed with avfilter_inout_free().
1090 * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
1091 * If non-NULL, *outputs is updated to contain the list of open outputs
1092 * after the parsing, should be freed with avfilter_inout_free().
1093 * @return non negative on success, a negative AVERROR code on error
1094 */
1095int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
1096 AVFilterInOut **inputs, AVFilterInOut **outputs,
1097 void *log_ctx);
1098
1099/**
1100 * Add a graph described by a string to a graph.
1101 *
1102 * @param[in] graph the filter graph where to link the parsed graph context
1103 * @param[in] filters string to be parsed
1104 * @param[out] inputs a linked list of all free (unlinked) inputs of the
1105 * parsed graph will be returned here. It is to be freed
1106 * by the caller using avfilter_inout_free().
1107 * @param[out] outputs a linked list of all free (unlinked) outputs of the
1108 * parsed graph will be returned here. It is to be freed by the
1109 * caller using avfilter_inout_free().
1110 * @return zero on success, a negative AVERROR code on error
1111 *
1112 * @note This function returns the inputs and outputs that are left
1113 * unlinked after parsing the graph and the caller then deals with
1114 * them.
1115 * @note This function makes no reference whatsoever to already
1116 * existing parts of the graph and the inputs parameter will on return
1117 * contain inputs of the newly parsed part of the graph. Analogously
1118 * the outputs parameter will contain outputs of the newly created
1119 * filters.
1120 */
1121int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1122 AVFilterInOut **inputs,
1123 AVFilterInOut **outputs);
1124
1125/**
1126 * Parameters of a filter's input or output pad.
1127 *
1128 * Created as a child of AVFilterParams by avfilter_graph_segment_parse().
1129 * Freed in avfilter_graph_segment_free().
1130 */
1131typedef struct AVFilterPadParams {
1132 /**
1133 * An av_malloc()'ed string containing the pad label.
1134 *
1135 * May be av_free()'d and set to NULL by the caller, in which case this pad
1136 * will be treated as unlabeled for linking.
1137 * May also be replaced by another av_malloc()'ed string.
1138 */
1139 char *label;
1141
1142/**
1143 * Parameters describing a filter to be created in a filtergraph.
1144 *
1145 * Created as a child of AVFilterGraphSegment by avfilter_graph_segment_parse().
1146 * Freed in avfilter_graph_segment_free().
1147 */
1148typedef struct AVFilterParams {
1149 /**
1150 * The filter context.
1151 *
1152 * Created by avfilter_graph_segment_create_filters() based on
1153 * AVFilterParams.filter_name and instance_name.
1154 *
1155 * Callers may also create the filter context manually, then they should
1156 * av_free() filter_name and set it to NULL. Such AVFilterParams instances
1157 * are then skipped by avfilter_graph_segment_create_filters().
1158 */
1160
1161 /**
1162 * Name of the AVFilter to be used.
1163 *
1164 * An av_malloc()'ed string, set by avfilter_graph_segment_parse(). Will be
1165 * passed to avfilter_get_by_name() by
1166 * avfilter_graph_segment_create_filters().
1167 *
1168 * Callers may av_free() this string and replace it with another one or
1169 * NULL. If the caller creates the filter instance manually, this string
1170 * MUST be set to NULL.
1171 *
1172 * When both AVFilterParams.filter an AVFilterParams.filter_name are NULL,
1173 * this AVFilterParams instance is skipped by avfilter_graph_segment_*()
1174 * functions.
1175 */
1177 /**
1178 * Name to be used for this filter instance.
1179 *
1180 * An av_malloc()'ed string, may be set by avfilter_graph_segment_parse() or
1181 * left NULL. The caller may av_free() this string and replace with another
1182 * one or NULL.
1183 *
1184 * Will be used by avfilter_graph_segment_create_filters() - passed as the
1185 * third argument to avfilter_graph_alloc_filter(), then freed and set to
1186 * NULL.
1187 */
1189
1190 /**
1191 * Options to be apllied to the filter.
1192 *
1193 * Filled by avfilter_graph_segment_parse(). Afterwards may be freely
1194 * modified by the caller.
1195 *
1196 * Will be applied to the filter by avfilter_graph_segment_apply_opts()
1197 * with an equivalent of av_opt_set_dict2(filter, &opts, AV_OPT_SEARCH_CHILDREN),
1198 * i.e. any unapplied options will be left in this dictionary.
1199 */
1201
1203 unsigned nb_inputs;
1204
1206 unsigned nb_outputs;
1208
1209/**
1210 * A filterchain is a list of filter specifications.
1211 *
1212 * Created as a child of AVFilterGraphSegment by avfilter_graph_segment_parse().
1213 * Freed in avfilter_graph_segment_free().
1214 */
1215typedef struct AVFilterChain {
1219
1220/**
1221 * A parsed representation of a filtergraph segment.
1222 *
1223 * A filtergraph segment is conceptually a list of filterchains, with some
1224 * supplementary information (e.g. format conversion flags).
1225 *
1226 * Created by avfilter_graph_segment_parse(). Must be freed with
1227 * avfilter_graph_segment_free().
1228 */
1229typedef struct AVFilterGraphSegment {
1230 /**
1231 * The filtergraph this segment is associated with.
1232 * Set by avfilter_graph_segment_parse().
1233 */
1235
1236 /**
1237 * A list of filter chain contained in this segment.
1238 * Set in avfilter_graph_segment_parse().
1239 */
1242
1243 /**
1244 * A string containing a colon-separated list of key=value options applied
1245 * to all scale filters in this segment.
1246 *
1247 * May be set by avfilter_graph_segment_parse().
1248 * The caller may free this string with av_free() and replace it with a
1249 * different av_malloc()'ed string.
1250 */
1253
1254/**
1255 * Parse a textual filtergraph description into an intermediate form.
1256 *
1257 * This intermediate representation is intended to be modified by the caller as
1258 * described in the documentation of AVFilterGraphSegment and its children, and
1259 * then applied to the graph either manually or with other
1260 * avfilter_graph_segment_*() functions. See the documentation for
1261 * avfilter_graph_segment_apply() for the canonical way to apply
1262 * AVFilterGraphSegment.
1263 *
1264 * @param graph Filter graph the parsed segment is associated with. Will only be
1265 * used for logging and similar auxiliary purposes. The graph will
1266 * not be actually modified by this function - the parsing results
1267 * are instead stored in seg for further processing.
1268 * @param graph_str a string describing the filtergraph segment
1269 * @param flags reserved for future use, caller must set to 0 for now
1270 * @param seg A pointer to the newly-created AVFilterGraphSegment is written
1271 * here on success. The graph segment is owned by the caller and must
1272 * be freed with avfilter_graph_segment_free() before graph itself is
1273 * freed.
1274 *
1275 * @retval "non-negative number" success
1276 * @retval "negative error code" failure
1277 */
1278int avfilter_graph_segment_parse(AVFilterGraph *graph, const char *graph_str,
1279 int flags, AVFilterGraphSegment **seg);
1280
1281/**
1282 * Create filters specified in a graph segment.
1283 *
1284 * Walk through the creation-pending AVFilterParams in the segment and create
1285 * new filter instances for them.
1286 * Creation-pending params are those where AVFilterParams.filter_name is
1287 * non-NULL (and hence AVFilterParams.filter is NULL). All other AVFilterParams
1288 * instances are ignored.
1289 *
1290 * For any filter created by this function, the corresponding
1291 * AVFilterParams.filter is set to the newly-created filter context,
1292 * AVFilterParams.filter_name and AVFilterParams.instance_name are freed and set
1293 * to NULL.
1294 *
1295 * @param seg the filtergraph segment to process
1296 * @param flags reserved for future use, caller must set to 0 for now
1297 *
1298 * @retval "non-negative number" Success, all creation-pending filters were
1299 * successfully created
1300 * @retval AVERROR_FILTER_NOT_FOUND some filter's name did not correspond to a
1301 * known filter
1302 * @retval "another negative error code" other failures
1303 *
1304 * @note Calling this function multiple times is safe, as it is idempotent.
1305 */
1307
1308/**
1309 * Apply parsed options to filter instances in a graph segment.
1310 *
1311 * Walk through all filter instances in the graph segment that have option
1312 * dictionaries associated with them and apply those options with
1313 * av_opt_set_dict2(..., AV_OPT_SEARCH_CHILDREN). AVFilterParams.opts is
1314 * replaced by the dictionary output by av_opt_set_dict2(), which should be
1315 * empty (NULL) if all options were successfully applied.
1316 *
1317 * If any options could not be found, this function will continue processing all
1318 * other filters and finally return AVERROR_OPTION_NOT_FOUND (unless another
1319 * error happens). The calling program may then deal with unapplied options as
1320 * it wishes.
1321 *
1322 * Any creation-pending filters (see avfilter_graph_segment_create_filters())
1323 * present in the segment will cause this function to fail. AVFilterParams with
1324 * no associated filter context are simply skipped.
1325 *
1326 * @param seg the filtergraph segment to process
1327 * @param flags reserved for future use, caller must set to 0 for now
1328 *
1329 * @retval "non-negative number" Success, all options were successfully applied.
1330 * @retval AVERROR_OPTION_NOT_FOUND some options were not found in a filter
1331 * @retval "another negative error code" other failures
1332 *
1333 * @note Calling this function multiple times is safe, as it is idempotent.
1334 */
1336
1337/**
1338 * Initialize all filter instances in a graph segment.
1339 *
1340 * Walk through all filter instances in the graph segment and call
1341 * avfilter_init_dict(..., NULL) on those that have not been initialized yet.
1342 *
1343 * Any creation-pending filters (see avfilter_graph_segment_create_filters())
1344 * present in the segment will cause this function to fail. AVFilterParams with
1345 * no associated filter context or whose filter context is already initialized,
1346 * are simply skipped.
1347 *
1348 * @param seg the filtergraph segment to process
1349 * @param flags reserved for future use, caller must set to 0 for now
1350 *
1351 * @retval "non-negative number" Success, all filter instances were successfully
1352 * initialized
1353 * @retval "negative error code" failure
1354 *
1355 * @note Calling this function multiple times is safe, as it is idempotent.
1356 */
1358
1359/**
1360 * Link filters in a graph segment.
1361 *
1362 * Walk through all filter instances in the graph segment and try to link all
1363 * unlinked input and output pads. Any creation-pending filters (see
1364 * avfilter_graph_segment_create_filters()) present in the segment will cause
1365 * this function to fail. Disabled filters and already linked pads are skipped.
1366 *
1367 * Every filter output pad that has a corresponding AVFilterPadParams with a
1368 * non-NULL label is
1369 * - linked to the input with the matching label, if one exists;
1370 * - exported in the outputs linked list otherwise, with the label preserved.
1371 * Unlabeled outputs are
1372 * - linked to the first unlinked unlabeled input in the next non-disabled
1373 * filter in the chain, if one exists
1374 * - exported in the ouputs linked list otherwise, with NULL label
1375 *
1376 * Similarly, unlinked input pads are exported in the inputs linked list.
1377 *
1378 * @param seg the filtergraph segment to process
1379 * @param flags reserved for future use, caller must set to 0 for now
1380 * @param[out] inputs a linked list of all free (unlinked) inputs of the
1381 * filters in this graph segment will be returned here. It
1382 * is to be freed by the caller using avfilter_inout_free().
1383 * @param[out] outputs a linked list of all free (unlinked) outputs of the
1384 * filters in this graph segment will be returned here. It
1385 * is to be freed by the caller using avfilter_inout_free().
1386 *
1387 * @retval "non-negative number" success
1388 * @retval "negative error code" failure
1389 *
1390 * @note Calling this function multiple times is safe, as it is idempotent.
1391 */
1393 AVFilterInOut **inputs,
1394 AVFilterInOut **outputs);
1395
1396/**
1397 * Apply all filter/link descriptions from a graph segment to the associated filtergraph.
1398 *
1399 * This functions is currently equivalent to calling the following in sequence:
1400 * - avfilter_graph_segment_create_filters();
1401 * - avfilter_graph_segment_apply_opts();
1402 * - avfilter_graph_segment_init();
1403 * - avfilter_graph_segment_link();
1404 * failing if any of them fails. This list may be extended in the future.
1405 *
1406 * Since the above functions are idempotent, the caller may call some of them
1407 * manually, then do some custom processing on the filtergraph, then call this
1408 * function to do the rest.
1409 *
1410 * @param seg the filtergraph segment to process
1411 * @param flags reserved for future use, caller must set to 0 for now
1412 * @param[out] inputs passed to avfilter_graph_segment_link()
1413 * @param[out] outputs passed to avfilter_graph_segment_link()
1414 *
1415 * @retval "non-negative number" success
1416 * @retval "negative error code" failure
1417 *
1418 * @note Calling this function multiple times is safe, as it is idempotent.
1419 */
1421 AVFilterInOut **inputs,
1422 AVFilterInOut **outputs);
1423
1424/**
1425 * Free the provided AVFilterGraphSegment and everything associated with it.
1426 *
1427 * @param seg double pointer to the AVFilterGraphSegment to be freed. NULL will
1428 * be written to this pointer on exit from this function.
1429 *
1430 * @note
1431 * The filter contexts (AVFilterParams.filter) are owned by AVFilterGraph rather
1432 * than AVFilterGraphSegment, so they are not freed.
1433 */
1435
1436/**
1437 * Send a command to one or more filter instances.
1438 *
1439 * @param graph the filter graph
1440 * @param target the filter(s) to which the command should be sent
1441 * "all" sends to all filters
1442 * otherwise it can be a filter or filter instance name
1443 * which will send the command to all matching filters.
1444 * @param cmd the command to send, for handling simplicity all commands must be alphanumeric only
1445 * @param arg the argument for the command
1446 * @param res a buffer with size res_size where the filter(s) can return a response.
1447 *
1448 * @returns >=0 on success otherwise an error code.
1449 * AVERROR(ENOSYS) on unsupported commands
1450 */
1451int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
1452
1453/**
1454 * Queue a command for one or more filter instances.
1455 *
1456 * @param graph the filter graph
1457 * @param target the filter(s) to which the command should be sent
1458 * "all" sends to all filters
1459 * otherwise it can be a filter or filter instance name
1460 * which will send the command to all matching filters.
1461 * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
1462 * @param arg the argument for the command
1463 * @param ts time at which the command should be sent to the filter
1464 *
1465 * @note As this executes commands after this function returns, no return code
1466 * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
1467 */
1468int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
1469
1470
1471/**
1472 * Dump a graph into a human-readable string representation.
1473 *
1474 * @param graph the graph to dump
1475 * @param options formatting options; currently ignored
1476 * @return a string, or NULL in case of memory allocation failure;
1477 * the string must be freed using av_free
1478 */
1479char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
1480
1481/**
1482 * Request a frame on the oldest sink link.
1483 *
1484 * If the request returns AVERROR_EOF, try the next.
1485 *
1486 * Note that this function is not meant to be the sole scheduling mechanism
1487 * of a filtergraph, only a convenience function to help drain a filtergraph
1488 * in a balanced way under normal circumstances.
1489 *
1490 * Also note that AVERROR_EOF does not mean that frames did not arrive on
1491 * some of the sinks during the process.
1492 * When there are multiple sink links, in case the requested link
1493 * returns an EOF, this may cause a filter to flush pending frames
1494 * which are sent to another sink link, although unrequested.
1495 *
1496 * @return the return value of ff_request_frame(),
1497 * or AVERROR_EOF if all links returned AVERROR_EOF
1498 */
1500
1501/**
1502 * @}
1503 */
1504
1505#endif /* AVFILTER_AVFILTER_H */
Macro definitions for various function/variable attributes.
#define attribute_deprecated
Definition: attributes.h:100
Convenience header that includes libavutil's core.
refcounted data buffer API
Public dictionary API.
reference-counted frame API
struct AVFilterPad AVFilterPad
Definition: avfilter.h:75
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
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.
void avfilter_free(AVFilterContext *filter)
Free a filter context.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
char * avfilter_graph_dump(AVFilterGraph *graph, const char *options)
Dump a graph into a human-readable string representation.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
int avfilter_graph_segment_parse(AVFilterGraph *graph, const char *graph_str, int flags, AVFilterGraphSegment **seg)
Parse a textual filtergraph description into an intermediate form.
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.
const char * avfilter_configuration(void)
Return the libavfilter build-time configuration.
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.
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, const char *name)
Get a filter instance identified by instance name from graph.
void avfilter_graph_segment_free(AVFilterGraphSegment **seg)
Free the provided AVFilterGraphSegment and everything associated with it.
unsigned avfilter_filter_pad_count(const AVFilter *filter, int is_output)
Get the number of elements in an AVFilter's inputs or outputs array.
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
const AVFilter * av_filter_iterate(void **opaque)
Iterate over all registered filters.
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
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.
struct AVFilterInternal AVFilterInternal
Definition: avfilter.h:394
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
int avfilter_graph_segment_apply_opts(AVFilterGraphSegment *seg, int flags)
Apply parsed options to filter instances in a graph segment.
const char * avfilter_license(void)
Return the libavfilter license.
struct AVFilterChannelLayouts AVFilterChannelLayouts
Definition: avfilter.h:77
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:852
int avfilter_graph_segment_init(AVFilterGraphSegment *seg, int flags)
Initialize all filter instances in a graph segment.
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:866
struct AVFilterGraphInternal AVFilterGraphInternal
Definition: avfilter.h:838
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.
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
unsigned avfilter_version(void)
Return the LIBAVFILTER_VERSION_INT constant.
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.
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
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.
const AVClass * avfilter_get_class(void)
struct AVFilterFormats AVFilterFormats
Definition: avfilter.h:76
void avfilter_link_free(AVFilterLink **link)
Free the link in *link, and set its pointer to NULL.
int avfilter_graph_segment_link(AVFilterGraphSegment *seg, int flags, AVFilterInOut **inputs, AVFilterInOut **outputs)
Link filters in a graph segment.
int avfilter_graph_segment_apply(AVFilterGraphSegment *seg, int flags, AVFilterInOut **inputs, AVFilterInOut **outputs)
Apply all filter/link descriptions from a graph segment to the associated filtergraph.
int avfilter_graph_segment_create_filters(AVFilterGraphSegment *seg, int flags)
Create filters specified in a graph segment.
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
Definition: avfilter.h:1002
@ AVFILTER_AUTO_CONVERT_ALL
all automatic conversions enabled
Definition: avfilter.h:1001
struct AVDictionary AVDictionary
Definition: dict.h:94
AVMediaType
Definition: avutil.h:199
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
Libavfilter version macros.
Libavfilter version macros.
pixel format definitions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
Utilties for rational number calculation.
A reference to a data buffer.
Definition: buffer.h:82
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition: log.h:66
A filterchain is a list of filter specifications.
Definition: avfilter.h:1215
size_t nb_filters
Definition: avfilter.h:1217
AVFilterParams ** filters
Definition: avfilter.h:1216
An instance of a filter.
Definition: avfilter.h:397
const AVClass * av_class
needed for av_log() and filters common options
Definition: avfilter.h:398
int nb_threads
Max number of threads allowed in this filter instance.
Definition: avfilter.h:464
int thread_type
Type of multithreading being allowed/used.
Definition: avfilter.h:432
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:487
char * name
name of this filter instance
Definition: avfilter.h:402
void * enable
parsed expression (AVExpr*)
Definition: avfilter.h:442
unsigned nb_inputs
number of input pads
Definition: avfilter.h:406
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:405
char * enable_str
enable expression string
Definition: avfilter.h:441
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:400
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:437
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:414
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:404
void * priv
private data for use by the filter
Definition: avfilter.h:412
unsigned nb_outputs
number of output pads
Definition: avfilter.h:410
unsigned ready
Ready status of the filter.
Definition: avfilter.h:471
struct AVFilterCommand * command_queue
Definition: avfilter.h:439
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:408
double * var_values
variable values for the enable expression
Definition: avfilter.h:443
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:444
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
Definition: avfilter.h:457
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:409
Lists of formats / etc.
Definition: avfilter.h:500
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:505
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:515
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:510
A parsed representation of a filtergraph segment.
Definition: avfilter.h:1229
char * scale_sws_opts
A string containing a colon-separated list of key=value options applied to all scale filters in this ...
Definition: avfilter.h:1251
AVFilterGraph * graph
The filtergraph this segment is associated with.
Definition: avfilter.h:1234
AVFilterChain ** chains
A list of filter chain contained in this segment.
Definition: avfilter.h:1240
unsigned nb_filters
Definition: avfilter.h:872
AVFilterLink ** sink_links
Private fields.
Definition: avfilter.h:932
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:874
AVFilterContext ** filters
Definition: avfilter.h:871
void * opaque
Opaque user data.
Definition: avfilter.h:907
char * aresample_swr_opts
swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
Definition: avfilter.h:923
AVFilterGraphInternal * internal
Opaque object for libavfilter internal use.
Definition: avfilter.h:900
unsigned disable_auto_convert
Definition: avfilter.h:935
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:888
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:921
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:895
const AVClass * av_class
Definition: avfilter.h:870
int sink_links_count
Definition: avfilter.h:933
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1029
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1034
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1037
char * name
unique name for this input/output in the list
Definition: avfilter.h:1031
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1040
Parameters of a filter's input or output pad.
Definition: avfilter.h:1131
char * label
An av_malloc()'ed string containing the pad label.
Definition: avfilter.h:1139
Parameters describing a filter to be created in a filtergraph.
Definition: avfilter.h:1148
char * instance_name
Name to be used for this filter instance.
Definition: avfilter.h:1188
unsigned nb_inputs
Definition: avfilter.h:1203
AVFilterPadParams ** inputs
Definition: avfilter.h:1202
AVFilterPadParams ** outputs
Definition: avfilter.h:1205
unsigned nb_outputs
Definition: avfilter.h:1206
AVDictionary * opts
Options to be apllied to the filter.
Definition: avfilter.h:1200
AVFilterContext * filter
The filter context.
Definition: avfilter.h:1159
char * filter_name
Name of the AVFilter to be used.
Definition: avfilter.h:1176
Filter definition.
Definition: avfilter.h:166
uint8_t nb_inputs
The number of entries in the list of inputs.
Definition: avfilter.h:223
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:367
const char * name
Filter name.
Definition: avfilter.h:170
enum AVSampleFormat sample_fmt
Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
Definition: avfilter.h:348
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
Definition: avfilter.h:284
int(* query_func)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:318
int flags
A combination of AVFILTER_FLAG_*.
Definition: avfilter.h:210
uint8_t formats_state
This field determines the state of the formats union.
Definition: avfilter.h:234
union AVFilter::@1 formats
The state of the following union is determined by formats_state.
int(* preinit)(AVFilterContext *ctx)
Filter pre-initialization function.
Definition: avfilter.h:249
enum AVSampleFormat * samples_list
Analogous to pixels, but delimited by AV_SAMPLE_FMT_NONE and restricted to filters that only have AVM...
Definition: avfilter.h:340
int flags_internal
Additional flags for avfilter internal use only.
Definition: avfilter.h:353
const AVClass * priv_class
A class for the private data, used to declare filter private AVOptions.
Definition: avfilter.h:205
uint8_t nb_outputs
The number of entries in the list of outputs.
Definition: avfilter.h:228
int priv_size
size of private data to allocate for the filter
Definition: avfilter.h:351
int(* init)(AVFilterContext *ctx)
Filter initialization function.
Definition: avfilter.h:272
const AVFilterPad * outputs
List of static outputs.
Definition: avfilter.h:195
const AVFilterPad * inputs
List of static inputs.
Definition: avfilter.h:186
enum AVPixelFormat pix_fmt
Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
Definition: avfilter.h:344
enum AVPixelFormat * pixels_list
A pointer to an array of admissible pixel formats delimited by AV_PIX_FMT_NONE.
Definition: avfilter.h:329
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: avfilter.h:381
const char * description
A description of the filter.
Definition: avfilter.h:177
Rational number (pair of numerator and denominator).
Definition: rational.h:58