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.

1576 lines
55KB

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