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.

1545 lines
56KB

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