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.

1481 lines
53KB

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