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.

1561 lines
55KB

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