avformat.h 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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. * Return the LIBAVFORMAT_VERSION_INT constant.
  24. */
  25. unsigned avformat_version(void);
  26. /**
  27. * Return the libavformat build-time configuration.
  28. */
  29. const char *avformat_configuration(void);
  30. /**
  31. * Return the libavformat license.
  32. */
  33. const char *avformat_license(void);
  34. #include <time.h>
  35. #include <stdio.h> /* FILE */
  36. #include "libavcodec/avcodec.h"
  37. #include "libavutil/dict.h"
  38. #include "avio.h"
  39. #include "libavformat/version.h"
  40. struct AVFormatContext;
  41. /*
  42. * Public Metadata API.
  43. * The metadata API allows libavformat to export metadata tags to a client
  44. * application using a sequence of key/value pairs. Like all strings in FFmpeg,
  45. * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
  46. * exported by demuxers isn't checked to be valid UTF-8 in most cases.
  47. * Important concepts to keep in mind:
  48. * 1. Keys are unique; there can never be 2 tags with the same key. This is
  49. * also meant semantically, i.e., a demuxer should not knowingly produce
  50. * several keys that are literally different but semantically identical.
  51. * E.g., key=Author5, key=Author6. In this example, all authors must be
  52. * placed in the same tag.
  53. * 2. Metadata is flat, not hierarchical; there are no subtags. If you
  54. * want to store, e.g., the email address of the child of producer Alice
  55. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  56. * 3. Several modifiers can be applied to the tag name. This is done by
  57. * appending a dash character ('-') and the modifier name in the order
  58. * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
  59. * a) language -- a tag whose value is localized for a particular language
  60. * is appended with the ISO 639-2/B 3-letter language code.
  61. * For example: Author-ger=Michael, Author-eng=Mike
  62. * The original/default language is in the unqualified "Author" tag.
  63. * A demuxer should set a default if it sets any translated tag.
  64. * b) sorting -- a modified version of a tag that should be used for
  65. * sorting will have '-sort' appended. E.g. artist="The Beatles",
  66. * artist-sort="Beatles, The".
  67. *
  68. * 4. Demuxers attempt to export metadata in a generic format, however tags
  69. * with no generic equivalents are left as they are stored in the container.
  70. * Follows a list of generic tag names:
  71. *
  72. * album -- name of the set this work belongs to
  73. * album_artist -- main creator of the set/album, if different from artist.
  74. * e.g. "Various Artists" for compilation albums.
  75. * artist -- main creator of the work
  76. * comment -- any additional description of the file.
  77. * composer -- who composed the work, if different from artist.
  78. * copyright -- name of copyright holder.
  79. * creation_time-- date when the file was created, preferably in ISO 8601.
  80. * date -- date when the work was created, preferably in ISO 8601.
  81. * disc -- number of a subset, e.g. disc in a multi-disc collection.
  82. * encoder -- name/settings of the software/hardware that produced the file.
  83. * encoded_by -- person/group who created the file.
  84. * filename -- original name of the file.
  85. * genre -- <self-evident>.
  86. * language -- main language in which the work is performed, preferably
  87. * in ISO 639-2 format. Multiple languages can be specified by
  88. * separating them with commas.
  89. * performer -- artist who performed the work, if different from artist.
  90. * E.g for "Also sprach Zarathustra", artist would be "Richard
  91. * Strauss" and performer "London Philharmonic Orchestra".
  92. * publisher -- name of the label/publisher.
  93. * service_name -- name of the service in broadcasting (channel name).
  94. * service_provider -- name of the service provider in broadcasting.
  95. * title -- name of the work.
  96. * track -- number of this work in the set, can be in form current/total.
  97. * variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
  98. */
  99. #if FF_API_OLD_METADATA2
  100. /**
  101. * @defgroup old_metadata Old metadata API
  102. * The following functions are deprecated, use
  103. * their equivalents from libavutil/dict.h instead.
  104. * @{
  105. */
  106. #define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
  107. #define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
  108. #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
  109. #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
  110. #define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
  111. typedef attribute_deprecated AVDictionary AVMetadata;
  112. typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
  113. typedef struct AVMetadataConv AVMetadataConv;
  114. /**
  115. * Get a metadata element with matching key.
  116. *
  117. * @param prev Set to the previous matching element to find the next.
  118. * If set to NULL the first matching element is returned.
  119. * @param flags Allows case as well as suffix-insensitive comparisons.
  120. * @return Found tag or NULL, changing key or value leads to undefined behavior.
  121. */
  122. attribute_deprecated AVDictionaryEntry *
  123. av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
  124. /**
  125. * Set the given tag in *pm, overwriting an existing tag.
  126. *
  127. * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
  128. * a metadata struct is allocated and put in *pm.
  129. * @param key tag key to add to *pm (will be av_strduped depending on flags)
  130. * @param value tag value to add to *pm (will be av_strduped depending on flags).
  131. * Passing a NULL value will cause an existing tag to be deleted.
  132. * @return >= 0 on success otherwise an error code <0
  133. */
  134. attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
  135. /**
  136. * This function is provided for compatibility reason and currently does nothing.
  137. */
  138. attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
  139. const AVMetadataConv *s_conv);
  140. /**
  141. * Copy metadata from one AVDictionary struct into another.
  142. * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
  143. * this function will allocate a struct for you and put it in *dst
  144. * @param src pointer to source AVDictionary struct
  145. * @param flags flags to use when setting metadata in *dst
  146. * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
  147. */
  148. attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
  149. /**
  150. * Free all the memory allocated for an AVDictionary struct.
  151. */
  152. attribute_deprecated void av_metadata_free(AVDictionary **m);
  153. /**
  154. * @}
  155. */
  156. #endif
  157. /* packet functions */
  158. /**
  159. * Allocate and read the payload of a packet and initialize its
  160. * fields with default values.
  161. *
  162. * @param pkt packet
  163. * @param size desired payload size
  164. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  165. */
  166. int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
  167. /**
  168. * Read data and append it to the current content of the AVPacket.
  169. * If pkt->size is 0 this is identical to av_get_packet.
  170. * Note that this uses av_grow_packet and thus involves a realloc
  171. * which is inefficient. Thus this function should only be used
  172. * when there is no reasonable way to know (an upper bound of)
  173. * the final size.
  174. *
  175. * @param pkt packet
  176. * @param size amount of data to read
  177. * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
  178. * will not be lost even if an error occurs.
  179. */
  180. int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
  181. /*************************************************/
  182. /* fractional numbers for exact pts handling */
  183. /**
  184. * The exact value of the fractional number is: 'val + num / den'.
  185. * num is assumed to be 0 <= num < den.
  186. */
  187. typedef struct AVFrac {
  188. int64_t val, num, den;
  189. } AVFrac;
  190. /*************************************************/
  191. /* input/output formats */
  192. struct AVCodecTag;
  193. /**
  194. * This structure contains the data a format has to probe a file.
  195. */
  196. typedef struct AVProbeData {
  197. const char *filename;
  198. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  199. int buf_size; /**< Size of buf except extra allocated bytes */
  200. } AVProbeData;
  201. #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
  202. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  203. typedef struct AVFormatParameters {
  204. #if FF_API_FORMAT_PARAMETERS
  205. attribute_deprecated AVRational time_base;
  206. attribute_deprecated int sample_rate;
  207. attribute_deprecated int channels;
  208. attribute_deprecated int width;
  209. attribute_deprecated int height;
  210. attribute_deprecated enum PixelFormat pix_fmt;
  211. attribute_deprecated int channel; /**< Used to select DV channel. */
  212. attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
  213. attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */
  214. /**< deprecated, use mpegtsraw demuxer-specific options instead */
  215. attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
  216. attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream
  217. immediately (RTSP only). */
  218. attribute_deprecated unsigned int prealloced_context:1;
  219. #endif
  220. } AVFormatParameters;
  221. //! Demuxer will use avio_open, no opened file should be provided by the caller.
  222. #define AVFMT_NOFILE 0x0001
  223. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  224. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  225. #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
  226. raw picture data. */
  227. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  228. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  229. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  230. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
  231. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  232. #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
  233. #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
  234. #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
  235. #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
  236. #define AVFMT_TS_NONSTRICT 0x8000 /**< Format does not require strictly
  237. increasing timestamps, but they must
  238. still be monotonic */
  239. typedef struct AVOutputFormat {
  240. const char *name;
  241. /**
  242. * Descriptive name for the format, meant to be more human-readable
  243. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  244. * to define it.
  245. */
  246. const char *long_name;
  247. const char *mime_type;
  248. const char *extensions; /**< comma-separated filename extensions */
  249. /**
  250. * size of private data so that it can be allocated in the wrapper
  251. */
  252. int priv_data_size;
  253. /* output support */
  254. enum CodecID audio_codec; /**< default audio codec */
  255. enum CodecID video_codec; /**< default video codec */
  256. int (*write_header)(struct AVFormatContext *);
  257. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  258. int (*write_trailer)(struct AVFormatContext *);
  259. /**
  260. * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
  261. * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
  262. * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
  263. */
  264. int flags;
  265. void *dummy;
  266. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  267. AVPacket *in, int flush);
  268. /**
  269. * List of supported codec_id-codec_tag pairs, ordered by "better
  270. * choice first". The arrays are all terminated by CODEC_ID_NONE.
  271. */
  272. const struct AVCodecTag * const *codec_tag;
  273. enum CodecID subtitle_codec; /**< default subtitle codec */
  274. #if FF_API_OLD_METADATA2
  275. const AVMetadataConv *metadata_conv;
  276. #endif
  277. const AVClass *priv_class; ///< AVClass for the private context
  278. void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
  279. int64_t *dts, int64_t *wall);
  280. /* private fields */
  281. struct AVOutputFormat *next;
  282. } AVOutputFormat;
  283. typedef struct AVInputFormat {
  284. /**
  285. * A comma separated list of short names for the format. New names
  286. * may be appended with a minor bump.
  287. */
  288. const char *name;
  289. /**
  290. * Descriptive name for the format, meant to be more human-readable
  291. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  292. * to define it.
  293. */
  294. const char *long_name;
  295. /**
  296. * Size of private data so that it can be allocated in the wrapper.
  297. */
  298. int priv_data_size;
  299. /**
  300. * Tell if a given file has a chance of being parsed as this format.
  301. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  302. * big so you do not have to check for that unless you need more.
  303. */
  304. int (*read_probe)(AVProbeData *);
  305. /**
  306. * Read the format header and initialize the AVFormatContext
  307. * structure. Return 0 if OK. 'ap' if non-NULL contains
  308. * additional parameters. Only used in raw format right
  309. * now. 'av_new_stream' should be called to create new streams.
  310. */
  311. int (*read_header)(struct AVFormatContext *,
  312. AVFormatParameters *ap);
  313. /**
  314. * Read one packet and put it in 'pkt'. pts and flags are also
  315. * set. 'av_new_stream' can be called only if the flag
  316. * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
  317. * background thread).
  318. * @return 0 on success, < 0 on error.
  319. * When returning an error, pkt must not have been allocated
  320. * or must be freed before returning
  321. */
  322. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  323. /**
  324. * Close the stream. The AVFormatContext and AVStreams are not
  325. * freed by this function
  326. */
  327. int (*read_close)(struct AVFormatContext *);
  328. #if FF_API_READ_SEEK
  329. /**
  330. * Seek to a given timestamp relative to the frames in
  331. * stream component stream_index.
  332. * @param stream_index Must not be -1.
  333. * @param flags Selects which direction should be preferred if no exact
  334. * match is available.
  335. * @return >= 0 on success (but not necessarily the new offset)
  336. */
  337. attribute_deprecated int (*read_seek)(struct AVFormatContext *,
  338. int stream_index, int64_t timestamp, int flags);
  339. #endif
  340. /**
  341. * Gets the next timestamp in stream[stream_index].time_base units.
  342. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  343. */
  344. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  345. int64_t *pos, int64_t pos_limit);
  346. /**
  347. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
  348. */
  349. int flags;
  350. /**
  351. * If extensions are defined, then no probe is done. You should
  352. * usually not use extension format guessing because it is not
  353. * reliable enough
  354. */
  355. const char *extensions;
  356. /**
  357. * General purpose read-only value that the format can use.
  358. */
  359. int value;
  360. /**
  361. * Start/resume playing - only meaningful if using a network-based format
  362. * (RTSP).
  363. */
  364. int (*read_play)(struct AVFormatContext *);
  365. /**
  366. * Pause playing - only meaningful if using a network-based format
  367. * (RTSP).
  368. */
  369. int (*read_pause)(struct AVFormatContext *);
  370. const struct AVCodecTag * const *codec_tag;
  371. /**
  372. * Seek to timestamp ts.
  373. * Seeking will be done so that the point from which all active streams
  374. * can be presented successfully will be closest to ts and within min/max_ts.
  375. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  376. */
  377. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  378. #if FF_API_OLD_METADATA2
  379. const AVMetadataConv *metadata_conv;
  380. #endif
  381. const AVClass *priv_class; ///< AVClass for the private context
  382. /* private fields */
  383. struct AVInputFormat *next;
  384. } AVInputFormat;
  385. enum AVStreamParseType {
  386. AVSTREAM_PARSE_NONE,
  387. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  388. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  389. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  390. AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
  391. };
  392. typedef struct AVIndexEntry {
  393. int64_t pos;
  394. int64_t timestamp;
  395. #define AVINDEX_KEYFRAME 0x0001
  396. int flags:2;
  397. 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).
  398. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  399. } AVIndexEntry;
  400. #define AV_DISPOSITION_DEFAULT 0x0001
  401. #define AV_DISPOSITION_DUB 0x0002
  402. #define AV_DISPOSITION_ORIGINAL 0x0004
  403. #define AV_DISPOSITION_COMMENT 0x0008
  404. #define AV_DISPOSITION_LYRICS 0x0010
  405. #define AV_DISPOSITION_KARAOKE 0x0020
  406. /**
  407. * Track should be used during playback by default.
  408. * Useful for subtitle track that should be displayed
  409. * even when user did not explicitly ask for subtitles.
  410. */
  411. #define AV_DISPOSITION_FORCED 0x0040
  412. #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
  413. #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
  414. #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
  415. /**
  416. * Stream structure.
  417. * New fields can be added to the end with minor version bumps.
  418. * Removal, reordering and changes to existing fields require a major
  419. * version bump.
  420. * sizeof(AVStream) must not be used outside libav*.
  421. */
  422. typedef struct AVStream {
  423. int index; /**< stream index in AVFormatContext */
  424. int id; /**< format-specific stream ID */
  425. AVCodecContext *codec; /**< codec context */
  426. /**
  427. * Real base framerate of the stream.
  428. * This is the lowest framerate with which all timestamps can be
  429. * represented accurately (it is the least common multiple of all
  430. * framerates in the stream). Note, this value is just a guess!
  431. * For example, if the time base is 1/90000 and all frames have either
  432. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  433. */
  434. AVRational r_frame_rate;
  435. void *priv_data;
  436. /* internal data used in av_find_stream_info() */
  437. int64_t first_dts;
  438. /**
  439. * encoding: pts generation when outputting stream
  440. */
  441. struct AVFrac pts;
  442. /**
  443. * This is the fundamental unit of time (in seconds) in terms
  444. * of which frame timestamps are represented. For fixed-fps content,
  445. * time base should be 1/framerate and timestamp increments should be 1.
  446. * decoding: set by libavformat
  447. * encoding: set by libavformat in av_write_header
  448. */
  449. AVRational time_base;
  450. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  451. /* ffmpeg.c private use */
  452. int stream_copy; /**< If set, just copy stream. */
  453. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  454. //FIXME move stuff to a flags field?
  455. /**
  456. * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
  457. * MN: dunno if that is the right place for it
  458. */
  459. float quality;
  460. /**
  461. * Decoding: pts of the first frame of the stream, in stream time base.
  462. * Only set this if you are absolutely 100% sure that the value you set
  463. * it to really is the pts of the first frame.
  464. * This may be undefined (AV_NOPTS_VALUE).
  465. * @note The ASF header does NOT contain a correct start_time the ASF
  466. * demuxer must NOT set this.
  467. */
  468. int64_t start_time;
  469. /**
  470. * Decoding: duration of the stream, in stream time base.
  471. * If a source file does not specify a duration, but does specify
  472. * a bitrate, this value will be estimated from bitrate and file size.
  473. */
  474. int64_t duration;
  475. /* av_read_frame() support */
  476. enum AVStreamParseType need_parsing;
  477. struct AVCodecParserContext *parser;
  478. int64_t cur_dts;
  479. int last_IP_duration;
  480. int64_t last_IP_pts;
  481. /* av_seek_frame() support */
  482. AVIndexEntry *index_entries; /**< Only used if the format does not
  483. support seeking natively. */
  484. int nb_index_entries;
  485. unsigned int index_entries_allocated_size;
  486. int64_t nb_frames; ///< number of frames in this stream if known or 0
  487. int disposition; /**< AV_DISPOSITION_* bit field */
  488. AVProbeData probe_data;
  489. #define MAX_REORDER_DELAY 16
  490. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  491. /**
  492. * sample aspect ratio (0 if unknown)
  493. * - encoding: Set by user.
  494. * - decoding: Set by libavformat.
  495. */
  496. AVRational sample_aspect_ratio;
  497. AVDictionary *metadata;
  498. /* Intended mostly for av_read_frame() support. Not supposed to be used by */
  499. /* external applications; try to use something else if at all possible. */
  500. const uint8_t *cur_ptr;
  501. int cur_len;
  502. AVPacket cur_pkt;
  503. // Timestamp generation support:
  504. /**
  505. * Timestamp corresponding to the last dts sync point.
  506. *
  507. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  508. * a DTS is received from the underlying container. Otherwise set to
  509. * AV_NOPTS_VALUE by default.
  510. */
  511. int64_t reference_dts;
  512. /**
  513. * Number of packets to buffer for codec probing
  514. * NOT PART OF PUBLIC API
  515. */
  516. #define MAX_PROBE_PACKETS 2500
  517. int probe_packets;
  518. /**
  519. * last packet in packet_buffer for this stream when muxing.
  520. * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
  521. */
  522. struct AVPacketList *last_in_packet_buffer;
  523. /**
  524. * Average framerate
  525. */
  526. AVRational avg_frame_rate;
  527. /**
  528. * Number of frames that have been demuxed during av_find_stream_info()
  529. */
  530. int codec_info_nb_frames;
  531. /**
  532. * Stream Identifier
  533. * This is the MPEG-TS stream identifier +1
  534. * 0 means unknown
  535. */
  536. int stream_identifier;
  537. /**
  538. * Stream informations used internally by av_find_stream_info()
  539. */
  540. #define MAX_STD_TIMEBASES (60*12+5)
  541. struct {
  542. int64_t last_dts;
  543. int64_t duration_gcd;
  544. int duration_count;
  545. double duration_error[MAX_STD_TIMEBASES];
  546. int64_t codec_info_duration;
  547. } *info;
  548. /**
  549. * flag to indicate that probing is requested
  550. * NOT PART OF PUBLIC API
  551. */
  552. int request_probe;
  553. } AVStream;
  554. #define AV_PROGRAM_RUNNING 1
  555. /**
  556. * New fields can be added to the end with minor version bumps.
  557. * Removal, reordering and changes to existing fields require a major
  558. * version bump.
  559. * sizeof(AVProgram) must not be used outside libav*.
  560. */
  561. typedef struct AVProgram {
  562. int id;
  563. int flags;
  564. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  565. unsigned int *stream_index;
  566. unsigned int nb_stream_indexes;
  567. AVDictionary *metadata;
  568. int program_num;
  569. int pmt_pid;
  570. int pcr_pid;
  571. } AVProgram;
  572. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  573. (streams are added dynamically) */
  574. typedef struct AVChapter {
  575. int id; ///< unique ID to identify the chapter
  576. AVRational time_base; ///< time base in which the start/end timestamps are specified
  577. int64_t start, end; ///< chapter start/end time in time_base units
  578. AVDictionary *metadata;
  579. } AVChapter;
  580. /**
  581. * Format I/O context.
  582. * New fields can be added to the end with minor version bumps.
  583. * Removal, reordering and changes to existing fields require a major
  584. * version bump.
  585. * sizeof(AVFormatContext) must not be used outside libav*.
  586. */
  587. typedef struct AVFormatContext {
  588. const AVClass *av_class; /**< Set by avformat_alloc_context. */
  589. /* Can only be iformat or oformat, not both at the same time. */
  590. struct AVInputFormat *iformat;
  591. struct AVOutputFormat *oformat;
  592. void *priv_data;
  593. AVIOContext *pb;
  594. unsigned int nb_streams;
  595. AVStream **streams;
  596. char filename[1024]; /**< input or output filename */
  597. /* stream info */
  598. int64_t timestamp;
  599. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  600. /* private data for pts handling (do not modify directly). */
  601. /**
  602. * This buffer is only needed when packets were already buffered but
  603. * not decoded, for example to get the codec parameters in MPEG
  604. * streams.
  605. */
  606. struct AVPacketList *packet_buffer;
  607. /**
  608. * Decoding: position of the first frame of the component, in
  609. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  610. * It is deduced from the AVStream values.
  611. */
  612. int64_t start_time;
  613. /**
  614. * Decoding: duration of the stream, in AV_TIME_BASE fractional
  615. * seconds. Only set this value if you know none of the individual stream
  616. * durations and also dont set any of them. This is deduced from the
  617. * AVStream values if not set.
  618. */
  619. int64_t duration;
  620. /**
  621. * decoding: total file size, 0 if unknown
  622. */
  623. int64_t file_size;
  624. /**
  625. * Decoding: total stream bitrate in bit/s, 0 if not
  626. * available. Never set it directly if the file_size and the
  627. * duration are known as FFmpeg can compute it automatically.
  628. */
  629. int bit_rate;
  630. /* av_read_frame() support */
  631. AVStream *cur_st;
  632. /* av_seek_frame() support */
  633. int64_t data_offset; /**< offset of the first packet */
  634. int mux_rate;
  635. unsigned int packet_size;
  636. int preload;
  637. int max_delay;
  638. #define AVFMT_NOOUTPUTLOOP -1
  639. #define AVFMT_INFINITEOUTPUTLOOP 0
  640. /**
  641. * number of times to loop output in formats that support it
  642. */
  643. int loop_output;
  644. int flags;
  645. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  646. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  647. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  648. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  649. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  650. #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
  651. #if FF_API_FLAG_RTP_HINT
  652. #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
  653. #endif
  654. #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
  655. #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
  656. #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
  657. #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)
  658. #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate.
  659. int loop_input;
  660. /**
  661. * decoding: size of data to probe; encoding: unused.
  662. */
  663. unsigned int probesize;
  664. /**
  665. * Maximum time (in AV_TIME_BASE units) during which the input should
  666. * be analyzed in av_find_stream_info().
  667. */
  668. int max_analyze_duration;
  669. const uint8_t *key;
  670. int keylen;
  671. unsigned int nb_programs;
  672. AVProgram **programs;
  673. /**
  674. * Forced video codec_id.
  675. * Demuxing: Set by user.
  676. */
  677. enum CodecID video_codec_id;
  678. /**
  679. * Forced audio codec_id.
  680. * Demuxing: Set by user.
  681. */
  682. enum CodecID audio_codec_id;
  683. /**
  684. * Forced subtitle codec_id.
  685. * Demuxing: Set by user.
  686. */
  687. enum CodecID subtitle_codec_id;
  688. /**
  689. * Maximum amount of memory in bytes to use for the index of each stream.
  690. * If the index exceeds this size, entries will be discarded as
  691. * needed to maintain a smaller size. This can lead to slower or less
  692. * accurate seeking (depends on demuxer).
  693. * Demuxers for which a full in-memory index is mandatory will ignore
  694. * this.
  695. * muxing : unused
  696. * demuxing: set by user
  697. */
  698. unsigned int max_index_size;
  699. /**
  700. * Maximum amount of memory in bytes to use for buffering frames
  701. * obtained from realtime capture devices.
  702. */
  703. unsigned int max_picture_buffer;
  704. unsigned int nb_chapters;
  705. AVChapter **chapters;
  706. /**
  707. * Flags to enable debugging.
  708. */
  709. int debug;
  710. #define FF_FDEBUG_TS 0x0001
  711. /**
  712. * Raw packets from the demuxer, prior to parsing and decoding.
  713. * This buffer is used for buffering packets until the codec can
  714. * be identified, as parsing cannot be done without knowing the
  715. * codec.
  716. */
  717. struct AVPacketList *raw_packet_buffer;
  718. struct AVPacketList *raw_packet_buffer_end;
  719. struct AVPacketList *packet_buffer_end;
  720. AVDictionary *metadata;
  721. /**
  722. * Remaining size available for raw_packet_buffer, in bytes.
  723. * NOT PART OF PUBLIC API
  724. */
  725. #define RAW_PACKET_BUFFER_SIZE 2500000
  726. int raw_packet_buffer_remaining_size;
  727. /**
  728. * Start time of the stream in real world time, in microseconds
  729. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  730. * in the stream was captured at this real world time.
  731. * - encoding: Set by user.
  732. * - decoding: Unused.
  733. */
  734. int64_t start_time_realtime;
  735. /**
  736. * decoding: number of frames used to probe fps
  737. */
  738. int fps_probe_size;
  739. /**
  740. * Transport stream id.
  741. * This will be moved into demuxer private options. Thus no API/ABI compatibility
  742. */
  743. int ts_id;
  744. } AVFormatContext;
  745. typedef struct AVPacketList {
  746. AVPacket pkt;
  747. struct AVPacketList *next;
  748. } AVPacketList;
  749. /**
  750. * If f is NULL, returns the first registered input format,
  751. * if f is non-NULL, returns the next registered input format after f
  752. * or NULL if f is the last one.
  753. */
  754. AVInputFormat *av_iformat_next(AVInputFormat *f);
  755. /**
  756. * If f is NULL, returns the first registered output format,
  757. * if f is non-NULL, returns the next registered output format after f
  758. * or NULL if f is the last one.
  759. */
  760. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  761. #if FF_API_GUESS_IMG2_CODEC
  762. attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
  763. #endif
  764. /* XXX: Use automatic init with either ELF sections or C file parser */
  765. /* modules. */
  766. /* utils.c */
  767. void av_register_input_format(AVInputFormat *format);
  768. void av_register_output_format(AVOutputFormat *format);
  769. /**
  770. * Return the output format in the list of registered output formats
  771. * which best matches the provided parameters, or return NULL if
  772. * there is no match.
  773. *
  774. * @param short_name if non-NULL checks if short_name matches with the
  775. * names of the registered formats
  776. * @param filename if non-NULL checks if filename terminates with the
  777. * extensions of the registered formats
  778. * @param mime_type if non-NULL checks if mime_type matches with the
  779. * MIME type of the registered formats
  780. */
  781. AVOutputFormat *av_guess_format(const char *short_name,
  782. const char *filename,
  783. const char *mime_type);
  784. /**
  785. * Guess the codec ID based upon muxer and filename.
  786. */
  787. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  788. const char *filename, const char *mime_type,
  789. enum AVMediaType type);
  790. /**
  791. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  792. *
  793. * @param f The file stream pointer where the dump should be sent to.
  794. * @param buf buffer
  795. * @param size buffer size
  796. *
  797. * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
  798. */
  799. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  800. /**
  801. * Send a nice hexadecimal dump of a buffer to the log.
  802. *
  803. * @param avcl A pointer to an arbitrary struct of which the first field is a
  804. * pointer to an AVClass struct.
  805. * @param level The importance level of the message, lower values signifying
  806. * higher importance.
  807. * @param buf buffer
  808. * @param size buffer size
  809. *
  810. * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
  811. */
  812. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  813. /**
  814. * Send a nice dump of a packet to the specified file stream.
  815. *
  816. * @param f The file stream pointer where the dump should be sent to.
  817. * @param pkt packet to dump
  818. * @param dump_payload True if the payload must be displayed, too.
  819. * @param st AVStream that the packet belongs to
  820. */
  821. void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
  822. /**
  823. * Send a nice dump of a packet to the log.
  824. *
  825. * @param avcl A pointer to an arbitrary struct of which the first field is a
  826. * pointer to an AVClass struct.
  827. * @param level The importance level of the message, lower values signifying
  828. * higher importance.
  829. * @param pkt packet to dump
  830. * @param dump_payload True if the payload must be displayed, too.
  831. * @param st AVStream that the packet belongs to
  832. */
  833. void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
  834. AVStream *st);
  835. #if FF_API_PKT_DUMP
  836. attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  837. attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
  838. int dump_payload);
  839. #endif
  840. /**
  841. * Initialize libavformat and register all the muxers, demuxers and
  842. * protocols. If you do not call this function, then you can select
  843. * exactly which formats you want to support.
  844. *
  845. * @see av_register_input_format()
  846. * @see av_register_output_format()
  847. * @see av_register_protocol()
  848. */
  849. void av_register_all(void);
  850. /**
  851. * Get the CodecID for the given codec tag tag.
  852. * If no codec id is found returns CODEC_ID_NONE.
  853. *
  854. * @param tags list of supported codec_id-codec_tag pairs, as stored
  855. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  856. */
  857. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  858. /**
  859. * Get the codec tag for the given codec id id.
  860. * If no codec tag is found returns 0.
  861. *
  862. * @param tags list of supported codec_id-codec_tag pairs, as stored
  863. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  864. */
  865. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  866. /* media file input */
  867. /**
  868. * Find AVInputFormat based on the short name of the input format.
  869. */
  870. AVInputFormat *av_find_input_format(const char *short_name);
  871. /**
  872. * Guess the file format.
  873. *
  874. * @param is_opened Whether the file is already opened; determines whether
  875. * demuxers with or without AVFMT_NOFILE are probed.
  876. */
  877. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  878. /**
  879. * Guess the file format.
  880. *
  881. * @param is_opened Whether the file is already opened; determines whether
  882. * demuxers with or without AVFMT_NOFILE are probed.
  883. * @param score_max A probe score larger that this is required to accept a
  884. * detection, the variable is set to the actual detection
  885. * score afterwards.
  886. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  887. * to retry with a larger probe buffer.
  888. */
  889. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  890. /**
  891. * Guess the file format.
  892. *
  893. * @param is_opened Whether the file is already opened; determines whether
  894. * demuxers with or without AVFMT_NOFILE are probed.
  895. * @param score_ret The score of the best detection.
  896. */
  897. AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
  898. /**
  899. * Probe a bytestream to determine the input format. Each time a probe returns
  900. * with a score that is too low, the probe buffer size is increased and another
  901. * attempt is made. When the maximum probe size is reached, the input format
  902. * with the highest score is returned.
  903. *
  904. * @param pb the bytestream to probe
  905. * @param fmt the input format is put here
  906. * @param filename the filename of the stream
  907. * @param logctx the log context
  908. * @param offset the offset within the bytestream to probe from
  909. * @param max_probe_size the maximum probe buffer size (zero for default)
  910. * @return 0 in case of success, a negative value corresponding to an
  911. * AVERROR code otherwise
  912. */
  913. int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
  914. const char *filename, void *logctx,
  915. unsigned int offset, unsigned int max_probe_size);
  916. #if FF_API_FORMAT_PARAMETERS
  917. /**
  918. * Allocate all the structures needed to read an input stream.
  919. * This does not open the needed codecs for decoding the stream[s].
  920. * @deprecated use avformat_open_input instead.
  921. */
  922. attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
  923. AVIOContext *pb, const char *filename,
  924. AVInputFormat *fmt, AVFormatParameters *ap);
  925. /**
  926. * Open a media file as input. The codecs are not opened. Only the file
  927. * header (if present) is read.
  928. *
  929. * @param ic_ptr The opened media file handle is put here.
  930. * @param filename filename to open
  931. * @param fmt If non-NULL, force the file format to use.
  932. * @param buf_size optional buffer size (zero if default is OK)
  933. * @param ap Additional parameters needed when opening the file
  934. * (NULL if default).
  935. * @return 0 if OK, AVERROR_xxx otherwise
  936. *
  937. * @deprecated use avformat_open_input instead.
  938. */
  939. attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  940. AVInputFormat *fmt,
  941. int buf_size,
  942. AVFormatParameters *ap);
  943. #endif
  944. /**
  945. * Open an input stream and read the header. The codecs are not opened.
  946. * The stream must be closed with av_close_input_file().
  947. *
  948. * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
  949. * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
  950. * function and written into ps.
  951. * Note that a user-supplied AVFormatContext will be freed on failure.
  952. * @param filename Name of the stream to open.
  953. * @param fmt If non-NULL, this parameter forces a specific input format.
  954. * Otherwise the format is autodetected.
  955. * @param options A dictionary filled with AVFormatContext and demuxer-private options.
  956. * On return this parameter will be destroyed and replaced with a dict containing
  957. * options that were not found. May be NULL.
  958. *
  959. * @return 0 on success, a negative AVERROR on failure.
  960. *
  961. * @note If you want to use custom IO, preallocate the format context and set its pb field.
  962. */
  963. int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
  964. int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
  965. /**
  966. * Allocate an AVFormatContext.
  967. * avformat_free_context() can be used to free the context and everything
  968. * allocated by the framework within it.
  969. */
  970. AVFormatContext *avformat_alloc_context(void);
  971. #if FF_API_ALLOC_OUTPUT_CONTEXT
  972. /**
  973. * @deprecated deprecated in favor of avformat_alloc_output_context2()
  974. */
  975. attribute_deprecated
  976. AVFormatContext *avformat_alloc_output_context(const char *format,
  977. AVOutputFormat *oformat,
  978. const char *filename);
  979. #endif
  980. /**
  981. * Allocate an AVFormatContext for an output format.
  982. * avformat_free_context() can be used to free the context and
  983. * everything allocated by the framework within it.
  984. *
  985. * @param *ctx is set to the created format context, or to NULL in
  986. * case of failure
  987. * @param oformat format to use for allocating the context, if NULL
  988. * format_name and filename are used instead
  989. * @param format_name the name of output format to use for allocating the
  990. * context, if NULL filename is used instead
  991. * @param filename the name of the filename to use for allocating the
  992. * context, may be NULL
  993. * @return >= 0 in case of success, a negative AVERROR code in case of
  994. * failure
  995. */
  996. int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
  997. const char *format_name, const char *filename);
  998. /**
  999. * Read packets of a media file to get stream information. This
  1000. * is useful for file formats with no headers such as MPEG. This
  1001. * function also computes the real framerate in case of MPEG-2 repeat
  1002. * frame mode.
  1003. * The logical file position is not changed by this function;
  1004. * examined packets may be buffered for later processing.
  1005. *
  1006. * @param ic media file handle
  1007. * @return >=0 if OK, AVERROR_xxx on error
  1008. * @todo Let the user decide somehow what information is needed so that
  1009. * we do not waste time getting stuff the user does not need.
  1010. */
  1011. int av_find_stream_info(AVFormatContext *ic);
  1012. /**
  1013. * Find the "best" stream in the file.
  1014. * The best stream is determined according to various heuristics as the most
  1015. * likely to be what the user expects.
  1016. * If the decoder parameter is non-NULL, av_find_best_stream will find the
  1017. * default decoder for the stream's codec; streams for which no decoder can
  1018. * be found are ignored.
  1019. *
  1020. * @param ic media file handle
  1021. * @param type stream type: video, audio, subtitles, etc.
  1022. * @param wanted_stream_nb user-requested stream number,
  1023. * or -1 for automatic selection
  1024. * @param related_stream try to find a stream related (eg. in the same
  1025. * program) to this one, or -1 if none
  1026. * @param decoder_ret if non-NULL, returns the decoder for the
  1027. * selected stream
  1028. * @param flags flags; none are currently defined
  1029. * @return the non-negative stream number in case of success,
  1030. * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
  1031. * could be found,
  1032. * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
  1033. * @note If av_find_best_stream returns successfully and decoder_ret is not
  1034. * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
  1035. */
  1036. int av_find_best_stream(AVFormatContext *ic,
  1037. enum AVMediaType type,
  1038. int wanted_stream_nb,
  1039. int related_stream,
  1040. AVCodec **decoder_ret,
  1041. int flags);
  1042. /**
  1043. * Read a transport packet from a media file.
  1044. *
  1045. * This function is obsolete and should never be used.
  1046. * Use av_read_frame() instead.
  1047. *
  1048. * @param s media file handle
  1049. * @param pkt is filled
  1050. * @return 0 if OK, AVERROR_xxx on error
  1051. */
  1052. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  1053. /**
  1054. * Return the next frame of a stream.
  1055. * This function returns what is stored in the file, and does not validate
  1056. * that what is there are valid frames for the decoder. It will split what is
  1057. * stored in the file into frames and return one for each call. It will not
  1058. * omit invalid data between valid frames so as to give the decoder the maximum
  1059. * information possible for decoding.
  1060. *
  1061. * The returned packet is valid
  1062. * until the next av_read_frame() or until av_close_input_file() and
  1063. * must be freed with av_free_packet. For video, the packet contains
  1064. * exactly one frame. For audio, it contains an integer number of
  1065. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  1066. * data). If the audio frames have a variable size (e.g. MPEG audio),
  1067. * then it contains one frame.
  1068. *
  1069. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  1070. * values in AVStream.time_base units (and guessed if the format cannot
  1071. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  1072. * has B-frames, so it is better to rely on pkt->dts if you do not
  1073. * decompress the payload.
  1074. *
  1075. * @return 0 if OK, < 0 on error or end of file
  1076. */
  1077. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  1078. /**
  1079. * Seek to the keyframe at timestamp.
  1080. * 'timestamp' in 'stream_index'.
  1081. * @param stream_index If stream_index is (-1), a default
  1082. * stream is selected, and timestamp is automatically converted
  1083. * from AV_TIME_BASE units to the stream specific time_base.
  1084. * @param timestamp Timestamp in AVStream.time_base units
  1085. * or, if no stream is specified, in AV_TIME_BASE units.
  1086. * @param flags flags which select direction and seeking mode
  1087. * @return >= 0 on success
  1088. */
  1089. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  1090. int flags);
  1091. /**
  1092. * Seek to timestamp ts.
  1093. * Seeking will be done so that the point from which all active streams
  1094. * can be presented successfully will be closest to ts and within min/max_ts.
  1095. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  1096. *
  1097. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  1098. * are the file position (this may not be supported by all demuxers).
  1099. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  1100. * in the stream with stream_index (this may not be supported by all demuxers).
  1101. * Otherwise all timestamps are in units of the stream selected by stream_index
  1102. * or if stream_index is -1, in AV_TIME_BASE units.
  1103. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  1104. * keyframes (this may not be supported by all demuxers).
  1105. *
  1106. * @param stream_index index of the stream which is used as time base reference
  1107. * @param min_ts smallest acceptable timestamp
  1108. * @param ts target timestamp
  1109. * @param max_ts largest acceptable timestamp
  1110. * @param flags flags
  1111. * @return >=0 on success, error code otherwise
  1112. *
  1113. * @note This is part of the new seek API which is still under construction.
  1114. * Thus do not use this yet. It may change at any time, do not expect
  1115. * ABI compatibility yet!
  1116. */
  1117. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1118. /**
  1119. * Start playing a network-based stream (e.g. RTSP stream) at the
  1120. * current position.
  1121. */
  1122. int av_read_play(AVFormatContext *s);
  1123. /**
  1124. * Pause a network-based stream (e.g. RTSP stream).
  1125. *
  1126. * Use av_read_play() to resume it.
  1127. */
  1128. int av_read_pause(AVFormatContext *s);
  1129. /**
  1130. * Free a AVFormatContext allocated by av_open_input_stream.
  1131. * @param s context to free
  1132. */
  1133. void av_close_input_stream(AVFormatContext *s);
  1134. /**
  1135. * Close a media file (but not its codecs).
  1136. *
  1137. * @param s media file handle
  1138. */
  1139. void av_close_input_file(AVFormatContext *s);
  1140. /**
  1141. * Free an AVFormatContext and all its streams.
  1142. * @param s context to free
  1143. */
  1144. void avformat_free_context(AVFormatContext *s);
  1145. /**
  1146. * Add a new stream to a media file.
  1147. *
  1148. * Can only be called in the read_header() function. If the flag
  1149. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1150. * can be added in read_packet too.
  1151. *
  1152. * @param s media file handle
  1153. * @param id file-format-dependent stream ID
  1154. */
  1155. AVStream *av_new_stream(AVFormatContext *s, int id);
  1156. AVProgram *av_new_program(AVFormatContext *s, int id);
  1157. /**
  1158. * Set the pts for a given stream. If the new values would be invalid
  1159. * (<= 0), it leaves the AVStream unchanged.
  1160. *
  1161. * @param s stream
  1162. * @param pts_wrap_bits number of bits effectively used by the pts
  1163. * (used for wrap control, 33 is the value for MPEG)
  1164. * @param pts_num numerator to convert to seconds (MPEG: 1)
  1165. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  1166. */
  1167. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1168. unsigned int pts_num, unsigned int pts_den);
  1169. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1170. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1171. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1172. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1173. int av_find_default_stream_index(AVFormatContext *s);
  1174. /**
  1175. * Get the index for a specific timestamp.
  1176. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1177. * to the timestamp which is <= the requested one, if backward
  1178. * is 0, then it will be >=
  1179. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1180. * @return < 0 if no such timestamp could be found
  1181. */
  1182. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1183. /**
  1184. * Add an index entry into a sorted list. Update the entry if the list
  1185. * already contains it.
  1186. *
  1187. * @param timestamp timestamp in the time base of the given stream
  1188. */
  1189. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1190. int size, int distance, int flags);
  1191. /**
  1192. * Perform a binary search using av_index_search_timestamp() and
  1193. * AVInputFormat.read_timestamp().
  1194. * This is not supposed to be called directly by a user application,
  1195. * but by demuxers.
  1196. * @param target_ts target timestamp in the time base of the given stream
  1197. * @param stream_index stream number
  1198. */
  1199. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  1200. int64_t target_ts, int flags);
  1201. /**
  1202. * Update cur_dts of all streams based on the given timestamp and AVStream.
  1203. *
  1204. * Stream ref_st unchanged, others set cur_dts in their native time base.
  1205. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  1206. * @param timestamp new dts expressed in time_base of param ref_st
  1207. * @param ref_st reference stream giving time_base of param timestamp
  1208. */
  1209. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  1210. /**
  1211. * Perform a binary search using read_timestamp().
  1212. * This is not supposed to be called directly by a user application,
  1213. * but by demuxers.
  1214. * @param target_ts target timestamp in the time base of the given stream
  1215. * @param stream_index stream number
  1216. */
  1217. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  1218. int64_t target_ts, int64_t pos_min,
  1219. int64_t pos_max, int64_t pos_limit,
  1220. int64_t ts_min, int64_t ts_max,
  1221. int flags, int64_t *ts_ret,
  1222. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1223. /**
  1224. * media file output
  1225. */
  1226. #if FF_API_FORMAT_PARAMETERS
  1227. /**
  1228. * @deprecated pass the options to avformat_write_header directly.
  1229. */
  1230. attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1231. #endif
  1232. /**
  1233. * Split a URL string into components.
  1234. *
  1235. * The pointers to buffers for storing individual components may be null,
  1236. * in order to ignore that component. Buffers for components not found are
  1237. * set to empty strings. If the port is not found, it is set to a negative
  1238. * value.
  1239. *
  1240. * @param proto the buffer for the protocol
  1241. * @param proto_size the size of the proto buffer
  1242. * @param authorization the buffer for the authorization
  1243. * @param authorization_size the size of the authorization buffer
  1244. * @param hostname the buffer for the host name
  1245. * @param hostname_size the size of the hostname buffer
  1246. * @param port_ptr a pointer to store the port number in
  1247. * @param path the buffer for the path
  1248. * @param path_size the size of the path buffer
  1249. * @param url the URL to split
  1250. */
  1251. void av_url_split(char *proto, int proto_size,
  1252. char *authorization, int authorization_size,
  1253. char *hostname, int hostname_size,
  1254. int *port_ptr,
  1255. char *path, int path_size,
  1256. const char *url);
  1257. /**
  1258. * Allocate the stream private data and write the stream header to
  1259. * an output media file.
  1260. *
  1261. * @param s Media file handle, must be allocated with avformat_alloc_context().
  1262. * Its oformat field must be set to the desired output format;
  1263. * Its pb field must be set to an already openened AVIOContext.
  1264. * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
  1265. * On return this parameter will be destroyed and replaced with a dict containing
  1266. * options that were not found. May be NULL.
  1267. *
  1268. * @return 0 on success, negative AVERROR on failure.
  1269. *
  1270. * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
  1271. */
  1272. int avformat_write_header(AVFormatContext *s, AVDictionary **options);
  1273. #if FF_API_FORMAT_PARAMETERS
  1274. /**
  1275. * Allocate the stream private data and write the stream header to an
  1276. * output media file.
  1277. * @note: this sets stream time-bases, if possible to stream->codec->time_base
  1278. * but for some formats it might also be some other time base
  1279. *
  1280. * @param s media file handle
  1281. * @return 0 if OK, AVERROR_xxx on error
  1282. *
  1283. * @deprecated use avformat_write_header.
  1284. */
  1285. attribute_deprecated int av_write_header(AVFormatContext *s);
  1286. #endif
  1287. /**
  1288. * Write a packet to an output media file.
  1289. *
  1290. * The packet shall contain one audio or video frame.
  1291. * The packet must be correctly interleaved according to the container
  1292. * specification, if not then av_interleaved_write_frame must be used.
  1293. *
  1294. * @param s media file handle
  1295. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1296. dts/pts, ...
  1297. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1298. */
  1299. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1300. /**
  1301. * Write a packet to an output media file ensuring correct interleaving.
  1302. *
  1303. * The packet must contain one audio or video frame.
  1304. * If the packets are already correctly interleaved, the application should
  1305. * call av_write_frame() instead as it is slightly faster. It is also important
  1306. * to keep in mind that completely non-interleaved input will need huge amounts
  1307. * of memory to interleave with this, so it is preferable to interleave at the
  1308. * demuxer level.
  1309. *
  1310. * @param s media file handle
  1311. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1312. dts/pts, ...
  1313. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1314. */
  1315. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1316. /**
  1317. * Interleave a packet per dts in an output media file.
  1318. *
  1319. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1320. * function, so they cannot be used after it. Note that calling av_free_packet()
  1321. * on them is still safe.
  1322. *
  1323. * @param s media file handle
  1324. * @param out the interleaved packet will be output here
  1325. * @param pkt the input packet
  1326. * @param flush 1 if no further packets are available as input and all
  1327. * remaining packets should be output
  1328. * @return 1 if a packet was output, 0 if no packet could be output,
  1329. * < 0 if an error occurred
  1330. */
  1331. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1332. AVPacket *pkt, int flush);
  1333. /**
  1334. * Write the stream trailer to an output media file and free the
  1335. * file private data.
  1336. *
  1337. * May only be called after a successful call to av_write_header.
  1338. *
  1339. * @param s media file handle
  1340. * @return 0 if OK, AVERROR_xxx on error
  1341. */
  1342. int av_write_trailer(AVFormatContext *s);
  1343. /**
  1344. * Get timing information for the data currently output.
  1345. * The exact meaning of "currently output" depends on the format.
  1346. * It is mostly relevant for devices that have an internal buffer and/or
  1347. * work in real time.
  1348. * @param s media file handle
  1349. * @param stream stream in the media file
  1350. * @param dts[out] DTS of the last packet output for the stream, in stream
  1351. * time_base units
  1352. * @param wall[out] absolute time when that packet whas output,
  1353. * in microsecond
  1354. * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it
  1355. * Note: some formats or devices may not allow to measure dts and wall
  1356. * atomically.
  1357. */
  1358. int av_get_output_timestamp(struct AVFormatContext *s, int stream,
  1359. int64_t *dts, int64_t *wall);
  1360. #if FF_API_DUMP_FORMAT
  1361. /**
  1362. * @deprecated Deprecated in favor of av_dump_format().
  1363. */
  1364. attribute_deprecated void dump_format(AVFormatContext *ic,
  1365. int index,
  1366. const char *url,
  1367. int is_output);
  1368. #endif
  1369. void av_dump_format(AVFormatContext *ic,
  1370. int index,
  1371. const char *url,
  1372. int is_output);
  1373. #if FF_API_PARSE_DATE
  1374. /**
  1375. * Parse datestr and return a corresponding number of microseconds.
  1376. *
  1377. * @param datestr String representing a date or a duration.
  1378. * See av_parse_time() for the syntax of the provided string.
  1379. * @deprecated in favor of av_parse_time()
  1380. */
  1381. attribute_deprecated
  1382. int64_t parse_date(const char *datestr, int duration);
  1383. #endif
  1384. /**
  1385. * Get the current time in microseconds.
  1386. */
  1387. int64_t av_gettime(void);
  1388. #if FF_API_FIND_INFO_TAG
  1389. /**
  1390. * @deprecated use av_find_info_tag in libavutil instead.
  1391. */
  1392. attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1393. #endif
  1394. /**
  1395. * Return in 'buf' the path with '%d' replaced by a number.
  1396. *
  1397. * Also handles the '%0nd' format where 'n' is the total number
  1398. * of digits and '%%'.
  1399. *
  1400. * @param buf destination buffer
  1401. * @param buf_size destination buffer size
  1402. * @param path numbered sequence string
  1403. * @param number frame number
  1404. * @return 0 if OK, -1 on format error
  1405. */
  1406. int av_get_frame_filename(char *buf, int buf_size,
  1407. const char *path, int number);
  1408. /**
  1409. * Check whether filename actually is a numbered sequence generator.
  1410. *
  1411. * @param filename possible numbered sequence string
  1412. * @return 1 if a valid numbered sequence string, 0 otherwise
  1413. */
  1414. int av_filename_number_test(const char *filename);
  1415. /**
  1416. * Generate an SDP for an RTP session.
  1417. *
  1418. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1419. * array is composed by only one context, such context can contain
  1420. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1421. * all the contexts in the array (an AVCodecContext per RTP stream)
  1422. * must contain only one AVStream.
  1423. * @param n_files number of AVCodecContexts contained in ac
  1424. * @param buf buffer where the SDP will be stored (must be allocated by
  1425. * the caller)
  1426. * @param size the size of the buffer
  1427. * @return 0 if OK, AVERROR_xxx on error
  1428. */
  1429. int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
  1430. #if FF_API_SDP_CREATE
  1431. attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1432. #endif
  1433. /**
  1434. * Return a positive value if the given filename has one of the given
  1435. * extensions, 0 otherwise.
  1436. *
  1437. * @param extensions a comma-separated list of filename extensions
  1438. */
  1439. int av_match_ext(const char *filename, const char *extensions);
  1440. #endif /* AVFORMAT_AVFORMAT_H */