avfilter.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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, 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 initialzed, 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 attemps 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 or failure.
  1120. */
  1121. AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
  1122. const AVFilter *filter,
  1123. const char *name);
  1124. /**
  1125. * Get a filter instance with name name from graph.
  1126. *
  1127. * @return the pointer to the found filter instance or NULL if it
  1128. * cannot be found.
  1129. */
  1130. AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
  1131. #if FF_API_AVFILTER_OPEN
  1132. /**
  1133. * Add an existing filter instance to a filter graph.
  1134. *
  1135. * @param graphctx the filter graph
  1136. * @param filter the filter to be added
  1137. *
  1138. * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
  1139. * filter graph
  1140. */
  1141. attribute_deprecated
  1142. int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
  1143. #endif
  1144. /**
  1145. * Create and add a filter instance into an existing graph.
  1146. * The filter instance is created from the filter filt and inited
  1147. * with the parameters args and opaque.
  1148. *
  1149. * In case of success put in *filt_ctx the pointer to the created
  1150. * filter instance, otherwise set *filt_ctx to NULL.
  1151. *
  1152. * @param name the instance name to give to the created filter instance
  1153. * @param graph_ctx the filter graph
  1154. * @return a negative AVERROR error code in case of failure, a non
  1155. * negative value otherwise
  1156. */
  1157. int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
  1158. const char *name, const char *args, void *opaque,
  1159. AVFilterGraph *graph_ctx);
  1160. /**
  1161. * Enable or disable automatic format conversion inside the graph.
  1162. *
  1163. * Note that format conversion can still happen inside explicitly inserted
  1164. * scale and aresample filters.
  1165. *
  1166. * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
  1167. */
  1168. void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags);
  1169. enum {
  1170. AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
  1171. AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
  1172. };
  1173. /**
  1174. * Check validity and configure all the links and formats in the graph.
  1175. *
  1176. * @param graphctx the filter graph
  1177. * @param log_ctx context used for logging
  1178. * @return >= 0 in case of success, a negative AVERROR code otherwise
  1179. */
  1180. int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
  1181. /**
  1182. * Free a graph, destroy its links, and set *graph to NULL.
  1183. * If *graph is NULL, do nothing.
  1184. */
  1185. void avfilter_graph_free(AVFilterGraph **graph);
  1186. /**
  1187. * A linked-list of the inputs/outputs of the filter chain.
  1188. *
  1189. * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
  1190. * where it is used to communicate open (unlinked) inputs and outputs from and
  1191. * to the caller.
  1192. * This struct specifies, per each not connected pad contained in the graph, the
  1193. * filter context and the pad index required for establishing a link.
  1194. */
  1195. typedef struct AVFilterInOut {
  1196. /** unique name for this input/output in the list */
  1197. char *name;
  1198. /** filter context associated to this input/output */
  1199. AVFilterContext *filter_ctx;
  1200. /** index of the filt_ctx pad to use for linking */
  1201. int pad_idx;
  1202. /** next input/input in the list, NULL if this is the last */
  1203. struct AVFilterInOut *next;
  1204. } AVFilterInOut;
  1205. /**
  1206. * Allocate a single AVFilterInOut entry.
  1207. * Must be freed with avfilter_inout_free().
  1208. * @return allocated AVFilterInOut on success, NULL on failure.
  1209. */
  1210. AVFilterInOut *avfilter_inout_alloc(void);
  1211. /**
  1212. * Free the supplied list of AVFilterInOut and set *inout to NULL.
  1213. * If *inout is NULL, do nothing.
  1214. */
  1215. void avfilter_inout_free(AVFilterInOut **inout);
  1216. #if AV_HAVE_INCOMPATIBLE_LIBAV_ABI || !FF_API_OLD_GRAPH_PARSE
  1217. /**
  1218. * Add a graph described by a string to a graph.
  1219. *
  1220. * @note The caller must provide the lists of inputs and outputs,
  1221. * which therefore must be known before calling the function.
  1222. *
  1223. * @note The inputs parameter describes inputs of the already existing
  1224. * part of the graph; i.e. from the point of view of the newly created
  1225. * part, they are outputs. Similarly the outputs parameter describes
  1226. * outputs of the already existing filters, which are provided as
  1227. * inputs to the parsed filters.
  1228. *
  1229. * @param graph the filter graph where to link the parsed grap context
  1230. * @param filters string to be parsed
  1231. * @param inputs linked list to the inputs of the graph
  1232. * @param outputs linked list to the outputs of the graph
  1233. * @return zero on success, a negative AVERROR code on error
  1234. */
  1235. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  1236. AVFilterInOut *inputs, AVFilterInOut *outputs,
  1237. void *log_ctx);
  1238. #else
  1239. /**
  1240. * Add a graph described by a string to a graph.
  1241. *
  1242. * @param graph the filter graph where to link the parsed graph context
  1243. * @param filters string to be parsed
  1244. * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
  1245. * If non-NULL, *inputs is updated to contain the list of open inputs
  1246. * after the parsing, should be freed with avfilter_inout_free().
  1247. * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
  1248. * If non-NULL, *outputs is updated to contain the list of open outputs
  1249. * after the parsing, should be freed with avfilter_inout_free().
  1250. * @return non negative on success, a negative AVERROR code on error
  1251. * @deprecated Use avfilter_graph_parse_ptr() instead.
  1252. */
  1253. attribute_deprecated
  1254. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  1255. AVFilterInOut **inputs, AVFilterInOut **outputs,
  1256. void *log_ctx);
  1257. #endif
  1258. /**
  1259. * Add a graph described by a string to a graph.
  1260. *
  1261. * @param graph the filter graph where to link the parsed graph context
  1262. * @param filters string to be parsed
  1263. * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
  1264. * If non-NULL, *inputs is updated to contain the list of open inputs
  1265. * after the parsing, should be freed with avfilter_inout_free().
  1266. * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
  1267. * If non-NULL, *outputs is updated to contain the list of open outputs
  1268. * after the parsing, should be freed with avfilter_inout_free().
  1269. * @return non negative on success, a negative AVERROR code on error
  1270. */
  1271. int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
  1272. AVFilterInOut **inputs, AVFilterInOut **outputs,
  1273. void *log_ctx);
  1274. /**
  1275. * Add a graph described by a string to a graph.
  1276. *
  1277. * @param[in] graph the filter graph where to link the parsed graph context
  1278. * @param[in] filters string to be parsed
  1279. * @param[out] inputs a linked list of all free (unlinked) inputs of the
  1280. * parsed graph will be returned here. It is to be freed
  1281. * by the caller using avfilter_inout_free().
  1282. * @param[out] outputs a linked list of all free (unlinked) outputs of the
  1283. * parsed graph will be returned here. It is to be freed by the
  1284. * caller using avfilter_inout_free().
  1285. * @return zero on success, a negative AVERROR code on error
  1286. *
  1287. * @note This function returns the inputs and outputs that are left
  1288. * unlinked after parsing the graph and the caller then deals with
  1289. * them.
  1290. * @note This function makes no reference whatsoever to already
  1291. * existing parts of the graph and the inputs parameter will on return
  1292. * contain inputs of the newly parsed part of the graph. Analogously
  1293. * the outputs parameter will contain outputs of the newly created
  1294. * filters.
  1295. */
  1296. int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
  1297. AVFilterInOut **inputs,
  1298. AVFilterInOut **outputs);
  1299. /**
  1300. * Send a command to one or more filter instances.
  1301. *
  1302. * @param graph the filter graph
  1303. * @param target the filter(s) to which the command should be sent
  1304. * "all" sends to all filters
  1305. * otherwise it can be a filter or filter instance name
  1306. * which will send the command to all matching filters.
  1307. * @param cmd the command to send, for handling simplicity all commands must be alphanumeric only
  1308. * @param arg the argument for the command
  1309. * @param res a buffer with size res_size where the filter(s) can return a response.
  1310. *
  1311. * @returns >=0 on success otherwise an error code.
  1312. * AVERROR(ENOSYS) on unsupported commands
  1313. */
  1314. int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
  1315. /**
  1316. * Queue a command for one or more filter instances.
  1317. *
  1318. * @param graph the filter graph
  1319. * @param target the filter(s) to which the command should be sent
  1320. * "all" sends to all filters
  1321. * otherwise it can be a filter or filter instance name
  1322. * which will send the command to all matching filters.
  1323. * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only
  1324. * @param arg the argument for the command
  1325. * @param ts time at which the command should be sent to the filter
  1326. *
  1327. * @note As this executes commands after this function returns, no return code
  1328. * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
  1329. */
  1330. int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
  1331. /**
  1332. * Dump a graph into a human-readable string representation.
  1333. *
  1334. * @param graph the graph to dump
  1335. * @param options formatting options; currently ignored
  1336. * @return a string, or NULL in case of memory allocation failure;
  1337. * the string must be freed using av_free
  1338. */
  1339. char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
  1340. /**
  1341. * Request a frame on the oldest sink link.
  1342. *
  1343. * If the request returns AVERROR_EOF, try the next.
  1344. *
  1345. * Note that this function is not meant to be the sole scheduling mechanism
  1346. * of a filtergraph, only a convenience function to help drain a filtergraph
  1347. * in a balanced way under normal circumstances.
  1348. *
  1349. * Also note that AVERROR_EOF does not mean that frames did not arrive on
  1350. * some of the sinks during the process.
  1351. * When there are multiple sink links, in case the requested link
  1352. * returns an EOF, this may cause a filter to flush pending frames
  1353. * which are sent to another sink link, although unrequested.
  1354. *
  1355. * @return the return value of ff_request_frame(),
  1356. * or AVERROR_EOF if all links returned AVERROR_EOF
  1357. */
  1358. int avfilter_graph_request_oldest(AVFilterGraph *graph);
  1359. /**
  1360. * @}
  1361. */
  1362. #endif /* AVFILTER_AVFILTER_H */