avformat.h 100 KB

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