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.

1846 lines
65KB

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