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.

1474 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. #endif
  204. int width;
  205. int height;
  206. enum PixelFormat pix_fmt;
  207. int channel; /**< Used to select DV channel. */
  208. const char *standard; /**< TV standard, NTSC, PAL, SECAM */
  209. #if FF_API_FORMAT_PARAMETERS
  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. #endif
  214. unsigned int initial_pause:1; /**< Do not begin to play the stream
  215. immediately (RTSP only). */
  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. #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file
  631. int loop_input;
  632. /**
  633. * decoding: size of data to probe; encoding: unused.
  634. */
  635. unsigned int probesize;
  636. /**
  637. * Maximum time (in AV_TIME_BASE units) during which the input should
  638. * be analyzed in av_find_stream_info().
  639. */
  640. int max_analyze_duration;
  641. const uint8_t *key;
  642. int keylen;
  643. unsigned int nb_programs;
  644. AVProgram **programs;
  645. /**
  646. * Forced video codec_id.
  647. * Demuxing: Set by user.
  648. */
  649. enum CodecID video_codec_id;
  650. /**
  651. * Forced audio codec_id.
  652. * Demuxing: Set by user.
  653. */
  654. enum CodecID audio_codec_id;
  655. /**
  656. * Forced subtitle codec_id.
  657. * Demuxing: Set by user.
  658. */
  659. enum CodecID subtitle_codec_id;
  660. /**
  661. * Maximum amount of memory in bytes to use for the index of each stream.
  662. * If the index exceeds this size, entries will be discarded as
  663. * needed to maintain a smaller size. This can lead to slower or less
  664. * accurate seeking (depends on demuxer).
  665. * Demuxers for which a full in-memory index is mandatory will ignore
  666. * this.
  667. * muxing : unused
  668. * demuxing: set by user
  669. */
  670. unsigned int max_index_size;
  671. /**
  672. * Maximum amount of memory in bytes to use for buffering frames
  673. * obtained from realtime capture devices.
  674. */
  675. unsigned int max_picture_buffer;
  676. unsigned int nb_chapters;
  677. AVChapter **chapters;
  678. /**
  679. * Flags to enable debugging.
  680. */
  681. int debug;
  682. #define FF_FDEBUG_TS 0x0001
  683. /**
  684. * Raw packets from the demuxer, prior to parsing and decoding.
  685. * This buffer is used for buffering packets until the codec can
  686. * be identified, as parsing cannot be done without knowing the
  687. * codec.
  688. */
  689. struct AVPacketList *raw_packet_buffer;
  690. struct AVPacketList *raw_packet_buffer_end;
  691. struct AVPacketList *packet_buffer_end;
  692. AVMetadata *metadata;
  693. /**
  694. * Remaining size available for raw_packet_buffer, in bytes.
  695. * NOT PART OF PUBLIC API
  696. */
  697. #define RAW_PACKET_BUFFER_SIZE 2500000
  698. int raw_packet_buffer_remaining_size;
  699. /**
  700. * Start time of the stream in real world time, in microseconds
  701. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  702. * in the stream was captured at this real world time.
  703. * - encoding: Set by user.
  704. * - decoding: Unused.
  705. */
  706. int64_t start_time_realtime;
  707. } AVFormatContext;
  708. typedef struct AVPacketList {
  709. AVPacket pkt;
  710. struct AVPacketList *next;
  711. } AVPacketList;
  712. /**
  713. * If f is NULL, returns the first registered input format,
  714. * if f is non-NULL, returns the next registered input format after f
  715. * or NULL if f is the last one.
  716. */
  717. AVInputFormat *av_iformat_next(AVInputFormat *f);
  718. /**
  719. * If f is NULL, returns the first registered output format,
  720. * if f is non-NULL, returns the next registered output format after f
  721. * or NULL if f is the last one.
  722. */
  723. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  724. #if FF_API_GUESS_IMG2_CODEC
  725. attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
  726. #endif
  727. /* XXX: Use automatic init with either ELF sections or C file parser */
  728. /* modules. */
  729. /* utils.c */
  730. void av_register_input_format(AVInputFormat *format);
  731. void av_register_output_format(AVOutputFormat *format);
  732. /**
  733. * Return the output format in the list of registered output formats
  734. * which best matches the provided parameters, or return NULL if
  735. * there is no match.
  736. *
  737. * @param short_name if non-NULL checks if short_name matches with the
  738. * names of the registered formats
  739. * @param filename if non-NULL checks if filename terminates with the
  740. * extensions of the registered formats
  741. * @param mime_type if non-NULL checks if mime_type matches with the
  742. * MIME type of the registered formats
  743. */
  744. AVOutputFormat *av_guess_format(const char *short_name,
  745. const char *filename,
  746. const char *mime_type);
  747. /**
  748. * Guess the codec ID based upon muxer and filename.
  749. */
  750. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  751. const char *filename, const char *mime_type,
  752. enum AVMediaType type);
  753. /**
  754. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  755. *
  756. * @param f The file stream pointer where the dump should be sent to.
  757. * @param buf buffer
  758. * @param size buffer size
  759. *
  760. * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
  761. */
  762. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  763. /**
  764. * Send a nice hexadecimal dump of a buffer to the log.
  765. *
  766. * @param avcl A pointer to an arbitrary struct of which the first field is a
  767. * pointer to an AVClass struct.
  768. * @param level The importance level of the message, lower values signifying
  769. * higher importance.
  770. * @param buf buffer
  771. * @param size buffer size
  772. *
  773. * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
  774. */
  775. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  776. /**
  777. * Send a nice dump of a packet to the specified file stream.
  778. *
  779. * @param f The file stream pointer where the dump should be sent to.
  780. * @param pkt packet to dump
  781. * @param dump_payload True if the payload must be displayed, too.
  782. * @param st AVStream that the packet belongs to
  783. */
  784. void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
  785. /**
  786. * Send a nice dump of a packet to the log.
  787. *
  788. * @param avcl A pointer to an arbitrary struct of which the first field is a
  789. * pointer to an AVClass struct.
  790. * @param level The importance level of the message, lower values signifying
  791. * higher importance.
  792. * @param pkt packet to dump
  793. * @param dump_payload True if the payload must be displayed, too.
  794. * @param st AVStream that the packet belongs to
  795. */
  796. void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
  797. AVStream *st);
  798. #if FF_API_PKT_DUMP
  799. attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  800. attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
  801. int dump_payload);
  802. #endif
  803. /**
  804. * Initialize libavformat and register all the muxers, demuxers and
  805. * protocols. If you do not call this function, then you can select
  806. * exactly which formats you want to support.
  807. *
  808. * @see av_register_input_format()
  809. * @see av_register_output_format()
  810. * @see av_register_protocol()
  811. */
  812. void av_register_all(void);
  813. /**
  814. * Get the CodecID for the given codec tag tag.
  815. * If no codec id is found returns CODEC_ID_NONE.
  816. *
  817. * @param tags list of supported codec_id-codec_tag pairs, as stored
  818. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  819. */
  820. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  821. /**
  822. * Get the codec tag for the given codec id id.
  823. * If no codec tag is found returns 0.
  824. *
  825. * @param tags list of supported codec_id-codec_tag pairs, as stored
  826. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  827. */
  828. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  829. /* media file input */
  830. /**
  831. * Find AVInputFormat based on the short name of the input format.
  832. */
  833. AVInputFormat *av_find_input_format(const char *short_name);
  834. /**
  835. * Guess the file format.
  836. *
  837. * @param is_opened Whether the file is already opened; determines whether
  838. * demuxers with or without AVFMT_NOFILE are probed.
  839. */
  840. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  841. /**
  842. * Guess the file format.
  843. *
  844. * @param is_opened Whether the file is already opened; determines whether
  845. * demuxers with or without AVFMT_NOFILE are probed.
  846. * @param score_max A probe score larger that this is required to accept a
  847. * detection, the variable is set to the actual detection
  848. * score afterwards.
  849. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  850. * to retry with a larger probe buffer.
  851. */
  852. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  853. /**
  854. * Probe a bytestream to determine the input format. Each time a probe returns
  855. * with a score that is too low, the probe buffer size is increased and another
  856. * attempt is made. When the maximum probe size is reached, the input format
  857. * with the highest score is returned.
  858. *
  859. * @param pb the bytestream to probe
  860. * @param fmt the input format is put here
  861. * @param filename the filename of the stream
  862. * @param logctx the log context
  863. * @param offset the offset within the bytestream to probe from
  864. * @param max_probe_size the maximum probe buffer size (zero for default)
  865. * @return 0 in case of success, a negative value corresponding to an
  866. * AVERROR code otherwise
  867. */
  868. int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
  869. const char *filename, void *logctx,
  870. unsigned int offset, unsigned int max_probe_size);
  871. /**
  872. * Allocate all the structures needed to read an input stream.
  873. * This does not open the needed codecs for decoding the stream[s].
  874. */
  875. int av_open_input_stream(AVFormatContext **ic_ptr,
  876. AVIOContext *pb, const char *filename,
  877. AVInputFormat *fmt, AVFormatParameters *ap);
  878. /**
  879. * Open a media file as input. The codecs are not opened. Only the file
  880. * header (if present) is read.
  881. *
  882. * @param ic_ptr The opened media file handle is put here.
  883. * @param filename filename to open
  884. * @param fmt If non-NULL, force the file format to use.
  885. * @param buf_size optional buffer size (zero if default is OK)
  886. * @param ap Additional parameters needed when opening the file
  887. * (NULL if default).
  888. * @return 0 if OK, AVERROR_xxx otherwise
  889. */
  890. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  891. AVInputFormat *fmt,
  892. int buf_size,
  893. AVFormatParameters *ap);
  894. /**
  895. * Allocate an AVFormatContext.
  896. * avformat_free_context() can be used to free the context and everything
  897. * allocated by the framework within it.
  898. */
  899. AVFormatContext *avformat_alloc_context(void);
  900. /**
  901. * Read packets of a media file to get stream information. This
  902. * is useful for file formats with no headers such as MPEG. This
  903. * function also computes the real framerate in case of MPEG-2 repeat
  904. * frame mode.
  905. * The logical file position is not changed by this function;
  906. * examined packets may be buffered for later processing.
  907. *
  908. * @param ic media file handle
  909. * @return >=0 if OK, AVERROR_xxx on error
  910. * @todo Let the user decide somehow what information is needed so that
  911. * we do not waste time getting stuff the user does not need.
  912. */
  913. int av_find_stream_info(AVFormatContext *ic);
  914. /**
  915. * Find the "best" stream in the file.
  916. * The best stream is determined according to various heuristics as the most
  917. * likely to be what the user expects.
  918. * If the decoder parameter is non-NULL, av_find_best_stream will find the
  919. * default decoder for the stream's codec; streams for which no decoder can
  920. * be found are ignored.
  921. *
  922. * @param ic media file handle
  923. * @param type stream type: video, audio, subtitles, etc.
  924. * @param wanted_stream_nb user-requested stream number,
  925. * or -1 for automatic selection
  926. * @param related_stream try to find a stream related (eg. in the same
  927. * program) to this one, or -1 if none
  928. * @param decoder_ret if non-NULL, returns the decoder for the
  929. * selected stream
  930. * @param flags flags; none are currently defined
  931. * @return the non-negative stream number in case of success,
  932. * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
  933. * could be found,
  934. * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
  935. * @note If av_find_best_stream returns successfully and decoder_ret is not
  936. * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
  937. */
  938. int av_find_best_stream(AVFormatContext *ic,
  939. enum AVMediaType type,
  940. int wanted_stream_nb,
  941. int related_stream,
  942. AVCodec **decoder_ret,
  943. int flags);
  944. /**
  945. * Read a transport packet from a media file.
  946. *
  947. * This function is obsolete and should never be used.
  948. * Use av_read_frame() instead.
  949. *
  950. * @param s media file handle
  951. * @param pkt is filled
  952. * @return 0 if OK, AVERROR_xxx on error
  953. */
  954. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  955. /**
  956. * Return the next frame of a stream.
  957. * This function returns what is stored in the file, and does not validate
  958. * that what is there are valid frames for the decoder. It will split what is
  959. * stored in the file into frames and return one for each call. It will not
  960. * omit invalid data between valid frames so as to give the decoder the maximum
  961. * information possible for decoding.
  962. *
  963. * The returned packet is valid
  964. * until the next av_read_frame() or until av_close_input_file() and
  965. * must be freed with av_free_packet. For video, the packet contains
  966. * exactly one frame. For audio, it contains an integer number of
  967. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  968. * data). If the audio frames have a variable size (e.g. MPEG audio),
  969. * then it contains one frame.
  970. *
  971. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  972. * values in AVStream.time_base units (and guessed if the format cannot
  973. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  974. * has B-frames, so it is better to rely on pkt->dts if you do not
  975. * decompress the payload.
  976. *
  977. * @return 0 if OK, < 0 on error or end of file
  978. */
  979. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  980. /**
  981. * Seek to the keyframe at timestamp.
  982. * 'timestamp' in 'stream_index'.
  983. * @param stream_index If stream_index is (-1), a default
  984. * stream is selected, and timestamp is automatically converted
  985. * from AV_TIME_BASE units to the stream specific time_base.
  986. * @param timestamp Timestamp in AVStream.time_base units
  987. * or, if no stream is specified, in AV_TIME_BASE units.
  988. * @param flags flags which select direction and seeking mode
  989. * @return >= 0 on success
  990. */
  991. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  992. int flags);
  993. /**
  994. * Seek to timestamp ts.
  995. * Seeking will be done so that the point from which all active streams
  996. * can be presented successfully will be closest to ts and within min/max_ts.
  997. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  998. *
  999. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  1000. * are the file position (this may not be supported by all demuxers).
  1001. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  1002. * in the stream with stream_index (this may not be supported by all demuxers).
  1003. * Otherwise all timestamps are in units of the stream selected by stream_index
  1004. * or if stream_index is -1, in AV_TIME_BASE units.
  1005. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  1006. * keyframes (this may not be supported by all demuxers).
  1007. *
  1008. * @param stream_index index of the stream which is used as time base reference
  1009. * @param min_ts smallest acceptable timestamp
  1010. * @param ts target timestamp
  1011. * @param max_ts largest acceptable timestamp
  1012. * @param flags flags
  1013. * @return >=0 on success, error code otherwise
  1014. *
  1015. * @note This is part of the new seek API which is still under construction.
  1016. * Thus do not use this yet. It may change at any time, do not expect
  1017. * ABI compatibility yet!
  1018. */
  1019. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1020. /**
  1021. * Start playing a network-based stream (e.g. RTSP stream) at the
  1022. * current position.
  1023. */
  1024. int av_read_play(AVFormatContext *s);
  1025. /**
  1026. * Pause a network-based stream (e.g. RTSP stream).
  1027. *
  1028. * Use av_read_play() to resume it.
  1029. */
  1030. int av_read_pause(AVFormatContext *s);
  1031. /**
  1032. * Free a AVFormatContext allocated by av_open_input_stream.
  1033. * @param s context to free
  1034. */
  1035. void av_close_input_stream(AVFormatContext *s);
  1036. /**
  1037. * Close a media file (but not its codecs).
  1038. *
  1039. * @param s media file handle
  1040. */
  1041. void av_close_input_file(AVFormatContext *s);
  1042. /**
  1043. * Free an AVFormatContext and all its streams.
  1044. * @param s context to free
  1045. */
  1046. void avformat_free_context(AVFormatContext *s);
  1047. /**
  1048. * Add a new stream to a media file.
  1049. *
  1050. * Can only be called in the read_header() function. If the flag
  1051. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1052. * can be added in read_packet too.
  1053. *
  1054. * @param s media file handle
  1055. * @param id file-format-dependent stream ID
  1056. */
  1057. AVStream *av_new_stream(AVFormatContext *s, int id);
  1058. AVProgram *av_new_program(AVFormatContext *s, int id);
  1059. /**
  1060. * Set the pts for a given stream. If the new values would be invalid
  1061. * (<= 0), it leaves the AVStream unchanged.
  1062. *
  1063. * @param s stream
  1064. * @param pts_wrap_bits number of bits effectively used by the pts
  1065. * (used for wrap control, 33 is the value for MPEG)
  1066. * @param pts_num numerator to convert to seconds (MPEG: 1)
  1067. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  1068. */
  1069. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1070. unsigned int pts_num, unsigned int pts_den);
  1071. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1072. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1073. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1074. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1075. int av_find_default_stream_index(AVFormatContext *s);
  1076. /**
  1077. * Get the index for a specific timestamp.
  1078. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1079. * to the timestamp which is <= the requested one, if backward
  1080. * is 0, then it will be >=
  1081. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1082. * @return < 0 if no such timestamp could be found
  1083. */
  1084. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1085. /**
  1086. * Add an index entry into a sorted list. Update the entry if the list
  1087. * already contains it.
  1088. *
  1089. * @param timestamp timestamp in the time base of the given stream
  1090. */
  1091. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1092. int size, int distance, int flags);
  1093. /**
  1094. * Perform a binary search using av_index_search_timestamp() and
  1095. * AVInputFormat.read_timestamp().
  1096. * This is not supposed to be called directly by a user application,
  1097. * but by demuxers.
  1098. * @param target_ts target timestamp in the time base of the given stream
  1099. * @param stream_index stream number
  1100. */
  1101. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  1102. int64_t target_ts, int flags);
  1103. /**
  1104. * Update cur_dts of all streams based on the given timestamp and AVStream.
  1105. *
  1106. * Stream ref_st unchanged, others set cur_dts in their native time base.
  1107. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  1108. * @param timestamp new dts expressed in time_base of param ref_st
  1109. * @param ref_st reference stream giving time_base of param timestamp
  1110. */
  1111. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  1112. /**
  1113. * Perform a binary search using read_timestamp().
  1114. * This is not supposed to be called directly by a user application,
  1115. * but by demuxers.
  1116. * @param target_ts target timestamp in the time base of the given stream
  1117. * @param stream_index stream number
  1118. */
  1119. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  1120. int64_t target_ts, int64_t pos_min,
  1121. int64_t pos_max, int64_t pos_limit,
  1122. int64_t ts_min, int64_t ts_max,
  1123. int flags, int64_t *ts_ret,
  1124. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1125. /**
  1126. * media file output
  1127. */
  1128. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1129. /**
  1130. * Split a URL string into components.
  1131. *
  1132. * The pointers to buffers for storing individual components may be null,
  1133. * in order to ignore that component. Buffers for components not found are
  1134. * set to empty strings. If the port is not found, it is set to a negative
  1135. * value.
  1136. *
  1137. * @param proto the buffer for the protocol
  1138. * @param proto_size the size of the proto buffer
  1139. * @param authorization the buffer for the authorization
  1140. * @param authorization_size the size of the authorization buffer
  1141. * @param hostname the buffer for the host name
  1142. * @param hostname_size the size of the hostname buffer
  1143. * @param port_ptr a pointer to store the port number in
  1144. * @param path the buffer for the path
  1145. * @param path_size the size of the path buffer
  1146. * @param url the URL to split
  1147. */
  1148. void av_url_split(char *proto, int proto_size,
  1149. char *authorization, int authorization_size,
  1150. char *hostname, int hostname_size,
  1151. int *port_ptr,
  1152. char *path, int path_size,
  1153. const char *url);
  1154. /**
  1155. * Allocate the stream private data and write the stream header to an
  1156. * output media file.
  1157. * @note: this sets stream time-bases, if possible to stream->codec->time_base
  1158. * but for some formats it might also be some other time base
  1159. *
  1160. * @param s media file handle
  1161. * @return 0 if OK, AVERROR_xxx on error
  1162. */
  1163. int av_write_header(AVFormatContext *s);
  1164. /**
  1165. * Write a packet to an output media file.
  1166. *
  1167. * The packet shall contain one audio or video frame.
  1168. * The packet must be correctly interleaved according to the container
  1169. * specification, if not then av_interleaved_write_frame must be used.
  1170. *
  1171. * @param s media file handle
  1172. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1173. dts/pts, ...
  1174. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1175. */
  1176. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1177. /**
  1178. * Write a packet to an output media file ensuring correct interleaving.
  1179. *
  1180. * The packet must contain one audio or video frame.
  1181. * If the packets are already correctly interleaved, the application should
  1182. * call av_write_frame() instead as it is slightly faster. It is also important
  1183. * to keep in mind that completely non-interleaved input will need huge amounts
  1184. * of memory to interleave with this, so it is preferable to interleave at the
  1185. * demuxer level.
  1186. *
  1187. * @param s media file handle
  1188. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1189. dts/pts, ...
  1190. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1191. */
  1192. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1193. /**
  1194. * Interleave a packet per dts in an output media file.
  1195. *
  1196. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1197. * function, so they cannot be used after it. Note that calling av_free_packet()
  1198. * on them is still safe.
  1199. *
  1200. * @param s media file handle
  1201. * @param out the interleaved packet will be output here
  1202. * @param pkt the input packet
  1203. * @param flush 1 if no further packets are available as input and all
  1204. * remaining packets should be output
  1205. * @return 1 if a packet was output, 0 if no packet could be output,
  1206. * < 0 if an error occurred
  1207. */
  1208. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1209. AVPacket *pkt, int flush);
  1210. /**
  1211. * Write the stream trailer to an output media file and free the
  1212. * file private data.
  1213. *
  1214. * May only be called after a successful call to av_write_header.
  1215. *
  1216. * @param s media file handle
  1217. * @return 0 if OK, AVERROR_xxx on error
  1218. */
  1219. int av_write_trailer(AVFormatContext *s);
  1220. #if FF_API_DUMP_FORMAT
  1221. attribute_deprecated void dump_format(AVFormatContext *ic,
  1222. int index,
  1223. const char *url,
  1224. int is_output);
  1225. #endif
  1226. void av_dump_format(AVFormatContext *ic,
  1227. int index,
  1228. const char *url,
  1229. int is_output);
  1230. #if FF_API_PARSE_DATE
  1231. /**
  1232. * Parse datestr and return a corresponding number of microseconds.
  1233. *
  1234. * @param datestr String representing a date or a duration.
  1235. * See av_parse_time() for the syntax of the provided string.
  1236. * @deprecated in favor of av_parse_time()
  1237. */
  1238. attribute_deprecated
  1239. int64_t parse_date(const char *datestr, int duration);
  1240. #endif
  1241. /**
  1242. * Get the current time in microseconds.
  1243. */
  1244. int64_t av_gettime(void);
  1245. #if FF_API_FIND_INFO_TAG
  1246. /**
  1247. * @deprecated use av_find_info_tag in libavutil instead.
  1248. */
  1249. attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1250. #endif
  1251. /**
  1252. * Return in 'buf' the path with '%d' replaced by a number.
  1253. *
  1254. * Also handles the '%0nd' format where 'n' is the total number
  1255. * of digits and '%%'.
  1256. *
  1257. * @param buf destination buffer
  1258. * @param buf_size destination buffer size
  1259. * @param path numbered sequence string
  1260. * @param number frame number
  1261. * @return 0 if OK, -1 on format error
  1262. */
  1263. int av_get_frame_filename(char *buf, int buf_size,
  1264. const char *path, int number);
  1265. /**
  1266. * Check whether filename actually is a numbered sequence generator.
  1267. *
  1268. * @param filename possible numbered sequence string
  1269. * @return 1 if a valid numbered sequence string, 0 otherwise
  1270. */
  1271. int av_filename_number_test(const char *filename);
  1272. /**
  1273. * Generate an SDP for an RTP session.
  1274. *
  1275. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1276. * array is composed by only one context, such context can contain
  1277. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1278. * all the contexts in the array (an AVCodecContext per RTP stream)
  1279. * must contain only one AVStream.
  1280. * @param n_files number of AVCodecContexts contained in ac
  1281. * @param buf buffer where the SDP will be stored (must be allocated by
  1282. * the caller)
  1283. * @param size the size of the buffer
  1284. * @return 0 if OK, AVERROR_xxx on error
  1285. */
  1286. int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
  1287. #if FF_API_SDP_CREATE
  1288. attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1289. #endif
  1290. /**
  1291. * Return a positive value if the given filename has one of the given
  1292. * extensions, 0 otherwise.
  1293. *
  1294. * @param extensions a comma-separated list of filename extensions
  1295. */
  1296. int av_match_ext(const char *filename, const char *extensions);
  1297. #endif /* AVFORMAT_AVFORMAT_H */