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.

1540 lines
54KB

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