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.

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