avfilter.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  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/dict.h"
  36. #include "libavutil/frame.h"
  37. #include "libavutil/log.h"
  38. #include "libavutil/samplefmt.h"
  39. #include "libavutil/pixfmt.h"
  40. #include "libavutil/rational.h"
  41. #include "libavfilter/version.h"
  42. /**
  43. * Return the LIBAVFILTER_VERSION_INT constant.
  44. */
  45. unsigned avfilter_version(void);
  46. /**
  47. * Return the libavfilter build-time configuration.
  48. */
  49. const char *avfilter_configuration(void);
  50. /**
  51. * Return the libavfilter license.
  52. */
  53. const char *avfilter_license(void);
  54. typedef struct AVFilterContext AVFilterContext;
  55. typedef struct AVFilterLink AVFilterLink;
  56. typedef struct AVFilterPad AVFilterPad;
  57. typedef struct AVFilterFormats AVFilterFormats;
  58. #if FF_API_AVFILTERBUFFER
  59. /**
  60. * A reference-counted buffer data type used by the filter system. Filters
  61. * should not store pointers to this structure directly, but instead use the
  62. * AVFilterBufferRef structure below.
  63. */
  64. typedef struct AVFilterBuffer {
  65. uint8_t *data[8]; ///< buffer data for each plane/channel
  66. /**
  67. * pointers to the data planes/channels.
  68. *
  69. * For video, this should simply point to data[].
  70. *
  71. * For planar audio, each channel has a separate data pointer, and
  72. * linesize[0] contains the size of each channel buffer.
  73. * For packed audio, there is just one data pointer, and linesize[0]
  74. * contains the total size of the buffer for all channels.
  75. *
  76. * Note: Both data and extended_data will always be set, but for planar
  77. * audio with more channels that can fit in data, extended_data must be used
  78. * in order to access all channels.
  79. */
  80. uint8_t **extended_data;
  81. int linesize[8]; ///< number of bytes per line
  82. /** private data to be used by a custom free function */
  83. void *priv;
  84. /**
  85. * A pointer to the function to deallocate this buffer if the default
  86. * function is not sufficient. This could, for example, add the memory
  87. * back into a memory pool to be reused later without the overhead of
  88. * reallocating it from scratch.
  89. */
  90. void (*free)(struct AVFilterBuffer *buf);
  91. int format; ///< media format
  92. int w, h; ///< width and height of the allocated buffer
  93. unsigned refcount; ///< number of references to this buffer
  94. } AVFilterBuffer;
  95. #define AV_PERM_READ 0x01 ///< can read from the buffer
  96. #define AV_PERM_WRITE 0x02 ///< can write to the buffer
  97. #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
  98. #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
  99. #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
  100. #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
  101. #define AV_PERM_ALIGN 0x40 ///< the buffer must be aligned
  102. #define AVFILTER_ALIGN 16 //not part of ABI
  103. /**
  104. * Audio specific properties in a reference to an AVFilterBuffer. Since
  105. * AVFilterBufferRef is common to different media formats, audio specific
  106. * per reference properties must be separated out.
  107. */
  108. typedef struct AVFilterBufferRefAudioProps {
  109. uint64_t channel_layout; ///< channel layout of audio buffer
  110. int nb_samples; ///< number of audio samples per channel
  111. int sample_rate; ///< audio buffer sample rate
  112. int channels; ///< number of channels (do not access directly)
  113. } AVFilterBufferRefAudioProps;
  114. /**
  115. * Video specific properties in a reference to an AVFilterBuffer. Since
  116. * AVFilterBufferRef is common to different media formats, video specific
  117. * per reference properties must be separated out.
  118. */
  119. typedef struct AVFilterBufferRefVideoProps {
  120. int w; ///< image width
  121. int h; ///< image height
  122. AVRational sample_aspect_ratio; ///< sample aspect ratio
  123. int interlaced; ///< is frame interlaced
  124. int top_field_first; ///< field order
  125. enum AVPictureType pict_type; ///< picture type of the frame
  126. int key_frame; ///< 1 -> keyframe, 0-> not
  127. int qp_table_linesize; ///< qp_table stride
  128. int qp_table_size; ///< qp_table size
  129. int8_t *qp_table; ///< array of Quantization Parameters
  130. } AVFilterBufferRefVideoProps;
  131. /**
  132. * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
  133. * a buffer to, for example, crop image without any memcpy, the buffer origin
  134. * and dimensions are per-reference properties. Linesize is also useful for
  135. * image flipping, frame to field filters, etc, and so is also per-reference.
  136. *
  137. * TODO: add anything necessary for frame reordering
  138. */
  139. typedef struct AVFilterBufferRef {
  140. AVFilterBuffer *buf; ///< the buffer that this is a reference to
  141. uint8_t *data[8]; ///< picture/audio data for each plane
  142. /**
  143. * pointers to the data planes/channels.
  144. *
  145. * For video, this should simply point to data[].
  146. *
  147. * For planar audio, each channel has a separate data pointer, and
  148. * linesize[0] contains the size of each channel buffer.
  149. * For packed audio, there is just one data pointer, and linesize[0]
  150. * contains the total size of the buffer for all channels.
  151. *
  152. * Note: Both data and extended_data will always be set, but for planar
  153. * audio with more channels that can fit in data, extended_data must be used
  154. * in order to access all channels.
  155. */
  156. uint8_t **extended_data;
  157. int linesize[8]; ///< number of bytes per line
  158. AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
  159. AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
  160. /**
  161. * presentation timestamp. The time unit may change during
  162. * filtering, as it is specified in the link and the filter code
  163. * may need to rescale the PTS accordingly.
  164. */
  165. int64_t pts;
  166. int64_t pos; ///< byte position in stream, -1 if unknown
  167. int format; ///< media format
  168. int perms; ///< permissions, see the AV_PERM_* flags
  169. enum AVMediaType type; ///< media type of buffer data
  170. AVDictionary *metadata; ///< dictionary containing metadata key=value tags
  171. } AVFilterBufferRef;
  172. /**
  173. * Copy properties of src to dst, without copying the actual data
  174. */
  175. attribute_deprecated
  176. void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, const AVFilterBufferRef *src);
  177. /**
  178. * Add a new reference to a buffer.
  179. *
  180. * @param ref an existing reference to the buffer
  181. * @param pmask a bitmask containing the allowable permissions in the new
  182. * reference
  183. * @return a new reference to the buffer with the same properties as the
  184. * old, excluding any permissions denied by pmask
  185. */
  186. attribute_deprecated
  187. AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
  188. /**
  189. * Remove a reference to a buffer. If this is the last reference to the
  190. * buffer, the buffer itself is also automatically freed.
  191. *
  192. * @param ref reference to the buffer, may be NULL
  193. *
  194. * @note it is recommended to use avfilter_unref_bufferp() instead of this
  195. * function
  196. */
  197. attribute_deprecated
  198. void avfilter_unref_buffer(AVFilterBufferRef *ref);
  199. /**
  200. * Remove a reference to a buffer and set the pointer to NULL.
  201. * If this is the last reference to the buffer, the buffer itself
  202. * is also automatically freed.
  203. *
  204. * @param ref pointer to the buffer reference
  205. */
  206. attribute_deprecated
  207. void avfilter_unref_bufferp(AVFilterBufferRef **ref);
  208. #endif
  209. /**
  210. * Get the number of channels of a buffer reference.
  211. */
  212. attribute_deprecated
  213. int avfilter_ref_get_channels(AVFilterBufferRef *ref);
  214. #if FF_API_AVFILTERPAD_PUBLIC
  215. /**
  216. * A filter pad used for either input or output.
  217. *
  218. * See doc/filter_design.txt for details on how to implement the methods.
  219. *
  220. * @warning this struct might be removed from public API.
  221. * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
  222. * to access the name and type fields; there should be no need to access
  223. * any other fields from outside of libavfilter.
  224. */
  225. struct AVFilterPad {
  226. /**
  227. * Pad name. The name is unique among inputs and among outputs, but an
  228. * input may have the same name as an output. This may be NULL if this
  229. * pad has no need to ever be referenced by name.
  230. */
  231. const char *name;
  232. /**
  233. * AVFilterPad type.
  234. */
  235. enum AVMediaType type;
  236. /**
  237. * Input pads:
  238. * Minimum required permissions on incoming buffers. Any buffer with
  239. * insufficient permissions will be automatically copied by the filter
  240. * system to a new buffer which provides the needed access permissions.
  241. *
  242. * Output pads:
  243. * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
  244. * link must have at least these permissions; this fact is checked by
  245. * asserts. It can be used to optimize buffer allocation.
  246. */
  247. attribute_deprecated int min_perms;
  248. /**
  249. * Input pads:
  250. * Permissions which are not accepted on incoming buffers. Any buffer
  251. * which has any of these permissions set will be automatically copied
  252. * by the filter system to a new buffer which does not have those
  253. * permissions. This can be used to easily disallow buffers with
  254. * AV_PERM_REUSE.
  255. *
  256. * Output pads:
  257. * Permissions which are automatically removed on outgoing buffers. It
  258. * can be used to optimize buffer allocation.
  259. */
  260. attribute_deprecated int rej_perms;
  261. /**
  262. * @deprecated unused
  263. */
  264. int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
  265. /**
  266. * Callback function to get a video buffer. If NULL, the filter system will
  267. * use ff_default_get_video_buffer().
  268. *
  269. * Input video pads only.
  270. */
  271. AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
  272. /**
  273. * Callback function to get an audio buffer. If NULL, the filter system will
  274. * use ff_default_get_audio_buffer().
  275. *
  276. * Input audio pads only.
  277. */
  278. AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
  279. /**
  280. * @deprecated unused
  281. */
  282. int (*end_frame)(AVFilterLink *link);
  283. /**
  284. * @deprecated unused
  285. */
  286. int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  287. /**
  288. * Filtering callback. This is where a filter receives a frame with
  289. * audio/video data and should do its processing.
  290. *
  291. * Input pads only.
  292. *
  293. * @return >= 0 on success, a negative AVERROR on error. This function
  294. * must ensure that frame is properly unreferenced on error if it
  295. * hasn't been passed on to another filter.
  296. */
  297. int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
  298. /**
  299. * Frame poll callback. This returns the number of immediately available
  300. * samples. It should return a positive value if the next request_frame()
  301. * is guaranteed to return one frame (with no delay).
  302. *
  303. * Defaults to just calling the source poll_frame() method.
  304. *
  305. * Output pads only.
  306. */
  307. int (*poll_frame)(AVFilterLink *link);
  308. /**
  309. * Frame request callback. A call to this should result in at least one
  310. * frame being output over the given link. This should return zero on
  311. * success, and another value on error.
  312. * See ff_request_frame() for the error codes with a specific
  313. * meaning.
  314. *
  315. * Output pads only.
  316. */
  317. int (*request_frame)(AVFilterLink *link);
  318. /**
  319. * Link configuration callback.
  320. *
  321. * For output pads, this should set the following link properties:
  322. * video: width, height, sample_aspect_ratio, time_base
  323. * audio: sample_rate.
  324. *
  325. * This should NOT set properties such as format, channel_layout, etc which
  326. * are negotiated between filters by the filter system using the
  327. * query_formats() callback before this function is called.
  328. *
  329. * For input pads, this should check the properties of the link, and update
  330. * the filter's internal state as necessary.
  331. *
  332. * For both input and output pads, this should return zero on success,
  333. * and another value on error.
  334. */
  335. int (*config_props)(AVFilterLink *link);
  336. /**
  337. * The filter expects a fifo to be inserted on its input link,
  338. * typically because it has a delay.
  339. *
  340. * input pads only.
  341. */
  342. int needs_fifo;
  343. /**
  344. * The filter expects writable frames from its input link,
  345. * duplicating data buffers if needed.
  346. *
  347. * input pads only.
  348. */
  349. int needs_writable;
  350. };
  351. #endif
  352. /**
  353. * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
  354. * AVFilter.inputs/outputs).
  355. */
  356. int avfilter_pad_count(const AVFilterPad *pads);
  357. /**
  358. * Get the name of an AVFilterPad.
  359. *
  360. * @param pads an array of AVFilterPads
  361. * @param pad_idx index of the pad in the array it; is the caller's
  362. * responsibility to ensure the index is valid
  363. *
  364. * @return name of the pad_idx'th pad in pads
  365. */
  366. const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
  367. /**
  368. * Get the type of an AVFilterPad.
  369. *
  370. * @param pads an array of AVFilterPads
  371. * @param pad_idx index of the pad in the array; it is the caller's
  372. * responsibility to ensure the index is valid
  373. *
  374. * @return type of the pad_idx'th pad in pads
  375. */
  376. enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
  377. /**
  378. * The number of the filter inputs is not determined just by AVFilter.inputs.
  379. * The filter might add additional inputs during initialization depending on the
  380. * options supplied to it.
  381. */
  382. #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
  383. /**
  384. * The number of the filter outputs is not determined just by AVFilter.outputs.
  385. * The filter might add additional outputs during initialization depending on
  386. * the options supplied to it.
  387. */
  388. #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
  389. /**
  390. * The filter supports multithreading by splitting frames into multiple parts
  391. * and processing them concurrently.
  392. */
  393. #define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
  394. /**
  395. * Some filters support a generic "enable" expression option that can be used
  396. * to enable or disable a filter in the timeline. Filters supporting this
  397. * option have this flag set. When the enable expression is false, the default
  398. * no-op filter_frame() function is called in place of the filter_frame()
  399. * callback defined on each input pad, thus the frame is passed unchanged to
  400. * the next filters.
  401. */
  402. #define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC (1 << 16)
  403. /**
  404. * Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will
  405. * have its filter_frame() callback(s) called as usual even when the enable
  406. * expression is false. The filter will disable filtering within the
  407. * filter_frame() callback(s) itself, for example executing code depending on
  408. * the AVFilterContext->is_disabled value.
  409. */
  410. #define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL (1 << 17)
  411. /**
  412. * Handy mask to test whether the filter supports or no the timeline feature
  413. * (internally or generically).
  414. */
  415. #define AVFILTER_FLAG_SUPPORT_TIMELINE (AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL)
  416. /**
  417. * Filter definition. This defines the pads a filter contains, and all the
  418. * callback functions used to interact with the filter.
  419. */
  420. typedef struct AVFilter {
  421. /**
  422. * Filter name. Must be non-NULL and unique among filters.
  423. */
  424. const char *name;
  425. /**
  426. * A description of the filter. May be NULL.
  427. *
  428. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  429. */
  430. const char *description;
  431. /**
  432. * List of inputs, terminated by a zeroed element.
  433. *
  434. * NULL if there are no (static) inputs. Instances of filters with
  435. * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
  436. * this list.
  437. */
  438. const AVFilterPad *inputs;
  439. /**
  440. * List of outputs, terminated by a zeroed element.
  441. *
  442. * NULL if there are no (static) outputs. Instances of filters with
  443. * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
  444. * this list.
  445. */
  446. const AVFilterPad *outputs;
  447. /**
  448. * A class for the private data, used to declare filter private AVOptions.
  449. * This field is NULL for filters that do not declare any options.
  450. *
  451. * If this field is non-NULL, the first member of the filter private data
  452. * must be a pointer to AVClass, which will be set by libavfilter generic
  453. * code to this class.
  454. */
  455. const AVClass *priv_class;
  456. /**
  457. * A combination of AVFILTER_FLAG_*
  458. */
  459. int flags;
  460. /*****************************************************************
  461. * All fields below this line are not part of the public API. They
  462. * may not be used outside of libavfilter and can be changed and
  463. * removed at will.
  464. * New public fields should be added right above.
  465. *****************************************************************
  466. */
  467. /**
  468. * Filter initialization function.
  469. *
  470. * This callback will be called only once during the filter lifetime, after
  471. * all the options have been set, but before links between filters are
  472. * established and format negotiation is done.
  473. *
  474. * Basic filter initialization should be done here. Filters with dynamic
  475. * inputs and/or outputs should create those inputs/outputs here based on
  476. * provided options. No more changes to this filter's inputs/outputs can be
  477. * done after this callback.
  478. *
  479. * This callback must not assume that the filter links exist or frame
  480. * parameters are known.
  481. *
  482. * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
  483. * initialization fails, so this callback does not have to clean up on
  484. * failure.
  485. *
  486. * @return 0 on success, a negative AVERROR on failure
  487. */
  488. int (*init)(AVFilterContext *ctx);
  489. /**
  490. * Should be set instead of @ref AVFilter.init "init" by the filters that
  491. * want to pass a dictionary of AVOptions to nested contexts that are
  492. * allocated during init.
  493. *
  494. * On return, the options dict should be freed and replaced with one that
  495. * contains all the options which could not be processed by this filter (or
  496. * with NULL if all the options were processed).
  497. *
  498. * Otherwise the semantics is the same as for @ref AVFilter.init "init".
  499. */
  500. int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
  501. /**
  502. * Filter uninitialization function.
  503. *
  504. * Called only once right before the filter is freed. Should deallocate any
  505. * memory held by the filter, release any buffer references, etc. It does
  506. * not need to deallocate the AVFilterContext.priv memory itself.
  507. *
  508. * This callback may be called even if @ref AVFilter.init "init" was not
  509. * called or failed, so it must be prepared to handle such a situation.
  510. */
  511. void (*uninit)(AVFilterContext *ctx);
  512. /**
  513. * Query formats supported by the filter on its inputs and outputs.
  514. *
  515. * This callback is called after the filter is initialized (so the inputs
  516. * and outputs are fixed), shortly before the format negotiation. This
  517. * callback may be called more than once.
  518. *
  519. * This callback must set AVFilterLink.out_formats on every input link and
  520. * AVFilterLink.in_formats on every output link to a list of pixel/sample
  521. * formats that the filter supports on that link. For audio links, this
  522. * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
  523. * @ref AVFilterLink.out_samplerates "out_samplerates" and
  524. * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
  525. * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
  526. *
  527. * This callback may be NULL for filters with one input, in which case
  528. * libavfilter assumes that it supports all input formats and preserves
  529. * them on output.
  530. *
  531. * @return zero on success, a negative value corresponding to an
  532. * AVERROR code otherwise
  533. */
  534. int (*query_formats)(AVFilterContext *);
  535. int priv_size; ///< size of private data to allocate for the filter
  536. /**
  537. * Used by the filter registration system. Must not be touched by any other
  538. * code.
  539. */
  540. struct AVFilter *next;
  541. /**
  542. * Make the filter instance process a command.
  543. *
  544. * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
  545. * @param arg the argument for the command
  546. * @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.
  547. * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
  548. * time consuming then a filter should treat it like an unsupported command
  549. *
  550. * @returns >=0 on success otherwise an error code.
  551. * AVERROR(ENOSYS) on unsupported commands
  552. */
  553. int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
  554. /**
  555. * Filter initialization function, alternative to the init()
  556. * callback. Args contains the user-supplied parameters, opaque is
  557. * used for providing binary data.
  558. */
  559. int (*init_opaque)(AVFilterContext *ctx, void *opaque);
  560. } AVFilter;
  561. /**
  562. * Process multiple parts of the frame concurrently.
  563. */
  564. #define AVFILTER_THREAD_SLICE (1 << 0)
  565. typedef struct AVFilterInternal AVFilterInternal;
  566. /** An instance of a filter */
  567. struct AVFilterContext {
  568. const AVClass *av_class; ///< needed for av_log() and filters common options
  569. const AVFilter *filter; ///< the AVFilter of which this is an instance
  570. char *name; ///< name of this filter instance
  571. AVFilterPad *input_pads; ///< array of input pads
  572. AVFilterLink **inputs; ///< array of pointers to input links
  573. #if FF_API_FOO_COUNT
  574. attribute_deprecated unsigned input_count; ///< @deprecated use nb_inputs
  575. #endif
  576. unsigned nb_inputs; ///< number of input pads
  577. AVFilterPad *output_pads; ///< array of output pads
  578. AVFilterLink **outputs; ///< array of pointers to output links
  579. #if FF_API_FOO_COUNT
  580. attribute_deprecated unsigned output_count; ///< @deprecated use nb_outputs
  581. #endif
  582. unsigned nb_outputs; ///< number of output pads
  583. void *priv; ///< private data for use by the filter
  584. struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
  585. /**
  586. * Type of multithreading being allowed/used. A combination of
  587. * AVFILTER_THREAD_* flags.
  588. *
  589. * May be set by the caller before initializing the filter to forbid some
  590. * or all kinds of multithreading for this filter. The default is allowing
  591. * everything.
  592. *
  593. * When the filter is initialized, this field is combined using bit AND with
  594. * AVFilterGraph.thread_type to get the final mask used for determining
  595. * allowed threading types. I.e. a threading type needs to be set in both
  596. * to be allowed.
  597. *
  598. * After the filter is initialized, libavfilter sets this field to the
  599. * threading type that is actually used (0 for no multithreading).
  600. */
  601. int thread_type;
  602. /**
  603. * An opaque struct for libavfilter internal use.
  604. */
  605. AVFilterInternal *internal;
  606. struct AVFilterCommand *command_queue;
  607. char *enable_str; ///< enable expression string
  608. void *enable; ///< parsed expression (AVExpr*)
  609. double *var_values; ///< variable values for the enable expression
  610. int is_disabled; ///< the enabled state from the last expression evaluation
  611. };
  612. /**
  613. * A link between two filters. This contains pointers to the source and
  614. * destination filters between which this link exists, and the indexes of
  615. * the pads involved. In addition, this link also contains the parameters
  616. * which have been negotiated and agreed upon between the filter, such as
  617. * image dimensions, format, etc.
  618. */
  619. struct AVFilterLink {
  620. AVFilterContext *src; ///< source filter
  621. AVFilterPad *srcpad; ///< output pad on the source filter
  622. AVFilterContext *dst; ///< dest filter
  623. AVFilterPad *dstpad; ///< input pad on the dest filter
  624. enum AVMediaType type; ///< filter media type
  625. /* These parameters apply only to video */
  626. int w; ///< agreed upon image width
  627. int h; ///< agreed upon image height
  628. AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
  629. /* These parameters apply only to audio */
  630. uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
  631. int sample_rate; ///< samples per second
  632. int format; ///< agreed upon media format
  633. /**
  634. * Define the time base used by the PTS of the frames/samples
  635. * which will pass through this link.
  636. * During the configuration stage, each filter is supposed to
  637. * change only the output timebase, while the timebase of the
  638. * input link is assumed to be an unchangeable property.
  639. */
  640. AVRational time_base;
  641. /*****************************************************************
  642. * All fields below this line are not part of the public API. They
  643. * may not be used outside of libavfilter and can be changed and
  644. * removed at will.
  645. * New public fields should be added right above.
  646. *****************************************************************
  647. */
  648. /**
  649. * Lists of formats and channel layouts supported by the input and output
  650. * filters respectively. These lists are used for negotiating the format
  651. * to actually be used, which will be loaded into the format and
  652. * channel_layout members, above, when chosen.
  653. *
  654. */
  655. AVFilterFormats *in_formats;
  656. AVFilterFormats *out_formats;
  657. /**
  658. * Lists of channel layouts and sample rates used for automatic
  659. * negotiation.
  660. */
  661. AVFilterFormats *in_samplerates;
  662. AVFilterFormats *out_samplerates;
  663. struct AVFilterChannelLayouts *in_channel_layouts;
  664. struct AVFilterChannelLayouts *out_channel_layouts;
  665. /**
  666. * Audio only, the destination filter sets this to a non-zero value to
  667. * request that buffers with the given number of samples should be sent to
  668. * it. AVFilterPad.needs_fifo must also be set on the corresponding input
  669. * pad.
  670. * Last buffer before EOF will be padded with silence.
  671. */
  672. int request_samples;
  673. /** stage of the initialization of the link properties (dimensions, etc) */
  674. enum {
  675. AVLINK_UNINIT = 0, ///< not started
  676. AVLINK_STARTINIT, ///< started, but incomplete
  677. AVLINK_INIT ///< complete
  678. } init_state;
  679. struct AVFilterPool *pool;
  680. /**
  681. * Graph the filter belongs to.
  682. */
  683. struct AVFilterGraph *graph;
  684. /**
  685. * Current timestamp of the link, as defined by the most recent
  686. * frame(s), in AV_TIME_BASE units.
  687. */
  688. int64_t current_pts;
  689. /**
  690. * Index in the age array.
  691. */
  692. int age_index;
  693. /**
  694. * Frame rate of the stream on the link, or 1/0 if unknown;
  695. * if left to 0/0, will be automatically be copied from the first input
  696. * of the source filter if it exists.
  697. *
  698. * Sources should set it to the best estimation of the real frame rate.
  699. * Filters should update it if necessary depending on their function.
  700. * Sinks can use it to set a default output frame rate.
  701. * It is similar to the r_frame_rate field in AVStream.
  702. */
  703. AVRational frame_rate;
  704. /**
  705. * Buffer partially filled with samples to achieve a fixed/minimum size.
  706. */
  707. AVFrame *partial_buf;
  708. /**
  709. * Size of the partial buffer to allocate.
  710. * Must be between min_samples and max_samples.
  711. */
  712. int partial_buf_size;
  713. /**
  714. * Minimum number of samples to filter at once. If filter_frame() is
  715. * called with fewer samples, it will accumulate them in partial_buf.
  716. * This field and the related ones must not be changed after filtering
  717. * has started.
  718. * If 0, all related fields are ignored.
  719. */
  720. int min_samples;
  721. /**
  722. * Maximum number of samples to filter at once. If filter_frame() is
  723. * called with more samples, it will split them.
  724. */
  725. int max_samples;
  726. /**
  727. * The buffer reference currently being received across the link by the
  728. * destination filter. This is used internally by the filter system to
  729. * allow automatic copying of buffers which do not have sufficient
  730. * permissions for the destination. This should not be accessed directly
  731. * by the filters.
  732. */
  733. AVFilterBufferRef *cur_buf_copy;
  734. /**
  735. * True if the link is closed.
  736. * If set, all attempts of start_frame, filter_frame or request_frame
  737. * will fail with AVERROR_EOF, and if necessary the reference will be
  738. * destroyed.
  739. * If request_frame returns AVERROR_EOF, this flag is set on the
  740. * corresponding link.
  741. * It can be set also be set by either the source or the destination
  742. * filter.
  743. */
  744. int closed;
  745. /**
  746. * Number of channels.
  747. */
  748. int channels;
  749. /**
  750. * True if a frame is being requested on the link.
  751. * Used internally by the framework.
  752. */
  753. unsigned frame_requested;
  754. /**
  755. * Link processing flags.
  756. */
  757. unsigned flags;
  758. /**
  759. * Number of past frames sent through the link.
  760. */
  761. int64_t frame_count;
  762. };
  763. /**
  764. * Link two filters together.
  765. *
  766. * @param src the source filter
  767. * @param srcpad index of the output pad on the source filter
  768. * @param dst the destination filter
  769. * @param dstpad index of the input pad on the destination filter
  770. * @return zero on success
  771. */
  772. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  773. AVFilterContext *dst, unsigned dstpad);
  774. /**
  775. * Free the link in *link, and set its pointer to NULL.
  776. */
  777. void avfilter_link_free(AVFilterLink **link);
  778. /**
  779. * Get the number of channels of a link.
  780. */
  781. int avfilter_link_get_channels(AVFilterLink *link);
  782. /**
  783. * Set the closed field of a link.
  784. */
  785. void avfilter_link_set_closed(AVFilterLink *link, int closed);
  786. /**
  787. * Negotiate the media format, dimensions, etc of all inputs to a filter.
  788. *
  789. * @param filter the filter to negotiate the properties for its inputs
  790. * @return zero on successful negotiation
  791. */
  792. int avfilter_config_links(AVFilterContext *filter);
  793. #if FF_API_AVFILTERBUFFER
  794. /**
  795. * Create a buffer reference wrapped around an already allocated image
  796. * buffer.
  797. *
  798. * @param data pointers to the planes of the image to reference
  799. * @param linesize linesizes for the planes of the image to reference
  800. * @param perms the required access permissions
  801. * @param w the width of the image specified by the data and linesize arrays
  802. * @param h the height of the image specified by the data and linesize arrays
  803. * @param format the pixel format of the image specified by the data and linesize arrays
  804. */
  805. attribute_deprecated
  806. AVFilterBufferRef *
  807. avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
  808. int w, int h, enum AVPixelFormat format);
  809. /**
  810. * Create an audio buffer reference wrapped around an already
  811. * allocated samples buffer.
  812. *
  813. * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
  814. * that can handle unknown channel layouts.
  815. *
  816. * @param data pointers to the samples plane buffers
  817. * @param linesize linesize for the samples plane buffers
  818. * @param perms the required access permissions
  819. * @param nb_samples number of samples per channel
  820. * @param sample_fmt the format of each sample in the buffer to allocate
  821. * @param channel_layout the channel layout of the buffer
  822. */
  823. attribute_deprecated
  824. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
  825. int linesize,
  826. int perms,
  827. int nb_samples,
  828. enum AVSampleFormat sample_fmt,
  829. uint64_t channel_layout);
  830. /**
  831. * Create an audio buffer reference wrapped around an already
  832. * allocated samples buffer.
  833. *
  834. * @param data pointers to the samples plane buffers
  835. * @param linesize linesize for the samples plane buffers
  836. * @param perms the required access permissions
  837. * @param nb_samples number of samples per channel
  838. * @param sample_fmt the format of each sample in the buffer to allocate
  839. * @param channels the number of channels of the buffer
  840. * @param channel_layout the channel layout of the buffer,
  841. * must be either 0 or consistent with channels
  842. */
  843. attribute_deprecated
  844. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
  845. int linesize,
  846. int perms,
  847. int nb_samples,
  848. enum AVSampleFormat sample_fmt,
  849. int channels,
  850. uint64_t channel_layout);
  851. #endif
  852. #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
  853. #define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
  854. /**
  855. * Make the filter instance process a command.
  856. * It is recommended to use avfilter_graph_send_command().
  857. */
  858. int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
  859. /** Initialize the filter system. Register all builtin filters. */
  860. void avfilter_register_all(void);
  861. #if FF_API_OLD_FILTER_REGISTER
  862. /** Uninitialize the filter system. Unregister all filters. */
  863. attribute_deprecated
  864. void avfilter_uninit(void);
  865. #endif
  866. /**
  867. * Register a filter. This is only needed if you plan to use
  868. * avfilter_get_by_name later to lookup the AVFilter structure by name. A
  869. * filter can still by instantiated with avfilter_graph_alloc_filter even if it
  870. * is not registered.
  871. *
  872. * @param filter the filter to register
  873. * @return 0 if the registration was successful, a negative value
  874. * otherwise
  875. */
  876. int avfilter_register(AVFilter *filter);
  877. /**
  878. * Get a filter definition matching the given name.
  879. *
  880. * @param name the filter name to find
  881. * @return the filter definition, if any matching one is registered.
  882. * NULL if none found.
  883. */
  884. #if !FF_API_NOCONST_GET_NAME
  885. const
  886. #endif
  887. AVFilter *avfilter_get_by_name(const char *name);
  888. /**
  889. * Iterate over all registered filters.
  890. * @return If prev is non-NULL, next registered filter after prev or NULL if
  891. * prev is the last filter. If prev is NULL, return the first registered filter.
  892. */
  893. const AVFilter *avfilter_next(const AVFilter *prev);
  894. #if FF_API_OLD_FILTER_REGISTER
  895. /**
  896. * If filter is NULL, returns a pointer to the first registered filter pointer,
  897. * if filter is non-NULL, returns the next pointer after filter.
  898. * If the returned pointer points to NULL, the last registered filter
  899. * was already reached.
  900. * @deprecated use avfilter_next()
  901. */
  902. attribute_deprecated
  903. AVFilter **av_filter_next(AVFilter **filter);
  904. #endif
  905. #if FF_API_AVFILTER_OPEN
  906. /**
  907. * Create a filter instance.
  908. *
  909. * @param filter_ctx put here a pointer to the created filter context
  910. * on success, NULL on failure
  911. * @param filter the filter to create an instance of
  912. * @param inst_name Name to give to the new instance. Can be NULL for none.
  913. * @return >= 0 in case of success, a negative error code otherwise
  914. * @deprecated use avfilter_graph_alloc_filter() instead
  915. */
  916. attribute_deprecated
  917. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
  918. #endif
  919. #if FF_API_AVFILTER_INIT_FILTER
  920. /**
  921. * Initialize a filter.
  922. *
  923. * @param filter the filter to initialize
  924. * @param args A string of parameters to use when initializing the filter.
  925. * The format and meaning of this string varies by filter.
  926. * @param opaque Any extra non-string data needed by the filter. The meaning
  927. * of this parameter varies by filter.
  928. * @return zero on success
  929. */
  930. attribute_deprecated
  931. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  932. #endif
  933. /**
  934. * Initialize a filter with the supplied parameters.
  935. *
  936. * @param ctx uninitialized filter context to initialize
  937. * @param args Options to initialize the filter with. This must be a
  938. * ':'-separated list of options in the 'key=value' form.
  939. * May be NULL if the options have been set directly using the
  940. * AVOptions API or there are no options that need to be set.
  941. * @return 0 on success, a negative AVERROR on failure
  942. */
  943. int avfilter_init_str(AVFilterContext *ctx, const char *args);
  944. /**
  945. * Initialize a filter with the supplied dictionary of options.
  946. *
  947. * @param ctx uninitialized filter context to initialize
  948. * @param options An AVDictionary filled with options for this filter. On
  949. * return this parameter will be destroyed and replaced with
  950. * a dict containing options that were not found. This dictionary
  951. * must be freed by the caller.
  952. * May be NULL, then this function is equivalent to
  953. * avfilter_init_str() with the second parameter set to NULL.
  954. * @return 0 on success, a negative AVERROR on failure
  955. *
  956. * @note This function and avfilter_init_str() do essentially the same thing,
  957. * the difference is in manner in which the options are passed. It is up to the
  958. * calling code to choose whichever is more preferable. The two functions also
  959. * behave differently when some of the provided options are not declared as
  960. * supported by the filter. In such a case, avfilter_init_str() will fail, but
  961. * this function will leave those extra options in the options AVDictionary and
  962. * continue as usual.
  963. */
  964. int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
  965. /**
  966. * Free a filter context. This will also remove the filter from its
  967. * filtergraph's list of filters.
  968. *
  969. * @param filter the filter to free
  970. */
  971. void avfilter_free(AVFilterContext *filter);
  972. /**
  973. * Insert a filter in the middle of an existing link.
  974. *
  975. * @param link the link into which the filter should be inserted
  976. * @param filt the filter to be inserted
  977. * @param filt_srcpad_idx the input pad on the filter to connect
  978. * @param filt_dstpad_idx the output pad on the filter to connect
  979. * @return zero on success
  980. */
  981. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  982. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
  983. #if FF_API_AVFILTERBUFFER
  984. /**
  985. * Copy the frame properties of src to dst, without copying the actual
  986. * image data.
  987. *
  988. * @return 0 on success, a negative number on error.
  989. */
  990. attribute_deprecated
  991. int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
  992. /**
  993. * Copy the frame properties and data pointers of src to dst, without copying
  994. * the actual data.
  995. *
  996. * @return 0 on success, a negative number on error.
  997. */
  998. attribute_deprecated
  999. int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
  1000. #endif
  1001. /**
  1002. * @return AVClass for AVFilterContext.
  1003. *
  1004. * @see av_opt_find().
  1005. */
  1006. const AVClass *avfilter_get_class(void);
  1007. typedef struct AVFilterGraphInternal AVFilterGraphInternal;
  1008. /**
  1009. * A function pointer passed to the @ref AVFilterGraph.execute callback to be
  1010. * executed multiple times, possibly in parallel.
  1011. *
  1012. * @param ctx the filter context the job belongs to
  1013. * @param arg an opaque parameter passed through from @ref
  1014. * AVFilterGraph.execute
  1015. * @param jobnr the index of the job being executed
  1016. * @param nb_jobs the total number of jobs
  1017. *
  1018. * @return 0 on success, a negative AVERROR on error
  1019. */
  1020. typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
  1021. /**
  1022. * A function executing multiple jobs, possibly in parallel.
  1023. *
  1024. * @param ctx the filter context to which the jobs belong
  1025. * @param func the function to be called multiple times
  1026. * @param arg the argument to be passed to func
  1027. * @param ret a nb_jobs-sized array to be filled with return values from each
  1028. * invocation of func
  1029. * @param nb_jobs the number of jobs to execute
  1030. *
  1031. * @return 0 on success, a negative AVERROR on error
  1032. */
  1033. typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
  1034. void *arg, int *ret, int nb_jobs);
  1035. typedef struct AVFilterGraph {
  1036. const AVClass *av_class;
  1037. #if FF_API_FOO_COUNT
  1038. attribute_deprecated
  1039. unsigned filter_count_unused;
  1040. #endif
  1041. AVFilterContext **filters;
  1042. #if !FF_API_FOO_COUNT
  1043. unsigned nb_filters;
  1044. #endif
  1045. char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
  1046. char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
  1047. #if FF_API_FOO_COUNT
  1048. unsigned nb_filters;
  1049. #endif
  1050. /**
  1051. * Type of multithreading allowed for filters in this graph. A combination
  1052. * of AVFILTER_THREAD_* flags.
  1053. *
  1054. * May be set by the caller at any point, the setting will apply to all
  1055. * filters initialized after that. The default is allowing everything.
  1056. *
  1057. * When a filter in this graph is initialized, this field is combined using
  1058. * bit AND with AVFilterContext.thread_type to get the final mask used for
  1059. * determining allowed threading types. I.e. a threading type needs to be
  1060. * set in both to be allowed.
  1061. */
  1062. int thread_type;
  1063. /**
  1064. * Maximum number of threads used by filters in this graph. May be set by
  1065. * the caller before adding any filters to the filtergraph. Zero (the
  1066. * default) means that the number of threads is determined automatically.
  1067. */
  1068. int nb_threads;
  1069. /**
  1070. * Opaque object for libavfilter internal use.
  1071. */
  1072. AVFilterGraphInternal *internal;
  1073. /**
  1074. * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
  1075. * be used from callbacks like @ref AVFilterGraph.execute.
  1076. * Libavfilter will not touch this field in any way.
  1077. */
  1078. void *opaque;
  1079. /**
  1080. * This callback may be set by the caller immediately after allocating the
  1081. * graph and before adding any filters to it, to provide a custom
  1082. * multithreading implementation.
  1083. *
  1084. * If set, filters with slice threading capability will call this callback
  1085. * to execute multiple jobs in parallel.
  1086. *
  1087. * If this field is left unset, libavfilter will use its internal
  1088. * implementation, which may or may not be multithreaded depending on the
  1089. * platform and build options.
  1090. */
  1091. avfilter_execute_func *execute;
  1092. char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
  1093. /**
  1094. * Private fields
  1095. *
  1096. * The following fields are for internal use only.
  1097. * Their type, offset, number and semantic can change without notice.
  1098. */
  1099. AVFilterLink **sink_links;
  1100. int sink_links_count;
  1101. unsigned disable_auto_convert;
  1102. } AVFilterGraph;
  1103. /**
  1104. * Allocate a filter graph.
  1105. */
  1106. AVFilterGraph *avfilter_graph_alloc(void);
  1107. /**
  1108. * Create a new filter instance in a filter graph.
  1109. *
  1110. * @param graph graph in which the new filter will be used
  1111. * @param filter the filter to create an instance of
  1112. * @param name Name to give to the new instance (will be copied to
  1113. * AVFilterContext.name). This may be used by the caller to identify
  1114. * different filters, libavfilter itself assigns no semantics to
  1115. * this parameter. May be NULL.
  1116. *
  1117. * @return the context of the newly created filter instance (note that it is
  1118. * also retrievable directly through AVFilterGraph.filters or with
  1119. * avfilter_graph_get_filter()) on success or NULL on failure.
  1120. */
  1121. AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
  1122. const AVFilter *filter,
  1123. const char *name);
  1124. /**
  1125. * Get a filter instance identified by instance name from graph.
  1126. *
  1127. * @param graph filter graph to search through.
  1128. * @param name filter instance name (should be unique in the graph).
  1129. * @return the pointer to the found filter instance or NULL if it
  1130. * cannot be found.
  1131. */
  1132. AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name);
  1133. #if FF_API_AVFILTER_OPEN
  1134. /**
  1135. * Add an existing filter instance to a filter graph.
  1136. *
  1137. * @param graphctx the filter graph
  1138. * @param filter the filter to be added
  1139. *
  1140. * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
  1141. * filter graph
  1142. */
  1143. attribute_deprecated
  1144. int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
  1145. #endif
  1146. /**
  1147. * Create and add a filter instance into an existing graph.
  1148. * The filter instance is created from the filter filt and inited
  1149. * with the parameters args and opaque.
  1150. *
  1151. * In case of success put in *filt_ctx the pointer to the created
  1152. * filter instance, otherwise set *filt_ctx to NULL.
  1153. *
  1154. * @param name the instance name to give to the created filter instance
  1155. * @param graph_ctx the filter graph
  1156. * @return a negative AVERROR error code in case of failure, a non
  1157. * negative value otherwise
  1158. */
  1159. int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
  1160. const char *name, const char *args, void *opaque,
  1161. AVFilterGraph *graph_ctx);
  1162. /**
  1163. * Enable or disable automatic format conversion inside the graph.
  1164. *
  1165. * Note that format conversion can still happen inside explicitly inserted
  1166. * scale and aresample filters.
  1167. *
  1168. * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
  1169. */
  1170. void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags);
  1171. enum {
  1172. AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
  1173. AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
  1174. };
  1175. /**
  1176. * Check validity and configure all the links and formats in the graph.
  1177. *
  1178. * @param graphctx the filter graph
  1179. * @param log_ctx context used for logging
  1180. * @return >= 0 in case of success, a negative AVERROR code otherwise
  1181. */
  1182. int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
  1183. /**
  1184. * Free a graph, destroy its links, and set *graph to NULL.
  1185. * If *graph is NULL, do nothing.
  1186. */
  1187. void avfilter_graph_free(AVFilterGraph **graph);
  1188. /**
  1189. * A linked-list of the inputs/outputs of the filter chain.
  1190. *
  1191. * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
  1192. * where it is used to communicate open (unlinked) inputs and outputs from and
  1193. * to the caller.
  1194. * This struct specifies, per each not connected pad contained in the graph, the
  1195. * filter context and the pad index required for establishing a link.
  1196. */
  1197. typedef struct AVFilterInOut {
  1198. /** unique name for this input/output in the list */
  1199. char *name;
  1200. /** filter context associated to this input/output */
  1201. AVFilterContext *filter_ctx;
  1202. /** index of the filt_ctx pad to use for linking */
  1203. int pad_idx;
  1204. /** next input/input in the list, NULL if this is the last */
  1205. struct AVFilterInOut *next;
  1206. } AVFilterInOut;
  1207. /**
  1208. * Allocate a single AVFilterInOut entry.
  1209. * Must be freed with avfilter_inout_free().
  1210. * @return allocated AVFilterInOut on success, NULL on failure.
  1211. */
  1212. AVFilterInOut *avfilter_inout_alloc(void);
  1213. /**
  1214. * Free the supplied list of AVFilterInOut and set *inout to NULL.
  1215. * If *inout is NULL, do nothing.
  1216. */
  1217. void avfilter_inout_free(AVFilterInOut **inout);
  1218. #if AV_HAVE_INCOMPATIBLE_LIBAV_ABI || !FF_API_OLD_GRAPH_PARSE
  1219. /**
  1220. * Add a graph described by a string to a graph.
  1221. *
  1222. * @note The caller must provide the lists of inputs and outputs,
  1223. * which therefore must be known before calling the function.
  1224. *
  1225. * @note The inputs parameter describes inputs of the already existing
  1226. * part of the graph; i.e. from the point of view of the newly created
  1227. * part, they are outputs. Similarly the outputs parameter describes
  1228. * outputs of the already existing filters, which are provided as
  1229. * inputs to the parsed filters.
  1230. *
  1231. * @param graph the filter graph where to link the parsed graph context
  1232. * @param filters string to be parsed
  1233. * @param inputs linked list to the inputs of the graph
  1234. * @param outputs linked list to the outputs of the graph
  1235. * @return zero on success, a negative AVERROR code on error
  1236. */
  1237. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  1238. AVFilterInOut *inputs, AVFilterInOut *outputs,
  1239. void *log_ctx);
  1240. #else
  1241. /**
  1242. * Add a graph described by a string to a graph.
  1243. *
  1244. * @param graph the filter graph where to link the parsed graph context
  1245. * @param filters string to be parsed
  1246. * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
  1247. * If non-NULL, *inputs is updated to contain the list of open inputs
  1248. * after the parsing, should be freed with avfilter_inout_free().
  1249. * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
  1250. * If non-NULL, *outputs is updated to contain the list of open outputs
  1251. * after the parsing, should be freed with avfilter_inout_free().
  1252. * @return non negative on success, a negative AVERROR code on error
  1253. * @deprecated Use avfilter_graph_parse_ptr() instead.
  1254. */
  1255. attribute_deprecated
  1256. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  1257. AVFilterInOut **inputs, AVFilterInOut **outputs,
  1258. void *log_ctx);
  1259. #endif
  1260. /**
  1261. * Add a graph described by a string to a graph.
  1262. *
  1263. * @param graph the filter graph where to link the parsed graph context
  1264. * @param filters string to be parsed
  1265. * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
  1266. * If non-NULL, *inputs is updated to contain the list of open inputs
  1267. * after the parsing, should be freed with avfilter_inout_free().
  1268. * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
  1269. * If non-NULL, *outputs is updated to contain the list of open outputs
  1270. * after the parsing, should be freed with avfilter_inout_free().
  1271. * @return non negative on success, a negative AVERROR code on error
  1272. */
  1273. int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
  1274. AVFilterInOut **inputs, AVFilterInOut **outputs,
  1275. void *log_ctx);
  1276. /**
  1277. * Add a graph described by a string to a graph.
  1278. *
  1279. * @param[in] graph the filter graph where to link the parsed graph context
  1280. * @param[in] filters string to be parsed
  1281. * @param[out] inputs a linked list of all free (unlinked) inputs of the
  1282. * parsed graph will be returned here. It is to be freed
  1283. * by the caller using avfilter_inout_free().
  1284. * @param[out] outputs a linked list of all free (unlinked) outputs of the
  1285. * parsed graph will be returned here. It is to be freed by the
  1286. * caller using avfilter_inout_free().
  1287. * @return zero on success, a negative AVERROR code on error
  1288. *
  1289. * @note This function returns the inputs and outputs that are left
  1290. * unlinked after parsing the graph and the caller then deals with
  1291. * them.
  1292. * @note This function makes no reference whatsoever to already
  1293. * existing parts of the graph and the inputs parameter will on return
  1294. * contain inputs of the newly parsed part of the graph. Analogously
  1295. * the outputs parameter will contain outputs of the newly created
  1296. * filters.
  1297. */
  1298. int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
  1299. AVFilterInOut **inputs,
  1300. AVFilterInOut **outputs);
  1301. /**
  1302. * Send a command to one or more filter instances.
  1303. *
  1304. * @param graph the filter graph
  1305. * @param target the filter(s) to which the command should be sent
  1306. * "all" sends to all filters
  1307. * otherwise it can be a filter or filter instance name
  1308. * which will send the command to all matching filters.
  1309. * @param cmd the command to send, for handling simplicity all commands must be alphanumeric only
  1310. * @param arg the argument for the command
  1311. * @param res a buffer with size res_size where the filter(s) can return a response.
  1312. *
  1313. * @returns >=0 on success otherwise an error code.
  1314. * AVERROR(ENOSYS) on unsupported commands
  1315. */
  1316. int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
  1317. /**
  1318. * Queue a command for one or more filter instances.
  1319. *
  1320. * @param graph the filter graph
  1321. * @param target the filter(s) to which the command should be sent
  1322. * "all" sends to all filters
  1323. * otherwise it can be a filter or filter instance name
  1324. * which will send the command to all matching filters.
  1325. * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
  1326. * @param arg the argument for the command
  1327. * @param ts time at which the command should be sent to the filter
  1328. *
  1329. * @note As this executes commands after this function returns, no return code
  1330. * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
  1331. */
  1332. int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
  1333. /**
  1334. * Dump a graph into a human-readable string representation.
  1335. *
  1336. * @param graph the graph to dump
  1337. * @param options formatting options; currently ignored
  1338. * @return a string, or NULL in case of memory allocation failure;
  1339. * the string must be freed using av_free
  1340. */
  1341. char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
  1342. /**
  1343. * Request a frame on the oldest sink link.
  1344. *
  1345. * If the request returns AVERROR_EOF, try the next.
  1346. *
  1347. * Note that this function is not meant to be the sole scheduling mechanism
  1348. * of a filtergraph, only a convenience function to help drain a filtergraph
  1349. * in a balanced way under normal circumstances.
  1350. *
  1351. * Also note that AVERROR_EOF does not mean that frames did not arrive on
  1352. * some of the sinks during the process.
  1353. * When there are multiple sink links, in case the requested link
  1354. * returns an EOF, this may cause a filter to flush pending frames
  1355. * which are sent to another sink link, although unrequested.
  1356. *
  1357. * @return the return value of ff_request_frame(),
  1358. * or AVERROR_EOF if all links returned AVERROR_EOF
  1359. */
  1360. int avfilter_graph_request_oldest(AVFilterGraph *graph);
  1361. /**
  1362. * @}
  1363. */
  1364. #endif /* AVFILTER_AVFILTER_H */