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.

1608 lines
57KB

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