You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

avformat.h 100KB

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