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.

1622 lines
57KB

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