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

1843 lines
64KB

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