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.

1551 lines
56KB

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