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.

1506 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. #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.
  322. * @return 0 on success, < 0 on error.
  323. * When returning an error, pkt must not have been allocated
  324. * or must be freed before returning
  325. */
  326. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  327. /**
  328. * Close the stream. The AVFormatContext and AVStreams are not
  329. * freed by this function
  330. */
  331. int (*read_close)(struct AVFormatContext *);
  332. #if LIBAVFORMAT_VERSION_MAJOR < 53
  333. /**
  334. * Seek to a given timestamp relative to the frames in
  335. * stream component stream_index.
  336. * @param stream_index Must not be -1.
  337. * @param flags Selects which direction should be preferred if no exact
  338. * match is available.
  339. * @return >= 0 on success (but not necessarily the new offset)
  340. */
  341. int (*read_seek)(struct AVFormatContext *,
  342. int stream_index, int64_t timestamp, int flags);
  343. #endif
  344. /**
  345. * Gets the next timestamp in stream[stream_index].time_base units.
  346. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  347. */
  348. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  349. int64_t *pos, int64_t pos_limit);
  350. /**
  351. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
  352. */
  353. int flags;
  354. /**
  355. * If extensions are defined, then no probe is done. You should
  356. * usually not use extension format guessing because it is not
  357. * reliable enough
  358. */
  359. const char *extensions;
  360. /**
  361. * General purpose read-only value that the format can use.
  362. */
  363. int value;
  364. /**
  365. * Start/resume playing - only meaningful if using a network-based format
  366. * (RTSP).
  367. */
  368. int (*read_play)(struct AVFormatContext *);
  369. /**
  370. * Pause playing - only meaningful if using a network-based format
  371. * (RTSP).
  372. */
  373. int (*read_pause)(struct AVFormatContext *);
  374. const struct AVCodecTag * const *codec_tag;
  375. /**
  376. * Seek to timestamp ts.
  377. * Seeking will be done so that the point from which all active streams
  378. * can be presented successfully will be closest to ts and within min/max_ts.
  379. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  380. */
  381. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  382. const AVMetadataConv *metadata_conv;
  383. /* private fields */
  384. struct AVInputFormat *next;
  385. } AVInputFormat;
  386. enum AVStreamParseType {
  387. AVSTREAM_PARSE_NONE,
  388. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  389. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  390. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  391. AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
  392. };
  393. typedef struct AVIndexEntry {
  394. int64_t pos;
  395. int64_t timestamp;
  396. #define AVINDEX_KEYFRAME 0x0001
  397. int flags:2;
  398. 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).
  399. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  400. } AVIndexEntry;
  401. #define AV_DISPOSITION_DEFAULT 0x0001
  402. #define AV_DISPOSITION_DUB 0x0002
  403. #define AV_DISPOSITION_ORIGINAL 0x0004
  404. #define AV_DISPOSITION_COMMENT 0x0008
  405. #define AV_DISPOSITION_LYRICS 0x0010
  406. #define AV_DISPOSITION_KARAOKE 0x0020
  407. /**
  408. * Track should be used during playback by default.
  409. * Useful for subtitle track that should be displayed
  410. * even when user did not explicitly ask for subtitles.
  411. */
  412. #define AV_DISPOSITION_FORCED 0x0040
  413. /**
  414. * Stream structure.
  415. * New fields can be added to the end with minor version bumps.
  416. * Removal, reordering and changes to existing fields require a major
  417. * version bump.
  418. * sizeof(AVStream) must not be used outside libav*.
  419. */
  420. typedef struct AVStream {
  421. int index; /**< stream index in AVFormatContext */
  422. int id; /**< format-specific stream ID */
  423. AVCodecContext *codec; /**< codec context */
  424. /**
  425. * Real base framerate of the stream.
  426. * This is the lowest framerate with which all timestamps can be
  427. * represented accurately (it is the least common multiple of all
  428. * framerates in the stream). Note, this value is just a guess!
  429. * For example, if the time base is 1/90000 and all frames have either
  430. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  431. */
  432. AVRational r_frame_rate;
  433. void *priv_data;
  434. /* internal data used in av_find_stream_info() */
  435. int64_t first_dts;
  436. /**
  437. * encoding: pts generation when outputting stream
  438. */
  439. struct AVFrac pts;
  440. /**
  441. * This is the fundamental unit of time (in seconds) in terms
  442. * of which frame timestamps are represented. For fixed-fps content,
  443. * time base should be 1/framerate and timestamp increments should be 1.
  444. */
  445. AVRational time_base;
  446. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  447. /* ffmpeg.c private use */
  448. int stream_copy; /**< If set, just copy stream. */
  449. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  450. //FIXME move stuff to a flags field?
  451. /**
  452. * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
  453. * MN: dunno if that is the right place for it
  454. */
  455. float quality;
  456. /**
  457. * Decoding: pts of the first frame of the stream, in stream time base.
  458. * Only set this if you are absolutely 100% sure that the value you set
  459. * it to really is the pts of the first frame.
  460. * This may be undefined (AV_NOPTS_VALUE).
  461. * @note The ASF header does NOT contain a correct start_time the ASF
  462. * demuxer must NOT set this.
  463. */
  464. int64_t start_time;
  465. /**
  466. * Decoding: duration of the stream, in stream time base.
  467. * If a source file does not specify a duration, but does specify
  468. * a bitrate, this value will be estimated from bitrate and file size.
  469. */
  470. int64_t duration;
  471. #if FF_API_OLD_METADATA
  472. char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */
  473. #endif
  474. /* av_read_frame() support */
  475. enum AVStreamParseType need_parsing;
  476. struct AVCodecParserContext *parser;
  477. int64_t cur_dts;
  478. int last_IP_duration;
  479. int64_t last_IP_pts;
  480. /* av_seek_frame() support */
  481. AVIndexEntry *index_entries; /**< Only used if the format does not
  482. support seeking natively. */
  483. int nb_index_entries;
  484. unsigned int index_entries_allocated_size;
  485. int64_t nb_frames; ///< number of frames in this stream if known or 0
  486. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  487. int64_t unused[4+1];
  488. #endif
  489. #if FF_API_OLD_METADATA
  490. char *filename; /**< source filename of the stream */
  491. #endif
  492. int disposition; /**< AV_DISPOSITION_* bit field */
  493. AVProbeData probe_data;
  494. #define MAX_REORDER_DELAY 16
  495. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  496. /**
  497. * sample aspect ratio (0 if unknown)
  498. * - encoding: Set by user.
  499. * - decoding: Set by libavformat.
  500. */
  501. AVRational sample_aspect_ratio;
  502. AVMetadata *metadata;
  503. /* Intended mostly for av_read_frame() support. Not supposed to be used by */
  504. /* external applications; try to use something else if at all possible. */
  505. const uint8_t *cur_ptr;
  506. int cur_len;
  507. AVPacket cur_pkt;
  508. // Timestamp generation support:
  509. /**
  510. * Timestamp corresponding to the last dts sync point.
  511. *
  512. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  513. * a DTS is received from the underlying container. Otherwise set to
  514. * AV_NOPTS_VALUE by default.
  515. */
  516. int64_t reference_dts;
  517. /**
  518. * Number of packets to buffer for codec probing
  519. * NOT PART OF PUBLIC API
  520. */
  521. #define MAX_PROBE_PACKETS 2500
  522. int probe_packets;
  523. /**
  524. * last packet in packet_buffer for this stream when muxing.
  525. * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
  526. */
  527. struct AVPacketList *last_in_packet_buffer;
  528. /**
  529. * Average framerate
  530. */
  531. AVRational avg_frame_rate;
  532. /**
  533. * Number of frames that have been demuxed during av_find_stream_info()
  534. */
  535. int codec_info_nb_frames;
  536. } AVStream;
  537. #define AV_PROGRAM_RUNNING 1
  538. /**
  539. * New fields can be added to the end with minor version bumps.
  540. * Removal, reordering and changes to existing fields require a major
  541. * version bump.
  542. * sizeof(AVProgram) must not be used outside libav*.
  543. */
  544. typedef struct AVProgram {
  545. int id;
  546. #if FF_API_OLD_METADATA
  547. char *provider_name; ///< network name for DVB streams
  548. char *name; ///< service name for DVB streams
  549. #endif
  550. int flags;
  551. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  552. unsigned int *stream_index;
  553. unsigned int nb_stream_indexes;
  554. AVMetadata *metadata;
  555. } AVProgram;
  556. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  557. (streams are added dynamically) */
  558. typedef struct AVChapter {
  559. int id; ///< unique ID to identify the chapter
  560. AVRational time_base; ///< time base in which the start/end timestamps are specified
  561. int64_t start, end; ///< chapter start/end time in time_base units
  562. #if FF_API_OLD_METADATA
  563. char *title; ///< chapter title
  564. #endif
  565. AVMetadata *metadata;
  566. } AVChapter;
  567. #if FF_API_MAX_STREAMS
  568. #define MAX_STREAMS 20
  569. #endif
  570. /**
  571. * Format I/O context.
  572. * New fields can be added to the end with minor version bumps.
  573. * Removal, reordering and changes to existing fields require a major
  574. * version bump.
  575. * sizeof(AVFormatContext) must not be used outside libav*.
  576. */
  577. typedef struct AVFormatContext {
  578. const AVClass *av_class; /**< Set by avformat_alloc_context. */
  579. /* Can only be iformat or oformat, not both at the same time. */
  580. struct AVInputFormat *iformat;
  581. struct AVOutputFormat *oformat;
  582. void *priv_data;
  583. ByteIOContext *pb;
  584. unsigned int nb_streams;
  585. AVStream *streams[MAX_STREAMS];
  586. char filename[1024]; /**< input or output filename */
  587. /* stream info */
  588. int64_t timestamp;
  589. #if FF_API_OLD_METADATA
  590. char title[512];
  591. char author[512];
  592. char copyright[512];
  593. char comment[512];
  594. char album[512];
  595. int year; /**< ID3 year, 0 if none */
  596. int track; /**< track number, 0 if none */
  597. char genre[32]; /**< ID3 genre */
  598. #endif
  599. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  600. /* private data for pts handling (do not modify directly). */
  601. /**
  602. * This buffer is only needed when packets were already buffered but
  603. * not decoded, for example to get the codec parameters in MPEG
  604. * streams.
  605. */
  606. struct AVPacketList *packet_buffer;
  607. /**
  608. * Decoding: position of the first frame of the component, in
  609. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  610. * It is deduced from the AVStream values.
  611. */
  612. int64_t start_time;
  613. /**
  614. * Decoding: duration of the stream, in AV_TIME_BASE fractional
  615. * seconds. Only set this value if you know none of the individual stream
  616. * durations and also dont set any of them. This is deduced from the
  617. * AVStream values if not set.
  618. */
  619. int64_t duration;
  620. /**
  621. * decoding: total file size, 0 if unknown
  622. */
  623. int64_t file_size;
  624. /**
  625. * Decoding: total stream bitrate in bit/s, 0 if not
  626. * available. Never set it directly if the file_size and the
  627. * duration are known as FFmpeg can compute it automatically.
  628. */
  629. int bit_rate;
  630. /* av_read_frame() support */
  631. AVStream *cur_st;
  632. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  633. const uint8_t *cur_ptr_deprecated;
  634. int cur_len_deprecated;
  635. AVPacket cur_pkt_deprecated;
  636. #endif
  637. /* av_seek_frame() support */
  638. int64_t data_offset; /**< offset of the first packet */
  639. int index_built;
  640. int mux_rate;
  641. unsigned int packet_size;
  642. int preload;
  643. int max_delay;
  644. #define AVFMT_NOOUTPUTLOOP -1
  645. #define AVFMT_INFINITEOUTPUTLOOP 0
  646. /**
  647. * number of times to loop output in formats that support it
  648. */
  649. int loop_output;
  650. int flags;
  651. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  652. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  653. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  654. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  655. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  656. #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
  657. #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file
  658. int loop_input;
  659. /**
  660. * decoding: size of data to probe; encoding: unused.
  661. */
  662. unsigned int probesize;
  663. /**
  664. * Maximum time (in AV_TIME_BASE units) during which the input should
  665. * be analyzed in av_find_stream_info().
  666. */
  667. int max_analyze_duration;
  668. const uint8_t *key;
  669. int keylen;
  670. unsigned int nb_programs;
  671. AVProgram **programs;
  672. /**
  673. * Forced video codec_id.
  674. * Demuxing: Set by user.
  675. */
  676. enum CodecID video_codec_id;
  677. /**
  678. * Forced audio codec_id.
  679. * Demuxing: Set by user.
  680. */
  681. enum CodecID audio_codec_id;
  682. /**
  683. * Forced subtitle codec_id.
  684. * Demuxing: Set by user.
  685. */
  686. enum CodecID subtitle_codec_id;
  687. /**
  688. * Maximum amount of memory in bytes to use for the index of each stream.
  689. * If the index exceeds this size, entries will be discarded as
  690. * needed to maintain a smaller size. This can lead to slower or less
  691. * accurate seeking (depends on demuxer).
  692. * Demuxers for which a full in-memory index is mandatory will ignore
  693. * this.
  694. * muxing : unused
  695. * demuxing: set by user
  696. */
  697. unsigned int max_index_size;
  698. /**
  699. * Maximum amount of memory in bytes to use for buffering frames
  700. * obtained from realtime capture devices.
  701. */
  702. unsigned int max_picture_buffer;
  703. unsigned int nb_chapters;
  704. AVChapter **chapters;
  705. /**
  706. * Flags to enable debugging.
  707. */
  708. int debug;
  709. #define FF_FDEBUG_TS 0x0001
  710. /**
  711. * Raw packets from the demuxer, prior to parsing and decoding.
  712. * This buffer is used for buffering packets until the codec can
  713. * be identified, as parsing cannot be done without knowing the
  714. * codec.
  715. */
  716. struct AVPacketList *raw_packet_buffer;
  717. struct AVPacketList *raw_packet_buffer_end;
  718. struct AVPacketList *packet_buffer_end;
  719. AVMetadata *metadata;
  720. /**
  721. * Remaining size available for raw_packet_buffer, in bytes.
  722. * NOT PART OF PUBLIC API
  723. */
  724. #define RAW_PACKET_BUFFER_SIZE 2500000
  725. int raw_packet_buffer_remaining_size;
  726. /**
  727. * Start time of the stream in real world time, in microseconds
  728. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  729. * in the stream was captured at this real world time.
  730. * - encoding: Set by user.
  731. * - decoding: Unused.
  732. */
  733. int64_t start_time_realtime;
  734. } AVFormatContext;
  735. typedef struct AVPacketList {
  736. AVPacket pkt;
  737. struct AVPacketList *next;
  738. } AVPacketList;
  739. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  740. extern AVInputFormat *first_iformat;
  741. extern AVOutputFormat *first_oformat;
  742. #endif
  743. /**
  744. * If f is NULL, returns the first registered input format,
  745. * if f is non-NULL, returns the next registered input format after f
  746. * or NULL if f is the last one.
  747. */
  748. AVInputFormat *av_iformat_next(AVInputFormat *f);
  749. /**
  750. * If f is NULL, returns the first registered output format,
  751. * if f is non-NULL, returns the next registered output format after f
  752. * or NULL if f is the last one.
  753. */
  754. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  755. enum CodecID av_guess_image2_codec(const char *filename);
  756. /* XXX: Use automatic init with either ELF sections or C file parser */
  757. /* modules. */
  758. /* utils.c */
  759. void av_register_input_format(AVInputFormat *format);
  760. void av_register_output_format(AVOutputFormat *format);
  761. #if LIBAVFORMAT_VERSION_MAJOR < 53
  762. attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
  763. const char *filename,
  764. const char *mime_type);
  765. /**
  766. * @deprecated Use av_guess_format() instead.
  767. */
  768. attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
  769. const char *filename,
  770. const char *mime_type);
  771. #endif
  772. /**
  773. * Return the output format in the list of registered output formats
  774. * which best matches the provided parameters, or return NULL if
  775. * there is no match.
  776. *
  777. * @param short_name if non-NULL checks if short_name matches with the
  778. * names of the registered formats
  779. * @param filename if non-NULL checks if filename terminates with the
  780. * extensions of the registered formats
  781. * @param mime_type if non-NULL checks if mime_type matches with the
  782. * MIME type of the registered formats
  783. */
  784. AVOutputFormat *av_guess_format(const char *short_name,
  785. const char *filename,
  786. const char *mime_type);
  787. /**
  788. * Guess the codec ID based upon muxer and filename.
  789. */
  790. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  791. const char *filename, const char *mime_type,
  792. enum AVMediaType type);
  793. /**
  794. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  795. *
  796. * @param f The file stream pointer where the dump should be sent to.
  797. * @param buf buffer
  798. * @param size buffer size
  799. *
  800. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  801. */
  802. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  803. /**
  804. * Send a nice hexadecimal dump of a buffer to the log.
  805. *
  806. * @param avcl A pointer to an arbitrary struct of which the first field is a
  807. * pointer to an AVClass struct.
  808. * @param level The importance level of the message, lower values signifying
  809. * higher importance.
  810. * @param buf buffer
  811. * @param size buffer size
  812. *
  813. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  814. */
  815. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  816. /**
  817. * Send a nice dump of a packet to the specified file stream.
  818. *
  819. * @param f The file stream pointer where the dump should be sent to.
  820. * @param pkt packet to dump
  821. * @param dump_payload True if the payload must be displayed, too.
  822. */
  823. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  824. /**
  825. * Send a nice dump of a packet to the log.
  826. *
  827. * @param avcl A pointer to an arbitrary struct of which the first field is a
  828. * pointer to an AVClass struct.
  829. * @param level The importance level of the message, lower values signifying
  830. * higher importance.
  831. * @param pkt packet to dump
  832. * @param dump_payload True if the payload must be displayed, too.
  833. */
  834. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  835. /**
  836. * Initialize libavformat and register all the muxers, demuxers and
  837. * protocols. If you do not call this function, then you can select
  838. * exactly which formats you want to support.
  839. *
  840. * @see av_register_input_format()
  841. * @see av_register_output_format()
  842. * @see av_register_protocol()
  843. */
  844. void av_register_all(void);
  845. /**
  846. * Get the CodecID for the given codec tag tag.
  847. * If no codec id is found returns CODEC_ID_NONE.
  848. *
  849. * @param tags list of supported codec_id-codec_tag pairs, as stored
  850. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  851. */
  852. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  853. /**
  854. * Get the codec tag for the given codec id id.
  855. * If no codec tag is found returns 0.
  856. *
  857. * @param tags list of supported codec_id-codec_tag pairs, as stored
  858. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  859. */
  860. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  861. /* media file input */
  862. /**
  863. * Find AVInputFormat based on the short name of the input format.
  864. */
  865. AVInputFormat *av_find_input_format(const char *short_name);
  866. /**
  867. * Guess the file format.
  868. *
  869. * @param is_opened Whether the file is already opened; determines whether
  870. * demuxers with or without AVFMT_NOFILE are probed.
  871. */
  872. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  873. /**
  874. * Guess the file format.
  875. *
  876. * @param is_opened Whether the file is already opened; determines whether
  877. * demuxers with or without AVFMT_NOFILE are probed.
  878. * @param score_max A probe score larger that this is required to accept a
  879. * detection, the variable is set to the actual detection
  880. * score afterwards.
  881. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  882. * to retry with a larger probe buffer.
  883. */
  884. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  885. /**
  886. * Allocate all the structures needed to read an input stream.
  887. * This does not open the needed codecs for decoding the stream[s].
  888. */
  889. int av_open_input_stream(AVFormatContext **ic_ptr,
  890. ByteIOContext *pb, const char *filename,
  891. AVInputFormat *fmt, AVFormatParameters *ap);
  892. /**
  893. * Open a media file as input. The codecs are not opened. Only the file
  894. * header (if present) is read.
  895. *
  896. * @param ic_ptr The opened media file handle is put here.
  897. * @param filename filename to open
  898. * @param fmt If non-NULL, force the file format to use.
  899. * @param buf_size optional buffer size (zero if default is OK)
  900. * @param ap Additional parameters needed when opening the file
  901. * (NULL if default).
  902. * @return 0 if OK, AVERROR_xxx otherwise
  903. */
  904. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  905. AVInputFormat *fmt,
  906. int buf_size,
  907. AVFormatParameters *ap);
  908. #if LIBAVFORMAT_VERSION_MAJOR < 53
  909. /**
  910. * @deprecated Use avformat_alloc_context() instead.
  911. */
  912. attribute_deprecated AVFormatContext *av_alloc_format_context(void);
  913. #endif
  914. /**
  915. * Allocate an AVFormatContext.
  916. * Can be freed with av_free() but do not forget to free everything you
  917. * explicitly allocated as well!
  918. */
  919. AVFormatContext *avformat_alloc_context(void);
  920. /**
  921. * Read packets of a media file to get stream information. This
  922. * is useful for file formats with no headers such as MPEG. This
  923. * function also computes the real framerate in case of MPEG-2 repeat
  924. * frame mode.
  925. * The logical file position is not changed by this function;
  926. * examined packets may be buffered for later processing.
  927. *
  928. * @param ic media file handle
  929. * @return >=0 if OK, AVERROR_xxx on error
  930. * @todo Let the user decide somehow what information is needed so that
  931. * we do not waste time getting stuff the user does not need.
  932. */
  933. int av_find_stream_info(AVFormatContext *ic);
  934. /**
  935. * Read a transport packet from a media file.
  936. *
  937. * This function is obsolete and should never be used.
  938. * Use av_read_frame() instead.
  939. *
  940. * @param s media file handle
  941. * @param pkt is filled
  942. * @return 0 if OK, AVERROR_xxx on error
  943. */
  944. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  945. /**
  946. * Return the next frame of a stream.
  947. *
  948. * The returned packet is valid
  949. * until the next av_read_frame() or until av_close_input_file() and
  950. * must be freed with av_free_packet. For video, the packet contains
  951. * exactly one frame. For audio, it contains an integer number of
  952. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  953. * data). If the audio frames have a variable size (e.g. MPEG audio),
  954. * then it contains one frame.
  955. *
  956. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  957. * values in AVStream.time_base units (and guessed if the format cannot
  958. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  959. * has B-frames, so it is better to rely on pkt->dts if you do not
  960. * decompress the payload.
  961. *
  962. * @return 0 if OK, < 0 on error or end of file
  963. */
  964. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  965. /**
  966. * Seek to the keyframe at timestamp.
  967. * 'timestamp' in 'stream_index'.
  968. * @param stream_index If stream_index is (-1), a default
  969. * stream is selected, and timestamp is automatically converted
  970. * from AV_TIME_BASE units to the stream specific time_base.
  971. * @param timestamp Timestamp in AVStream.time_base units
  972. * or, if no stream is specified, in AV_TIME_BASE units.
  973. * @param flags flags which select direction and seeking mode
  974. * @return >= 0 on success
  975. */
  976. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  977. int flags);
  978. /**
  979. * Seek to timestamp ts.
  980. * Seeking will be done so that the point from which all active streams
  981. * can be presented successfully will be closest to ts and within min/max_ts.
  982. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  983. *
  984. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  985. * are the file position (this may not be supported by all demuxers).
  986. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  987. * in the stream with stream_index (this may not be supported by all demuxers).
  988. * Otherwise all timestamps are in units of the stream selected by stream_index
  989. * or if stream_index is -1, in AV_TIME_BASE units.
  990. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  991. * keyframes (this may not be supported by all demuxers).
  992. *
  993. * @param stream_index index of the stream which is used as time base reference
  994. * @param min_ts smallest acceptable timestamp
  995. * @param ts target timestamp
  996. * @param max_ts largest acceptable timestamp
  997. * @param flags flags
  998. * @return >=0 on success, error code otherwise
  999. *
  1000. * @note This is part of the new seek API which is still under construction.
  1001. * Thus do not use this yet. It may change at any time, do not expect
  1002. * ABI compatibility yet!
  1003. */
  1004. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1005. /**
  1006. * Start playing a network-based stream (e.g. RTSP stream) at the
  1007. * current position.
  1008. */
  1009. int av_read_play(AVFormatContext *s);
  1010. /**
  1011. * Pause a network-based stream (e.g. RTSP stream).
  1012. *
  1013. * Use av_read_play() to resume it.
  1014. */
  1015. int av_read_pause(AVFormatContext *s);
  1016. /**
  1017. * Free a AVFormatContext allocated by av_open_input_stream.
  1018. * @param s context to free
  1019. */
  1020. void av_close_input_stream(AVFormatContext *s);
  1021. /**
  1022. * Close a media file (but not its codecs).
  1023. *
  1024. * @param s media file handle
  1025. */
  1026. void av_close_input_file(AVFormatContext *s);
  1027. /**
  1028. * Add a new stream to a media file.
  1029. *
  1030. * Can only be called in the read_header() function. If the flag
  1031. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1032. * can be added in read_packet too.
  1033. *
  1034. * @param s media file handle
  1035. * @param id file-format-dependent stream ID
  1036. */
  1037. AVStream *av_new_stream(AVFormatContext *s, int id);
  1038. AVProgram *av_new_program(AVFormatContext *s, int id);
  1039. /**
  1040. * Add a new chapter.
  1041. * This function is NOT part of the public API
  1042. * and should ONLY be used by demuxers.
  1043. *
  1044. * @param s media file handle
  1045. * @param id unique ID for this chapter
  1046. * @param start chapter start time in time_base units
  1047. * @param end chapter end time in time_base units
  1048. * @param title chapter title
  1049. *
  1050. * @return AVChapter or NULL on error
  1051. */
  1052. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
  1053. int64_t start, int64_t end, const char *title);
  1054. /**
  1055. * Set the pts for a given stream.
  1056. *
  1057. * @param s stream
  1058. * @param pts_wrap_bits number of bits effectively used by the pts
  1059. * (used for wrap control, 33 is the value for MPEG)
  1060. * @param pts_num numerator to convert to seconds (MPEG: 1)
  1061. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  1062. */
  1063. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1064. unsigned int pts_num, unsigned int pts_den);
  1065. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1066. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1067. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1068. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1069. int av_find_default_stream_index(AVFormatContext *s);
  1070. /**
  1071. * Get the index for a specific timestamp.
  1072. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1073. * to the timestamp which is <= the requested one, if backward
  1074. * is 0, then it will be >=
  1075. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1076. * @return < 0 if no such timestamp could be found
  1077. */
  1078. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1079. /**
  1080. * Ensure the index uses less memory than the maximum specified in
  1081. * AVFormatContext.max_index_size by discarding entries if it grows
  1082. * too large.
  1083. * This function is not part of the public API and should only be called
  1084. * by demuxers.
  1085. */
  1086. void ff_reduce_index(AVFormatContext *s, int stream_index);
  1087. /**
  1088. * Add an index entry into a sorted list. Update the entry if the list
  1089. * already contains it.
  1090. *
  1091. * @param timestamp timestamp in the time base of the given stream
  1092. */
  1093. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1094. int size, int distance, int flags);
  1095. /**
  1096. * Perform a binary search using av_index_search_timestamp() and
  1097. * AVInputFormat.read_timestamp().
  1098. * This is not supposed to be called directly by a user application,
  1099. * but by demuxers.
  1100. * @param target_ts target timestamp in the time base of the given stream
  1101. * @param stream_index stream number
  1102. */
  1103. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  1104. int64_t target_ts, int flags);
  1105. /**
  1106. * Update cur_dts of all streams based on the given timestamp and AVStream.
  1107. *
  1108. * Stream ref_st unchanged, others set cur_dts in their native time base.
  1109. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  1110. * @param timestamp new dts expressed in time_base of param ref_st
  1111. * @param ref_st reference stream giving time_base of param timestamp
  1112. */
  1113. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  1114. /**
  1115. * Perform a binary search using read_timestamp().
  1116. * This is not supposed to be called directly by a user application,
  1117. * but by demuxers.
  1118. * @param target_ts target timestamp in the time base of the given stream
  1119. * @param stream_index stream number
  1120. */
  1121. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  1122. int64_t target_ts, int64_t pos_min,
  1123. int64_t pos_max, int64_t pos_limit,
  1124. int64_t ts_min, int64_t ts_max,
  1125. int flags, int64_t *ts_ret,
  1126. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1127. /**
  1128. * media file output
  1129. */
  1130. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1131. /**
  1132. * Split a URL string into components.
  1133. *
  1134. * The pointers to buffers for storing individual components may be null,
  1135. * in order to ignore that component. Buffers for components not found are
  1136. * set to empty strings. If the port is not found, it is set to a negative
  1137. * value.
  1138. *
  1139. * @param proto the buffer for the protocol
  1140. * @param proto_size the size of the proto buffer
  1141. * @param authorization the buffer for the authorization
  1142. * @param authorization_size the size of the authorization buffer
  1143. * @param hostname the buffer for the host name
  1144. * @param hostname_size the size of the hostname buffer
  1145. * @param port_ptr a pointer to store the port number in
  1146. * @param path the buffer for the path
  1147. * @param path_size the size of the path buffer
  1148. * @param url the URL to split
  1149. */
  1150. void av_url_split(char *proto, int proto_size,
  1151. char *authorization, int authorization_size,
  1152. char *hostname, int hostname_size,
  1153. int *port_ptr,
  1154. char *path, int path_size,
  1155. const char *url);
  1156. /**
  1157. * Allocate the stream private data and write the stream header to an
  1158. * output media file.
  1159. *
  1160. * @param s media file handle
  1161. * @return 0 if OK, AVERROR_xxx on error
  1162. */
  1163. int av_write_header(AVFormatContext *s);
  1164. /**
  1165. * Write a packet to an output media file.
  1166. *
  1167. * The packet shall contain one audio or video frame.
  1168. * The packet must be correctly interleaved according to the container
  1169. * specification, if not then av_interleaved_write_frame must be used.
  1170. *
  1171. * @param s media file handle
  1172. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1173. dts/pts, ...
  1174. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1175. */
  1176. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1177. /**
  1178. * Write a packet to an output media file ensuring correct interleaving.
  1179. *
  1180. * The packet must contain one audio or video frame.
  1181. * If the packets are already correctly interleaved, the application should
  1182. * call av_write_frame() instead as it is slightly faster. It is also important
  1183. * to keep in mind that completely non-interleaved input will need huge amounts
  1184. * of memory to interleave with this, so it is preferable to interleave at the
  1185. * demuxer level.
  1186. *
  1187. * @param s media file handle
  1188. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1189. dts/pts, ...
  1190. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1191. */
  1192. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1193. /**
  1194. * Interleave a packet per dts in an output media file.
  1195. *
  1196. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1197. * function, so they cannot be used after it. Note that calling av_free_packet()
  1198. * on them is still safe.
  1199. *
  1200. * @param s media file handle
  1201. * @param out the interleaved packet will be output here
  1202. * @param pkt the input packet
  1203. * @param flush 1 if no further packets are available as input and all
  1204. * remaining packets should be output
  1205. * @return 1 if a packet was output, 0 if no packet could be output,
  1206. * < 0 if an error occurred
  1207. */
  1208. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1209. AVPacket *pkt, int flush);
  1210. /**
  1211. * Write the stream trailer to an output media file and free the
  1212. * file private data.
  1213. *
  1214. * May only be called after a successful call to av_write_header.
  1215. *
  1216. * @param s media file handle
  1217. * @return 0 if OK, AVERROR_xxx on error
  1218. */
  1219. int av_write_trailer(AVFormatContext *s);
  1220. void dump_format(AVFormatContext *ic,
  1221. int index,
  1222. const char *url,
  1223. int is_output);
  1224. #if LIBAVFORMAT_VERSION_MAJOR < 53
  1225. /**
  1226. * Parse width and height out of string str.
  1227. * @deprecated Use av_parse_video_frame_size instead.
  1228. */
  1229. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
  1230. const char *str);
  1231. /**
  1232. * Convert framerate from a string to a fraction.
  1233. * @deprecated Use av_parse_video_frame_rate instead.
  1234. */
  1235. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
  1236. const char *arg);
  1237. #endif
  1238. /**
  1239. * Parse datestr and return a corresponding number of microseconds.
  1240. * @param datestr String representing a date or a duration.
  1241. * - If a date the syntax is:
  1242. * @code
  1243. * now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
  1244. * @endcode
  1245. * If the value is "now" it takes the current time.
  1246. * Time is local time unless Z is appended, in which case it is
  1247. * interpreted as UTC.
  1248. * If the year-month-day part is not specified it takes the current
  1249. * year-month-day.
  1250. * @return the number of microseconds since 1st of January, 1970 up to
  1251. * the time of the parsed date or INT64_MIN if datestr cannot be
  1252. * successfully parsed.
  1253. * - If a duration the syntax is:
  1254. * @code
  1255. * [-]HH[:MM[:SS[.m...]]]
  1256. * [-]S+[.m...]
  1257. * @endcode
  1258. * @return the number of microseconds contained in a time interval
  1259. * with the specified duration or INT64_MIN if datestr cannot be
  1260. * successfully parsed.
  1261. * @param duration Flag which tells how to interpret datestr, if
  1262. * not zero datestr is interpreted as a duration, otherwise as a
  1263. * date.
  1264. */
  1265. int64_t parse_date(const char *datestr, int duration);
  1266. /**
  1267. * Get the current time in microseconds.
  1268. */
  1269. int64_t av_gettime(void);
  1270. /* ffm-specific for ffserver */
  1271. #define FFM_PACKET_SIZE 4096
  1272. int64_t ffm_read_write_index(int fd);
  1273. int ffm_write_write_index(int fd, int64_t pos);
  1274. void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
  1275. /**
  1276. * Attempt to find a specific tag in a URL.
  1277. *
  1278. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  1279. * Return 1 if found.
  1280. */
  1281. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1282. /**
  1283. * Return in 'buf' the path with '%d' replaced by a number.
  1284. *
  1285. * Also handles the '%0nd' format where 'n' is the total number
  1286. * of digits and '%%'.
  1287. *
  1288. * @param buf destination buffer
  1289. * @param buf_size destination buffer size
  1290. * @param path numbered sequence string
  1291. * @param number frame number
  1292. * @return 0 if OK, -1 on format error
  1293. */
  1294. int av_get_frame_filename(char *buf, int buf_size,
  1295. const char *path, int number);
  1296. /**
  1297. * Check whether filename actually is a numbered sequence generator.
  1298. *
  1299. * @param filename possible numbered sequence string
  1300. * @return 1 if a valid numbered sequence string, 0 otherwise
  1301. */
  1302. int av_filename_number_test(const char *filename);
  1303. /**
  1304. * Generate an SDP for an RTP session.
  1305. *
  1306. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1307. * array is composed by only one context, such context can contain
  1308. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1309. * all the contexts in the array (an AVCodecContext per RTP stream)
  1310. * must contain only one AVStream.
  1311. * @param n_files number of AVCodecContexts contained in ac
  1312. * @param buff buffer where the SDP will be stored (must be allocated by
  1313. * the caller)
  1314. * @param size the size of the buffer
  1315. * @return 0 if OK, AVERROR_xxx on error
  1316. */
  1317. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1318. /**
  1319. * Return a positive value if the given filename has one of the given
  1320. * extensions, 0 otherwise.
  1321. *
  1322. * @param extensions a comma-separated list of filename extensions
  1323. */
  1324. int av_match_ext(const char *filename, const char *extensions);
  1325. #endif /* AVFORMAT_AVFORMAT_H */