avformat.h 113 KB

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