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.

1500 lines
52KB

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