avfilter.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. #ifndef AVFILTER_AVFILTER_H
  22. #define AVFILTER_AVFILTER_H
  23. /**
  24. * @file
  25. * @ingroup lavfi
  26. * Main libavfilter public API header
  27. */
  28. /**
  29. * @defgroup lavfi Libavfilter - graph-based frame editing library
  30. * @{
  31. */
  32. #include <stddef.h>
  33. #include "libavutil/attributes.h"
  34. #include "libavutil/avutil.h"
  35. #include "libavutil/buffer.h"
  36. #include "libavutil/dict.h"
  37. #include "libavutil/frame.h"
  38. #include "libavutil/log.h"
  39. #include "libavutil/samplefmt.h"
  40. #include "libavutil/pixfmt.h"
  41. #include "libavutil/rational.h"
  42. #include "libavfilter/version.h"
  43. /**
  44. * Return the LIBAVFILTER_VERSION_INT constant.
  45. */
  46. unsigned avfilter_version(void);
  47. /**
  48. * Return the libavfilter build-time configuration.
  49. */
  50. const char *avfilter_configuration(void);
  51. /**
  52. * Return the libavfilter license.
  53. */
  54. const char *avfilter_license(void);
  55. typedef struct AVFilterContext AVFilterContext;
  56. typedef struct AVFilterLink AVFilterLink;
  57. typedef struct AVFilterPad AVFilterPad;
  58. typedef struct AVFilterFormats AVFilterFormats;
  59. /**
  60. * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
  61. * AVFilter.inputs/outputs).
  62. */
  63. int avfilter_pad_count(const AVFilterPad *pads);
  64. /**
  65. * Get the name of an AVFilterPad.
  66. *
  67. * @param pads an array of AVFilterPads
  68. * @param pad_idx index of the pad in the array it; is the caller's
  69. * responsibility to ensure the index is valid
  70. *
  71. * @return name of the pad_idx'th pad in pads
  72. */
  73. const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
  74. /**
  75. * Get the type of an AVFilterPad.
  76. *
  77. * @param pads an array of AVFilterPads
  78. * @param pad_idx index of the pad in the array; it is the caller's
  79. * responsibility to ensure the index is valid
  80. *
  81. * @return type of the pad_idx'th pad in pads
  82. */
  83. enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
  84. /**
  85. * The number of the filter inputs is not determined just by AVFilter.inputs.
  86. * The filter might add additional inputs during initialization depending on the
  87. * options supplied to it.
  88. */
  89. #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
  90. /**
  91. * The number of the filter outputs is not determined just by AVFilter.outputs.
  92. * The filter might add additional outputs during initialization depending on
  93. * the options supplied to it.
  94. */
  95. #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
  96. /**
  97. * The filter supports multithreading by splitting frames into multiple parts
  98. * and processing them concurrently.
  99. */
  100. #define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
  101. /**
  102. * Some filters support a generic "enable" expression option that can be used
  103. * to enable or disable a filter in the timeline. Filters supporting this
  104. * option have this flag set. When the enable expression is false, the default
  105. * no-op filter_frame() function is called in place of the filter_frame()
  106. * callback defined on each input pad, thus the frame is passed unchanged to
  107. * the next filters.
  108. */
  109. #define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC (1 << 16)
  110. /**
  111. * Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will
  112. * have its filter_frame() callback(s) called as usual even when the enable
  113. * expression is false. The filter will disable filtering within the
  114. * filter_frame() callback(s) itself, for example executing code depending on
  115. * the AVFilterContext->is_disabled value.
  116. */
  117. #define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL (1 << 17)
  118. /**
  119. * Handy mask to test whether the filter supports or no the timeline feature
  120. * (internally or generically).
  121. */
  122. #define AVFILTER_FLAG_SUPPORT_TIMELINE (AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL)
  123. /**
  124. * Filter definition. This defines the pads a filter contains, and all the
  125. * callback functions used to interact with the filter.
  126. */
  127. typedef struct AVFilter {
  128. /**
  129. * Filter name. Must be non-NULL and unique among filters.
  130. */
  131. const char *name;
  132. /**
  133. * A description of the filter. May be NULL.
  134. *
  135. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  136. */
  137. const char *description;
  138. /**
  139. * List of inputs, terminated by a zeroed element.
  140. *
  141. * NULL if there are no (static) inputs. Instances of filters with
  142. * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
  143. * this list.
  144. */
  145. const AVFilterPad *inputs;
  146. /**
  147. * List of outputs, terminated by a zeroed element.
  148. *
  149. * NULL if there are no (static) outputs. Instances of filters with
  150. * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
  151. * this list.
  152. */
  153. const AVFilterPad *outputs;
  154. /**
  155. * A class for the private data, used to declare filter private AVOptions.
  156. * This field is NULL for filters that do not declare any options.
  157. *
  158. * If this field is non-NULL, the first member of the filter private data
  159. * must be a pointer to AVClass, which will be set by libavfilter generic
  160. * code to this class.
  161. */
  162. const AVClass *priv_class;
  163. /**
  164. * A combination of AVFILTER_FLAG_*
  165. */
  166. int flags;
  167. /*****************************************************************
  168. * All fields below this line are not part of the public API. They
  169. * may not be used outside of libavfilter and can be changed and
  170. * removed at will.
  171. * New public fields should be added right above.
  172. *****************************************************************
  173. */
  174. /**
  175. * Filter initialization function.
  176. *
  177. * This callback will be called only once during the filter lifetime, after
  178. * all the options have been set, but before links between filters are
  179. * established and format negotiation is done.
  180. *
  181. * Basic filter initialization should be done here. Filters with dynamic
  182. * inputs and/or outputs should create those inputs/outputs here based on
  183. * provided options. No more changes to this filter's inputs/outputs can be
  184. * done after this callback.
  185. *
  186. * This callback must not assume that the filter links exist or frame
  187. * parameters are known.
  188. *
  189. * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
  190. * initialization fails, so this callback does not have to clean up on
  191. * failure.
  192. *
  193. * @return 0 on success, a negative AVERROR on failure
  194. */
  195. int (*init)(AVFilterContext *ctx);
  196. /**
  197. * Should be set instead of @ref AVFilter.init "init" by the filters that
  198. * want to pass a dictionary of AVOptions to nested contexts that are
  199. * allocated during init.
  200. *
  201. * On return, the options dict should be freed and replaced with one that
  202. * contains all the options which could not be processed by this filter (or
  203. * with NULL if all the options were processed).
  204. *
  205. * Otherwise the semantics is the same as for @ref AVFilter.init "init".
  206. */
  207. int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
  208. /**
  209. * Filter uninitialization function.
  210. *
  211. * Called only once right before the filter is freed. Should deallocate any
  212. * memory held by the filter, release any buffer references, etc. It does
  213. * not need to deallocate the AVFilterContext.priv memory itself.
  214. *
  215. * This callback may be called even if @ref AVFilter.init "init" was not
  216. * called or failed, so it must be prepared to handle such a situation.
  217. */
  218. void (*uninit)(AVFilterContext *ctx);
  219. /**
  220. * Query formats supported by the filter on its inputs and outputs.
  221. *
  222. * This callback is called after the filter is initialized (so the inputs
  223. * and outputs are fixed), shortly before the format negotiation. This
  224. * callback may be called more than once.
  225. *
  226. * This callback must set AVFilterLink.out_formats on every input link and
  227. * AVFilterLink.in_formats on every output link to a list of pixel/sample
  228. * formats that the filter supports on that link. For audio links, this
  229. * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
  230. * @ref AVFilterLink.out_samplerates "out_samplerates" and
  231. * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
  232. * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
  233. *
  234. * This callback may be NULL for filters with one input, in which case
  235. * libavfilter assumes that it supports all input formats and preserves
  236. * them on output.
  237. *
  238. * @return zero on success, a negative value corresponding to an
  239. * AVERROR code otherwise
  240. */
  241. int (*query_formats)(AVFilterContext *);
  242. int priv_size; ///< size of private data to allocate for the filter
  243. /**
  244. * Used by the filter registration system. Must not be touched by any other
  245. * code.
  246. */
  247. struct AVFilter *next;
  248. /**
  249. * Make the filter instance process a command.
  250. *
  251. * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
  252. * @param arg the argument for the command
  253. * @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.
  254. * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
  255. * time consuming then a filter should treat it like an unsupported command
  256. *
  257. * @returns >=0 on success otherwise an error code.
  258. * AVERROR(ENOSYS) on unsupported commands
  259. */
  260. int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
  261. /**
  262. * Filter initialization function, alternative to the init()
  263. * callback. Args contains the user-supplied parameters, opaque is
  264. * used for providing binary data.
  265. */
  266. int (*init_opaque)(AVFilterContext *ctx, void *opaque);
  267. } AVFilter;
  268. /**
  269. * Process multiple parts of the frame concurrently.
  270. */
  271. #define AVFILTER_THREAD_SLICE (1 << 0)
  272. typedef struct AVFilterInternal AVFilterInternal;
  273. /** An instance of a filter */
  274. struct AVFilterContext {
  275. const AVClass *av_class; ///< needed for av_log() and filters common options
  276. const AVFilter *filter; ///< the AVFilter of which this is an instance
  277. char *name; ///< name of this filter instance
  278. AVFilterPad *input_pads; ///< array of input pads
  279. AVFilterLink **inputs; ///< array of pointers to input links
  280. unsigned nb_inputs; ///< number of input pads
  281. AVFilterPad *output_pads; ///< array of output pads
  282. AVFilterLink **outputs; ///< array of pointers to output links
  283. unsigned nb_outputs; ///< number of output pads
  284. void *priv; ///< private data for use by the filter
  285. struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
  286. /**
  287. * Type of multithreading being allowed/used. A combination of
  288. * AVFILTER_THREAD_* flags.
  289. *
  290. * May be set by the caller before initializing the filter to forbid some
  291. * or all kinds of multithreading for this filter. The default is allowing
  292. * everything.
  293. *
  294. * When the filter is initialized, this field is combined using bit AND with
  295. * AVFilterGraph.thread_type to get the final mask used for determining
  296. * allowed threading types. I.e. a threading type needs to be set in both
  297. * to be allowed.
  298. *
  299. * After the filter is initialized, libavfilter sets this field to the
  300. * threading type that is actually used (0 for no multithreading).
  301. */
  302. int thread_type;
  303. /**
  304. * An opaque struct for libavfilter internal use.
  305. */
  306. AVFilterInternal *internal;
  307. struct AVFilterCommand *command_queue;
  308. char *enable_str; ///< enable expression string
  309. void *enable; ///< parsed expression (AVExpr*)
  310. double *var_values; ///< variable values for the enable expression
  311. int is_disabled; ///< the enabled state from the last expression evaluation
  312. /**
  313. * For filters which will create hardware frames, sets the device the
  314. * filter should create them in. All other filters will ignore this field:
  315. * in particular, a filter which consumes or processes hardware frames will
  316. * instead use the hw_frames_ctx field in AVFilterLink to carry the
  317. * hardware context information.
  318. */
  319. AVBufferRef *hw_device_ctx;
  320. };
  321. /**
  322. * A link between two filters. This contains pointers to the source and
  323. * destination filters between which this link exists, and the indexes of
  324. * the pads involved. In addition, this link also contains the parameters
  325. * which have been negotiated and agreed upon between the filter, such as
  326. * image dimensions, format, etc.
  327. */
  328. struct AVFilterLink {
  329. AVFilterContext *src; ///< source filter
  330. AVFilterPad *srcpad; ///< output pad on the source filter
  331. AVFilterContext *dst; ///< dest filter
  332. AVFilterPad *dstpad; ///< input pad on the dest filter
  333. enum AVMediaType type; ///< filter media type
  334. /* These parameters apply only to video */
  335. int w; ///< agreed upon image width
  336. int h; ///< agreed upon image height
  337. AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
  338. /* These parameters apply only to audio */
  339. uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
  340. int sample_rate; ///< samples per second
  341. int format; ///< agreed upon media format
  342. /**
  343. * Define the time base used by the PTS of the frames/samples
  344. * which will pass through this link.
  345. * During the configuration stage, each filter is supposed to
  346. * change only the output timebase, while the timebase of the
  347. * input link is assumed to be an unchangeable property.
  348. */
  349. AVRational time_base;
  350. /*****************************************************************
  351. * All fields below this line are not part of the public API. They
  352. * may not be used outside of libavfilter and can be changed and
  353. * removed at will.
  354. * New public fields should be added right above.
  355. *****************************************************************
  356. */
  357. /**
  358. * Lists of formats and channel layouts supported by the input and output
  359. * filters respectively. These lists are used for negotiating the format
  360. * to actually be used, which will be loaded into the format and
  361. * channel_layout members, above, when chosen.
  362. *
  363. */
  364. AVFilterFormats *in_formats;
  365. AVFilterFormats *out_formats;
  366. /**
  367. * Lists of channel layouts and sample rates used for automatic
  368. * negotiation.
  369. */
  370. AVFilterFormats *in_samplerates;
  371. AVFilterFormats *out_samplerates;
  372. struct AVFilterChannelLayouts *in_channel_layouts;
  373. struct AVFilterChannelLayouts *out_channel_layouts;
  374. /**
  375. * Audio only, the destination filter sets this to a non-zero value to
  376. * request that buffers with the given number of samples should be sent to
  377. * it. AVFilterPad.needs_fifo must also be set on the corresponding input
  378. * pad.
  379. * Last buffer before EOF will be padded with silence.
  380. */
  381. int request_samples;
  382. /** stage of the initialization of the link properties (dimensions, etc) */
  383. enum {
  384. AVLINK_UNINIT = 0, ///< not started
  385. AVLINK_STARTINIT, ///< started, but incomplete
  386. AVLINK_INIT ///< complete
  387. } init_state;
  388. /**
  389. * Graph the filter belongs to.
  390. */
  391. struct AVFilterGraph *graph;
  392. /**
  393. * Current timestamp of the link, as defined by the most recent
  394. * frame(s), in link time_base units.
  395. */
  396. int64_t current_pts;
  397. /**
  398. * Current timestamp of the link, as defined by the most recent
  399. * frame(s), in AV_TIME_BASE units.
  400. */
  401. int64_t current_pts_us;
  402. /**
  403. * Index in the age array.
  404. */
  405. int age_index;
  406. /**
  407. * Frame rate of the stream on the link, or 1/0 if unknown or variable;
  408. * if left to 0/0, will be automatically copied from the first input
  409. * of the source filter if it exists.
  410. *
  411. * Sources should set it to the best estimation of the real frame rate.
  412. * If the source frame rate is unknown or variable, set this to 1/0.
  413. * Filters should update it if necessary depending on their function.
  414. * Sinks can use it to set a default output frame rate.
  415. * It is similar to the r_frame_rate field in AVStream.
  416. */
  417. AVRational frame_rate;
  418. /**
  419. * Buffer partially filled with samples to achieve a fixed/minimum size.
  420. */
  421. AVFrame *partial_buf;
  422. /**
  423. * Size of the partial buffer to allocate.
  424. * Must be between min_samples and max_samples.
  425. */
  426. int partial_buf_size;
  427. /**
  428. * Minimum number of samples to filter at once. If filter_frame() is
  429. * called with fewer samples, it will accumulate them in partial_buf.
  430. * This field and the related ones must not be changed after filtering
  431. * has started.
  432. * If 0, all related fields are ignored.
  433. */
  434. int min_samples;
  435. /**
  436. * Maximum number of samples to filter at once. If filter_frame() is
  437. * called with more samples, it will split them.
  438. */
  439. int max_samples;
  440. /**
  441. * Link status.
  442. * If not zero, all attempts of filter_frame or request_frame
  443. * will fail with the corresponding code, and if necessary the reference
  444. * will be destroyed.
  445. * If request_frame returns an error, the status is set on the
  446. * corresponding link.
  447. * It can be set also be set by either the source or the destination
  448. * filter.
  449. */
  450. int status;
  451. /**
  452. * Number of channels.
  453. */
  454. int channels;
  455. /**
  456. * Link processing flags.
  457. */
  458. unsigned flags;
  459. /**
  460. * Number of past frames sent through the link.
  461. */
  462. int64_t frame_count;
  463. /**
  464. * A pointer to a FFVideoFramePool struct.
  465. */
  466. void *video_frame_pool;
  467. /**
  468. * True if a frame is currently wanted on the input of this filter.
  469. * Set when ff_request_frame() is called by the output,
  470. * cleared when the request is handled or forwarded.
  471. */
  472. int frame_wanted_in;
  473. /**
  474. * True if a frame is currently wanted on the output of this filter.
  475. * Set when ff_request_frame() is called by the output,
  476. * cleared when a frame is filtered.
  477. */
  478. int frame_wanted_out;
  479. /**
  480. * For hwaccel pixel formats, this should be a reference to the
  481. * AVHWFramesContext describing the frames.
  482. */
  483. AVBufferRef *hw_frames_ctx;
  484. };
  485. /**
  486. * Link two filters together.
  487. *
  488. * @param src the source filter
  489. * @param srcpad index of the output pad on the source filter
  490. * @param dst the destination filter
  491. * @param dstpad index of the input pad on the destination filter
  492. * @return zero on success
  493. */
  494. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  495. AVFilterContext *dst, unsigned dstpad);
  496. /**
  497. * Free the link in *link, and set its pointer to NULL.
  498. */
  499. void avfilter_link_free(AVFilterLink **link);
  500. /**
  501. * Get the number of channels of a link.
  502. */
  503. int avfilter_link_get_channels(AVFilterLink *link);
  504. /**
  505. * Set the closed field of a link.
  506. * @deprecated applications are not supposed to mess with links, they should
  507. * close the sinks.
  508. */
  509. attribute_deprecated
  510. void avfilter_link_set_closed(AVFilterLink *link, int closed);
  511. /**
  512. * Negotiate the media format, dimensions, etc of all inputs to a filter.
  513. *
  514. * @param filter the filter to negotiate the properties for its inputs
  515. * @return zero on successful negotiation
  516. */
  517. int avfilter_config_links(AVFilterContext *filter);
  518. #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
  519. #define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
  520. /**
  521. * Make the filter instance process a command.
  522. * It is recommended to use avfilter_graph_send_command().
  523. */
  524. int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
  525. /** Initialize the filter system. Register all builtin filters. */
  526. void avfilter_register_all(void);
  527. #if FF_API_OLD_FILTER_REGISTER
  528. /** Uninitialize the filter system. Unregister all filters. */
  529. attribute_deprecated
  530. void avfilter_uninit(void);
  531. #endif
  532. /**
  533. * Register a filter. This is only needed if you plan to use
  534. * avfilter_get_by_name later to lookup the AVFilter structure by name. A
  535. * filter can still by instantiated with avfilter_graph_alloc_filter even if it
  536. * is not registered.
  537. *
  538. * @param filter the filter to register
  539. * @return 0 if the registration was successful, a negative value
  540. * otherwise
  541. */
  542. int avfilter_register(AVFilter *filter);
  543. /**
  544. * Get a filter definition matching the given name.
  545. *
  546. * @param name the filter name to find
  547. * @return the filter definition, if any matching one is registered.
  548. * NULL if none found.
  549. */
  550. #if !FF_API_NOCONST_GET_NAME
  551. const
  552. #endif
  553. AVFilter *avfilter_get_by_name(const char *name);
  554. /**
  555. * Iterate over all registered filters.
  556. * @return If prev is non-NULL, next registered filter after prev or NULL if
  557. * prev is the last filter. If prev is NULL, return the first registered filter.
  558. */
  559. const AVFilter *avfilter_next(const AVFilter *prev);
  560. #if FF_API_OLD_FILTER_REGISTER
  561. /**
  562. * If filter is NULL, returns a pointer to the first registered filter pointer,
  563. * if filter is non-NULL, returns the next pointer after filter.
  564. * If the returned pointer points to NULL, the last registered filter
  565. * was already reached.
  566. * @deprecated use avfilter_next()
  567. */
  568. attribute_deprecated
  569. AVFilter **av_filter_next(AVFilter **filter);
  570. #endif
  571. #if FF_API_AVFILTER_OPEN
  572. /**
  573. * Create a filter instance.
  574. *
  575. * @param filter_ctx put here a pointer to the created filter context
  576. * on success, NULL on failure
  577. * @param filter the filter to create an instance of
  578. * @param inst_name Name to give to the new instance. Can be NULL for none.
  579. * @return >= 0 in case of success, a negative error code otherwise
  580. * @deprecated use avfilter_graph_alloc_filter() instead
  581. */
  582. attribute_deprecated
  583. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
  584. #endif
  585. #if FF_API_AVFILTER_INIT_FILTER
  586. /**
  587. * Initialize a filter.
  588. *
  589. * @param filter the filter to initialize
  590. * @param args A string of parameters to use when initializing the filter.
  591. * The format and meaning of this string varies by filter.
  592. * @param opaque Any extra non-string data needed by the filter. The meaning
  593. * of this parameter varies by filter.
  594. * @return zero on success
  595. */
  596. attribute_deprecated
  597. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  598. #endif
  599. /**
  600. * Initialize a filter with the supplied parameters.
  601. *
  602. * @param ctx uninitialized filter context to initialize
  603. * @param args Options to initialize the filter with. This must be a
  604. * ':'-separated list of options in the 'key=value' form.
  605. * May be NULL if the options have been set directly using the
  606. * AVOptions API or there are no options that need to be set.
  607. * @return 0 on success, a negative AVERROR on failure
  608. */
  609. int avfilter_init_str(AVFilterContext *ctx, const char *args);
  610. /**
  611. * Initialize a filter with the supplied dictionary of options.
  612. *
  613. * @param ctx uninitialized filter context to initialize
  614. * @param options An AVDictionary filled with options for this filter. On
  615. * return this parameter will be destroyed and replaced with
  616. * a dict containing options that were not found. This dictionary
  617. * must be freed by the caller.
  618. * May be NULL, then this function is equivalent to
  619. * avfilter_init_str() with the second parameter set to NULL.
  620. * @return 0 on success, a negative AVERROR on failure
  621. *
  622. * @note This function and avfilter_init_str() do essentially the same thing,
  623. * the difference is in manner in which the options are passed. It is up to the
  624. * calling code to choose whichever is more preferable. The two functions also
  625. * behave differently when some of the provided options are not declared as
  626. * supported by the filter. In such a case, avfilter_init_str() will fail, but
  627. * this function will leave those extra options in the options AVDictionary and
  628. * continue as usual.
  629. */
  630. int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
  631. /**
  632. * Free a filter context. This will also remove the filter from its
  633. * filtergraph's list of filters.
  634. *
  635. * @param filter the filter to free
  636. */
  637. void avfilter_free(AVFilterContext *filter);
  638. /**
  639. * Insert a filter in the middle of an existing link.
  640. *
  641. * @param link the link into which the filter should be inserted
  642. * @param filt the filter to be inserted
  643. * @param filt_srcpad_idx the input pad on the filter to connect
  644. * @param filt_dstpad_idx the output pad on the filter to connect
  645. * @return zero on success
  646. */
  647. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  648. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
  649. /**
  650. * @return AVClass for AVFilterContext.
  651. *
  652. * @see av_opt_find().
  653. */
  654. const AVClass *avfilter_get_class(void);
  655. typedef struct AVFilterGraphInternal AVFilterGraphInternal;
  656. /**
  657. * A function pointer passed to the @ref AVFilterGraph.execute callback to be
  658. * executed multiple times, possibly in parallel.
  659. *
  660. * @param ctx the filter context the job belongs to
  661. * @param arg an opaque parameter passed through from @ref
  662. * AVFilterGraph.execute
  663. * @param jobnr the index of the job being executed
  664. * @param nb_jobs the total number of jobs
  665. *
  666. * @return 0 on success, a negative AVERROR on error
  667. */
  668. typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
  669. /**
  670. * A function executing multiple jobs, possibly in parallel.
  671. *
  672. * @param ctx the filter context to which the jobs belong
  673. * @param func the function to be called multiple times
  674. * @param arg the argument to be passed to func
  675. * @param ret a nb_jobs-sized array to be filled with return values from each
  676. * invocation of func
  677. * @param nb_jobs the number of jobs to execute
  678. *
  679. * @return 0 on success, a negative AVERROR on error
  680. */
  681. typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
  682. void *arg, int *ret, int nb_jobs);
  683. typedef struct AVFilterGraph {
  684. const AVClass *av_class;
  685. AVFilterContext **filters;
  686. unsigned nb_filters;
  687. char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
  688. char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
  689. /**
  690. * Type of multithreading allowed for filters in this graph. A combination
  691. * of AVFILTER_THREAD_* flags.
  692. *
  693. * May be set by the caller at any point, the setting will apply to all
  694. * filters initialized after that. The default is allowing everything.
  695. *
  696. * When a filter in this graph is initialized, this field is combined using
  697. * bit AND with AVFilterContext.thread_type to get the final mask used for
  698. * determining allowed threading types. I.e. a threading type needs to be
  699. * set in both to be allowed.
  700. */
  701. int thread_type;
  702. /**
  703. * Maximum number of threads used by filters in this graph. May be set by
  704. * the caller before adding any filters to the filtergraph. Zero (the
  705. * default) means that the number of threads is determined automatically.
  706. */
  707. int nb_threads;
  708. /**
  709. * Opaque object for libavfilter internal use.
  710. */
  711. AVFilterGraphInternal *internal;
  712. /**
  713. * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
  714. * be used from callbacks like @ref AVFilterGraph.execute.
  715. * Libavfilter will not touch this field in any way.
  716. */
  717. void *opaque;
  718. /**
  719. * This callback may be set by the caller immediately after allocating the
  720. * graph and before adding any filters to it, to provide a custom
  721. * multithreading implementation.
  722. *
  723. * If set, filters with slice threading capability will call this callback
  724. * to execute multiple jobs in parallel.
  725. *
  726. * If this field is left unset, libavfilter will use its internal
  727. * implementation, which may or may not be multithreaded depending on the
  728. * platform and build options.
  729. */
  730. avfilter_execute_func *execute;
  731. char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
  732. /**
  733. * Private fields
  734. *
  735. * The following fields are for internal use only.
  736. * Their type, offset, number and semantic can change without notice.
  737. */
  738. AVFilterLink **sink_links;
  739. int sink_links_count;
  740. unsigned disable_auto_convert;
  741. } AVFilterGraph;
  742. /**
  743. * Allocate a filter graph.
  744. *
  745. * @return the allocated filter graph on success or NULL.
  746. */
  747. AVFilterGraph *avfilter_graph_alloc(void);
  748. /**
  749. * Create a new filter instance in a filter graph.
  750. *
  751. * @param graph graph in which the new filter will be used
  752. * @param filter the filter to create an instance of
  753. * @param name Name to give to the new instance (will be copied to
  754. * AVFilterContext.name). This may be used by the caller to identify
  755. * different filters, libavfilter itself assigns no semantics to
  756. * this parameter. May be NULL.
  757. *
  758. * @return the context of the newly created filter instance (note that it is
  759. * also retrievable directly through AVFilterGraph.filters or with
  760. * avfilter_graph_get_filter()) on success or NULL on failure.
  761. */
  762. AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
  763. const AVFilter *filter,
  764. const char *name);
  765. /**
  766. * Get a filter instance identified by instance name from graph.
  767. *
  768. * @param graph filter graph to search through.
  769. * @param name filter instance name (should be unique in the graph).
  770. * @return the pointer to the found filter instance or NULL if it
  771. * cannot be found.
  772. */
  773. AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name);
  774. #if FF_API_AVFILTER_OPEN
  775. /**
  776. * Add an existing filter instance to a filter graph.
  777. *
  778. * @param graphctx the filter graph
  779. * @param filter the filter to be added
  780. *
  781. * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
  782. * filter graph
  783. */
  784. attribute_deprecated
  785. int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
  786. #endif
  787. /**
  788. * Create and add a filter instance into an existing graph.
  789. * The filter instance is created from the filter filt and inited
  790. * with the parameters args and opaque.
  791. *
  792. * In case of success put in *filt_ctx the pointer to the created
  793. * filter instance, otherwise set *filt_ctx to NULL.
  794. *
  795. * @param name the instance name to give to the created filter instance
  796. * @param graph_ctx the filter graph
  797. * @return a negative AVERROR error code in case of failure, a non
  798. * negative value otherwise
  799. */
  800. int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
  801. const char *name, const char *args, void *opaque,
  802. AVFilterGraph *graph_ctx);
  803. /**
  804. * Enable or disable automatic format conversion inside the graph.
  805. *
  806. * Note that format conversion can still happen inside explicitly inserted
  807. * scale and aresample filters.
  808. *
  809. * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
  810. */
  811. void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags);
  812. enum {
  813. AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
  814. AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
  815. };
  816. /**
  817. * Check validity and configure all the links and formats in the graph.
  818. *
  819. * @param graphctx the filter graph
  820. * @param log_ctx context used for logging
  821. * @return >= 0 in case of success, a negative AVERROR code otherwise
  822. */
  823. int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
  824. /**
  825. * Free a graph, destroy its links, and set *graph to NULL.
  826. * If *graph is NULL, do nothing.
  827. */
  828. void avfilter_graph_free(AVFilterGraph **graph);
  829. /**
  830. * A linked-list of the inputs/outputs of the filter chain.
  831. *
  832. * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
  833. * where it is used to communicate open (unlinked) inputs and outputs from and
  834. * to the caller.
  835. * This struct specifies, per each not connected pad contained in the graph, the
  836. * filter context and the pad index required for establishing a link.
  837. */
  838. typedef struct AVFilterInOut {
  839. /** unique name for this input/output in the list */
  840. char *name;
  841. /** filter context associated to this input/output */
  842. AVFilterContext *filter_ctx;
  843. /** index of the filt_ctx pad to use for linking */
  844. int pad_idx;
  845. /** next input/input in the list, NULL if this is the last */
  846. struct AVFilterInOut *next;
  847. } AVFilterInOut;
  848. /**
  849. * Allocate a single AVFilterInOut entry.
  850. * Must be freed with avfilter_inout_free().
  851. * @return allocated AVFilterInOut on success, NULL on failure.
  852. */
  853. AVFilterInOut *avfilter_inout_alloc(void);
  854. /**
  855. * Free the supplied list of AVFilterInOut and set *inout to NULL.
  856. * If *inout is NULL, do nothing.
  857. */
  858. void avfilter_inout_free(AVFilterInOut **inout);
  859. /**
  860. * Add a graph described by a string to a graph.
  861. *
  862. * @note The caller must provide the lists of inputs and outputs,
  863. * which therefore must be known before calling the function.
  864. *
  865. * @note The inputs parameter describes inputs of the already existing
  866. * part of the graph; i.e. from the point of view of the newly created
  867. * part, they are outputs. Similarly the outputs parameter describes
  868. * outputs of the already existing filters, which are provided as
  869. * inputs to the parsed filters.
  870. *
  871. * @param graph the filter graph where to link the parsed graph context
  872. * @param filters string to be parsed
  873. * @param inputs linked list to the inputs of the graph
  874. * @param outputs linked list to the outputs of the graph
  875. * @return zero on success, a negative AVERROR code on error
  876. */
  877. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  878. AVFilterInOut *inputs, AVFilterInOut *outputs,
  879. void *log_ctx);
  880. /**
  881. * Add a graph described by a string to a graph.
  882. *
  883. * In the graph filters description, if the input label of the first
  884. * filter is not specified, "in" is assumed; if the output label of
  885. * the last filter is not specified, "out" is assumed.
  886. *
  887. * @param graph the filter graph where to link the parsed graph context
  888. * @param filters string to be parsed
  889. * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
  890. * If non-NULL, *inputs is updated to contain the list of open inputs
  891. * after the parsing, should be freed with avfilter_inout_free().
  892. * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
  893. * If non-NULL, *outputs is updated to contain the list of open outputs
  894. * after the parsing, should be freed with avfilter_inout_free().
  895. * @return non negative on success, a negative AVERROR code on error
  896. */
  897. int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
  898. AVFilterInOut **inputs, AVFilterInOut **outputs,
  899. void *log_ctx);
  900. /**
  901. * Add a graph described by a string to a graph.
  902. *
  903. * @param[in] graph the filter graph where to link the parsed graph context
  904. * @param[in] filters string to be parsed
  905. * @param[out] inputs a linked list of all free (unlinked) inputs of the
  906. * parsed graph will be returned here. It is to be freed
  907. * by the caller using avfilter_inout_free().
  908. * @param[out] outputs a linked list of all free (unlinked) outputs of the
  909. * parsed graph will be returned here. It is to be freed by the
  910. * caller using avfilter_inout_free().
  911. * @return zero on success, a negative AVERROR code on error
  912. *
  913. * @note This function returns the inputs and outputs that are left
  914. * unlinked after parsing the graph and the caller then deals with
  915. * them.
  916. * @note This function makes no reference whatsoever to already
  917. * existing parts of the graph and the inputs parameter will on return
  918. * contain inputs of the newly parsed part of the graph. Analogously
  919. * the outputs parameter will contain outputs of the newly created
  920. * filters.
  921. */
  922. int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
  923. AVFilterInOut **inputs,
  924. AVFilterInOut **outputs);
  925. /**
  926. * Send a command to one or more filter instances.
  927. *
  928. * @param graph the filter graph
  929. * @param target the filter(s) to which the command should be sent
  930. * "all" sends to all filters
  931. * otherwise it can be a filter or filter instance name
  932. * which will send the command to all matching filters.
  933. * @param cmd the command to send, for handling simplicity all commands must be alphanumeric only
  934. * @param arg the argument for the command
  935. * @param res a buffer with size res_size where the filter(s) can return a response.
  936. *
  937. * @returns >=0 on success otherwise an error code.
  938. * AVERROR(ENOSYS) on unsupported commands
  939. */
  940. int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
  941. /**
  942. * Queue a command for one or more filter instances.
  943. *
  944. * @param graph the filter graph
  945. * @param target the filter(s) to which the command should be sent
  946. * "all" sends to all filters
  947. * otherwise it can be a filter or filter instance name
  948. * which will send the command to all matching filters.
  949. * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
  950. * @param arg the argument for the command
  951. * @param ts time at which the command should be sent to the filter
  952. *
  953. * @note As this executes commands after this function returns, no return code
  954. * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
  955. */
  956. int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
  957. /**
  958. * Dump a graph into a human-readable string representation.
  959. *
  960. * @param graph the graph to dump
  961. * @param options formatting options; currently ignored
  962. * @return a string, or NULL in case of memory allocation failure;
  963. * the string must be freed using av_free
  964. */
  965. char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
  966. /**
  967. * Request a frame on the oldest sink link.
  968. *
  969. * If the request returns AVERROR_EOF, try the next.
  970. *
  971. * Note that this function is not meant to be the sole scheduling mechanism
  972. * of a filtergraph, only a convenience function to help drain a filtergraph
  973. * in a balanced way under normal circumstances.
  974. *
  975. * Also note that AVERROR_EOF does not mean that frames did not arrive on
  976. * some of the sinks during the process.
  977. * When there are multiple sink links, in case the requested link
  978. * returns an EOF, this may cause a filter to flush pending frames
  979. * which are sent to another sink link, although unrequested.
  980. *
  981. * @return the return value of ff_request_frame(),
  982. * or AVERROR_EOF if all links returned AVERROR_EOF
  983. */
  984. int avfilter_graph_request_oldest(AVFilterGraph *graph);
  985. /**
  986. * @}
  987. */
  988. #endif /* AVFILTER_AVFILTER_H */