avformat.h 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVFORMAT_AVFORMAT_H
  21. #define AVFORMAT_AVFORMAT_H
  22. /**
  23. * @file
  24. * @ingroup libavf
  25. * Main libavformat public API header
  26. */
  27. /**
  28. * @defgroup libavf libavformat
  29. * I/O and Muxing/Demuxing Library
  30. *
  31. * Libavformat (lavf) is a library for dealing with various media container
  32. * formats. Its main two purposes are demuxing - i.e. splitting a media file
  33. * into component streams, and the reverse process of muxing - writing supplied
  34. * data in a specified container format. It also has an @ref lavf_io
  35. * "I/O module" which supports a number of protocols for accessing the data (e.g.
  36. * file, tcp, http and others).
  37. * Unless you are absolutely sure you won't use libavformat's network
  38. * capabilities, you should also call avformat_network_init().
  39. *
  40. * A supported input format is described by an AVInputFormat struct, conversely
  41. * an output format is described by AVOutputFormat. You can iterate over all
  42. * input/output formats using the av_demuxer_iterate / av_muxer_iterate() functions.
  43. * The protocols layer is not part of the public API, so you can only get the names
  44. * of supported protocols with the avio_enum_protocols() function.
  45. *
  46. * Main lavf structure used for both muxing and demuxing is AVFormatContext,
  47. * which exports all information about the file being read or written. As with
  48. * most Libavformat structures, its size is not part of public ABI, so it cannot be
  49. * allocated on stack or directly with av_malloc(). To create an
  50. * AVFormatContext, use avformat_alloc_context() (some functions, like
  51. * avformat_open_input() might do that for you).
  52. *
  53. * Most importantly an AVFormatContext contains:
  54. * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat
  55. * "output" format. It is either autodetected or set by user for input;
  56. * always set by user for output.
  57. * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all
  58. * elementary streams stored in the file. AVStreams are typically referred to
  59. * using their index in this array.
  60. * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or
  61. * set by user for input, always set by user for output (unless you are dealing
  62. * with an AVFMT_NOFILE format).
  63. *
  64. * @section lavf_options Passing options to (de)muxers
  65. * It is possible to configure lavf muxers and demuxers using the @ref avoptions
  66. * mechanism. Generic (format-independent) libavformat options are provided by
  67. * AVFormatContext, they can be examined from a user program by calling
  68. * av_opt_next() / av_opt_find() on an allocated AVFormatContext (or its AVClass
  69. * from avformat_get_class()). Private (format-specific) options are provided by
  70. * AVFormatContext.priv_data if and only if AVInputFormat.priv_class /
  71. * AVOutputFormat.priv_class of the corresponding format struct is non-NULL.
  72. * Further options may be provided by the @ref AVFormatContext.pb "I/O context",
  73. * if its AVClass is non-NULL, and the protocols layer. See the discussion on
  74. * nesting in @ref avoptions documentation to learn how to access those.
  75. *
  76. * @section urls
  77. * URL strings in libavformat are made of a scheme/protocol, a ':', and a
  78. * scheme specific string. URLs without a scheme and ':' used for local files
  79. * are supported but deprecated. "file:" should be used for local files.
  80. *
  81. * It is important that the scheme string is not taken from untrusted
  82. * sources without checks.
  83. *
  84. * Note that some schemes/protocols are quite powerful, allowing access to
  85. * both local and remote files, parts of them, concatenations of them, local
  86. * audio and video devices and so on.
  87. *
  88. * @{
  89. *
  90. * @defgroup lavf_decoding Demuxing
  91. * @{
  92. * Demuxers read a media file and split it into chunks of data (@em packets). A
  93. * @ref AVPacket "packet" contains one or more encoded frames which belongs to a
  94. * single elementary stream. In the lavf API this process is represented by the
  95. * avformat_open_input() function for opening a file, av_read_frame() for
  96. * reading a single packet and finally avformat_close_input(), which does the
  97. * cleanup.
  98. *
  99. * @section lavf_decoding_open Opening a media file
  100. * The minimum information required to open a file is its URL, which
  101. * is passed to avformat_open_input(), as in the following code:
  102. * @code
  103. * const char *url = "file:in.mp3";
  104. * AVFormatContext *s = NULL;
  105. * int ret = avformat_open_input(&s, url, NULL, NULL);
  106. * if (ret < 0)
  107. * abort();
  108. * @endcode
  109. * The above code attempts to allocate an AVFormatContext, open the
  110. * specified file (autodetecting the format) and read the header, exporting the
  111. * information stored there into s. Some formats do not have a header or do not
  112. * store enough information there, so it is recommended that you call the
  113. * avformat_find_stream_info() function which tries to read and decode a few
  114. * frames to find missing information.
  115. *
  116. * In some cases you might want to preallocate an AVFormatContext yourself with
  117. * avformat_alloc_context() and do some tweaking on it before passing it to
  118. * avformat_open_input(). One such case is when you want to use custom functions
  119. * for reading input data instead of lavf internal I/O layer.
  120. * To do that, create your own AVIOContext with avio_alloc_context(), passing
  121. * your reading callbacks to it. Then set the @em pb field of your
  122. * AVFormatContext to newly created AVIOContext.
  123. *
  124. * Since the format of the opened file is in general not known until after
  125. * avformat_open_input() has returned, it is not possible to set demuxer private
  126. * options on a preallocated context. Instead, the options should be passed to
  127. * avformat_open_input() wrapped in an AVDictionary:
  128. * @code
  129. * AVDictionary *options = NULL;
  130. * av_dict_set(&options, "video_size", "640x480", 0);
  131. * av_dict_set(&options, "pixel_format", "rgb24", 0);
  132. *
  133. * if (avformat_open_input(&s, url, NULL, &options) < 0)
  134. * abort();
  135. * av_dict_free(&options);
  136. * @endcode
  137. * This code passes the private options 'video_size' and 'pixel_format' to the
  138. * demuxer. They would be necessary for e.g. the rawvideo demuxer, since it
  139. * cannot know how to interpret raw video data otherwise. If the format turns
  140. * out to be something different than raw video, those options will not be
  141. * recognized by the demuxer and therefore will not be applied. Such unrecognized
  142. * options are then returned in the options dictionary (recognized options are
  143. * consumed). The calling program can handle such unrecognized options as it
  144. * wishes, e.g.
  145. * @code
  146. * AVDictionaryEntry *e;
  147. * if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
  148. * fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
  149. * abort();
  150. * }
  151. * @endcode
  152. *
  153. * After you have finished reading the file, you must close it with
  154. * avformat_close_input(). It will free everything associated with the file.
  155. *
  156. * @section lavf_decoding_read Reading from an opened file
  157. * Reading data from an opened AVFormatContext is done by repeatedly calling
  158. * av_read_frame() on it. Each call, if successful, will return an AVPacket
  159. * containing encoded data for one AVStream, identified by
  160. * AVPacket.stream_index. This packet may be passed straight into the libavcodec
  161. * decoding functions avcodec_send_packet() or avcodec_decode_subtitle2() if the
  162. * caller wishes to decode the data.
  163. *
  164. * AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be
  165. * set if known. They may also be unset (i.e. AV_NOPTS_VALUE for
  166. * pts/dts, 0 for duration) if the stream does not provide them. The timing
  167. * information will be in AVStream.time_base units, i.e. it has to be
  168. * multiplied by the timebase to convert them to seconds.
  169. *
  170. * A packet returned by av_read_frame() is always reference-counted,
  171. * i.e. AVPacket.buf is set and the user may keep it indefinitely.
  172. * The packet must be freed with av_packet_unref() when it is no
  173. * longer needed.
  174. *
  175. * @section lavf_decoding_seek Seeking
  176. * @}
  177. *
  178. * @defgroup lavf_encoding Muxing
  179. * @{
  180. * Muxers take encoded data in the form of @ref AVPacket "AVPackets" and write
  181. * it into files or other output bytestreams in the specified container format.
  182. *
  183. * The main API functions for muxing are avformat_write_header() for writing the
  184. * file header, av_write_frame() / av_interleaved_write_frame() for writing the
  185. * packets and av_write_trailer() for finalizing the file.
  186. *
  187. * At the beginning of the muxing process, the caller must first call
  188. * avformat_alloc_context() to create a muxing context. The caller then sets up
  189. * the muxer by filling the various fields in this context:
  190. *
  191. * - The @ref AVFormatContext.oformat "oformat" field must be set to select the
  192. * muxer that will be used.
  193. * - Unless the format is of the AVFMT_NOFILE type, the @ref AVFormatContext.pb
  194. * "pb" field must be set to an opened IO context, either returned from
  195. * avio_open2() or a custom one.
  196. * - Unless the format is of the AVFMT_NOSTREAMS type, at least one stream must
  197. * be created with the avformat_new_stream() function. The caller should fill
  198. * the @ref AVStream.codecpar "stream codec parameters" information, such as the
  199. * codec @ref AVCodecParameters.codec_type "type", @ref AVCodecParameters.codec_id
  200. * "id" and other parameters (e.g. width / height, the pixel or sample format,
  201. * etc.) as known. The @ref AVStream.time_base "stream timebase" should
  202. * be set to the timebase that the caller desires to use for this stream (note
  203. * that the timebase actually used by the muxer can be different, as will be
  204. * described later).
  205. * - It is advised to manually initialize only the relevant fields in
  206. * AVCodecParameters, rather than using @ref avcodec_parameters_copy() during
  207. * remuxing: there is no guarantee that the codec context values remain valid
  208. * for both input and output format contexts.
  209. * - The caller may fill in additional information, such as @ref
  210. * AVFormatContext.metadata "global" or @ref AVStream.metadata "per-stream"
  211. * metadata, @ref AVFormatContext.chapters "chapters", @ref
  212. * AVFormatContext.programs "programs", etc. as described in the
  213. * AVFormatContext documentation. Whether such information will actually be
  214. * stored in the output depends on what the container format and the muxer
  215. * support.
  216. *
  217. * When the muxing context is fully set up, the caller must call
  218. * avformat_write_header() to initialize the muxer internals and write the file
  219. * header. Whether anything actually is written to the IO context at this step
  220. * depends on the muxer, but this function must always be called. Any muxer
  221. * private options must be passed in the options parameter to this function.
  222. *
  223. * The data is then sent to the muxer by repeatedly calling av_write_frame() or
  224. * av_interleaved_write_frame() (consult those functions' documentation for
  225. * discussion on the difference between them; only one of them may be used with
  226. * a single muxing context, they should not be mixed). Do note that the timing
  227. * information on the packets sent to the muxer must be in the corresponding
  228. * AVStream's timebase. That timebase is set by the muxer (in the
  229. * avformat_write_header() step) and may be different from the timebase
  230. * requested by the caller.
  231. *
  232. * Once all the data has been written, the caller must call av_write_trailer()
  233. * to flush any buffered packets and finalize the output file, then close the IO
  234. * context (if any) and finally free the muxing context with
  235. * avformat_free_context().
  236. * @}
  237. *
  238. * @defgroup lavf_io I/O Read/Write
  239. * @{
  240. * @section lavf_io_dirlist Directory listing
  241. * The directory listing API makes it possible to list files on remote servers.
  242. *
  243. * Some of possible use cases:
  244. * - an "open file" dialog to choose files from a remote location,
  245. * - a recursive media finder providing a player with an ability to play all
  246. * files from a given directory.
  247. *
  248. * @subsection lavf_io_dirlist_open Opening a directory
  249. * At first, a directory needs to be opened by calling avio_open_dir()
  250. * supplied with a URL and, optionally, ::AVDictionary containing
  251. * protocol-specific parameters. The function returns zero or positive
  252. * integer and allocates AVIODirContext on success.
  253. *
  254. * @code
  255. * AVIODirContext *ctx = NULL;
  256. * if (avio_open_dir(&ctx, "smb://example.com/some_dir", NULL) < 0) {
  257. * fprintf(stderr, "Cannot open directory.\n");
  258. * abort();
  259. * }
  260. * @endcode
  261. *
  262. * This code tries to open a sample directory using smb protocol without
  263. * any additional parameters.
  264. *
  265. * @subsection lavf_io_dirlist_read Reading entries
  266. * Each directory's entry (i.e. file, another directory, anything else
  267. * within ::AVIODirEntryType) is represented by AVIODirEntry.
  268. * Reading consecutive entries from an opened AVIODirContext is done by
  269. * repeatedly calling avio_read_dir() on it. Each call returns zero or
  270. * positive integer if successful. Reading can be stopped right after the
  271. * NULL entry has been read -- it means there are no entries left to be
  272. * read. The following code reads all entries from a directory associated
  273. * with ctx and prints their names to standard output.
  274. * @code
  275. * AVIODirEntry *entry = NULL;
  276. * for (;;) {
  277. * if (avio_read_dir(ctx, &entry) < 0) {
  278. * fprintf(stderr, "Cannot list directory.\n");
  279. * abort();
  280. * }
  281. * if (!entry)
  282. * break;
  283. * printf("%s\n", entry->name);
  284. * avio_free_directory_entry(&entry);
  285. * }
  286. * @endcode
  287. * @}
  288. *
  289. * @defgroup lavf_codec Demuxers
  290. * @{
  291. * @defgroup lavf_codec_native Native Demuxers
  292. * @{
  293. * @}
  294. * @defgroup lavf_codec_wrappers External library wrappers
  295. * @{
  296. * @}
  297. * @}
  298. * @defgroup lavf_protos I/O Protocols
  299. * @{
  300. * @}
  301. * @defgroup lavf_internal Internal
  302. * @{
  303. * @}
  304. * @}
  305. */
  306. #include <stdio.h> /* FILE */
  307. #include "libavcodec/codec_par.h"
  308. #include "libavcodec/defs.h"
  309. #include "libavcodec/packet.h"
  310. #include "libavutil/dict.h"
  311. #include "libavutil/log.h"
  312. #include "avio.h"
  313. #include "libavformat/version_major.h"
  314. #ifndef HAVE_AV_CONFIG_H
  315. /* When included as part of the ffmpeg build, only include the major version
  316. * to avoid unnecessary rebuilds. When included externally, keep including
  317. * the full version information. */
  318. #include "libavformat/version.h"
  319. #include "libavutil/frame.h"
  320. #include "libavcodec/codec.h"
  321. #endif
  322. struct AVFormatContext;
  323. struct AVFrame;
  324. /**
  325. * @defgroup metadata_api Public Metadata API
  326. * @{
  327. * @ingroup libavf
  328. * The metadata API allows libavformat to export metadata tags to a client
  329. * application when demuxing. Conversely it allows a client application to
  330. * set metadata when muxing.
  331. *
  332. * Metadata is exported or set as pairs of key/value strings in the 'metadata'
  333. * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs
  334. * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg,
  335. * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata
  336. * exported by demuxers isn't checked to be valid UTF-8 in most cases.
  337. *
  338. * Important concepts to keep in mind:
  339. * - Keys are unique; there can never be 2 tags with the same key. This is
  340. * also meant semantically, i.e., a demuxer should not knowingly produce
  341. * several keys that are literally different but semantically identical.
  342. * E.g., key=Author5, key=Author6. In this example, all authors must be
  343. * placed in the same tag.
  344. * - Metadata is flat, not hierarchical; there are no subtags. If you
  345. * want to store, e.g., the email address of the child of producer Alice
  346. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  347. * - Several modifiers can be applied to the tag name. This is done by
  348. * appending a dash character ('-') and the modifier name in the order
  349. * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
  350. * - language -- a tag whose value is localized for a particular language
  351. * is appended with the ISO 639-2/B 3-letter language code.
  352. * For example: Author-ger=Michael, Author-eng=Mike
  353. * The original/default language is in the unqualified "Author" tag.
  354. * A demuxer should set a default if it sets any translated tag.
  355. * - sorting -- a modified version of a tag that should be used for
  356. * sorting will have '-sort' appended. E.g. artist="The Beatles",
  357. * artist-sort="Beatles, The".
  358. * - Some protocols and demuxers support metadata updates. After a successful
  359. * call to av_read_frame(), AVFormatContext.event_flags or AVStream.event_flags
  360. * will be updated to indicate if metadata changed. In order to detect metadata
  361. * changes on a stream, you need to loop through all streams in the AVFormatContext
  362. * and check their individual event_flags.
  363. *
  364. * - Demuxers attempt to export metadata in a generic format, however tags
  365. * with no generic equivalents are left as they are stored in the container.
  366. * Follows a list of generic tag names:
  367. *
  368. @verbatim
  369. album -- name of the set this work belongs to
  370. album_artist -- main creator of the set/album, if different from artist.
  371. e.g. "Various Artists" for compilation albums.
  372. artist -- main creator of the work
  373. comment -- any additional description of the file.
  374. composer -- who composed the work, if different from artist.
  375. copyright -- name of copyright holder.
  376. creation_time-- date when the file was created, preferably in ISO 8601.
  377. date -- date when the work was created, preferably in ISO 8601.
  378. disc -- number of a subset, e.g. disc in a multi-disc collection.
  379. encoder -- name/settings of the software/hardware that produced the file.
  380. encoded_by -- person/group who created the file.
  381. filename -- original name of the file.
  382. genre -- <self-evident>.
  383. language -- main language in which the work is performed, preferably
  384. in ISO 639-2 format. Multiple languages can be specified by
  385. separating them with commas.
  386. performer -- artist who performed the work, if different from artist.
  387. E.g for "Also sprach Zarathustra", artist would be "Richard
  388. Strauss" and performer "London Philharmonic Orchestra".
  389. publisher -- name of the label/publisher.
  390. service_name -- name of the service in broadcasting (channel name).
  391. service_provider -- name of the service provider in broadcasting.
  392. title -- name of the work.
  393. track -- number of this work in the set, can be in form current/total.
  394. variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
  395. @endverbatim
  396. *
  397. * Look in the examples section for an application example how to use the Metadata API.
  398. *
  399. * @}
  400. */
  401. /* packet functions */
  402. /**
  403. * Allocate and read the payload of a packet and initialize its
  404. * fields with default values.
  405. *
  406. * @param s associated IO context
  407. * @param pkt packet
  408. * @param size desired payload size
  409. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  410. */
  411. int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
  412. /**
  413. * Read data and append it to the current content of the AVPacket.
  414. * If pkt->size is 0 this is identical to av_get_packet.
  415. * Note that this uses av_grow_packet and thus involves a realloc
  416. * which is inefficient. Thus this function should only be used
  417. * when there is no reasonable way to know (an upper bound of)
  418. * the final size.
  419. *
  420. * @param s associated IO context
  421. * @param pkt packet
  422. * @param size amount of data to read
  423. * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
  424. * will not be lost even if an error occurs.
  425. */
  426. int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
  427. /*************************************************/
  428. /* input/output formats */
  429. struct AVCodecTag;
  430. /**
  431. * This structure contains the data a format has to probe a file.
  432. */
  433. typedef struct AVProbeData {
  434. const char *filename;
  435. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  436. int buf_size; /**< Size of buf except extra allocated bytes */
  437. const char *mime_type; /**< mime_type, when known. */
  438. } AVProbeData;
  439. #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
  440. #define AVPROBE_SCORE_STREAM_RETRY (AVPROBE_SCORE_MAX/4-1)
  441. #define AVPROBE_SCORE_EXTENSION 50 ///< score for file extension
  442. #define AVPROBE_SCORE_MIME 75 ///< score for file mime type
  443. #define AVPROBE_SCORE_MAX 100 ///< maximum score
  444. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  445. /// Demuxer will use avio_open, no opened file should be provided by the caller.
  446. #define AVFMT_NOFILE 0x0001
  447. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  448. /**
  449. * The muxer/demuxer is experimental and should be used with caution.
  450. *
  451. * - demuxers: will not be selected automatically by probing, must be specified
  452. * explicitly.
  453. */
  454. #define AVFMT_EXPERIMENTAL 0x0004
  455. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  456. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  457. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  458. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  459. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
  460. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  461. #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
  462. #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
  463. #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fall back on binary search via read_timestamp */
  464. #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fall back on generic search */
  465. #define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */
  466. #if FF_API_ALLOW_FLUSH
  467. #define AVFMT_ALLOW_FLUSH 0x10000 /**< @deprecated: Just send a NULL packet if you want to flush a muxer. */
  468. #endif
  469. #define AVFMT_TS_NONSTRICT 0x20000 /**< Format does not require strictly
  470. increasing timestamps, but they must
  471. still be monotonic */
  472. #define AVFMT_TS_NEGATIVE 0x40000 /**< Format allows muxing negative
  473. timestamps. If not set the timestamp
  474. will be shifted in av_write_frame and
  475. av_interleaved_write_frame so they
  476. start from 0.
  477. The user or muxer can override this through
  478. AVFormatContext.avoid_negative_ts
  479. */
  480. #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
  481. /**
  482. * @addtogroup lavf_encoding
  483. * @{
  484. */
  485. typedef struct AVOutputFormat {
  486. const char *name;
  487. /**
  488. * Descriptive name for the format, meant to be more human-readable
  489. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  490. * to define it.
  491. */
  492. const char *long_name;
  493. const char *mime_type;
  494. const char *extensions; /**< comma-separated filename extensions */
  495. /* output support */
  496. enum AVCodecID audio_codec; /**< default audio codec */
  497. enum AVCodecID video_codec; /**< default video codec */
  498. enum AVCodecID subtitle_codec; /**< default subtitle codec */
  499. /**
  500. * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER,
  501. * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
  502. * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS,
  503. * AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE
  504. */
  505. int flags;
  506. /**
  507. * List of supported codec_id-codec_tag pairs, ordered by "better
  508. * choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
  509. */
  510. const struct AVCodecTag * const *codec_tag;
  511. const AVClass *priv_class; ///< AVClass for the private context
  512. } AVOutputFormat;
  513. /**
  514. * @}
  515. */
  516. /**
  517. * @addtogroup lavf_decoding
  518. * @{
  519. */
  520. typedef struct AVInputFormat {
  521. /**
  522. * A comma separated list of short names for the format. New names
  523. * may be appended with a minor bump.
  524. */
  525. const char *name;
  526. /**
  527. * Descriptive name for the format, meant to be more human-readable
  528. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  529. * to define it.
  530. */
  531. const char *long_name;
  532. /**
  533. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
  534. * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
  535. * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
  536. */
  537. int flags;
  538. /**
  539. * If extensions are defined, then no probe is done. You should
  540. * usually not use extension format guessing because it is not
  541. * reliable enough
  542. */
  543. const char *extensions;
  544. const struct AVCodecTag * const *codec_tag;
  545. const AVClass *priv_class; ///< AVClass for the private context
  546. /**
  547. * Comma-separated list of mime types.
  548. * It is used check for matching mime types while probing.
  549. * @see av_probe_input_format2
  550. */
  551. const char *mime_type;
  552. } AVInputFormat;
  553. /**
  554. * @}
  555. */
  556. enum AVStreamParseType {
  557. AVSTREAM_PARSE_NONE,
  558. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  559. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  560. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  561. AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
  562. AVSTREAM_PARSE_FULL_RAW, /**< full parsing and repack with timestamp and position generation by parser for raw
  563. this assumes that each packet in the file contains no demuxer level headers and
  564. just codec level data, otherwise position generation would fail */
  565. };
  566. typedef struct AVIndexEntry {
  567. int64_t pos;
  568. int64_t timestamp; /**<
  569. * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available
  570. * when seeking to this entry. That means preferable PTS on keyframe based formats.
  571. * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better
  572. * is known
  573. */
  574. #define AVINDEX_KEYFRAME 0x0001
  575. #define AVINDEX_DISCARD_FRAME 0x0002 /**
  576. * Flag is used to indicate which frame should be discarded after decoding.
  577. */
  578. int flags:2;
  579. int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
  580. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  581. } AVIndexEntry;
  582. /**
  583. * The stream should be chosen by default among other streams of the same type,
  584. * unless the user has explicitly specified otherwise.
  585. */
  586. #define AV_DISPOSITION_DEFAULT (1 << 0)
  587. /**
  588. * The stream is not in original language.
  589. *
  590. * @note AV_DISPOSITION_ORIGINAL is the inverse of this disposition. At most
  591. * one of them should be set in properly tagged streams.
  592. * @note This disposition may apply to any stream type, not just audio.
  593. */
  594. #define AV_DISPOSITION_DUB (1 << 1)
  595. /**
  596. * The stream is in original language.
  597. *
  598. * @see the notes for AV_DISPOSITION_DUB
  599. */
  600. #define AV_DISPOSITION_ORIGINAL (1 << 2)
  601. /**
  602. * The stream is a commentary track.
  603. */
  604. #define AV_DISPOSITION_COMMENT (1 << 3)
  605. /**
  606. * The stream contains song lyrics.
  607. */
  608. #define AV_DISPOSITION_LYRICS (1 << 4)
  609. /**
  610. * The stream contains karaoke audio.
  611. */
  612. #define AV_DISPOSITION_KARAOKE (1 << 5)
  613. /**
  614. * Track should be used during playback by default.
  615. * Useful for subtitle track that should be displayed
  616. * even when user did not explicitly ask for subtitles.
  617. */
  618. #define AV_DISPOSITION_FORCED (1 << 6)
  619. /**
  620. * The stream is intended for hearing impaired audiences.
  621. */
  622. #define AV_DISPOSITION_HEARING_IMPAIRED (1 << 7)
  623. /**
  624. * The stream is intended for visually impaired audiences.
  625. */
  626. #define AV_DISPOSITION_VISUAL_IMPAIRED (1 << 8)
  627. /**
  628. * The audio stream contains music and sound effects without voice.
  629. */
  630. #define AV_DISPOSITION_CLEAN_EFFECTS (1 << 9)
  631. /**
  632. * The stream is stored in the file as an attached picture/"cover art" (e.g.
  633. * APIC frame in ID3v2). The first (usually only) packet associated with it
  634. * will be returned among the first few packets read from the file unless
  635. * seeking takes place. It can also be accessed at any time in
  636. * AVStream.attached_pic.
  637. */
  638. #define AV_DISPOSITION_ATTACHED_PIC (1 << 10)
  639. /**
  640. * The stream is sparse, and contains thumbnail images, often corresponding
  641. * to chapter markers. Only ever used with AV_DISPOSITION_ATTACHED_PIC.
  642. */
  643. #define AV_DISPOSITION_TIMED_THUMBNAILS (1 << 11)
  644. /**
  645. * The stream is intended to be mixed with a spatial audio track. For example,
  646. * it could be used for narration or stereo music, and may remain unchanged by
  647. * listener head rotation.
  648. */
  649. #define AV_DISPOSITION_NON_DIEGETIC (1 << 12)
  650. /**
  651. * The subtitle stream contains captions, providing a transcription and possibly
  652. * a translation of audio. Typically intended for hearing-impaired audiences.
  653. */
  654. #define AV_DISPOSITION_CAPTIONS (1 << 16)
  655. /**
  656. * The subtitle stream contains a textual description of the video content.
  657. * Typically intended for visually-impaired audiences or for the cases where the
  658. * video cannot be seen.
  659. */
  660. #define AV_DISPOSITION_DESCRIPTIONS (1 << 17)
  661. /**
  662. * The subtitle stream contains time-aligned metadata that is not intended to be
  663. * directly presented to the user.
  664. */
  665. #define AV_DISPOSITION_METADATA (1 << 18)
  666. /**
  667. * The stream is intended to be mixed with another stream before presentation.
  668. * Used for example to signal the stream contains an image part of a HEIF grid,
  669. * or for mix_type=0 in mpegts.
  670. */
  671. #define AV_DISPOSITION_DEPENDENT (1 << 19)
  672. /**
  673. * The video stream contains still images.
  674. */
  675. #define AV_DISPOSITION_STILL_IMAGE (1 << 20)
  676. /**
  677. * @return The AV_DISPOSITION_* flag corresponding to disp or a negative error
  678. * code if disp does not correspond to a known stream disposition.
  679. */
  680. int av_disposition_from_string(const char *disp);
  681. /**
  682. * @param disposition a combination of AV_DISPOSITION_* values
  683. * @return The string description corresponding to the lowest set bit in
  684. * disposition. NULL when the lowest set bit does not correspond
  685. * to a known disposition or when disposition is 0.
  686. */
  687. const char *av_disposition_to_string(int disposition);
  688. /**
  689. * Options for behavior on timestamp wrap detection.
  690. */
  691. #define AV_PTS_WRAP_IGNORE 0 ///< ignore the wrap
  692. #define AV_PTS_WRAP_ADD_OFFSET 1 ///< add the format specific offset on wrap detection
  693. #define AV_PTS_WRAP_SUB_OFFSET -1 ///< subtract the format specific offset on wrap detection
  694. /**
  695. * Stream structure.
  696. * New fields can be added to the end with minor version bumps.
  697. * Removal, reordering and changes to existing fields require a major
  698. * version bump.
  699. * sizeof(AVStream) must not be used outside libav*.
  700. */
  701. typedef struct AVStream {
  702. /**
  703. * A class for @ref avoptions. Set on stream creation.
  704. */
  705. const AVClass *av_class;
  706. int index; /**< stream index in AVFormatContext */
  707. /**
  708. * Format-specific stream ID.
  709. * decoding: set by libavformat
  710. * encoding: set by the user, replaced by libavformat if left unset
  711. */
  712. int id;
  713. /**
  714. * Codec parameters associated with this stream. Allocated and freed by
  715. * libavformat in avformat_new_stream() and avformat_free_context()
  716. * respectively.
  717. *
  718. * - demuxing: filled by libavformat on stream creation or in
  719. * avformat_find_stream_info()
  720. * - muxing: filled by the caller before avformat_write_header()
  721. */
  722. AVCodecParameters *codecpar;
  723. void *priv_data;
  724. /**
  725. * This is the fundamental unit of time (in seconds) in terms
  726. * of which frame timestamps are represented.
  727. *
  728. * decoding: set by libavformat
  729. * encoding: May be set by the caller before avformat_write_header() to
  730. * provide a hint to the muxer about the desired timebase. In
  731. * avformat_write_header(), the muxer will overwrite this field
  732. * with the timebase that will actually be used for the timestamps
  733. * written into the file (which may or may not be related to the
  734. * user-provided one, depending on the format).
  735. */
  736. AVRational time_base;
  737. /**
  738. * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
  739. * Only set this if you are absolutely 100% sure that the value you set
  740. * it to really is the pts of the first frame.
  741. * This may be undefined (AV_NOPTS_VALUE).
  742. * @note The ASF header does NOT contain a correct start_time the ASF
  743. * demuxer must NOT set this.
  744. */
  745. int64_t start_time;
  746. /**
  747. * Decoding: duration of the stream, in stream time base.
  748. * If a source file does not specify a duration, but does specify
  749. * a bitrate, this value will be estimated from bitrate and file size.
  750. *
  751. * Encoding: May be set by the caller before avformat_write_header() to
  752. * provide a hint to the muxer about the estimated duration.
  753. */
  754. int64_t duration;
  755. int64_t nb_frames; ///< number of frames in this stream if known or 0
  756. /**
  757. * Stream disposition - a combination of AV_DISPOSITION_* flags.
  758. * - demuxing: set by libavformat when creating the stream or in
  759. * avformat_find_stream_info().
  760. * - muxing: may be set by the caller before avformat_write_header().
  761. */
  762. int disposition;
  763. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  764. /**
  765. * sample aspect ratio (0 if unknown)
  766. * - encoding: Set by user.
  767. * - decoding: Set by libavformat.
  768. */
  769. AVRational sample_aspect_ratio;
  770. AVDictionary *metadata;
  771. /**
  772. * Average framerate
  773. *
  774. * - demuxing: May be set by libavformat when creating the stream or in
  775. * avformat_find_stream_info().
  776. * - muxing: May be set by the caller before avformat_write_header().
  777. */
  778. AVRational avg_frame_rate;
  779. /**
  780. * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
  781. * will contain the attached picture.
  782. *
  783. * decoding: set by libavformat, must not be modified by the caller.
  784. * encoding: unused
  785. */
  786. AVPacket attached_pic;
  787. #if FF_API_AVSTREAM_SIDE_DATA
  788. /**
  789. * An array of side data that applies to the whole stream (i.e. the
  790. * container does not allow it to change between packets).
  791. *
  792. * There may be no overlap between the side data in this array and side data
  793. * in the packets. I.e. a given side data is either exported by the muxer
  794. * (demuxing) / set by the caller (muxing) in this array, then it never
  795. * appears in the packets, or the side data is exported / sent through
  796. * the packets (always in the first packet where the value becomes known or
  797. * changes), then it does not appear in this array.
  798. *
  799. * - demuxing: Set by libavformat when the stream is created.
  800. * - muxing: May be set by the caller before avformat_write_header().
  801. *
  802. * Freed by libavformat in avformat_free_context().
  803. *
  804. * @deprecated use AVStream's @ref AVCodecParameters.coded_side_data
  805. * "codecpar side data".
  806. */
  807. attribute_deprecated
  808. AVPacketSideData *side_data;
  809. /**
  810. * The number of elements in the AVStream.side_data array.
  811. *
  812. * @deprecated use AVStream's @ref AVCodecParameters.nb_coded_side_data
  813. * "codecpar side data".
  814. */
  815. attribute_deprecated
  816. int nb_side_data;
  817. #endif
  818. /**
  819. * Flags indicating events happening on the stream, a combination of
  820. * AVSTREAM_EVENT_FLAG_*.
  821. *
  822. * - demuxing: may be set by the demuxer in avformat_open_input(),
  823. * avformat_find_stream_info() and av_read_frame(). Flags must be cleared
  824. * by the user once the event has been handled.
  825. * - muxing: may be set by the user after avformat_write_header(). to
  826. * indicate a user-triggered event. The muxer will clear the flags for
  827. * events it has handled in av_[interleaved]_write_frame().
  828. */
  829. int event_flags;
  830. /**
  831. * - demuxing: the demuxer read new metadata from the file and updated
  832. * AVStream.metadata accordingly
  833. * - muxing: the user updated AVStream.metadata and wishes the muxer to write
  834. * it into the file
  835. */
  836. #define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001
  837. /**
  838. * - demuxing: new packets for this stream were read from the file. This
  839. * event is informational only and does not guarantee that new packets
  840. * for this stream will necessarily be returned from av_read_frame().
  841. */
  842. #define AVSTREAM_EVENT_FLAG_NEW_PACKETS (1 << 1)
  843. /**
  844. * Real base framerate of the stream.
  845. * This is the lowest framerate with which all timestamps can be
  846. * represented accurately (it is the least common multiple of all
  847. * framerates in the stream). Note, this value is just a guess!
  848. * For example, if the time base is 1/90000 and all frames have either
  849. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  850. */
  851. AVRational r_frame_rate;
  852. /**
  853. * Number of bits in timestamps. Used for wrapping control.
  854. *
  855. * - demuxing: set by libavformat
  856. * - muxing: set by libavformat
  857. *
  858. */
  859. int pts_wrap_bits;
  860. } AVStream;
  861. /**
  862. * AVStreamGroupTileGrid holds information on how to combine several
  863. * independent images on a single canvas for presentation.
  864. *
  865. * The output should be a @ref AVStreamGroupTileGrid.background "background"
  866. * colored @ref AVStreamGroupTileGrid.coded_width "coded_width" x
  867. * @ref AVStreamGroupTileGrid.coded_height "coded_height" canvas where a
  868. * @ref AVStreamGroupTileGrid.nb_tiles "nb_tiles" amount of tiles are placed in
  869. * the order they appear in the @ref AVStreamGroupTileGrid.offsets "offsets"
  870. * array, at the exact offset described for them. In particular, if two or more
  871. * tiles overlap, the image with higher index in the
  872. * @ref AVStreamGroupTileGrid.offsets "offsets" array takes priority.
  873. * Note that a single image may be used multiple times, i.e. multiple entries
  874. * in @ref AVStreamGroupTileGrid.offsets "offsets" may have the same value of
  875. * idx.
  876. *
  877. * The following is an example of a simple grid with 3 rows and 4 columns:
  878. *
  879. * +---+---+---+---+
  880. * | 0 | 1 | 2 | 3 |
  881. * +---+---+---+---+
  882. * | 4 | 5 | 6 | 7 |
  883. * +---+---+---+---+
  884. * | 8 | 9 |10 |11 |
  885. * +---+---+---+---+
  886. *
  887. * Assuming all tiles have a dimension of 512x512, the
  888. * @ref AVStreamGroupTileGrid.offsets "offset" of the topleft pixel of
  889. * the first @ref AVStreamGroup.streams "stream" in the group is "0,0", the
  890. * @ref AVStreamGroupTileGrid.offsets "offset" of the topleft pixel of
  891. * the second @ref AVStreamGroup.streams "stream" in the group is "512,0", the
  892. * @ref AVStreamGroupTileGrid.offsets "offset" of the topleft pixel of
  893. * the fifth @ref AVStreamGroup.streams "stream" in the group is "0,512", the
  894. * @ref AVStreamGroupTileGrid.offsets "offset", of the topleft pixel of
  895. * the sixth @ref AVStreamGroup.streams "stream" in the group is "512,512",
  896. * etc.
  897. *
  898. * The following is an example of a canvas with overlaping tiles:
  899. *
  900. * +-----------+
  901. * | %%%%% |
  902. * |***%%3%%@@@|
  903. * |**0%%%%%2@@|
  904. * |***##1@@@@@|
  905. * | ##### |
  906. * +-----------+
  907. *
  908. * Assuming a canvas with size 1024x1024 and all tiles with a dimension of
  909. * 512x512, a possible @ref AVStreamGroupTileGrid.offsets "offset" for the
  910. * topleft pixel of the first @ref AVStreamGroup.streams "stream" in the group
  911. * would be 0x256, the @ref AVStreamGroupTileGrid.offsets "offset" for the
  912. * topleft pixel of the second @ref AVStreamGroup.streams "stream" in the group
  913. * would be 256x512, the @ref AVStreamGroupTileGrid.offsets "offset" for the
  914. * topleft pixel of the third @ref AVStreamGroup.streams "stream" in the group
  915. * would be 512x256, and the @ref AVStreamGroupTileGrid.offsets "offset" for
  916. * the topleft pixel of the fourth @ref AVStreamGroup.streams "stream" in the
  917. * group would be 256x0.
  918. *
  919. * sizeof(AVStreamGroupTileGrid) is not a part of the ABI and may only be
  920. * allocated by avformat_stream_group_create().
  921. */
  922. typedef struct AVStreamGroupTileGrid {
  923. const AVClass *av_class;
  924. /**
  925. * Amount of tiles in the grid.
  926. *
  927. * Must be > 0.
  928. */
  929. unsigned int nb_tiles;
  930. /**
  931. * Width of the canvas.
  932. *
  933. * Must be > 0.
  934. */
  935. int coded_width;
  936. /**
  937. * Width of the canvas.
  938. *
  939. * Must be > 0.
  940. */
  941. int coded_height;
  942. /**
  943. * An @ref nb_tiles sized array of offsets in pixels from the topleft edge
  944. * of the canvas, indicating where each stream should be placed.
  945. * It must be allocated with the av_malloc() family of functions.
  946. *
  947. * - demuxing: set by libavformat, must not be modified by the caller.
  948. * - muxing: set by the caller before avformat_write_header().
  949. *
  950. * Freed by libavformat in avformat_free_context().
  951. */
  952. struct {
  953. /**
  954. * Index of the stream in the group this tile references.
  955. *
  956. * Must be < @ref AVStreamGroup.nb_streams "nb_streams".
  957. */
  958. unsigned int idx;
  959. /**
  960. * Offset in pixels from the left edge of the canvas where the tile
  961. * should be placed.
  962. */
  963. int horizontal;
  964. /**
  965. * Offset in pixels from the top edge of the canvas where the tile
  966. * should be placed.
  967. */
  968. int vertical;
  969. } *offsets;
  970. /**
  971. * The pixel value per channel in RGBA format used if no pixel of any tile
  972. * is located at a particular pixel location.
  973. *
  974. * @see av_image_fill_color().
  975. * @see av_parse_color().
  976. */
  977. uint8_t background[4];
  978. /**
  979. * Offset in pixels from the left edge of the canvas where the actual image
  980. * meant for presentation starts.
  981. *
  982. * This field must be >= 0 and < @ref coded_width.
  983. */
  984. int horizontal_offset;
  985. /**
  986. * Offset in pixels from the top edge of the canvas where the actual image
  987. * meant for presentation starts.
  988. *
  989. * This field must be >= 0 and < @ref coded_height.
  990. */
  991. int vertical_offset;
  992. /**
  993. * Width of the final image for presentation.
  994. *
  995. * Must be > 0 and <= (@ref coded_width - @ref horizontal_offset).
  996. * When it's not equal to (@ref coded_width - @ref horizontal_offset), the
  997. * result of (@ref coded_width - width - @ref horizontal_offset) is the
  998. * amount amount of pixels to be cropped from the right edge of the
  999. * final image before presentation.
  1000. */
  1001. int width;
  1002. /**
  1003. * Height of the final image for presentation.
  1004. *
  1005. * Must be > 0 and <= (@ref coded_height - @ref vertical_offset).
  1006. * When it's not equal to (@ref coded_height - @ref vertical_offset), the
  1007. * result of (@ref coded_height - height - @ref vertical_offset) is the
  1008. * amount amount of pixels to be cropped from the bottom edge of the
  1009. * final image before presentation.
  1010. */
  1011. int height;
  1012. } AVStreamGroupTileGrid;
  1013. enum AVStreamGroupParamsType {
  1014. AV_STREAM_GROUP_PARAMS_NONE,
  1015. AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT,
  1016. AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION,
  1017. AV_STREAM_GROUP_PARAMS_TILE_GRID,
  1018. };
  1019. struct AVIAMFAudioElement;
  1020. struct AVIAMFMixPresentation;
  1021. typedef struct AVStreamGroup {
  1022. /**
  1023. * A class for @ref avoptions. Set by avformat_stream_group_create().
  1024. */
  1025. const AVClass *av_class;
  1026. void *priv_data;
  1027. /**
  1028. * Group index in AVFormatContext.
  1029. */
  1030. unsigned int index;
  1031. /**
  1032. * Group type-specific group ID.
  1033. *
  1034. * decoding: set by libavformat
  1035. * encoding: may set by the user
  1036. */
  1037. int64_t id;
  1038. /**
  1039. * Group type
  1040. *
  1041. * decoding: set by libavformat on group creation
  1042. * encoding: set by avformat_stream_group_create()
  1043. */
  1044. enum AVStreamGroupParamsType type;
  1045. /**
  1046. * Group type-specific parameters
  1047. */
  1048. union {
  1049. struct AVIAMFAudioElement *iamf_audio_element;
  1050. struct AVIAMFMixPresentation *iamf_mix_presentation;
  1051. struct AVStreamGroupTileGrid *tile_grid;
  1052. } params;
  1053. /**
  1054. * Metadata that applies to the whole group.
  1055. *
  1056. * - demuxing: set by libavformat on group creation
  1057. * - muxing: may be set by the caller before avformat_write_header()
  1058. *
  1059. * Freed by libavformat in avformat_free_context().
  1060. */
  1061. AVDictionary *metadata;
  1062. /**
  1063. * Number of elements in AVStreamGroup.streams.
  1064. *
  1065. * Set by avformat_stream_group_add_stream() must not be modified by any other code.
  1066. */
  1067. unsigned int nb_streams;
  1068. /**
  1069. * A list of streams in the group. New entries are created with
  1070. * avformat_stream_group_add_stream().
  1071. *
  1072. * - demuxing: entries are created by libavformat on group creation.
  1073. * If AVFMTCTX_NOHEADER is set in ctx_flags, then new entries may also
  1074. * appear in av_read_frame().
  1075. * - muxing: entries are created by the user before avformat_write_header().
  1076. *
  1077. * Freed by libavformat in avformat_free_context().
  1078. */
  1079. AVStream **streams;
  1080. /**
  1081. * Stream group disposition - a combination of AV_DISPOSITION_* flags.
  1082. * This field currently applies to all defined AVStreamGroupParamsType.
  1083. *
  1084. * - demuxing: set by libavformat when creating the group or in
  1085. * avformat_find_stream_info().
  1086. * - muxing: may be set by the caller before avformat_write_header().
  1087. */
  1088. int disposition;
  1089. } AVStreamGroup;
  1090. struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);
  1091. #define AV_PROGRAM_RUNNING 1
  1092. /**
  1093. * New fields can be added to the end with minor version bumps.
  1094. * Removal, reordering and changes to existing fields require a major
  1095. * version bump.
  1096. * sizeof(AVProgram) must not be used outside libav*.
  1097. */
  1098. typedef struct AVProgram {
  1099. int id;
  1100. int flags;
  1101. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  1102. unsigned int *stream_index;
  1103. unsigned int nb_stream_indexes;
  1104. AVDictionary *metadata;
  1105. int program_num;
  1106. int pmt_pid;
  1107. int pcr_pid;
  1108. int pmt_version;
  1109. /*****************************************************************
  1110. * All fields below this line are not part of the public API. They
  1111. * may not be used outside of libavformat and can be changed and
  1112. * removed at will.
  1113. * New public fields should be added right above.
  1114. *****************************************************************
  1115. */
  1116. int64_t start_time;
  1117. int64_t end_time;
  1118. int64_t pts_wrap_reference; ///< reference dts for wrap detection
  1119. int pts_wrap_behavior; ///< behavior on wrap detection
  1120. } AVProgram;
  1121. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  1122. (streams are added dynamically) */
  1123. #define AVFMTCTX_UNSEEKABLE 0x0002 /**< signal that the stream is definitely
  1124. not seekable, and attempts to call the
  1125. seek function will fail. For some
  1126. network protocols (e.g. HLS), this can
  1127. change dynamically at runtime. */
  1128. typedef struct AVChapter {
  1129. int64_t id; ///< unique ID to identify the chapter
  1130. AVRational time_base; ///< time base in which the start/end timestamps are specified
  1131. int64_t start, end; ///< chapter start/end time in time_base units
  1132. AVDictionary *metadata;
  1133. } AVChapter;
  1134. /**
  1135. * Callback used by devices to communicate with application.
  1136. */
  1137. typedef int (*av_format_control_message)(struct AVFormatContext *s, int type,
  1138. void *data, size_t data_size);
  1139. typedef int (*AVOpenCallback)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags,
  1140. const AVIOInterruptCB *int_cb, AVDictionary **options);
  1141. /**
  1142. * The duration of a video can be estimated through various ways, and this enum can be used
  1143. * to know how the duration was estimated.
  1144. */
  1145. enum AVDurationEstimationMethod {
  1146. AVFMT_DURATION_FROM_PTS, ///< Duration accurately estimated from PTSes
  1147. AVFMT_DURATION_FROM_STREAM, ///< Duration estimated from a stream with a known duration
  1148. AVFMT_DURATION_FROM_BITRATE ///< Duration estimated from bitrate (less accurate)
  1149. };
  1150. /**
  1151. * Format I/O context.
  1152. * New fields can be added to the end with minor version bumps.
  1153. * Removal, reordering and changes to existing fields require a major
  1154. * version bump.
  1155. * sizeof(AVFormatContext) must not be used outside libav*, use
  1156. * avformat_alloc_context() to create an AVFormatContext.
  1157. *
  1158. * Fields can be accessed through AVOptions (av_opt*),
  1159. * the name string used matches the associated command line parameter name and
  1160. * can be found in libavformat/options_table.h.
  1161. * The AVOption/command line parameter names differ in some cases from the C
  1162. * structure field names for historic reasons or brevity.
  1163. */
  1164. typedef struct AVFormatContext {
  1165. /**
  1166. * A class for logging and @ref avoptions. Set by avformat_alloc_context().
  1167. * Exports (de)muxer private options if they exist.
  1168. */
  1169. const AVClass *av_class;
  1170. /**
  1171. * The input container format.
  1172. *
  1173. * Demuxing only, set by avformat_open_input().
  1174. */
  1175. const struct AVInputFormat *iformat;
  1176. /**
  1177. * The output container format.
  1178. *
  1179. * Muxing only, must be set by the caller before avformat_write_header().
  1180. */
  1181. const struct AVOutputFormat *oformat;
  1182. /**
  1183. * Format private data. This is an AVOptions-enabled struct
  1184. * if and only if iformat/oformat.priv_class is not NULL.
  1185. *
  1186. * - muxing: set by avformat_write_header()
  1187. * - demuxing: set by avformat_open_input()
  1188. */
  1189. void *priv_data;
  1190. /**
  1191. * I/O context.
  1192. *
  1193. * - demuxing: either set by the user before avformat_open_input() (then
  1194. * the user must close it manually) or set by avformat_open_input().
  1195. * - muxing: set by the user before avformat_write_header(). The caller must
  1196. * take care of closing / freeing the IO context.
  1197. *
  1198. * Do NOT set this field if AVFMT_NOFILE flag is set in
  1199. * iformat/oformat.flags. In such a case, the (de)muxer will handle
  1200. * I/O in some other way and this field will be NULL.
  1201. */
  1202. AVIOContext *pb;
  1203. /* stream info */
  1204. /**
  1205. * Flags signalling stream properties. A combination of AVFMTCTX_*.
  1206. * Set by libavformat.
  1207. */
  1208. int ctx_flags;
  1209. /**
  1210. * Number of elements in AVFormatContext.streams.
  1211. *
  1212. * Set by avformat_new_stream(), must not be modified by any other code.
  1213. */
  1214. unsigned int nb_streams;
  1215. /**
  1216. * A list of all streams in the file. New streams are created with
  1217. * avformat_new_stream().
  1218. *
  1219. * - demuxing: streams are created by libavformat in avformat_open_input().
  1220. * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
  1221. * appear in av_read_frame().
  1222. * - muxing: streams are created by the user before avformat_write_header().
  1223. *
  1224. * Freed by libavformat in avformat_free_context().
  1225. */
  1226. AVStream **streams;
  1227. /**
  1228. * Number of elements in AVFormatContext.stream_groups.
  1229. *
  1230. * Set by avformat_stream_group_create(), must not be modified by any other code.
  1231. */
  1232. unsigned int nb_stream_groups;
  1233. /**
  1234. * A list of all stream groups in the file. New groups are created with
  1235. * avformat_stream_group_create(), and filled with avformat_stream_group_add_stream().
  1236. *
  1237. * - demuxing: groups may be created by libavformat in avformat_open_input().
  1238. * If AVFMTCTX_NOHEADER is set in ctx_flags, then new groups may also
  1239. * appear in av_read_frame().
  1240. * - muxing: groups may be created by the user before avformat_write_header().
  1241. *
  1242. * Freed by libavformat in avformat_free_context().
  1243. */
  1244. AVStreamGroup **stream_groups;
  1245. /**
  1246. * Number of chapters in AVChapter array.
  1247. * When muxing, chapters are normally written in the file header,
  1248. * so nb_chapters should normally be initialized before write_header
  1249. * is called. Some muxers (e.g. mov and mkv) can also write chapters
  1250. * in the trailer. To write chapters in the trailer, nb_chapters
  1251. * must be zero when write_header is called and non-zero when
  1252. * write_trailer is called.
  1253. * - muxing: set by user
  1254. * - demuxing: set by libavformat
  1255. */
  1256. unsigned int nb_chapters;
  1257. AVChapter **chapters;
  1258. /**
  1259. * input or output URL. Unlike the old filename field, this field has no
  1260. * length restriction.
  1261. *
  1262. * - demuxing: set by avformat_open_input(), initialized to an empty
  1263. * string if url parameter was NULL in avformat_open_input().
  1264. * - muxing: may be set by the caller before calling avformat_write_header()
  1265. * (or avformat_init_output() if that is called first) to a string
  1266. * which is freeable by av_free(). Set to an empty string if it
  1267. * was NULL in avformat_init_output().
  1268. *
  1269. * Freed by libavformat in avformat_free_context().
  1270. */
  1271. char *url;
  1272. /**
  1273. * Position of the first frame of the component, in
  1274. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  1275. * It is deduced from the AVStream values.
  1276. *
  1277. * Demuxing only, set by libavformat.
  1278. */
  1279. int64_t start_time;
  1280. /**
  1281. * Duration of the stream, in AV_TIME_BASE fractional
  1282. * seconds. Only set this value if you know none of the individual stream
  1283. * durations and also do not set any of them. This is deduced from the
  1284. * AVStream values if not set.
  1285. *
  1286. * Demuxing only, set by libavformat.
  1287. */
  1288. int64_t duration;
  1289. /**
  1290. * Total stream bitrate in bit/s, 0 if not
  1291. * available. Never set it directly if the file_size and the
  1292. * duration are known as FFmpeg can compute it automatically.
  1293. */
  1294. int64_t bit_rate;
  1295. unsigned int packet_size;
  1296. int max_delay;
  1297. /**
  1298. * Flags modifying the (de)muxer behaviour. A combination of AVFMT_FLAG_*.
  1299. * Set by the user before avformat_open_input() / avformat_write_header().
  1300. */
  1301. int flags;
  1302. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  1303. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  1304. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  1305. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  1306. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  1307. #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
  1308. #define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible
  1309. #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
  1310. #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
  1311. #define AVFMT_FLAG_FLUSH_PACKETS 0x0200 ///< Flush the AVIOContext every packet.
  1312. /**
  1313. * When muxing, try to avoid writing any random/volatile data to the output.
  1314. * This includes any random IDs, real-time timestamps/dates, muxer version, etc.
  1315. *
  1316. * This flag is mainly intended for testing.
  1317. */
  1318. #define AVFMT_FLAG_BITEXACT 0x0400
  1319. #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
  1320. #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats
  1321. #if FF_API_LAVF_SHORTEST
  1322. #define AVFMT_FLAG_SHORTEST 0x100000 ///< Stop muxing when the shortest stream stops.
  1323. #endif
  1324. #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer
  1325. /**
  1326. * Maximum number of bytes read from input in order to determine stream
  1327. * properties. Used when reading the global header and in
  1328. * avformat_find_stream_info().
  1329. *
  1330. * Demuxing only, set by the caller before avformat_open_input().
  1331. *
  1332. * @note this is \e not used for determining the \ref AVInputFormat
  1333. * "input format"
  1334. * @sa format_probesize
  1335. */
  1336. int64_t probesize;
  1337. /**
  1338. * Maximum duration (in AV_TIME_BASE units) of the data read
  1339. * from input in avformat_find_stream_info().
  1340. * Demuxing only, set by the caller before avformat_find_stream_info().
  1341. * Can be set to 0 to let avformat choose using a heuristic.
  1342. */
  1343. int64_t max_analyze_duration;
  1344. const uint8_t *key;
  1345. int keylen;
  1346. unsigned int nb_programs;
  1347. AVProgram **programs;
  1348. /**
  1349. * Forced video codec_id.
  1350. * Demuxing: Set by user.
  1351. */
  1352. enum AVCodecID video_codec_id;
  1353. /**
  1354. * Forced audio codec_id.
  1355. * Demuxing: Set by user.
  1356. */
  1357. enum AVCodecID audio_codec_id;
  1358. /**
  1359. * Forced subtitle codec_id.
  1360. * Demuxing: Set by user.
  1361. */
  1362. enum AVCodecID subtitle_codec_id;
  1363. /**
  1364. * Forced Data codec_id.
  1365. * Demuxing: Set by user.
  1366. */
  1367. enum AVCodecID data_codec_id;
  1368. /**
  1369. * Metadata that applies to the whole file.
  1370. *
  1371. * - demuxing: set by libavformat in avformat_open_input()
  1372. * - muxing: may be set by the caller before avformat_write_header()
  1373. *
  1374. * Freed by libavformat in avformat_free_context().
  1375. */
  1376. AVDictionary *metadata;
  1377. /**
  1378. * Start time of the stream in real world time, in microseconds
  1379. * since the Unix epoch (00:00 1st January 1970). That is, pts=0 in the
  1380. * stream was captured at this real world time.
  1381. * - muxing: Set by the caller before avformat_write_header(). If set to
  1382. * either 0 or AV_NOPTS_VALUE, then the current wall-time will
  1383. * be used.
  1384. * - demuxing: Set by libavformat. AV_NOPTS_VALUE if unknown. Note that
  1385. * the value may become known after some number of frames
  1386. * have been received.
  1387. */
  1388. int64_t start_time_realtime;
  1389. /**
  1390. * The number of frames used for determining the framerate in
  1391. * avformat_find_stream_info().
  1392. * Demuxing only, set by the caller before avformat_find_stream_info().
  1393. */
  1394. int fps_probe_size;
  1395. /**
  1396. * Error recognition; higher values will detect more errors but may
  1397. * misdetect some more or less valid parts as errors.
  1398. * Demuxing only, set by the caller before avformat_open_input().
  1399. */
  1400. int error_recognition;
  1401. /**
  1402. * Custom interrupt callbacks for the I/O layer.
  1403. *
  1404. * demuxing: set by the user before avformat_open_input().
  1405. * muxing: set by the user before avformat_write_header()
  1406. * (mainly useful for AVFMT_NOFILE formats). The callback
  1407. * should also be passed to avio_open2() if it's used to
  1408. * open the file.
  1409. */
  1410. AVIOInterruptCB interrupt_callback;
  1411. /**
  1412. * Flags to enable debugging.
  1413. */
  1414. int debug;
  1415. #define FF_FDEBUG_TS 0x0001
  1416. /**
  1417. * The maximum number of streams.
  1418. * - encoding: unused
  1419. * - decoding: set by user
  1420. */
  1421. int max_streams;
  1422. /**
  1423. * Maximum amount of memory in bytes to use for the index of each stream.
  1424. * If the index exceeds this size, entries will be discarded as
  1425. * needed to maintain a smaller size. This can lead to slower or less
  1426. * accurate seeking (depends on demuxer).
  1427. * Demuxers for which a full in-memory index is mandatory will ignore
  1428. * this.
  1429. * - muxing: unused
  1430. * - demuxing: set by user
  1431. */
  1432. unsigned int max_index_size;
  1433. /**
  1434. * Maximum amount of memory in bytes to use for buffering frames
  1435. * obtained from realtime capture devices.
  1436. */
  1437. unsigned int max_picture_buffer;
  1438. /**
  1439. * Maximum buffering duration for interleaving.
  1440. *
  1441. * To ensure all the streams are interleaved correctly,
  1442. * av_interleaved_write_frame() will wait until it has at least one packet
  1443. * for each stream before actually writing any packets to the output file.
  1444. * When some streams are "sparse" (i.e. there are large gaps between
  1445. * successive packets), this can result in excessive buffering.
  1446. *
  1447. * This field specifies the maximum difference between the timestamps of the
  1448. * first and the last packet in the muxing queue, above which libavformat
  1449. * will output a packet regardless of whether it has queued a packet for all
  1450. * the streams.
  1451. *
  1452. * Muxing only, set by the caller before avformat_write_header().
  1453. */
  1454. int64_t max_interleave_delta;
  1455. /**
  1456. * Maximum number of packets to read while waiting for the first timestamp.
  1457. * Decoding only.
  1458. */
  1459. int max_ts_probe;
  1460. /**
  1461. * Max chunk time in microseconds.
  1462. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1463. * - encoding: Set by user
  1464. * - decoding: unused
  1465. */
  1466. int max_chunk_duration;
  1467. /**
  1468. * Max chunk size in bytes
  1469. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1470. * - encoding: Set by user
  1471. * - decoding: unused
  1472. */
  1473. int max_chunk_size;
  1474. /**
  1475. * Maximum number of packets that can be probed
  1476. * - encoding: unused
  1477. * - decoding: set by user
  1478. */
  1479. int max_probe_packets;
  1480. /**
  1481. * Allow non-standard and experimental extension
  1482. * @see AVCodecContext.strict_std_compliance
  1483. */
  1484. int strict_std_compliance;
  1485. /**
  1486. * Flags indicating events happening on the file, a combination of
  1487. * AVFMT_EVENT_FLAG_*.
  1488. *
  1489. * - demuxing: may be set by the demuxer in avformat_open_input(),
  1490. * avformat_find_stream_info() and av_read_frame(). Flags must be cleared
  1491. * by the user once the event has been handled.
  1492. * - muxing: may be set by the user after avformat_write_header() to
  1493. * indicate a user-triggered event. The muxer will clear the flags for
  1494. * events it has handled in av_[interleaved]_write_frame().
  1495. */
  1496. int event_flags;
  1497. /**
  1498. * - demuxing: the demuxer read new metadata from the file and updated
  1499. * AVFormatContext.metadata accordingly
  1500. * - muxing: the user updated AVFormatContext.metadata and wishes the muxer to
  1501. * write it into the file
  1502. */
  1503. #define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001
  1504. /**
  1505. * Avoid negative timestamps during muxing.
  1506. * Any value of the AVFMT_AVOID_NEG_TS_* constants.
  1507. * Note, this works better when using av_interleaved_write_frame().
  1508. * - muxing: Set by user
  1509. * - demuxing: unused
  1510. */
  1511. int avoid_negative_ts;
  1512. #define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
  1513. #define AVFMT_AVOID_NEG_TS_DISABLED 0 ///< Do not shift timestamps even when they are negative.
  1514. #define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
  1515. #define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
  1516. /**
  1517. * Audio preload in microseconds.
  1518. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1519. * - encoding: Set by user
  1520. * - decoding: unused
  1521. */
  1522. int audio_preload;
  1523. /**
  1524. * forces the use of wallclock timestamps as pts/dts of packets
  1525. * This has undefined results in the presence of B frames.
  1526. * - encoding: unused
  1527. * - decoding: Set by user
  1528. */
  1529. int use_wallclock_as_timestamps;
  1530. /**
  1531. * Skip duration calcuation in estimate_timings_from_pts.
  1532. * - encoding: unused
  1533. * - decoding: set by user
  1534. */
  1535. int skip_estimate_duration_from_pts;
  1536. /**
  1537. * avio flags, used to force AVIO_FLAG_DIRECT.
  1538. * - encoding: unused
  1539. * - decoding: Set by user
  1540. */
  1541. int avio_flags;
  1542. /**
  1543. * The duration field can be estimated through various ways, and this field can be used
  1544. * to know how the duration was estimated.
  1545. * - encoding: unused
  1546. * - decoding: Read by user
  1547. */
  1548. enum AVDurationEstimationMethod duration_estimation_method;
  1549. /**
  1550. * Skip initial bytes when opening stream
  1551. * - encoding: unused
  1552. * - decoding: Set by user
  1553. */
  1554. int64_t skip_initial_bytes;
  1555. /**
  1556. * Correct single timestamp overflows
  1557. * - encoding: unused
  1558. * - decoding: Set by user
  1559. */
  1560. unsigned int correct_ts_overflow;
  1561. /**
  1562. * Force seeking to any (also non key) frames.
  1563. * - encoding: unused
  1564. * - decoding: Set by user
  1565. */
  1566. int seek2any;
  1567. /**
  1568. * Flush the I/O context after each packet.
  1569. * - encoding: Set by user
  1570. * - decoding: unused
  1571. */
  1572. int flush_packets;
  1573. /**
  1574. * format probing score.
  1575. * The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
  1576. * the format.
  1577. * - encoding: unused
  1578. * - decoding: set by avformat, read by user
  1579. */
  1580. int probe_score;
  1581. /**
  1582. * Maximum number of bytes read from input in order to identify the
  1583. * \ref AVInputFormat "input format". Only used when the format is not set
  1584. * explicitly by the caller.
  1585. *
  1586. * Demuxing only, set by the caller before avformat_open_input().
  1587. *
  1588. * @sa probesize
  1589. */
  1590. int format_probesize;
  1591. /**
  1592. * ',' separated list of allowed decoders.
  1593. * If NULL then all are allowed
  1594. * - encoding: unused
  1595. * - decoding: set by user
  1596. */
  1597. char *codec_whitelist;
  1598. /**
  1599. * ',' separated list of allowed demuxers.
  1600. * If NULL then all are allowed
  1601. * - encoding: unused
  1602. * - decoding: set by user
  1603. */
  1604. char *format_whitelist;
  1605. /**
  1606. * ',' separated list of allowed protocols.
  1607. * - encoding: unused
  1608. * - decoding: set by user
  1609. */
  1610. char *protocol_whitelist;
  1611. /**
  1612. * ',' separated list of disallowed protocols.
  1613. * - encoding: unused
  1614. * - decoding: set by user
  1615. */
  1616. char *protocol_blacklist;
  1617. /**
  1618. * IO repositioned flag.
  1619. * This is set by avformat when the underlaying IO context read pointer
  1620. * is repositioned, for example when doing byte based seeking.
  1621. * Demuxers can use the flag to detect such changes.
  1622. */
  1623. int io_repositioned;
  1624. /**
  1625. * Forced video codec.
  1626. * This allows forcing a specific decoder, even when there are multiple with
  1627. * the same codec_id.
  1628. * Demuxing: Set by user
  1629. */
  1630. const struct AVCodec *video_codec;
  1631. /**
  1632. * Forced audio codec.
  1633. * This allows forcing a specific decoder, even when there are multiple with
  1634. * the same codec_id.
  1635. * Demuxing: Set by user
  1636. */
  1637. const struct AVCodec *audio_codec;
  1638. /**
  1639. * Forced subtitle codec.
  1640. * This allows forcing a specific decoder, even when there are multiple with
  1641. * the same codec_id.
  1642. * Demuxing: Set by user
  1643. */
  1644. const struct AVCodec *subtitle_codec;
  1645. /**
  1646. * Forced data codec.
  1647. * This allows forcing a specific decoder, even when there are multiple with
  1648. * the same codec_id.
  1649. * Demuxing: Set by user
  1650. */
  1651. const struct AVCodec *data_codec;
  1652. /**
  1653. * Number of bytes to be written as padding in a metadata header.
  1654. * Demuxing: Unused.
  1655. * Muxing: Set by user.
  1656. */
  1657. int metadata_header_padding;
  1658. /**
  1659. * User data.
  1660. * This is a place for some private data of the user.
  1661. */
  1662. void *opaque;
  1663. /**
  1664. * Callback used by devices to communicate with application.
  1665. */
  1666. av_format_control_message control_message_cb;
  1667. /**
  1668. * Output timestamp offset, in microseconds.
  1669. * Muxing: set by user
  1670. */
  1671. int64_t output_ts_offset;
  1672. /**
  1673. * dump format separator.
  1674. * can be ", " or "\n " or anything else
  1675. * - muxing: Set by user.
  1676. * - demuxing: Set by user.
  1677. */
  1678. uint8_t *dump_separator;
  1679. /**
  1680. * A callback for opening new IO streams.
  1681. *
  1682. * Whenever a muxer or a demuxer needs to open an IO stream (typically from
  1683. * avformat_open_input() for demuxers, but for certain formats can happen at
  1684. * other times as well), it will call this callback to obtain an IO context.
  1685. *
  1686. * @param s the format context
  1687. * @param pb on success, the newly opened IO context should be returned here
  1688. * @param url the url to open
  1689. * @param flags a combination of AVIO_FLAG_*
  1690. * @param options a dictionary of additional options, with the same
  1691. * semantics as in avio_open2()
  1692. * @return 0 on success, a negative AVERROR code on failure
  1693. *
  1694. * @note Certain muxers and demuxers do nesting, i.e. they open one or more
  1695. * additional internal format contexts. Thus the AVFormatContext pointer
  1696. * passed to this callback may be different from the one facing the caller.
  1697. * It will, however, have the same 'opaque' field.
  1698. */
  1699. int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,
  1700. int flags, AVDictionary **options);
  1701. /**
  1702. * A callback for closing the streams opened with AVFormatContext.io_open().
  1703. *
  1704. * Using this is preferred over io_close, because this can return an error.
  1705. * Therefore this callback is used instead of io_close by the generic
  1706. * libavformat code if io_close is NULL or the default.
  1707. *
  1708. * @param s the format context
  1709. * @param pb IO context to be closed and freed
  1710. * @return 0 on success, a negative AVERROR code on failure
  1711. */
  1712. int (*io_close2)(struct AVFormatContext *s, AVIOContext *pb);
  1713. } AVFormatContext;
  1714. /**
  1715. * This function will cause global side data to be injected in the next packet
  1716. * of each stream as well as after any subsequent seek.
  1717. *
  1718. * @note global side data is always available in every AVStream's
  1719. * @ref AVCodecParameters.coded_side_data "codecpar side data" array, and
  1720. * in a @ref AVCodecContext.coded_side_data "decoder's side data" array if
  1721. * initialized with said stream's codecpar.
  1722. * @see av_packet_side_data_get()
  1723. */
  1724. void av_format_inject_global_side_data(AVFormatContext *s);
  1725. #if FF_API_GET_DUR_ESTIMATE_METHOD
  1726. /**
  1727. * Returns the method used to set ctx->duration.
  1728. *
  1729. * @return AVFMT_DURATION_FROM_PTS, AVFMT_DURATION_FROM_STREAM, or AVFMT_DURATION_FROM_BITRATE.
  1730. * @deprecated duration_estimation_method is public and can be read directly.
  1731. */
  1732. attribute_deprecated
  1733. enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx);
  1734. #endif
  1735. /**
  1736. * @defgroup lavf_core Core functions
  1737. * @ingroup libavf
  1738. *
  1739. * Functions for querying libavformat capabilities, allocating core structures,
  1740. * etc.
  1741. * @{
  1742. */
  1743. /**
  1744. * Return the LIBAVFORMAT_VERSION_INT constant.
  1745. */
  1746. unsigned avformat_version(void);
  1747. /**
  1748. * Return the libavformat build-time configuration.
  1749. */
  1750. const char *avformat_configuration(void);
  1751. /**
  1752. * Return the libavformat license.
  1753. */
  1754. const char *avformat_license(void);
  1755. /**
  1756. * Do global initialization of network libraries. This is optional,
  1757. * and not recommended anymore.
  1758. *
  1759. * This functions only exists to work around thread-safety issues
  1760. * with older GnuTLS or OpenSSL libraries. If libavformat is linked
  1761. * to newer versions of those libraries, or if you do not use them,
  1762. * calling this function is unnecessary. Otherwise, you need to call
  1763. * this function before any other threads using them are started.
  1764. *
  1765. * This function will be deprecated once support for older GnuTLS and
  1766. * OpenSSL libraries is removed, and this function has no purpose
  1767. * anymore.
  1768. */
  1769. int avformat_network_init(void);
  1770. /**
  1771. * Undo the initialization done by avformat_network_init. Call it only
  1772. * once for each time you called avformat_network_init.
  1773. */
  1774. int avformat_network_deinit(void);
  1775. /**
  1776. * Iterate over all registered muxers.
  1777. *
  1778. * @param opaque a pointer where libavformat will store the iteration state. Must
  1779. * point to NULL to start the iteration.
  1780. *
  1781. * @return the next registered muxer or NULL when the iteration is
  1782. * finished
  1783. */
  1784. const AVOutputFormat *av_muxer_iterate(void **opaque);
  1785. /**
  1786. * Iterate over all registered demuxers.
  1787. *
  1788. * @param opaque a pointer where libavformat will store the iteration state.
  1789. * Must point to NULL to start the iteration.
  1790. *
  1791. * @return the next registered demuxer or NULL when the iteration is
  1792. * finished
  1793. */
  1794. const AVInputFormat *av_demuxer_iterate(void **opaque);
  1795. /**
  1796. * Allocate an AVFormatContext.
  1797. * avformat_free_context() can be used to free the context and everything
  1798. * allocated by the framework within it.
  1799. */
  1800. AVFormatContext *avformat_alloc_context(void);
  1801. /**
  1802. * Free an AVFormatContext and all its streams.
  1803. * @param s context to free
  1804. */
  1805. void avformat_free_context(AVFormatContext *s);
  1806. /**
  1807. * Get the AVClass for AVFormatContext. It can be used in combination with
  1808. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  1809. *
  1810. * @see av_opt_find().
  1811. */
  1812. const AVClass *avformat_get_class(void);
  1813. /**
  1814. * Get the AVClass for AVStream. It can be used in combination with
  1815. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  1816. *
  1817. * @see av_opt_find().
  1818. */
  1819. const AVClass *av_stream_get_class(void);
  1820. /**
  1821. * Get the AVClass for AVStreamGroup. It can be used in combination with
  1822. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  1823. *
  1824. * @see av_opt_find().
  1825. */
  1826. const AVClass *av_stream_group_get_class(void);
  1827. /**
  1828. * @return a string identifying the stream group type, or NULL if unknown
  1829. */
  1830. const char *avformat_stream_group_name(enum AVStreamGroupParamsType type);
  1831. /**
  1832. * Add a new empty stream group to a media file.
  1833. *
  1834. * When demuxing, it may be called by the demuxer in read_header(). If the
  1835. * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
  1836. * be called in read_packet().
  1837. *
  1838. * When muxing, may be called by the user before avformat_write_header().
  1839. *
  1840. * User is required to call avformat_free_context() to clean up the allocation
  1841. * by avformat_stream_group_create().
  1842. *
  1843. * New streams can be added to the group with avformat_stream_group_add_stream().
  1844. *
  1845. * @param s media file handle
  1846. *
  1847. * @return newly created group or NULL on error.
  1848. * @see avformat_new_stream, avformat_stream_group_add_stream.
  1849. */
  1850. AVStreamGroup *avformat_stream_group_create(AVFormatContext *s,
  1851. enum AVStreamGroupParamsType type,
  1852. AVDictionary **options);
  1853. /**
  1854. * Add a new stream to a media file.
  1855. *
  1856. * When demuxing, it is called by the demuxer in read_header(). If the
  1857. * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
  1858. * be called in read_packet().
  1859. *
  1860. * When muxing, should be called by the user before avformat_write_header().
  1861. *
  1862. * User is required to call avformat_free_context() to clean up the allocation
  1863. * by avformat_new_stream().
  1864. *
  1865. * @param s media file handle
  1866. * @param c unused, does nothing
  1867. *
  1868. * @return newly created stream or NULL on error.
  1869. */
  1870. AVStream *avformat_new_stream(AVFormatContext *s, const struct AVCodec *c);
  1871. /**
  1872. * Add an already allocated stream to a stream group.
  1873. *
  1874. * When demuxing, it may be called by the demuxer in read_header(). If the
  1875. * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
  1876. * be called in read_packet().
  1877. *
  1878. * When muxing, may be called by the user before avformat_write_header() after
  1879. * having allocated a new group with avformat_stream_group_create() and stream with
  1880. * avformat_new_stream().
  1881. *
  1882. * User is required to call avformat_free_context() to clean up the allocation
  1883. * by avformat_stream_group_add_stream().
  1884. *
  1885. * @param stg stream group belonging to a media file.
  1886. * @param st stream in the media file to add to the group.
  1887. *
  1888. * @retval 0 success
  1889. * @retval AVERROR(EEXIST) the stream was already in the group
  1890. * @retval "another negative error code" legitimate errors
  1891. *
  1892. * @see avformat_new_stream, avformat_stream_group_create.
  1893. */
  1894. int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st);
  1895. #if FF_API_AVSTREAM_SIDE_DATA
  1896. /**
  1897. * Wrap an existing array as stream side data.
  1898. *
  1899. * @param st stream
  1900. * @param type side information type
  1901. * @param data the side data array. It must be allocated with the av_malloc()
  1902. * family of functions. The ownership of the data is transferred to
  1903. * st.
  1904. * @param size side information size
  1905. *
  1906. * @return zero on success, a negative AVERROR code on failure. On failure,
  1907. * the stream is unchanged and the data remains owned by the caller.
  1908. * @deprecated use av_packet_side_data_add() with the stream's
  1909. * @ref AVCodecParameters.coded_side_data "codecpar side data"
  1910. */
  1911. attribute_deprecated
  1912. int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
  1913. uint8_t *data, size_t size);
  1914. /**
  1915. * Allocate new information from stream.
  1916. *
  1917. * @param stream stream
  1918. * @param type desired side information type
  1919. * @param size side information size
  1920. *
  1921. * @return pointer to fresh allocated data or NULL otherwise
  1922. * @deprecated use av_packet_side_data_new() with the stream's
  1923. * @ref AVCodecParameters.coded_side_data "codecpar side data"
  1924. */
  1925. attribute_deprecated
  1926. uint8_t *av_stream_new_side_data(AVStream *stream,
  1927. enum AVPacketSideDataType type, size_t size);
  1928. /**
  1929. * Get side information from stream.
  1930. *
  1931. * @param stream stream
  1932. * @param type desired side information type
  1933. * @param size If supplied, *size will be set to the size of the side data
  1934. * or to zero if the desired side data is not present.
  1935. *
  1936. * @return pointer to data if present or NULL otherwise
  1937. * @deprecated use av_packet_side_data_get() with the stream's
  1938. * @ref AVCodecParameters.coded_side_data "codecpar side data"
  1939. */
  1940. attribute_deprecated
  1941. uint8_t *av_stream_get_side_data(const AVStream *stream,
  1942. enum AVPacketSideDataType type, size_t *size);
  1943. #endif
  1944. AVProgram *av_new_program(AVFormatContext *s, int id);
  1945. /**
  1946. * @}
  1947. */
  1948. /**
  1949. * Allocate an AVFormatContext for an output format.
  1950. * avformat_free_context() can be used to free the context and
  1951. * everything allocated by the framework within it.
  1952. *
  1953. * @param ctx pointee is set to the created format context,
  1954. * or to NULL in case of failure
  1955. * @param oformat format to use for allocating the context, if NULL
  1956. * format_name and filename are used instead
  1957. * @param format_name the name of output format to use for allocating the
  1958. * context, if NULL filename is used instead
  1959. * @param filename the name of the filename to use for allocating the
  1960. * context, may be NULL
  1961. *
  1962. * @return >= 0 in case of success, a negative AVERROR code in case of
  1963. * failure
  1964. */
  1965. int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat,
  1966. const char *format_name, const char *filename);
  1967. /**
  1968. * @addtogroup lavf_decoding
  1969. * @{
  1970. */
  1971. /**
  1972. * Find AVInputFormat based on the short name of the input format.
  1973. */
  1974. const AVInputFormat *av_find_input_format(const char *short_name);
  1975. /**
  1976. * Guess the file format.
  1977. *
  1978. * @param pd data to be probed
  1979. * @param is_opened Whether the file is already opened; determines whether
  1980. * demuxers with or without AVFMT_NOFILE are probed.
  1981. */
  1982. const AVInputFormat *av_probe_input_format(const AVProbeData *pd, int is_opened);
  1983. /**
  1984. * Guess the file format.
  1985. *
  1986. * @param pd data to be probed
  1987. * @param is_opened Whether the file is already opened; determines whether
  1988. * demuxers with or without AVFMT_NOFILE are probed.
  1989. * @param score_max A probe score larger that this is required to accept a
  1990. * detection, the variable is set to the actual detection
  1991. * score afterwards.
  1992. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  1993. * to retry with a larger probe buffer.
  1994. */
  1995. const AVInputFormat *av_probe_input_format2(const AVProbeData *pd,
  1996. int is_opened, int *score_max);
  1997. /**
  1998. * Guess the file format.
  1999. *
  2000. * @param is_opened Whether the file is already opened; determines whether
  2001. * demuxers with or without AVFMT_NOFILE are probed.
  2002. * @param score_ret The score of the best detection.
  2003. */
  2004. const AVInputFormat *av_probe_input_format3(const AVProbeData *pd,
  2005. int is_opened, int *score_ret);
  2006. /**
  2007. * Probe a bytestream to determine the input format. Each time a probe returns
  2008. * with a score that is too low, the probe buffer size is increased and another
  2009. * attempt is made. When the maximum probe size is reached, the input format
  2010. * with the highest score is returned.
  2011. *
  2012. * @param pb the bytestream to probe
  2013. * @param fmt the input format is put here
  2014. * @param url the url of the stream
  2015. * @param logctx the log context
  2016. * @param offset the offset within the bytestream to probe from
  2017. * @param max_probe_size the maximum probe buffer size (zero for default)
  2018. *
  2019. * @return the score in case of success, a negative value corresponding to an
  2020. * the maximal score is AVPROBE_SCORE_MAX
  2021. * AVERROR code otherwise
  2022. */
  2023. int av_probe_input_buffer2(AVIOContext *pb, const AVInputFormat **fmt,
  2024. const char *url, void *logctx,
  2025. unsigned int offset, unsigned int max_probe_size);
  2026. /**
  2027. * Like av_probe_input_buffer2() but returns 0 on success
  2028. */
  2029. int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt,
  2030. const char *url, void *logctx,
  2031. unsigned int offset, unsigned int max_probe_size);
  2032. /**
  2033. * Open an input stream and read the header. The codecs are not opened.
  2034. * The stream must be closed with avformat_close_input().
  2035. *
  2036. * @param ps Pointer to user-supplied AVFormatContext (allocated by
  2037. * avformat_alloc_context). May be a pointer to NULL, in
  2038. * which case an AVFormatContext is allocated by this
  2039. * function and written into ps.
  2040. * Note that a user-supplied AVFormatContext will be freed
  2041. * on failure.
  2042. * @param url URL of the stream to open.
  2043. * @param fmt If non-NULL, this parameter forces a specific input format.
  2044. * Otherwise the format is autodetected.
  2045. * @param options A dictionary filled with AVFormatContext and demuxer-private
  2046. * options.
  2047. * On return this parameter will be destroyed and replaced with
  2048. * a dict containing options that were not found. May be NULL.
  2049. *
  2050. * @return 0 on success, a negative AVERROR on failure.
  2051. *
  2052. * @note If you want to use custom IO, preallocate the format context and set its pb field.
  2053. */
  2054. int avformat_open_input(AVFormatContext **ps, const char *url,
  2055. const AVInputFormat *fmt, AVDictionary **options);
  2056. /**
  2057. * Read packets of a media file to get stream information. This
  2058. * is useful for file formats with no headers such as MPEG. This
  2059. * function also computes the real framerate in case of MPEG-2 repeat
  2060. * frame mode.
  2061. * The logical file position is not changed by this function;
  2062. * examined packets may be buffered for later processing.
  2063. *
  2064. * @param ic media file handle
  2065. * @param options If non-NULL, an ic.nb_streams long array of pointers to
  2066. * dictionaries, where i-th member contains options for
  2067. * codec corresponding to i-th stream.
  2068. * On return each dictionary will be filled with options that were not found.
  2069. * @return >=0 if OK, AVERROR_xxx on error
  2070. *
  2071. * @note this function isn't guaranteed to open all the codecs, so
  2072. * options being non-empty at return is a perfectly normal behavior.
  2073. *
  2074. * @todo Let the user decide somehow what information is needed so that
  2075. * we do not waste time getting stuff the user does not need.
  2076. */
  2077. int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
  2078. /**
  2079. * Find the programs which belong to a given stream.
  2080. *
  2081. * @param ic media file handle
  2082. * @param last the last found program, the search will start after this
  2083. * program, or from the beginning if it is NULL
  2084. * @param s stream index
  2085. *
  2086. * @return the next program which belongs to s, NULL if no program is found or
  2087. * the last program is not among the programs of ic.
  2088. */
  2089. AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
  2090. void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx);
  2091. /**
  2092. * Find the "best" stream in the file.
  2093. * The best stream is determined according to various heuristics as the most
  2094. * likely to be what the user expects.
  2095. * If the decoder parameter is non-NULL, av_find_best_stream will find the
  2096. * default decoder for the stream's codec; streams for which no decoder can
  2097. * be found are ignored.
  2098. *
  2099. * @param ic media file handle
  2100. * @param type stream type: video, audio, subtitles, etc.
  2101. * @param wanted_stream_nb user-requested stream number,
  2102. * or -1 for automatic selection
  2103. * @param related_stream try to find a stream related (eg. in the same
  2104. * program) to this one, or -1 if none
  2105. * @param decoder_ret if non-NULL, returns the decoder for the
  2106. * selected stream
  2107. * @param flags flags; none are currently defined
  2108. *
  2109. * @return the non-negative stream number in case of success,
  2110. * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
  2111. * could be found,
  2112. * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
  2113. *
  2114. * @note If av_find_best_stream returns successfully and decoder_ret is not
  2115. * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
  2116. */
  2117. int av_find_best_stream(AVFormatContext *ic,
  2118. enum AVMediaType type,
  2119. int wanted_stream_nb,
  2120. int related_stream,
  2121. const struct AVCodec **decoder_ret,
  2122. int flags);
  2123. /**
  2124. * Return the next frame of a stream.
  2125. * This function returns what is stored in the file, and does not validate
  2126. * that what is there are valid frames for the decoder. It will split what is
  2127. * stored in the file into frames and return one for each call. It will not
  2128. * omit invalid data between valid frames so as to give the decoder the maximum
  2129. * information possible for decoding.
  2130. *
  2131. * On success, the returned packet is reference-counted (pkt->buf is set) and
  2132. * valid indefinitely. The packet must be freed with av_packet_unref() when
  2133. * it is no longer needed. For video, the packet contains exactly one frame.
  2134. * For audio, it contains an integer number of frames if each frame has
  2135. * a known fixed size (e.g. PCM or ADPCM data). If the audio frames have
  2136. * a variable size (e.g. MPEG audio), then it contains one frame.
  2137. *
  2138. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  2139. * values in AVStream.time_base units (and guessed if the format cannot
  2140. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  2141. * has B-frames, so it is better to rely on pkt->dts if you do not
  2142. * decompress the payload.
  2143. *
  2144. * @return 0 if OK, < 0 on error or end of file. On error, pkt will be blank
  2145. * (as if it came from av_packet_alloc()).
  2146. *
  2147. * @note pkt will be initialized, so it may be uninitialized, but it must not
  2148. * contain data that needs to be freed.
  2149. */
  2150. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  2151. /**
  2152. * Seek to the keyframe at timestamp.
  2153. * 'timestamp' in 'stream_index'.
  2154. *
  2155. * @param s media file handle
  2156. * @param stream_index If stream_index is (-1), a default stream is selected,
  2157. * and timestamp is automatically converted from
  2158. * AV_TIME_BASE units to the stream specific time_base.
  2159. * @param timestamp Timestamp in AVStream.time_base units or, if no stream
  2160. * is specified, in AV_TIME_BASE units.
  2161. * @param flags flags which select direction and seeking mode
  2162. *
  2163. * @return >= 0 on success
  2164. */
  2165. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  2166. int flags);
  2167. /**
  2168. * Seek to timestamp ts.
  2169. * Seeking will be done so that the point from which all active streams
  2170. * can be presented successfully will be closest to ts and within min/max_ts.
  2171. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  2172. *
  2173. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  2174. * are the file position (this may not be supported by all demuxers).
  2175. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  2176. * in the stream with stream_index (this may not be supported by all demuxers).
  2177. * Otherwise all timestamps are in units of the stream selected by stream_index
  2178. * or if stream_index is -1, in AV_TIME_BASE units.
  2179. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  2180. * keyframes (this may not be supported by all demuxers).
  2181. * If flags contain AVSEEK_FLAG_BACKWARD, it is ignored.
  2182. *
  2183. * @param s media file handle
  2184. * @param stream_index index of the stream which is used as time base reference
  2185. * @param min_ts smallest acceptable timestamp
  2186. * @param ts target timestamp
  2187. * @param max_ts largest acceptable timestamp
  2188. * @param flags flags
  2189. * @return >=0 on success, error code otherwise
  2190. *
  2191. * @note This is part of the new seek API which is still under construction.
  2192. */
  2193. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  2194. /**
  2195. * Discard all internally buffered data. This can be useful when dealing with
  2196. * discontinuities in the byte stream. Generally works only with formats that
  2197. * can resync. This includes headerless formats like MPEG-TS/TS but should also
  2198. * work with NUT, Ogg and in a limited way AVI for example.
  2199. *
  2200. * The set of streams, the detected duration, stream parameters and codecs do
  2201. * not change when calling this function. If you want a complete reset, it's
  2202. * better to open a new AVFormatContext.
  2203. *
  2204. * This does not flush the AVIOContext (s->pb). If necessary, call
  2205. * avio_flush(s->pb) before calling this function.
  2206. *
  2207. * @param s media file handle
  2208. * @return >=0 on success, error code otherwise
  2209. */
  2210. int avformat_flush(AVFormatContext *s);
  2211. /**
  2212. * Start playing a network-based stream (e.g. RTSP stream) at the
  2213. * current position.
  2214. */
  2215. int av_read_play(AVFormatContext *s);
  2216. /**
  2217. * Pause a network-based stream (e.g. RTSP stream).
  2218. *
  2219. * Use av_read_play() to resume it.
  2220. */
  2221. int av_read_pause(AVFormatContext *s);
  2222. /**
  2223. * Close an opened input AVFormatContext. Free it and all its contents
  2224. * and set *s to NULL.
  2225. */
  2226. void avformat_close_input(AVFormatContext **s);
  2227. /**
  2228. * @}
  2229. */
  2230. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  2231. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  2232. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  2233. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  2234. /**
  2235. * @addtogroup lavf_encoding
  2236. * @{
  2237. */
  2238. #define AVSTREAM_INIT_IN_WRITE_HEADER 0 ///< stream parameters initialized in avformat_write_header
  2239. #define AVSTREAM_INIT_IN_INIT_OUTPUT 1 ///< stream parameters initialized in avformat_init_output
  2240. /**
  2241. * Allocate the stream private data and write the stream header to
  2242. * an output media file.
  2243. *
  2244. * @param s Media file handle, must be allocated with
  2245. * avformat_alloc_context().
  2246. * Its \ref AVFormatContext.oformat "oformat" field must be set
  2247. * to the desired output format;
  2248. * Its \ref AVFormatContext.pb "pb" field must be set to an
  2249. * already opened ::AVIOContext.
  2250. * @param options An ::AVDictionary filled with AVFormatContext and
  2251. * muxer-private options.
  2252. * On return this parameter will be destroyed and replaced with
  2253. * a dict containing options that were not found. May be NULL.
  2254. *
  2255. * @retval AVSTREAM_INIT_IN_WRITE_HEADER On success, if the codec had not already been
  2256. * fully initialized in avformat_init_output().
  2257. * @retval AVSTREAM_INIT_IN_INIT_OUTPUT On success, if the codec had already been fully
  2258. * initialized in avformat_init_output().
  2259. * @retval AVERROR A negative AVERROR on failure.
  2260. *
  2261. * @see av_opt_find, av_dict_set, avio_open, av_oformat_next, avformat_init_output.
  2262. */
  2263. av_warn_unused_result
  2264. int avformat_write_header(AVFormatContext *s, AVDictionary **options);
  2265. /**
  2266. * Allocate the stream private data and initialize the codec, but do not write the header.
  2267. * May optionally be used before avformat_write_header() to initialize stream parameters
  2268. * before actually writing the header.
  2269. * If using this function, do not pass the same options to avformat_write_header().
  2270. *
  2271. * @param s Media file handle, must be allocated with
  2272. * avformat_alloc_context().
  2273. * Its \ref AVFormatContext.oformat "oformat" field must be set
  2274. * to the desired output format;
  2275. * Its \ref AVFormatContext.pb "pb" field must be set to an
  2276. * already opened ::AVIOContext.
  2277. * @param options An ::AVDictionary filled with AVFormatContext and
  2278. * muxer-private options.
  2279. * On return this parameter will be destroyed and replaced with
  2280. * a dict containing options that were not found. May be NULL.
  2281. *
  2282. * @retval AVSTREAM_INIT_IN_WRITE_HEADER On success, if the codec requires
  2283. * avformat_write_header to fully initialize.
  2284. * @retval AVSTREAM_INIT_IN_INIT_OUTPUT On success, if the codec has been fully
  2285. * initialized.
  2286. * @retval AVERROR Anegative AVERROR on failure.
  2287. *
  2288. * @see av_opt_find, av_dict_set, avio_open, av_oformat_next, avformat_write_header.
  2289. */
  2290. av_warn_unused_result
  2291. int avformat_init_output(AVFormatContext *s, AVDictionary **options);
  2292. /**
  2293. * Write a packet to an output media file.
  2294. *
  2295. * This function passes the packet directly to the muxer, without any buffering
  2296. * or reordering. The caller is responsible for correctly interleaving the
  2297. * packets if the format requires it. Callers that want libavformat to handle
  2298. * the interleaving should call av_interleaved_write_frame() instead of this
  2299. * function.
  2300. *
  2301. * @param s media file handle
  2302. * @param pkt The packet containing the data to be written. Note that unlike
  2303. * av_interleaved_write_frame(), this function does not take
  2304. * ownership of the packet passed to it (though some muxers may make
  2305. * an internal reference to the input packet).
  2306. * <br>
  2307. * This parameter can be NULL (at any time, not just at the end), in
  2308. * order to immediately flush data buffered within the muxer, for
  2309. * muxers that buffer up data internally before writing it to the
  2310. * output.
  2311. * <br>
  2312. * Packet's @ref AVPacket.stream_index "stream_index" field must be
  2313. * set to the index of the corresponding stream in @ref
  2314. * AVFormatContext.streams "s->streams".
  2315. * <br>
  2316. * The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts")
  2317. * must be set to correct values in the stream's timebase (unless the
  2318. * output format is flagged with the AVFMT_NOTIMESTAMPS flag, then
  2319. * they can be set to AV_NOPTS_VALUE).
  2320. * The dts for subsequent packets passed to this function must be strictly
  2321. * increasing when compared in their respective timebases (unless the
  2322. * output format is flagged with the AVFMT_TS_NONSTRICT, then they
  2323. * merely have to be nondecreasing). @ref AVPacket.duration
  2324. * "duration") should also be set if known.
  2325. * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush
  2326. *
  2327. * @see av_interleaved_write_frame()
  2328. */
  2329. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  2330. /**
  2331. * Write a packet to an output media file ensuring correct interleaving.
  2332. *
  2333. * This function will buffer the packets internally as needed to make sure the
  2334. * packets in the output file are properly interleaved, usually ordered by
  2335. * increasing dts. Callers doing their own interleaving should call
  2336. * av_write_frame() instead of this function.
  2337. *
  2338. * Using this function instead of av_write_frame() can give muxers advance
  2339. * knowledge of future packets, improving e.g. the behaviour of the mp4
  2340. * muxer for VFR content in fragmenting mode.
  2341. *
  2342. * @param s media file handle
  2343. * @param pkt The packet containing the data to be written.
  2344. * <br>
  2345. * If the packet is reference-counted, this function will take
  2346. * ownership of this reference and unreference it later when it sees
  2347. * fit. If the packet is not reference-counted, libavformat will
  2348. * make a copy.
  2349. * The returned packet will be blank (as if returned from
  2350. * av_packet_alloc()), even on error.
  2351. * <br>
  2352. * This parameter can be NULL (at any time, not just at the end), to
  2353. * flush the interleaving queues.
  2354. * <br>
  2355. * Packet's @ref AVPacket.stream_index "stream_index" field must be
  2356. * set to the index of the corresponding stream in @ref
  2357. * AVFormatContext.streams "s->streams".
  2358. * <br>
  2359. * The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts")
  2360. * must be set to correct values in the stream's timebase (unless the
  2361. * output format is flagged with the AVFMT_NOTIMESTAMPS flag, then
  2362. * they can be set to AV_NOPTS_VALUE).
  2363. * The dts for subsequent packets in one stream must be strictly
  2364. * increasing (unless the output format is flagged with the
  2365. * AVFMT_TS_NONSTRICT, then they merely have to be nondecreasing).
  2366. * @ref AVPacket.duration "duration" should also be set if known.
  2367. *
  2368. * @return 0 on success, a negative AVERROR on error.
  2369. *
  2370. * @see av_write_frame(), AVFormatContext.max_interleave_delta
  2371. */
  2372. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  2373. /**
  2374. * Write an uncoded frame to an output media file.
  2375. *
  2376. * The frame must be correctly interleaved according to the container
  2377. * specification; if not, av_interleaved_write_uncoded_frame() must be used.
  2378. *
  2379. * See av_interleaved_write_uncoded_frame() for details.
  2380. */
  2381. int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
  2382. struct AVFrame *frame);
  2383. /**
  2384. * Write an uncoded frame to an output media file.
  2385. *
  2386. * If the muxer supports it, this function makes it possible to write an AVFrame
  2387. * structure directly, without encoding it into a packet.
  2388. * It is mostly useful for devices and similar special muxers that use raw
  2389. * video or PCM data and will not serialize it into a byte stream.
  2390. *
  2391. * To test whether it is possible to use it with a given muxer and stream,
  2392. * use av_write_uncoded_frame_query().
  2393. *
  2394. * The caller gives up ownership of the frame and must not access it
  2395. * afterwards.
  2396. *
  2397. * @return >=0 for success, a negative code on error
  2398. */
  2399. int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index,
  2400. struct AVFrame *frame);
  2401. /**
  2402. * Test whether a muxer supports uncoded frame.
  2403. *
  2404. * @return >=0 if an uncoded frame can be written to that muxer and stream,
  2405. * <0 if not
  2406. */
  2407. int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index);
  2408. /**
  2409. * Write the stream trailer to an output media file and free the
  2410. * file private data.
  2411. *
  2412. * May only be called after a successful call to avformat_write_header.
  2413. *
  2414. * @param s media file handle
  2415. * @return 0 if OK, AVERROR_xxx on error
  2416. */
  2417. int av_write_trailer(AVFormatContext *s);
  2418. /**
  2419. * Return the output format in the list of registered output formats
  2420. * which best matches the provided parameters, or return NULL if
  2421. * there is no match.
  2422. *
  2423. * @param short_name if non-NULL checks if short_name matches with the
  2424. * names of the registered formats
  2425. * @param filename if non-NULL checks if filename terminates with the
  2426. * extensions of the registered formats
  2427. * @param mime_type if non-NULL checks if mime_type matches with the
  2428. * MIME type of the registered formats
  2429. */
  2430. const AVOutputFormat *av_guess_format(const char *short_name,
  2431. const char *filename,
  2432. const char *mime_type);
  2433. /**
  2434. * Guess the codec ID based upon muxer and filename.
  2435. */
  2436. enum AVCodecID av_guess_codec(const AVOutputFormat *fmt, const char *short_name,
  2437. const char *filename, const char *mime_type,
  2438. enum AVMediaType type);
  2439. /**
  2440. * Get timing information for the data currently output.
  2441. * The exact meaning of "currently output" depends on the format.
  2442. * It is mostly relevant for devices that have an internal buffer and/or
  2443. * work in real time.
  2444. * @param s media file handle
  2445. * @param stream stream in the media file
  2446. * @param[out] dts DTS of the last packet output for the stream, in stream
  2447. * time_base units
  2448. * @param[out] wall absolute time when that packet whas output,
  2449. * in microsecond
  2450. * @retval 0 Success
  2451. * @retval AVERROR(ENOSYS) The format does not support it
  2452. *
  2453. * @note Some formats or devices may not allow to measure dts and wall
  2454. * atomically.
  2455. */
  2456. int av_get_output_timestamp(struct AVFormatContext *s, int stream,
  2457. int64_t *dts, int64_t *wall);
  2458. /**
  2459. * @}
  2460. */
  2461. /**
  2462. * @defgroup lavf_misc Utility functions
  2463. * @ingroup libavf
  2464. * @{
  2465. *
  2466. * Miscellaneous utility functions related to both muxing and demuxing
  2467. * (or neither).
  2468. */
  2469. /**
  2470. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  2471. *
  2472. * @param f The file stream pointer where the dump should be sent to.
  2473. * @param buf buffer
  2474. * @param size buffer size
  2475. *
  2476. * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
  2477. */
  2478. void av_hex_dump(FILE *f, const uint8_t *buf, int size);
  2479. /**
  2480. * Send a nice hexadecimal dump of a buffer to the log.
  2481. *
  2482. * @param avcl A pointer to an arbitrary struct of which the first field is a
  2483. * pointer to an AVClass struct.
  2484. * @param level The importance level of the message, lower values signifying
  2485. * higher importance.
  2486. * @param buf buffer
  2487. * @param size buffer size
  2488. *
  2489. * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
  2490. */
  2491. void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
  2492. /**
  2493. * Send a nice dump of a packet to the specified file stream.
  2494. *
  2495. * @param f The file stream pointer where the dump should be sent to.
  2496. * @param pkt packet to dump
  2497. * @param dump_payload True if the payload must be displayed, too.
  2498. * @param st AVStream that the packet belongs to
  2499. */
  2500. void av_pkt_dump2(FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st);
  2501. /**
  2502. * Send a nice dump of a packet to the log.
  2503. *
  2504. * @param avcl A pointer to an arbitrary struct of which the first field is a
  2505. * pointer to an AVClass struct.
  2506. * @param level The importance level of the message, lower values signifying
  2507. * higher importance.
  2508. * @param pkt packet to dump
  2509. * @param dump_payload True if the payload must be displayed, too.
  2510. * @param st AVStream that the packet belongs to
  2511. */
  2512. void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload,
  2513. const AVStream *st);
  2514. /**
  2515. * Get the AVCodecID for the given codec tag tag.
  2516. * If no codec id is found returns AV_CODEC_ID_NONE.
  2517. *
  2518. * @param tags list of supported codec_id-codec_tag pairs, as stored
  2519. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  2520. * @param tag codec tag to match to a codec ID
  2521. */
  2522. enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  2523. /**
  2524. * Get the codec tag for the given codec id id.
  2525. * If no codec tag is found returns 0.
  2526. *
  2527. * @param tags list of supported codec_id-codec_tag pairs, as stored
  2528. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  2529. * @param id codec ID to match to a codec tag
  2530. */
  2531. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
  2532. /**
  2533. * Get the codec tag for the given codec id.
  2534. *
  2535. * @param tags list of supported codec_id - codec_tag pairs, as stored
  2536. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  2537. * @param id codec id that should be searched for in the list
  2538. * @param tag A pointer to the found tag
  2539. * @return 0 if id was not found in tags, > 0 if it was found
  2540. */
  2541. int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
  2542. unsigned int *tag);
  2543. int av_find_default_stream_index(AVFormatContext *s);
  2544. /**
  2545. * Get the index for a specific timestamp.
  2546. *
  2547. * @param st stream that the timestamp belongs to
  2548. * @param timestamp timestamp to retrieve the index for
  2549. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  2550. * to the timestamp which is <= the requested one, if backward
  2551. * is 0, then it will be >=
  2552. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  2553. * @return < 0 if no such timestamp could be found
  2554. */
  2555. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  2556. /**
  2557. * Get the index entry count for the given AVStream.
  2558. *
  2559. * @param st stream
  2560. * @return the number of index entries in the stream
  2561. */
  2562. int avformat_index_get_entries_count(const AVStream *st);
  2563. /**
  2564. * Get the AVIndexEntry corresponding to the given index.
  2565. *
  2566. * @param st Stream containing the requested AVIndexEntry.
  2567. * @param idx The desired index.
  2568. * @return A pointer to the requested AVIndexEntry if it exists, NULL otherwise.
  2569. *
  2570. * @note The pointer returned by this function is only guaranteed to be valid
  2571. * until any function that takes the stream or the parent AVFormatContext
  2572. * as input argument is called.
  2573. */
  2574. const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
  2575. /**
  2576. * Get the AVIndexEntry corresponding to the given timestamp.
  2577. *
  2578. * @param st Stream containing the requested AVIndexEntry.
  2579. * @param wanted_timestamp Timestamp to retrieve the index entry for.
  2580. * @param flags If AVSEEK_FLAG_BACKWARD then the returned entry will correspond
  2581. * to the timestamp which is <= the requested one, if backward
  2582. * is 0, then it will be >=
  2583. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise.
  2584. * @return A pointer to the requested AVIndexEntry if it exists, NULL otherwise.
  2585. *
  2586. * @note The pointer returned by this function is only guaranteed to be valid
  2587. * until any function that takes the stream or the parent AVFormatContext
  2588. * as input argument is called.
  2589. */
  2590. const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
  2591. int64_t wanted_timestamp,
  2592. int flags);
  2593. /**
  2594. * Add an index entry into a sorted list. Update the entry if the list
  2595. * already contains it.
  2596. *
  2597. * @param timestamp timestamp in the time base of the given stream
  2598. */
  2599. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  2600. int size, int distance, int flags);
  2601. /**
  2602. * Split a URL string into components.
  2603. *
  2604. * The pointers to buffers for storing individual components may be null,
  2605. * in order to ignore that component. Buffers for components not found are
  2606. * set to empty strings. If the port is not found, it is set to a negative
  2607. * value.
  2608. *
  2609. * @param proto the buffer for the protocol
  2610. * @param proto_size the size of the proto buffer
  2611. * @param authorization the buffer for the authorization
  2612. * @param authorization_size the size of the authorization buffer
  2613. * @param hostname the buffer for the host name
  2614. * @param hostname_size the size of the hostname buffer
  2615. * @param port_ptr a pointer to store the port number in
  2616. * @param path the buffer for the path
  2617. * @param path_size the size of the path buffer
  2618. * @param url the URL to split
  2619. */
  2620. void av_url_split(char *proto, int proto_size,
  2621. char *authorization, int authorization_size,
  2622. char *hostname, int hostname_size,
  2623. int *port_ptr,
  2624. char *path, int path_size,
  2625. const char *url);
  2626. /**
  2627. * Print detailed information about the input or output format, such as
  2628. * duration, bitrate, streams, container, programs, metadata, side data,
  2629. * codec and time base.
  2630. *
  2631. * @param ic the context to analyze
  2632. * @param index index of the stream to dump information about
  2633. * @param url the URL to print, such as source or destination file
  2634. * @param is_output Select whether the specified context is an input(0) or output(1)
  2635. */
  2636. void av_dump_format(AVFormatContext *ic,
  2637. int index,
  2638. const char *url,
  2639. int is_output);
  2640. #define AV_FRAME_FILENAME_FLAGS_MULTIPLE 1 ///< Allow multiple %d
  2641. /**
  2642. * Return in 'buf' the path with '%d' replaced by a number.
  2643. *
  2644. * Also handles the '%0nd' format where 'n' is the total number
  2645. * of digits and '%%'.
  2646. *
  2647. * @param buf destination buffer
  2648. * @param buf_size destination buffer size
  2649. * @param path numbered sequence string
  2650. * @param number frame number
  2651. * @param flags AV_FRAME_FILENAME_FLAGS_*
  2652. * @return 0 if OK, -1 on format error
  2653. */
  2654. int av_get_frame_filename2(char *buf, int buf_size,
  2655. const char *path, int number, int flags);
  2656. int av_get_frame_filename(char *buf, int buf_size,
  2657. const char *path, int number);
  2658. /**
  2659. * Check whether filename actually is a numbered sequence generator.
  2660. *
  2661. * @param filename possible numbered sequence string
  2662. * @return 1 if a valid numbered sequence string, 0 otherwise
  2663. */
  2664. int av_filename_number_test(const char *filename);
  2665. /**
  2666. * Generate an SDP for an RTP session.
  2667. *
  2668. * Note, this overwrites the id values of AVStreams in the muxer contexts
  2669. * for getting unique dynamic payload types.
  2670. *
  2671. * @param ac array of AVFormatContexts describing the RTP streams. If the
  2672. * array is composed by only one context, such context can contain
  2673. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  2674. * all the contexts in the array (an AVCodecContext per RTP stream)
  2675. * must contain only one AVStream.
  2676. * @param n_files number of AVCodecContexts contained in ac
  2677. * @param buf buffer where the SDP will be stored (must be allocated by
  2678. * the caller)
  2679. * @param size the size of the buffer
  2680. * @return 0 if OK, AVERROR_xxx on error
  2681. */
  2682. int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
  2683. /**
  2684. * Return a positive value if the given filename has one of the given
  2685. * extensions, 0 otherwise.
  2686. *
  2687. * @param filename file name to check against the given extensions
  2688. * @param extensions a comma-separated list of filename extensions
  2689. */
  2690. int av_match_ext(const char *filename, const char *extensions);
  2691. /**
  2692. * Test if the given container can store a codec.
  2693. *
  2694. * @param ofmt container to check for compatibility
  2695. * @param codec_id codec to potentially store in container
  2696. * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
  2697. *
  2698. * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
  2699. * A negative number if this information is not available.
  2700. */
  2701. int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id,
  2702. int std_compliance);
  2703. /**
  2704. * @defgroup riff_fourcc RIFF FourCCs
  2705. * @{
  2706. * Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs. The tables are
  2707. * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the
  2708. * following code:
  2709. * @code
  2710. * uint32_t tag = MKTAG('H', '2', '6', '4');
  2711. * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 };
  2712. * enum AVCodecID id = av_codec_get_id(table, tag);
  2713. * @endcode
  2714. */
  2715. /**
  2716. * @return the table mapping RIFF FourCCs for video to libavcodec AVCodecID.
  2717. */
  2718. const struct AVCodecTag *avformat_get_riff_video_tags(void);
  2719. /**
  2720. * @return the table mapping RIFF FourCCs for audio to AVCodecID.
  2721. */
  2722. const struct AVCodecTag *avformat_get_riff_audio_tags(void);
  2723. /**
  2724. * @return the table mapping MOV FourCCs for video to libavcodec AVCodecID.
  2725. */
  2726. const struct AVCodecTag *avformat_get_mov_video_tags(void);
  2727. /**
  2728. * @return the table mapping MOV FourCCs for audio to AVCodecID.
  2729. */
  2730. const struct AVCodecTag *avformat_get_mov_audio_tags(void);
  2731. /**
  2732. * @}
  2733. */
  2734. /**
  2735. * Guess the sample aspect ratio of a frame, based on both the stream and the
  2736. * frame aspect ratio.
  2737. *
  2738. * Since the frame aspect ratio is set by the codec but the stream aspect ratio
  2739. * is set by the demuxer, these two may not be equal. This function tries to
  2740. * return the value that you should use if you would like to display the frame.
  2741. *
  2742. * Basic logic is to use the stream aspect ratio if it is set to something sane
  2743. * otherwise use the frame aspect ratio. This way a container setting, which is
  2744. * usually easy to modify can override the coded value in the frames.
  2745. *
  2746. * @param format the format context which the stream is part of
  2747. * @param stream the stream which the frame is part of
  2748. * @param frame the frame with the aspect ratio to be determined
  2749. * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea
  2750. */
  2751. AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream,
  2752. struct AVFrame *frame);
  2753. /**
  2754. * Guess the frame rate, based on both the container and codec information.
  2755. *
  2756. * @param ctx the format context which the stream is part of
  2757. * @param stream the stream which the frame is part of
  2758. * @param frame the frame for which the frame rate should be determined, may be NULL
  2759. * @return the guessed (valid) frame rate, 0/1 if no idea
  2760. */
  2761. AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream,
  2762. struct AVFrame *frame);
  2763. /**
  2764. * Check if the stream st contained in s is matched by the stream specifier
  2765. * spec.
  2766. *
  2767. * See the "stream specifiers" chapter in the documentation for the syntax
  2768. * of spec.
  2769. *
  2770. * @return >0 if st is matched by spec;
  2771. * 0 if st is not matched by spec;
  2772. * AVERROR code if spec is invalid
  2773. *
  2774. * @note A stream specifier can match several streams in the format.
  2775. */
  2776. int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
  2777. const char *spec);
  2778. int avformat_queue_attached_pictures(AVFormatContext *s);
  2779. enum AVTimebaseSource {
  2780. AVFMT_TBCF_AUTO = -1,
  2781. AVFMT_TBCF_DECODER,
  2782. AVFMT_TBCF_DEMUXER,
  2783. #if FF_API_R_FRAME_RATE
  2784. AVFMT_TBCF_R_FRAMERATE,
  2785. #endif
  2786. };
  2787. /**
  2788. * Transfer internal timing information from one stream to another.
  2789. *
  2790. * This function is useful when doing stream copy.
  2791. *
  2792. * @param ofmt target output format for ost
  2793. * @param ost output stream which needs timings copy and adjustments
  2794. * @param ist reference input stream to copy timings from
  2795. * @param copy_tb define from where the stream codec timebase needs to be imported
  2796. */
  2797. int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
  2798. AVStream *ost, const AVStream *ist,
  2799. enum AVTimebaseSource copy_tb);
  2800. /**
  2801. * Get the internal codec timebase from a stream.
  2802. *
  2803. * @param st input stream to extract the timebase from
  2804. */
  2805. AVRational av_stream_get_codec_timebase(const AVStream *st);
  2806. /**
  2807. * @}
  2808. */
  2809. #endif /* AVFORMAT_AVFORMAT_H */