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.

1721 lines
62KB

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