avformat.h 115 KB

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