avformat.h 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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.destruct is set on the returned packet, then the packet is
  159. * allocated dynamically and the user may keep it indefinitely.
  160. * Otherwise, if AVPacket.destruct 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. * @}
  174. *
  175. * @defgroup lavf_io I/O Read/Write
  176. * @{
  177. * @}
  178. *
  179. * @defgroup lavf_codec Demuxers
  180. * @{
  181. * @defgroup lavf_codec_native Native Demuxers
  182. * @{
  183. * @}
  184. * @defgroup lavf_codec_wrappers External library wrappers
  185. * @{
  186. * @}
  187. * @}
  188. * @defgroup lavf_protos I/O Protocols
  189. * @{
  190. * @}
  191. * @defgroup lavf_internal Internal
  192. * @{
  193. * @}
  194. * @}
  195. *
  196. */
  197. #include <time.h>
  198. #include <stdio.h> /* FILE */
  199. #include "libavcodec/avcodec.h"
  200. #include "libavutil/dict.h"
  201. #include "libavutil/log.h"
  202. #include "avio.h"
  203. #include "libavformat/version.h"
  204. #if FF_API_AV_GETTIME
  205. #include "libavutil/time.h"
  206. #endif
  207. struct AVFormatContext;
  208. /**
  209. * @defgroup metadata_api Public Metadata API
  210. * @{
  211. * @ingroup libavf
  212. * The metadata API allows libavformat to export metadata tags to a client
  213. * application when demuxing. Conversely it allows a client application to
  214. * set metadata when muxing.
  215. *
  216. * Metadata is exported or set as pairs of key/value strings in the 'metadata'
  217. * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs
  218. * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg,
  219. * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata
  220. * exported by demuxers isn't checked to be valid UTF-8 in most cases.
  221. *
  222. * Important concepts to keep in mind:
  223. * - Keys are unique; there can never be 2 tags with the same key. This is
  224. * also meant semantically, i.e., a demuxer should not knowingly produce
  225. * several keys that are literally different but semantically identical.
  226. * E.g., key=Author5, key=Author6. In this example, all authors must be
  227. * placed in the same tag.
  228. * - Metadata is flat, not hierarchical; there are no subtags. If you
  229. * want to store, e.g., the email address of the child of producer Alice
  230. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  231. * - Several modifiers can be applied to the tag name. This is done by
  232. * appending a dash character ('-') and the modifier name in the order
  233. * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
  234. * - language -- a tag whose value is localized for a particular language
  235. * is appended with the ISO 639-2/B 3-letter language code.
  236. * For example: Author-ger=Michael, Author-eng=Mike
  237. * The original/default language is in the unqualified "Author" tag.
  238. * A demuxer should set a default if it sets any translated tag.
  239. * - sorting -- a modified version of a tag that should be used for
  240. * sorting will have '-sort' appended. E.g. artist="The Beatles",
  241. * artist-sort="Beatles, The".
  242. *
  243. * - Demuxers attempt to export metadata in a generic format, however tags
  244. * with no generic equivalents are left as they are stored in the container.
  245. * Follows a list of generic tag names:
  246. *
  247. @verbatim
  248. album -- name of the set this work belongs to
  249. album_artist -- main creator of the set/album, if different from artist.
  250. e.g. "Various Artists" for compilation albums.
  251. artist -- main creator of the work
  252. comment -- any additional description of the file.
  253. composer -- who composed the work, if different from artist.
  254. copyright -- name of copyright holder.
  255. creation_time-- date when the file was created, preferably in ISO 8601.
  256. date -- date when the work was created, preferably in ISO 8601.
  257. disc -- number of a subset, e.g. disc in a multi-disc collection.
  258. encoder -- name/settings of the software/hardware that produced the file.
  259. encoded_by -- person/group who created the file.
  260. filename -- original name of the file.
  261. genre -- <self-evident>.
  262. language -- main language in which the work is performed, preferably
  263. in ISO 639-2 format. Multiple languages can be specified by
  264. separating them with commas.
  265. performer -- artist who performed the work, if different from artist.
  266. E.g for "Also sprach Zarathustra", artist would be "Richard
  267. Strauss" and performer "London Philharmonic Orchestra".
  268. publisher -- name of the label/publisher.
  269. service_name -- name of the service in broadcasting (channel name).
  270. service_provider -- name of the service provider in broadcasting.
  271. title -- name of the work.
  272. track -- number of this work in the set, can be in form current/total.
  273. variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
  274. @endverbatim
  275. *
  276. * Look in the examples section for an application example how to use the Metadata API.
  277. *
  278. * @}
  279. */
  280. /* packet functions */
  281. /**
  282. * Allocate and read the payload of a packet and initialize its
  283. * fields with default values.
  284. *
  285. * @param pkt packet
  286. * @param size desired payload size
  287. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  288. */
  289. int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
  290. /**
  291. * Read data and append it to the current content of the AVPacket.
  292. * If pkt->size is 0 this is identical to av_get_packet.
  293. * Note that this uses av_grow_packet and thus involves a realloc
  294. * which is inefficient. Thus this function should only be used
  295. * when there is no reasonable way to know (an upper bound of)
  296. * the final size.
  297. *
  298. * @param pkt packet
  299. * @param size amount of data to read
  300. * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
  301. * will not be lost even if an error occurs.
  302. */
  303. int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
  304. /*************************************************/
  305. /* fractional numbers for exact pts handling */
  306. /**
  307. * The exact value of the fractional number is: 'val + num / den'.
  308. * num is assumed to be 0 <= num < den.
  309. */
  310. typedef struct AVFrac {
  311. int64_t val, num, den;
  312. } AVFrac;
  313. /*************************************************/
  314. /* input/output formats */
  315. struct AVCodecTag;
  316. /**
  317. * This structure contains the data a format has to probe a file.
  318. */
  319. typedef struct AVProbeData {
  320. const char *filename;
  321. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  322. int buf_size; /**< Size of buf except extra allocated bytes */
  323. } AVProbeData;
  324. #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
  325. #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
  326. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  327. /// Demuxer will use avio_open, no opened file should be provided by the caller.
  328. #define AVFMT_NOFILE 0x0001
  329. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  330. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  331. #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
  332. raw picture data. */
  333. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  334. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  335. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  336. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
  337. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  338. #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
  339. #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
  340. #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
  341. #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
  342. #define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */
  343. #define AVFMT_ALLOW_FLUSH 0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */
  344. #if LIBAVFORMAT_VERSION_MAJOR <= 54
  345. #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
  346. #else
  347. #define AVFMT_TS_NONSTRICT 0x20000
  348. #endif
  349. /**< Format does not require strictly
  350. increasing timestamps, but they must
  351. still be monotonic */
  352. #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
  353. /**
  354. * @addtogroup lavf_encoding
  355. * @{
  356. */
  357. typedef struct AVOutputFormat {
  358. const char *name;
  359. /**
  360. * Descriptive name for the format, meant to be more human-readable
  361. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  362. * to define it.
  363. */
  364. const char *long_name;
  365. const char *mime_type;
  366. const char *extensions; /**< comma-separated filename extensions */
  367. /* output support */
  368. enum AVCodecID audio_codec; /**< default audio codec */
  369. enum AVCodecID video_codec; /**< default video codec */
  370. enum AVCodecID subtitle_codec; /**< default subtitle codec */
  371. /**
  372. * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
  373. * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
  374. * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH,
  375. * AVFMT_TS_NONSTRICT
  376. */
  377. int flags;
  378. /**
  379. * List of supported codec_id-codec_tag pairs, ordered by "better
  380. * choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
  381. */
  382. const struct AVCodecTag * const *codec_tag;
  383. const AVClass *priv_class; ///< AVClass for the private context
  384. /*****************************************************************
  385. * No fields below this line are part of the public API. They
  386. * may not be used outside of libavformat and can be changed and
  387. * removed at will.
  388. * New public fields should be added right above.
  389. *****************************************************************
  390. */
  391. struct AVOutputFormat *next;
  392. /**
  393. * size of private data so that it can be allocated in the wrapper
  394. */
  395. int priv_data_size;
  396. int (*write_header)(struct AVFormatContext *);
  397. /**
  398. * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
  399. * pkt can be NULL in order to flush data buffered in the muxer.
  400. * When flushing, return 0 if there still is more data to flush,
  401. * or 1 if everything was flushed and there is no more buffered
  402. * data.
  403. */
  404. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  405. int (*write_trailer)(struct AVFormatContext *);
  406. /**
  407. * Currently only used to set pixel format if not YUV420P.
  408. */
  409. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  410. AVPacket *in, int flush);
  411. /**
  412. * Test if the given codec can be stored in this container.
  413. *
  414. * @return 1 if the codec is supported, 0 if it is not.
  415. * A negative number if unknown.
  416. * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC
  417. */
  418. int (*query_codec)(enum AVCodecID id, int std_compliance);
  419. void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
  420. int64_t *dts, int64_t *wall);
  421. } AVOutputFormat;
  422. /**
  423. * @}
  424. */
  425. /**
  426. * @addtogroup lavf_decoding
  427. * @{
  428. */
  429. typedef struct AVInputFormat {
  430. /**
  431. * A comma separated list of short names for the format. New names
  432. * may be appended with a minor bump.
  433. */
  434. const char *name;
  435. /**
  436. * Descriptive name for the format, meant to be more human-readable
  437. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  438. * to define it.
  439. */
  440. const char *long_name;
  441. /**
  442. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
  443. * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
  444. * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
  445. */
  446. int flags;
  447. /**
  448. * If extensions are defined, then no probe is done. You should
  449. * usually not use extension format guessing because it is not
  450. * reliable enough
  451. */
  452. const char *extensions;
  453. const struct AVCodecTag * const *codec_tag;
  454. const AVClass *priv_class; ///< AVClass for the private context
  455. /*****************************************************************
  456. * No fields below this line are part of the public API. They
  457. * may not be used outside of libavformat and can be changed and
  458. * removed at will.
  459. * New public fields should be added right above.
  460. *****************************************************************
  461. */
  462. struct AVInputFormat *next;
  463. /**
  464. * Raw demuxers store their codec ID here.
  465. */
  466. int raw_codec_id;
  467. /**
  468. * Size of private data so that it can be allocated in the wrapper.
  469. */
  470. int priv_data_size;
  471. /**
  472. * Tell if a given file has a chance of being parsed as this format.
  473. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  474. * big so you do not have to check for that unless you need more.
  475. */
  476. int (*read_probe)(AVProbeData *);
  477. /**
  478. * Read the format header and initialize the AVFormatContext
  479. * structure. Return 0 if OK. Only used in raw format right
  480. * now. 'avformat_new_stream' should be called to create new streams.
  481. */
  482. int (*read_header)(struct AVFormatContext *);
  483. /**
  484. * Read one packet and put it in 'pkt'. pts and flags are also
  485. * set. 'avformat_new_stream' can be called only if the flag
  486. * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
  487. * background thread).
  488. * @return 0 on success, < 0 on error.
  489. * When returning an error, pkt must not have been allocated
  490. * or must be freed before returning
  491. */
  492. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  493. /**
  494. * Close the stream. The AVFormatContext and AVStreams are not
  495. * freed by this function
  496. */
  497. int (*read_close)(struct AVFormatContext *);
  498. /**
  499. * Seek to a given timestamp relative to the frames in
  500. * stream component stream_index.
  501. * @param stream_index Must not be -1.
  502. * @param flags Selects which direction should be preferred if no exact
  503. * match is available.
  504. * @return >= 0 on success (but not necessarily the new offset)
  505. */
  506. int (*read_seek)(struct AVFormatContext *,
  507. int stream_index, int64_t timestamp, int flags);
  508. /**
  509. * Get the next timestamp in stream[stream_index].time_base units.
  510. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  511. */
  512. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  513. int64_t *pos, int64_t pos_limit);
  514. /**
  515. * Start/resume playing - only meaningful if using a network-based format
  516. * (RTSP).
  517. */
  518. int (*read_play)(struct AVFormatContext *);
  519. /**
  520. * Pause playing - only meaningful if using a network-based format
  521. * (RTSP).
  522. */
  523. int (*read_pause)(struct AVFormatContext *);
  524. /**
  525. * Seek to timestamp ts.
  526. * Seeking will be done so that the point from which all active streams
  527. * can be presented successfully will be closest to ts and within min/max_ts.
  528. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  529. */
  530. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  531. } AVInputFormat;
  532. /**
  533. * @}
  534. */
  535. enum AVStreamParseType {
  536. AVSTREAM_PARSE_NONE,
  537. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  538. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  539. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  540. AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
  541. AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'), /**< full parsing and repack with timestamp and position generation by parser for raw
  542. this assumes that each packet in the file contains no demuxer level headers and
  543. just codec level data, otherwise position generation would fail */
  544. };
  545. typedef struct AVIndexEntry {
  546. int64_t pos;
  547. int64_t timestamp; /**<
  548. * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available
  549. * when seeking to this entry. That means preferable PTS on keyframe based formats.
  550. * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better
  551. * is known
  552. */
  553. #define AVINDEX_KEYFRAME 0x0001
  554. int flags:2;
  555. 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).
  556. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  557. } AVIndexEntry;
  558. #define AV_DISPOSITION_DEFAULT 0x0001
  559. #define AV_DISPOSITION_DUB 0x0002
  560. #define AV_DISPOSITION_ORIGINAL 0x0004
  561. #define AV_DISPOSITION_COMMENT 0x0008
  562. #define AV_DISPOSITION_LYRICS 0x0010
  563. #define AV_DISPOSITION_KARAOKE 0x0020
  564. /**
  565. * Track should be used during playback by default.
  566. * Useful for subtitle track that should be displayed
  567. * even when user did not explicitly ask for subtitles.
  568. */
  569. #define AV_DISPOSITION_FORCED 0x0040
  570. #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
  571. #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
  572. #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
  573. /**
  574. * The stream is stored in the file as an attached picture/"cover art" (e.g.
  575. * APIC frame in ID3v2). The single packet associated with it will be returned
  576. * among the first few packets read from the file unless seeking takes place.
  577. * It can also be accessed at any time in AVStream.attached_pic.
  578. */
  579. #define AV_DISPOSITION_ATTACHED_PIC 0x0400
  580. /**
  581. * Options for behavior on timestamp wrap detection.
  582. */
  583. #define AV_PTS_WRAP_IGNORE 0 ///< ignore the wrap
  584. #define AV_PTS_WRAP_ADD_OFFSET 1 ///< add the format specific offset on wrap detection
  585. #define AV_PTS_WRAP_SUB_OFFSET -1 ///< subtract the format specific offset on wrap detection
  586. /**
  587. * Stream structure.
  588. * New fields can be added to the end with minor version bumps.
  589. * Removal, reordering and changes to existing fields require a major
  590. * version bump.
  591. * sizeof(AVStream) must not be used outside libav*.
  592. */
  593. typedef struct AVStream {
  594. int index; /**< stream index in AVFormatContext */
  595. /**
  596. * Format-specific stream ID.
  597. * decoding: set by libavformat
  598. * encoding: set by the user, replaced by libavformat if left unset
  599. */
  600. int id;
  601. /**
  602. * Codec context associated with this stream. Allocated and freed by
  603. * libavformat.
  604. *
  605. * - decoding: The demuxer exports codec information stored in the headers
  606. * here.
  607. * - encoding: The user sets codec information, the muxer writes it to the
  608. * output. Mandatory fields as specified in AVCodecContext
  609. * documentation must be set even if this AVCodecContext is
  610. * not actually used for encoding.
  611. */
  612. AVCodecContext *codec;
  613. #if FF_API_R_FRAME_RATE
  614. /**
  615. * Real base framerate of the stream.
  616. * This is the lowest framerate with which all timestamps can be
  617. * represented accurately (it is the least common multiple of all
  618. * framerates in the stream). Note, this value is just a guess!
  619. * For example, if the time base is 1/90000 and all frames have either
  620. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  621. */
  622. AVRational r_frame_rate;
  623. #endif
  624. void *priv_data;
  625. /**
  626. * encoding: pts generation when outputting stream
  627. */
  628. struct AVFrac pts;
  629. /**
  630. * This is the fundamental unit of time (in seconds) in terms
  631. * of which frame timestamps are represented.
  632. *
  633. * decoding: set by libavformat
  634. * encoding: set by libavformat in avformat_write_header. The muxer may use the
  635. * user-provided value of @ref AVCodecContext.time_base "codec->time_base"
  636. * as a hint.
  637. */
  638. AVRational time_base;
  639. /**
  640. * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
  641. * Only set this if you are absolutely 100% sure that the value you set
  642. * it to really is the pts of the first frame.
  643. * This may be undefined (AV_NOPTS_VALUE).
  644. * @note The ASF header does NOT contain a correct start_time the ASF
  645. * demuxer must NOT set this.
  646. */
  647. int64_t start_time;
  648. /**
  649. * Decoding: duration of the stream, in stream time base.
  650. * If a source file does not specify a duration, but does specify
  651. * a bitrate, this value will be estimated from bitrate and file size.
  652. */
  653. int64_t duration;
  654. int64_t nb_frames; ///< number of frames in this stream if known or 0
  655. int disposition; /**< AV_DISPOSITION_* bit field */
  656. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  657. /**
  658. * sample aspect ratio (0 if unknown)
  659. * - encoding: Set by user.
  660. * - decoding: Set by libavformat.
  661. */
  662. AVRational sample_aspect_ratio;
  663. AVDictionary *metadata;
  664. /**
  665. * Average framerate
  666. */
  667. AVRational avg_frame_rate;
  668. /**
  669. * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
  670. * will contain the attached picture.
  671. *
  672. * decoding: set by libavformat, must not be modified by the caller.
  673. * encoding: unused
  674. */
  675. AVPacket attached_pic;
  676. /*****************************************************************
  677. * All fields below this line are not part of the public API. They
  678. * may not be used outside of libavformat and can be changed and
  679. * removed at will.
  680. * New public fields should be added right above.
  681. *****************************************************************
  682. */
  683. /**
  684. * Stream information used internally by av_find_stream_info()
  685. */
  686. #define MAX_STD_TIMEBASES (60*12+6)
  687. struct {
  688. int64_t last_dts;
  689. int64_t duration_gcd;
  690. int duration_count;
  691. double (*duration_error)[2][MAX_STD_TIMEBASES];
  692. int64_t codec_info_duration;
  693. int64_t codec_info_duration_fields;
  694. int found_decoder;
  695. int64_t last_duration;
  696. /**
  697. * Those are used for average framerate estimation.
  698. */
  699. int64_t fps_first_dts;
  700. int fps_first_dts_idx;
  701. int64_t fps_last_dts;
  702. int fps_last_dts_idx;
  703. } *info;
  704. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  705. // Timestamp generation support:
  706. /**
  707. * Timestamp corresponding to the last dts sync point.
  708. *
  709. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  710. * a DTS is received from the underlying container. Otherwise set to
  711. * AV_NOPTS_VALUE by default.
  712. */
  713. int64_t reference_dts;
  714. int64_t first_dts;
  715. int64_t cur_dts;
  716. int64_t last_IP_pts;
  717. int last_IP_duration;
  718. /**
  719. * Number of packets to buffer for codec probing
  720. */
  721. #define MAX_PROBE_PACKETS 2500
  722. int probe_packets;
  723. /**
  724. * Number of frames that have been demuxed during av_find_stream_info()
  725. */
  726. int codec_info_nb_frames;
  727. /**
  728. * Stream Identifier
  729. * This is the MPEG-TS stream identifier +1
  730. * 0 means unknown
  731. */
  732. int stream_identifier;
  733. int64_t interleaver_chunk_size;
  734. int64_t interleaver_chunk_duration;
  735. /* av_read_frame() support */
  736. enum AVStreamParseType need_parsing;
  737. struct AVCodecParserContext *parser;
  738. /**
  739. * last packet in packet_buffer for this stream when muxing.
  740. */
  741. struct AVPacketList *last_in_packet_buffer;
  742. AVProbeData probe_data;
  743. #define MAX_REORDER_DELAY 16
  744. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  745. AVIndexEntry *index_entries; /**< Only used if the format does not
  746. support seeking natively. */
  747. int nb_index_entries;
  748. unsigned int index_entries_allocated_size;
  749. /**
  750. * stream probing state
  751. * -1 -> probing finished
  752. * 0 -> no probing requested
  753. * rest -> perform probing with request_probe being the minimum score to accept.
  754. * NOT PART OF PUBLIC API
  755. */
  756. int request_probe;
  757. /**
  758. * Indicates that everything up to the next keyframe
  759. * should be discarded.
  760. */
  761. int skip_to_keyframe;
  762. /**
  763. * Number of samples to skip at the start of the frame decoded from the next packet.
  764. */
  765. int skip_samples;
  766. /**
  767. * Number of internally decoded frames, used internally in libavformat, do not access
  768. * its lifetime differs from info which is why it is not in that structure.
  769. */
  770. int nb_decoded_frames;
  771. /**
  772. * Timestamp offset added to timestamps before muxing
  773. * NOT PART OF PUBLIC API
  774. */
  775. int64_t mux_ts_offset;
  776. /**
  777. * Internal data to check for wrapping of the time stamp
  778. */
  779. int64_t pts_wrap_reference;
  780. /**
  781. * Options for behavior, when a wrap is detected.
  782. *
  783. * Defined by AV_PTS_WRAP_ values.
  784. *
  785. * If correction is enabled, there are two possibilities:
  786. * If the first time stamp is near the wrap point, the wrap offset
  787. * will be subtracted, which will create negative time stamps.
  788. * Otherwise the offset will be added.
  789. */
  790. int pts_wrap_behavior;
  791. } AVStream;
  792. #define AV_PROGRAM_RUNNING 1
  793. /**
  794. * New fields can be added to the end with minor version bumps.
  795. * Removal, reordering and changes to existing fields require a major
  796. * version bump.
  797. * sizeof(AVProgram) must not be used outside libav*.
  798. */
  799. typedef struct AVProgram {
  800. int id;
  801. int flags;
  802. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  803. unsigned int *stream_index;
  804. unsigned int nb_stream_indexes;
  805. AVDictionary *metadata;
  806. int program_num;
  807. int pmt_pid;
  808. int pcr_pid;
  809. /*****************************************************************
  810. * All fields below this line are not part of the public API. They
  811. * may not be used outside of libavformat and can be changed and
  812. * removed at will.
  813. * New public fields should be added right above.
  814. *****************************************************************
  815. */
  816. int64_t start_time;
  817. int64_t end_time;
  818. int64_t pts_wrap_reference; ///< reference dts for wrap detection
  819. int pts_wrap_behavior; ///< behavior on wrap detection
  820. } AVProgram;
  821. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  822. (streams are added dynamically) */
  823. typedef struct AVChapter {
  824. int id; ///< unique ID to identify the chapter
  825. AVRational time_base; ///< time base in which the start/end timestamps are specified
  826. int64_t start, end; ///< chapter start/end time in time_base units
  827. AVDictionary *metadata;
  828. } AVChapter;
  829. /**
  830. * The duration of a video can be estimated through various ways, and this enum can be used
  831. * to know how the duration was estimated.
  832. */
  833. enum AVDurationEstimationMethod {
  834. AVFMT_DURATION_FROM_PTS, ///< Duration accurately estimated from PTSes
  835. AVFMT_DURATION_FROM_STREAM, ///< Duration estimated from a stream with a known duration
  836. AVFMT_DURATION_FROM_BITRATE ///< Duration estimated from bitrate (less accurate)
  837. };
  838. /**
  839. * Format I/O context.
  840. * New fields can be added to the end with minor version bumps.
  841. * Removal, reordering and changes to existing fields require a major
  842. * version bump.
  843. * sizeof(AVFormatContext) must not be used outside libav*, use
  844. * avformat_alloc_context() to create an AVFormatContext.
  845. */
  846. typedef struct AVFormatContext {
  847. /**
  848. * A class for logging and AVOptions. Set by avformat_alloc_context().
  849. * Exports (de)muxer private options if they exist.
  850. */
  851. const AVClass *av_class;
  852. /**
  853. * Can only be iformat or oformat, not both at the same time.
  854. *
  855. * decoding: set by avformat_open_input().
  856. * encoding: set by the user.
  857. */
  858. struct AVInputFormat *iformat;
  859. struct AVOutputFormat *oformat;
  860. /**
  861. * Format private data. This is an AVOptions-enabled struct
  862. * if and only if iformat/oformat.priv_class is not NULL.
  863. */
  864. void *priv_data;
  865. /**
  866. * I/O context.
  867. *
  868. * decoding: either set by the user before avformat_open_input() (then
  869. * the user must close it manually) or set by avformat_open_input().
  870. * encoding: set by the user.
  871. *
  872. * Do NOT set this field if AVFMT_NOFILE flag is set in
  873. * iformat/oformat.flags. In such a case, the (de)muxer will handle
  874. * I/O in some other way and this field will be NULL.
  875. */
  876. AVIOContext *pb;
  877. /* stream info */
  878. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  879. /**
  880. * A list of all streams in the file. New streams are created with
  881. * avformat_new_stream().
  882. *
  883. * decoding: streams are created by libavformat in avformat_open_input().
  884. * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
  885. * appear in av_read_frame().
  886. * encoding: streams are created by the user before avformat_write_header().
  887. */
  888. unsigned int nb_streams;
  889. AVStream **streams;
  890. char filename[1024]; /**< input or output filename */
  891. /**
  892. * Decoding: position of the first frame of the component, in
  893. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  894. * It is deduced from the AVStream values.
  895. */
  896. int64_t start_time;
  897. /**
  898. * Decoding: duration of the stream, in AV_TIME_BASE fractional
  899. * seconds. Only set this value if you know none of the individual stream
  900. * durations and also do not set any of them. This is deduced from the
  901. * AVStream values if not set.
  902. */
  903. int64_t duration;
  904. /**
  905. * Decoding: total stream bitrate in bit/s, 0 if not
  906. * available. Never set it directly if the file_size and the
  907. * duration are known as FFmpeg can compute it automatically.
  908. */
  909. int bit_rate;
  910. unsigned int packet_size;
  911. int max_delay;
  912. int flags;
  913. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  914. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  915. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  916. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  917. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  918. #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
  919. #define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible
  920. #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
  921. #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
  922. #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
  923. #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
  924. #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)
  925. #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Don't merge side data but keep it separate.
  926. /**
  927. * decoding: size of data to probe; encoding: unused.
  928. */
  929. unsigned int probesize;
  930. /**
  931. * decoding: maximum time (in AV_TIME_BASE units) during which the input should
  932. * be analyzed in avformat_find_stream_info().
  933. */
  934. int max_analyze_duration;
  935. const uint8_t *key;
  936. int keylen;
  937. unsigned int nb_programs;
  938. AVProgram **programs;
  939. /**
  940. * Forced video codec_id.
  941. * Demuxing: Set by user.
  942. */
  943. enum AVCodecID video_codec_id;
  944. /**
  945. * Forced audio codec_id.
  946. * Demuxing: Set by user.
  947. */
  948. enum AVCodecID audio_codec_id;
  949. /**
  950. * Forced subtitle codec_id.
  951. * Demuxing: Set by user.
  952. */
  953. enum AVCodecID subtitle_codec_id;
  954. /**
  955. * Maximum amount of memory in bytes to use for the index of each stream.
  956. * If the index exceeds this size, entries will be discarded as
  957. * needed to maintain a smaller size. This can lead to slower or less
  958. * accurate seeking (depends on demuxer).
  959. * Demuxers for which a full in-memory index is mandatory will ignore
  960. * this.
  961. * muxing : unused
  962. * demuxing: set by user
  963. */
  964. unsigned int max_index_size;
  965. /**
  966. * Maximum amount of memory in bytes to use for buffering frames
  967. * obtained from realtime capture devices.
  968. */
  969. unsigned int max_picture_buffer;
  970. unsigned int nb_chapters;
  971. AVChapter **chapters;
  972. AVDictionary *metadata;
  973. /**
  974. * Start time of the stream in real world time, in microseconds
  975. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  976. * in the stream was captured at this real world time.
  977. * - encoding: Set by user.
  978. * - decoding: Unused.
  979. */
  980. int64_t start_time_realtime;
  981. /**
  982. * decoding: number of frames used to probe fps
  983. */
  984. int fps_probe_size;
  985. /**
  986. * Error recognition; higher values will detect more errors but may
  987. * misdetect some more or less valid parts as errors.
  988. * - encoding: unused
  989. * - decoding: Set by user.
  990. */
  991. int error_recognition;
  992. /**
  993. * Custom interrupt callbacks for the I/O layer.
  994. *
  995. * decoding: set by the user before avformat_open_input().
  996. * encoding: set by the user before avformat_write_header()
  997. * (mainly useful for AVFMT_NOFILE formats). The callback
  998. * should also be passed to avio_open2() if it's used to
  999. * open the file.
  1000. */
  1001. AVIOInterruptCB interrupt_callback;
  1002. /**
  1003. * Flags to enable debugging.
  1004. */
  1005. int debug;
  1006. #define FF_FDEBUG_TS 0x0001
  1007. /**
  1008. * Transport stream id.
  1009. * This will be moved into demuxer private options. Thus no API/ABI compatibility
  1010. */
  1011. int ts_id;
  1012. /**
  1013. * Audio preload in microseconds.
  1014. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1015. * - encoding: Set by user via AVOptions (NO direct access)
  1016. * - decoding: unused
  1017. */
  1018. int audio_preload;
  1019. /**
  1020. * Max chunk time in microseconds.
  1021. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1022. * - encoding: Set by user via AVOptions (NO direct access)
  1023. * - decoding: unused
  1024. */
  1025. int max_chunk_duration;
  1026. /**
  1027. * Max chunk size in bytes
  1028. * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
  1029. * - encoding: Set by user via AVOptions (NO direct access)
  1030. * - decoding: unused
  1031. */
  1032. int max_chunk_size;
  1033. /**
  1034. * forces the use of wallclock timestamps as pts/dts of packets
  1035. * This has undefined results in the presence of B frames.
  1036. * - encoding: unused
  1037. * - decoding: Set by user via AVOptions (NO direct access)
  1038. */
  1039. int use_wallclock_as_timestamps;
  1040. /**
  1041. * Avoids negative timestamps during muxing
  1042. * 0 -> allow negative timestamps
  1043. * 1 -> avoid negative timestamps
  1044. * -1 -> choose automatically (default)
  1045. * Note, this is only works when interleave_packet_per_dts is in use
  1046. * - encoding: Set by user via AVOptions (NO direct access)
  1047. * - decoding: unused
  1048. */
  1049. int avoid_negative_ts;
  1050. /**
  1051. * avio flags, used to force AVIO_FLAG_DIRECT.
  1052. * - encoding: unused
  1053. * - decoding: Set by user via AVOptions (NO direct access)
  1054. */
  1055. int avio_flags;
  1056. /**
  1057. * The duration field can be estimated through various ways, and this field can be used
  1058. * to know how the duration was estimated.
  1059. * - encoding: unused
  1060. * - decoding: Read by user via AVOptions (NO direct access)
  1061. */
  1062. enum AVDurationEstimationMethod duration_estimation_method;
  1063. /**
  1064. * Skip initial bytes when opening stream
  1065. * - encoding: unused
  1066. * - decoding: Set by user via AVOptions (NO direct access)
  1067. */
  1068. unsigned int skip_initial_bytes;
  1069. /**
  1070. * Correct single timestamp overflows
  1071. * - encoding: unused
  1072. * - decoding: Set by user via AVOPtions (NO direct access)
  1073. */
  1074. unsigned int correct_ts_overflow;
  1075. /**
  1076. * Force seeking to any (also non key) frames.
  1077. * - encoding: unused
  1078. * - decoding: Set by user via AVOPtions (NO direct access)
  1079. */
  1080. int seek2any;
  1081. /*****************************************************************
  1082. * All fields below this line are not part of the public API. They
  1083. * may not be used outside of libavformat and can be changed and
  1084. * removed at will.
  1085. * New public fields should be added right above.
  1086. *****************************************************************
  1087. */
  1088. /**
  1089. * This buffer is only needed when packets were already buffered but
  1090. * not decoded, for example to get the codec parameters in MPEG
  1091. * streams.
  1092. */
  1093. struct AVPacketList *packet_buffer;
  1094. struct AVPacketList *packet_buffer_end;
  1095. /* av_seek_frame() support */
  1096. int64_t data_offset; /**< offset of the first packet */
  1097. /**
  1098. * Raw packets from the demuxer, prior to parsing and decoding.
  1099. * This buffer is used for buffering packets until the codec can
  1100. * be identified, as parsing cannot be done without knowing the
  1101. * codec.
  1102. */
  1103. struct AVPacketList *raw_packet_buffer;
  1104. struct AVPacketList *raw_packet_buffer_end;
  1105. /**
  1106. * Packets split by the parser get queued here.
  1107. */
  1108. struct AVPacketList *parse_queue;
  1109. struct AVPacketList *parse_queue_end;
  1110. /**
  1111. * Remaining size available for raw_packet_buffer, in bytes.
  1112. */
  1113. #define RAW_PACKET_BUFFER_SIZE 2500000
  1114. int raw_packet_buffer_remaining_size;
  1115. } AVFormatContext;
  1116. /**
  1117. * Returns the method used to set ctx->duration.
  1118. *
  1119. * @return AVFMT_DURATION_FROM_PTS, AVFMT_DURATION_FROM_STREAM, or AVFMT_DURATION_FROM_BITRATE.
  1120. */
  1121. enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx);
  1122. typedef struct AVPacketList {
  1123. AVPacket pkt;
  1124. struct AVPacketList *next;
  1125. } AVPacketList;
  1126. /**
  1127. * @defgroup lavf_core Core functions
  1128. * @ingroup libavf
  1129. *
  1130. * Functions for querying libavformat capabilities, allocating core structures,
  1131. * etc.
  1132. * @{
  1133. */
  1134. /**
  1135. * Return the LIBAVFORMAT_VERSION_INT constant.
  1136. */
  1137. unsigned avformat_version(void);
  1138. /**
  1139. * Return the libavformat build-time configuration.
  1140. */
  1141. const char *avformat_configuration(void);
  1142. /**
  1143. * Return the libavformat license.
  1144. */
  1145. const char *avformat_license(void);
  1146. /**
  1147. * Initialize libavformat and register all the muxers, demuxers and
  1148. * protocols. If you do not call this function, then you can select
  1149. * exactly which formats you want to support.
  1150. *
  1151. * @see av_register_input_format()
  1152. * @see av_register_output_format()
  1153. */
  1154. void av_register_all(void);
  1155. void av_register_input_format(AVInputFormat *format);
  1156. void av_register_output_format(AVOutputFormat *format);
  1157. /**
  1158. * Do global initialization of network components. This is optional,
  1159. * but recommended, since it avoids the overhead of implicitly
  1160. * doing the setup for each session.
  1161. *
  1162. * Calling this function will become mandatory if using network
  1163. * protocols at some major version bump.
  1164. */
  1165. int avformat_network_init(void);
  1166. /**
  1167. * Undo the initialization done by avformat_network_init.
  1168. */
  1169. int avformat_network_deinit(void);
  1170. /**
  1171. * If f is NULL, returns the first registered input format,
  1172. * if f is non-NULL, returns the next registered input format after f
  1173. * or NULL if f is the last one.
  1174. */
  1175. AVInputFormat *av_iformat_next(AVInputFormat *f);
  1176. /**
  1177. * If f is NULL, returns the first registered output format,
  1178. * if f is non-NULL, returns the next registered output format after f
  1179. * or NULL if f is the last one.
  1180. */
  1181. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  1182. /**
  1183. * Allocate an AVFormatContext.
  1184. * avformat_free_context() can be used to free the context and everything
  1185. * allocated by the framework within it.
  1186. */
  1187. AVFormatContext *avformat_alloc_context(void);
  1188. /**
  1189. * Free an AVFormatContext and all its streams.
  1190. * @param s context to free
  1191. */
  1192. void avformat_free_context(AVFormatContext *s);
  1193. /**
  1194. * Get the AVClass for AVFormatContext. It can be used in combination with
  1195. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  1196. *
  1197. * @see av_opt_find().
  1198. */
  1199. const AVClass *avformat_get_class(void);
  1200. /**
  1201. * Add a new stream to a media file.
  1202. *
  1203. * When demuxing, it is called by the demuxer in read_header(). If the
  1204. * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
  1205. * be called in read_packet().
  1206. *
  1207. * When muxing, should be called by the user before avformat_write_header().
  1208. *
  1209. * @param c If non-NULL, the AVCodecContext corresponding to the new stream
  1210. * will be initialized to use this codec. This is needed for e.g. codec-specific
  1211. * defaults to be set, so codec should be provided if it is known.
  1212. *
  1213. * @return newly created stream or NULL on error.
  1214. */
  1215. AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
  1216. AVProgram *av_new_program(AVFormatContext *s, int id);
  1217. /**
  1218. * @}
  1219. */
  1220. #if FF_API_PKT_DUMP
  1221. attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  1222. attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
  1223. int dump_payload);
  1224. #endif
  1225. #if FF_API_ALLOC_OUTPUT_CONTEXT
  1226. /**
  1227. * @deprecated deprecated in favor of avformat_alloc_output_context2()
  1228. */
  1229. attribute_deprecated
  1230. AVFormatContext *avformat_alloc_output_context(const char *format,
  1231. AVOutputFormat *oformat,
  1232. const char *filename);
  1233. #endif
  1234. /**
  1235. * Allocate an AVFormatContext for an output format.
  1236. * avformat_free_context() can be used to free the context and
  1237. * everything allocated by the framework within it.
  1238. *
  1239. * @param *ctx is set to the created format context, or to NULL in
  1240. * case of failure
  1241. * @param oformat format to use for allocating the context, if NULL
  1242. * format_name and filename are used instead
  1243. * @param format_name the name of output format to use for allocating the
  1244. * context, if NULL filename is used instead
  1245. * @param filename the name of the filename to use for allocating the
  1246. * context, may be NULL
  1247. * @return >= 0 in case of success, a negative AVERROR code in case of
  1248. * failure
  1249. */
  1250. int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
  1251. const char *format_name, const char *filename);
  1252. /**
  1253. * @addtogroup lavf_decoding
  1254. * @{
  1255. */
  1256. /**
  1257. * Find AVInputFormat based on the short name of the input format.
  1258. */
  1259. AVInputFormat *av_find_input_format(const char *short_name);
  1260. /**
  1261. * Guess the file format.
  1262. *
  1263. * @param is_opened Whether the file is already opened; determines whether
  1264. * demuxers with or without AVFMT_NOFILE are probed.
  1265. */
  1266. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  1267. /**
  1268. * Guess the file format.
  1269. *
  1270. * @param is_opened Whether the file is already opened; determines whether
  1271. * demuxers with or without AVFMT_NOFILE are probed.
  1272. * @param score_max A probe score larger that this is required to accept a
  1273. * detection, the variable is set to the actual detection
  1274. * score afterwards.
  1275. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  1276. * to retry with a larger probe buffer.
  1277. */
  1278. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  1279. /**
  1280. * Guess the file format.
  1281. *
  1282. * @param is_opened Whether the file is already opened; determines whether
  1283. * demuxers with or without AVFMT_NOFILE are probed.
  1284. * @param score_ret The score of the best detection.
  1285. */
  1286. AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
  1287. /**
  1288. * Probe a bytestream to determine the input format. Each time a probe returns
  1289. * with a score that is too low, the probe buffer size is increased and another
  1290. * attempt is made. When the maximum probe size is reached, the input format
  1291. * with the highest score is returned.
  1292. *
  1293. * @param pb the bytestream to probe
  1294. * @param fmt the input format is put here
  1295. * @param filename the filename of the stream
  1296. * @param logctx the log context
  1297. * @param offset the offset within the bytestream to probe from
  1298. * @param max_probe_size the maximum probe buffer size (zero for default)
  1299. * @return 0 in case of success, a negative value corresponding to an
  1300. * AVERROR code otherwise
  1301. */
  1302. int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
  1303. const char *filename, void *logctx,
  1304. unsigned int offset, unsigned int max_probe_size);
  1305. /**
  1306. * Open an input stream and read the header. The codecs are not opened.
  1307. * The stream must be closed with av_close_input_file().
  1308. *
  1309. * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
  1310. * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
  1311. * function and written into ps.
  1312. * Note that a user-supplied AVFormatContext will be freed on failure.
  1313. * @param filename Name of the stream to open.
  1314. * @param fmt If non-NULL, this parameter forces a specific input format.
  1315. * Otherwise the format is autodetected.
  1316. * @param options A dictionary filled with AVFormatContext and demuxer-private options.
  1317. * On return this parameter will be destroyed and replaced with a dict containing
  1318. * options that were not found. May be NULL.
  1319. *
  1320. * @return 0 on success, a negative AVERROR on failure.
  1321. *
  1322. * @note If you want to use custom IO, preallocate the format context and set its pb field.
  1323. */
  1324. int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
  1325. attribute_deprecated
  1326. int av_demuxer_open(AVFormatContext *ic);
  1327. #if FF_API_FORMAT_PARAMETERS
  1328. /**
  1329. * Read packets of a media file to get stream information. This
  1330. * is useful for file formats with no headers such as MPEG. This
  1331. * function also computes the real framerate in case of MPEG-2 repeat
  1332. * frame mode.
  1333. * The logical file position is not changed by this function;
  1334. * examined packets may be buffered for later processing.
  1335. *
  1336. * @param ic media file handle
  1337. * @return >=0 if OK, AVERROR_xxx on error
  1338. * @todo Let the user decide somehow what information is needed so that
  1339. * we do not waste time getting stuff the user does not need.
  1340. *
  1341. * @deprecated use avformat_find_stream_info.
  1342. */
  1343. attribute_deprecated
  1344. int av_find_stream_info(AVFormatContext *ic);
  1345. #endif
  1346. /**
  1347. * Read packets of a media file to get stream information. This
  1348. * is useful for file formats with no headers such as MPEG. This
  1349. * function also computes the real framerate in case of MPEG-2 repeat
  1350. * frame mode.
  1351. * The logical file position is not changed by this function;
  1352. * examined packets may be buffered for later processing.
  1353. *
  1354. * @param ic media file handle
  1355. * @param options If non-NULL, an ic.nb_streams long array of pointers to
  1356. * dictionaries, where i-th member contains options for
  1357. * codec corresponding to i-th stream.
  1358. * On return each dictionary will be filled with options that were not found.
  1359. * @return >=0 if OK, AVERROR_xxx on error
  1360. *
  1361. * @note this function isn't guaranteed to open all the codecs, so
  1362. * options being non-empty at return is a perfectly normal behavior.
  1363. *
  1364. * @todo Let the user decide somehow what information is needed so that
  1365. * we do not waste time getting stuff the user does not need.
  1366. */
  1367. int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
  1368. /**
  1369. * Find the programs which belong to a given stream.
  1370. *
  1371. * @param ic media file handle
  1372. * @param last the last found program, the search will start after this
  1373. * program, or from the beginning if it is NULL
  1374. * @param s stream index
  1375. * @return the next program which belongs to s, NULL if no program is found or
  1376. * the last program is not among the programs of ic.
  1377. */
  1378. AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
  1379. /**
  1380. * Find the "best" stream in the file.
  1381. * The best stream is determined according to various heuristics as the most
  1382. * likely to be what the user expects.
  1383. * If the decoder parameter is non-NULL, av_find_best_stream will find the
  1384. * default decoder for the stream's codec; streams for which no decoder can
  1385. * be found are ignored.
  1386. *
  1387. * @param ic media file handle
  1388. * @param type stream type: video, audio, subtitles, etc.
  1389. * @param wanted_stream_nb user-requested stream number,
  1390. * or -1 for automatic selection
  1391. * @param related_stream try to find a stream related (eg. in the same
  1392. * program) to this one, or -1 if none
  1393. * @param decoder_ret if non-NULL, returns the decoder for the
  1394. * selected stream
  1395. * @param flags flags; none are currently defined
  1396. * @return the non-negative stream number in case of success,
  1397. * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
  1398. * could be found,
  1399. * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
  1400. * @note If av_find_best_stream returns successfully and decoder_ret is not
  1401. * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
  1402. */
  1403. int av_find_best_stream(AVFormatContext *ic,
  1404. enum AVMediaType type,
  1405. int wanted_stream_nb,
  1406. int related_stream,
  1407. AVCodec **decoder_ret,
  1408. int flags);
  1409. #if FF_API_READ_PACKET
  1410. /**
  1411. * @deprecated use AVFMT_FLAG_NOFILLIN | AVFMT_FLAG_NOPARSE to read raw
  1412. * unprocessed packets
  1413. *
  1414. * Read a transport packet from a media file.
  1415. *
  1416. * This function is obsolete and should never be used.
  1417. * Use av_read_frame() instead.
  1418. *
  1419. * @param s media file handle
  1420. * @param pkt is filled
  1421. * @return 0 if OK, AVERROR_xxx on error
  1422. */
  1423. attribute_deprecated
  1424. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  1425. #endif
  1426. /**
  1427. * Return the next frame of a stream.
  1428. * This function returns what is stored in the file, and does not validate
  1429. * that what is there are valid frames for the decoder. It will split what is
  1430. * stored in the file into frames and return one for each call. It will not
  1431. * omit invalid data between valid frames so as to give the decoder the maximum
  1432. * information possible for decoding.
  1433. *
  1434. * If pkt->destruct is NULL, then the packet is valid until the next
  1435. * av_read_frame() or until av_close_input_file(). Otherwise the packet is valid
  1436. * indefinitely. In both cases the packet must be freed with
  1437. * av_free_packet when it is no longer needed. For video, the packet contains
  1438. * exactly one frame. For audio, it contains an integer number of frames if each
  1439. * frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames
  1440. * have a variable size (e.g. MPEG audio), then it contains one frame.
  1441. *
  1442. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  1443. * values in AVStream.time_base units (and guessed if the format cannot
  1444. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  1445. * has B-frames, so it is better to rely on pkt->dts if you do not
  1446. * decompress the payload.
  1447. *
  1448. * @return 0 if OK, < 0 on error or end of file
  1449. */
  1450. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  1451. /**
  1452. * Seek to the keyframe at timestamp.
  1453. * 'timestamp' in 'stream_index'.
  1454. * @param stream_index If stream_index is (-1), a default
  1455. * stream is selected, and timestamp is automatically converted
  1456. * from AV_TIME_BASE units to the stream specific time_base.
  1457. * @param timestamp Timestamp in AVStream.time_base units
  1458. * or, if no stream is specified, in AV_TIME_BASE units.
  1459. * @param flags flags which select direction and seeking mode
  1460. * @return >= 0 on success
  1461. */
  1462. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  1463. int flags);
  1464. /**
  1465. * Seek to timestamp ts.
  1466. * Seeking will be done so that the point from which all active streams
  1467. * can be presented successfully will be closest to ts and within min/max_ts.
  1468. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  1469. *
  1470. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  1471. * are the file position (this may not be supported by all demuxers).
  1472. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  1473. * in the stream with stream_index (this may not be supported by all demuxers).
  1474. * Otherwise all timestamps are in units of the stream selected by stream_index
  1475. * or if stream_index is -1, in AV_TIME_BASE units.
  1476. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  1477. * keyframes (this may not be supported by all demuxers).
  1478. *
  1479. * @param stream_index index of the stream which is used as time base reference
  1480. * @param min_ts smallest acceptable timestamp
  1481. * @param ts target timestamp
  1482. * @param max_ts largest acceptable timestamp
  1483. * @param flags flags
  1484. * @return >=0 on success, error code otherwise
  1485. *
  1486. * @note This is part of the new seek API which is still under construction.
  1487. * Thus do not use this yet. It may change at any time, do not expect
  1488. * ABI compatibility yet!
  1489. */
  1490. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1491. /**
  1492. * Start playing a network-based stream (e.g. RTSP stream) at the
  1493. * current position.
  1494. */
  1495. int av_read_play(AVFormatContext *s);
  1496. /**
  1497. * Pause a network-based stream (e.g. RTSP stream).
  1498. *
  1499. * Use av_read_play() to resume it.
  1500. */
  1501. int av_read_pause(AVFormatContext *s);
  1502. #if FF_API_CLOSE_INPUT_FILE
  1503. /**
  1504. * @deprecated use avformat_close_input()
  1505. * Close a media file (but not its codecs).
  1506. *
  1507. * @param s media file handle
  1508. */
  1509. attribute_deprecated
  1510. void av_close_input_file(AVFormatContext *s);
  1511. #endif
  1512. /**
  1513. * Close an opened input AVFormatContext. Free it and all its contents
  1514. * and set *s to NULL.
  1515. */
  1516. void avformat_close_input(AVFormatContext **s);
  1517. /**
  1518. * @}
  1519. */
  1520. #if FF_API_NEW_STREAM
  1521. /**
  1522. * Add a new stream to a media file.
  1523. *
  1524. * Can only be called in the read_header() function. If the flag
  1525. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1526. * can be added in read_packet too.
  1527. *
  1528. * @param s media file handle
  1529. * @param id file-format-dependent stream ID
  1530. */
  1531. attribute_deprecated
  1532. AVStream *av_new_stream(AVFormatContext *s, int id);
  1533. #endif
  1534. #if FF_API_SET_PTS_INFO
  1535. /**
  1536. * @deprecated this function is not supposed to be called outside of lavf
  1537. */
  1538. attribute_deprecated
  1539. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1540. unsigned int pts_num, unsigned int pts_den);
  1541. #endif
  1542. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1543. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1544. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1545. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1546. /**
  1547. * @addtogroup lavf_encoding
  1548. * @{
  1549. */
  1550. /**
  1551. * Allocate the stream private data and write the stream header to
  1552. * an output media file.
  1553. *
  1554. * @param s Media file handle, must be allocated with avformat_alloc_context().
  1555. * Its oformat field must be set to the desired output format;
  1556. * Its pb field must be set to an already openened AVIOContext.
  1557. * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
  1558. * On return this parameter will be destroyed and replaced with a dict containing
  1559. * options that were not found. May be NULL.
  1560. *
  1561. * @return 0 on success, negative AVERROR on failure.
  1562. *
  1563. * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
  1564. */
  1565. int avformat_write_header(AVFormatContext *s, AVDictionary **options);
  1566. /**
  1567. * Write a packet to an output media file.
  1568. *
  1569. * The packet shall contain one audio or video frame.
  1570. * The packet must be correctly interleaved according to the container
  1571. * specification, if not then av_interleaved_write_frame must be used.
  1572. *
  1573. * @param s media file handle
  1574. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1575. * dts/pts, ...
  1576. * This can be NULL (at any time, not just at the end), in
  1577. * order to immediately flush data buffered within the muxer,
  1578. * for muxers that buffer up data internally before writing it
  1579. * to the output.
  1580. * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush
  1581. */
  1582. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1583. /**
  1584. * Write a packet to an output media file ensuring correct interleaving.
  1585. *
  1586. * The packet must contain one audio or video frame.
  1587. * If the packets are already correctly interleaved, the application should
  1588. * call av_write_frame() instead as it is slightly faster. It is also important
  1589. * to keep in mind that completely non-interleaved input will need huge amounts
  1590. * of memory to interleave with this, so it is preferable to interleave at the
  1591. * demuxer level.
  1592. *
  1593. * @param s media file handle
  1594. * @param pkt The packet containing the data to be written. Libavformat takes
  1595. * ownership of the data and will free it when it sees fit using the packet's
  1596. * @ref AVPacket.destruct "destruct" field. The caller must not access the data
  1597. * after this function returns, as it may already be freed.
  1598. * This can be NULL (at any time, not just at the end), to flush the
  1599. * interleaving queues.
  1600. * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the
  1601. * index of the corresponding stream in @ref AVFormatContext.streams
  1602. * "s.streams".
  1603. * It is very strongly recommended that timing information (@ref AVPacket.pts
  1604. * "pts", @ref AVPacket.dts "dts" @ref AVPacket.duration "duration") is set to
  1605. * correct values.
  1606. *
  1607. * @return 0 on success, a negative AVERROR on error.
  1608. */
  1609. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1610. #if FF_API_INTERLEAVE_PACKET
  1611. /**
  1612. * @deprecated this function was never meant to be called by the user
  1613. * programs.
  1614. */
  1615. attribute_deprecated
  1616. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1617. AVPacket *pkt, int flush);
  1618. #endif
  1619. /**
  1620. * Write the stream trailer to an output media file and free the
  1621. * file private data.
  1622. *
  1623. * May only be called after a successful call to avformat_write_header.
  1624. *
  1625. * @param s media file handle
  1626. * @return 0 if OK, AVERROR_xxx on error
  1627. */
  1628. int av_write_trailer(AVFormatContext *s);
  1629. /**
  1630. * Return the output format in the list of registered output formats
  1631. * which best matches the provided parameters, or return NULL if
  1632. * there is no match.
  1633. *
  1634. * @param short_name if non-NULL checks if short_name matches with the
  1635. * names of the registered formats
  1636. * @param filename if non-NULL checks if filename terminates with the
  1637. * extensions of the registered formats
  1638. * @param mime_type if non-NULL checks if mime_type matches with the
  1639. * MIME type of the registered formats
  1640. */
  1641. AVOutputFormat *av_guess_format(const char *short_name,
  1642. const char *filename,
  1643. const char *mime_type);
  1644. /**
  1645. * Guess the codec ID based upon muxer and filename.
  1646. */
  1647. enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  1648. const char *filename, const char *mime_type,
  1649. enum AVMediaType type);
  1650. /**
  1651. * Get timing information for the data currently output.
  1652. * The exact meaning of "currently output" depends on the format.
  1653. * It is mostly relevant for devices that have an internal buffer and/or
  1654. * work in real time.
  1655. * @param s media file handle
  1656. * @param stream stream in the media file
  1657. * @param[out] dts DTS of the last packet output for the stream, in stream
  1658. * time_base units
  1659. * @param[out] wall absolute time when that packet whas output,
  1660. * in microsecond
  1661. * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it
  1662. * Note: some formats or devices may not allow to measure dts and wall
  1663. * atomically.
  1664. */
  1665. int av_get_output_timestamp(struct AVFormatContext *s, int stream,
  1666. int64_t *dts, int64_t *wall);
  1667. /**
  1668. * @}
  1669. */
  1670. /**
  1671. * @defgroup lavf_misc Utility functions
  1672. * @ingroup libavf
  1673. * @{
  1674. *
  1675. * Miscellaneous utility functions related to both muxing and demuxing
  1676. * (or neither).
  1677. */
  1678. /**
  1679. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  1680. *
  1681. * @param f The file stream pointer where the dump should be sent to.
  1682. * @param buf buffer
  1683. * @param size buffer size
  1684. *
  1685. * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
  1686. */
  1687. void av_hex_dump(FILE *f, const uint8_t *buf, int size);
  1688. /**
  1689. * Send a nice hexadecimal dump of a buffer to the log.
  1690. *
  1691. * @param avcl A pointer to an arbitrary struct of which the first field is a
  1692. * pointer to an AVClass struct.
  1693. * @param level The importance level of the message, lower values signifying
  1694. * higher importance.
  1695. * @param buf buffer
  1696. * @param size buffer size
  1697. *
  1698. * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
  1699. */
  1700. void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
  1701. /**
  1702. * Send a nice dump of a packet to the specified file stream.
  1703. *
  1704. * @param f The file stream pointer where the dump should be sent to.
  1705. * @param pkt packet to dump
  1706. * @param dump_payload True if the payload must be displayed, too.
  1707. * @param st AVStream that the packet belongs to
  1708. */
  1709. void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
  1710. /**
  1711. * Send a nice dump of a packet to the log.
  1712. *
  1713. * @param avcl A pointer to an arbitrary struct of which the first field is a
  1714. * pointer to an AVClass struct.
  1715. * @param level The importance level of the message, lower values signifying
  1716. * higher importance.
  1717. * @param pkt packet to dump
  1718. * @param dump_payload True if the payload must be displayed, too.
  1719. * @param st AVStream that the packet belongs to
  1720. */
  1721. void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
  1722. AVStream *st);
  1723. /**
  1724. * Get the AVCodecID for the given codec tag tag.
  1725. * If no codec id is found returns AV_CODEC_ID_NONE.
  1726. *
  1727. * @param tags list of supported codec_id-codec_tag pairs, as stored
  1728. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  1729. */
  1730. enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  1731. /**
  1732. * Get the codec tag for the given codec id id.
  1733. * If no codec tag is found returns 0.
  1734. *
  1735. * @param tags list of supported codec_id-codec_tag pairs, as stored
  1736. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  1737. */
  1738. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
  1739. /**
  1740. * Get the codec tag for the given codec id.
  1741. *
  1742. * @param tags list of supported codec_id - codec_tag pairs, as stored
  1743. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  1744. * @param id codec id that should be searched for in the list
  1745. * @param tag A pointer to the found tag
  1746. * @return 0 if id was not found in tags, > 0 if it was found
  1747. */
  1748. int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
  1749. unsigned int *tag);
  1750. int av_find_default_stream_index(AVFormatContext *s);
  1751. /**
  1752. * Get the index for a specific timestamp.
  1753. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1754. * to the timestamp which is <= the requested one, if backward
  1755. * is 0, then it will be >=
  1756. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1757. * @return < 0 if no such timestamp could be found
  1758. */
  1759. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1760. /**
  1761. * Add an index entry into a sorted list. Update the entry if the list
  1762. * already contains it.
  1763. *
  1764. * @param timestamp timestamp in the time base of the given stream
  1765. */
  1766. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1767. int size, int distance, int flags);
  1768. /**
  1769. * Split a URL string into components.
  1770. *
  1771. * The pointers to buffers for storing individual components may be null,
  1772. * in order to ignore that component. Buffers for components not found are
  1773. * set to empty strings. If the port is not found, it is set to a negative
  1774. * value.
  1775. *
  1776. * @param proto the buffer for the protocol
  1777. * @param proto_size the size of the proto buffer
  1778. * @param authorization the buffer for the authorization
  1779. * @param authorization_size the size of the authorization buffer
  1780. * @param hostname the buffer for the host name
  1781. * @param hostname_size the size of the hostname buffer
  1782. * @param port_ptr a pointer to store the port number in
  1783. * @param path the buffer for the path
  1784. * @param path_size the size of the path buffer
  1785. * @param url the URL to split
  1786. */
  1787. void av_url_split(char *proto, int proto_size,
  1788. char *authorization, int authorization_size,
  1789. char *hostname, int hostname_size,
  1790. int *port_ptr,
  1791. char *path, int path_size,
  1792. const char *url);
  1793. void av_dump_format(AVFormatContext *ic,
  1794. int index,
  1795. const char *url,
  1796. int is_output);
  1797. /**
  1798. * Return in 'buf' the path with '%d' replaced by a number.
  1799. *
  1800. * Also handles the '%0nd' format where 'n' is the total number
  1801. * of digits and '%%'.
  1802. *
  1803. * @param buf destination buffer
  1804. * @param buf_size destination buffer size
  1805. * @param path numbered sequence string
  1806. * @param number frame number
  1807. * @return 0 if OK, -1 on format error
  1808. */
  1809. int av_get_frame_filename(char *buf, int buf_size,
  1810. const char *path, int number);
  1811. /**
  1812. * Check whether filename actually is a numbered sequence generator.
  1813. *
  1814. * @param filename possible numbered sequence string
  1815. * @return 1 if a valid numbered sequence string, 0 otherwise
  1816. */
  1817. int av_filename_number_test(const char *filename);
  1818. /**
  1819. * Generate an SDP for an RTP session.
  1820. *
  1821. * Note, this overwrites the id values of AVStreams in the muxer contexts
  1822. * for getting unique dynamic payload types.
  1823. *
  1824. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1825. * array is composed by only one context, such context can contain
  1826. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1827. * all the contexts in the array (an AVCodecContext per RTP stream)
  1828. * must contain only one AVStream.
  1829. * @param n_files number of AVCodecContexts contained in ac
  1830. * @param buf buffer where the SDP will be stored (must be allocated by
  1831. * the caller)
  1832. * @param size the size of the buffer
  1833. * @return 0 if OK, AVERROR_xxx on error
  1834. */
  1835. int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
  1836. /**
  1837. * Return a positive value if the given filename has one of the given
  1838. * extensions, 0 otherwise.
  1839. *
  1840. * @param extensions a comma-separated list of filename extensions
  1841. */
  1842. int av_match_ext(const char *filename, const char *extensions);
  1843. /**
  1844. * Test if the given container can store a codec.
  1845. *
  1846. * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
  1847. *
  1848. * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
  1849. * A negative number if this information is not available.
  1850. */
  1851. int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
  1852. /**
  1853. * @defgroup riff_fourcc RIFF FourCCs
  1854. * @{
  1855. * Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs. The tables are
  1856. * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the
  1857. * following code:
  1858. * @code
  1859. * uint32_t tag = MKTAG('H', '2', '6', '4');
  1860. * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 };
  1861. * enum AVCodecID id = av_codec_get_id(table, tag);
  1862. * @endcode
  1863. */
  1864. /**
  1865. * @return the table mapping RIFF FourCCs for video to libavcodec AVCodecID.
  1866. */
  1867. const struct AVCodecTag *avformat_get_riff_video_tags(void);
  1868. /**
  1869. * @return the table mapping RIFF FourCCs for audio to AVCodecID.
  1870. */
  1871. const struct AVCodecTag *avformat_get_riff_audio_tags(void);
  1872. /**
  1873. * @}
  1874. */
  1875. /**
  1876. * Guess the sample aspect ratio of a frame, based on both the stream and the
  1877. * frame aspect ratio.
  1878. *
  1879. * Since the frame aspect ratio is set by the codec but the stream aspect ratio
  1880. * is set by the demuxer, these two may not be equal. This function tries to
  1881. * return the value that you should use if you would like to display the frame.
  1882. *
  1883. * Basic logic is to use the stream aspect ratio if it is set to something sane
  1884. * otherwise use the frame aspect ratio. This way a container setting, which is
  1885. * usually easy to modify can override the coded value in the frames.
  1886. *
  1887. * @param format the format context which the stream is part of
  1888. * @param stream the stream which the frame is part of
  1889. * @param frame the frame with the aspect ratio to be determined
  1890. * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea
  1891. */
  1892. AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
  1893. /**
  1894. * Check if the stream st contained in s is matched by the stream specifier
  1895. * spec.
  1896. *
  1897. * See the "stream specifiers" chapter in the documentation for the syntax
  1898. * of spec.
  1899. *
  1900. * @return >0 if st is matched by spec;
  1901. * 0 if st is not matched by spec;
  1902. * AVERROR code if spec is invalid
  1903. *
  1904. * @note A stream specifier can match several streams in the format.
  1905. */
  1906. int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
  1907. const char *spec);
  1908. void avformat_queue_attached_pictures(AVFormatContext *s);
  1909. /**
  1910. * @}
  1911. */
  1912. #endif /* AVFORMAT_AVFORMAT_H */