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.

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