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.

1516 lines
53KB

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