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.

1543 lines
56KB

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