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.

1512 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. AVStream *streams[MAX_STREAMS];
  587. char filename[1024]; /**< input or output filename */
  588. /* stream info */
  589. int64_t timestamp;
  590. #if FF_API_OLD_METADATA
  591. char title[512];
  592. char author[512];
  593. char copyright[512];
  594. char comment[512];
  595. char album[512];
  596. int year; /**< ID3 year, 0 if none */
  597. int track; /**< track number, 0 if none */
  598. char genre[32]; /**< ID3 genre */
  599. #endif
  600. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  601. /* private data for pts handling (do not modify directly). */
  602. /**
  603. * This buffer is only needed when packets were already buffered but
  604. * not decoded, for example to get the codec parameters in MPEG
  605. * streams.
  606. */
  607. struct AVPacketList *packet_buffer;
  608. /**
  609. * Decoding: position of the first frame of the component, in
  610. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  611. * It is deduced from the AVStream values.
  612. */
  613. int64_t start_time;
  614. /**
  615. * Decoding: duration of the stream, in AV_TIME_BASE fractional
  616. * seconds. Only set this value if you know none of the individual stream
  617. * durations and also dont set any of them. This is deduced from the
  618. * AVStream values if not set.
  619. */
  620. int64_t duration;
  621. /**
  622. * decoding: total file size, 0 if unknown
  623. */
  624. int64_t file_size;
  625. /**
  626. * Decoding: total stream bitrate in bit/s, 0 if not
  627. * available. Never set it directly if the file_size and the
  628. * duration are known as FFmpeg can compute it automatically.
  629. */
  630. int bit_rate;
  631. /* av_read_frame() support */
  632. AVStream *cur_st;
  633. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  634. const uint8_t *cur_ptr_deprecated;
  635. int cur_len_deprecated;
  636. AVPacket cur_pkt_deprecated;
  637. #endif
  638. /* av_seek_frame() support */
  639. int64_t data_offset; /**< offset of the first packet */
  640. int index_built;
  641. int mux_rate;
  642. unsigned int packet_size;
  643. int preload;
  644. int max_delay;
  645. #define AVFMT_NOOUTPUTLOOP -1
  646. #define AVFMT_INFINITEOUTPUTLOOP 0
  647. /**
  648. * number of times to loop output in formats that support it
  649. */
  650. int loop_output;
  651. int flags;
  652. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  653. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  654. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  655. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  656. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  657. #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
  658. #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file
  659. int loop_input;
  660. /**
  661. * decoding: size of data to probe; encoding: unused.
  662. */
  663. unsigned int probesize;
  664. /**
  665. * Maximum time (in AV_TIME_BASE units) during which the input should
  666. * be analyzed in av_find_stream_info().
  667. */
  668. int max_analyze_duration;
  669. const uint8_t *key;
  670. int keylen;
  671. unsigned int nb_programs;
  672. AVProgram **programs;
  673. /**
  674. * Forced video codec_id.
  675. * Demuxing: Set by user.
  676. */
  677. enum CodecID video_codec_id;
  678. /**
  679. * Forced audio codec_id.
  680. * Demuxing: Set by user.
  681. */
  682. enum CodecID audio_codec_id;
  683. /**
  684. * Forced subtitle codec_id.
  685. * Demuxing: Set by user.
  686. */
  687. enum CodecID subtitle_codec_id;
  688. /**
  689. * Maximum amount of memory in bytes to use for the index of each stream.
  690. * If the index exceeds this size, entries will be discarded as
  691. * needed to maintain a smaller size. This can lead to slower or less
  692. * accurate seeking (depends on demuxer).
  693. * Demuxers for which a full in-memory index is mandatory will ignore
  694. * this.
  695. * muxing : unused
  696. * demuxing: set by user
  697. */
  698. unsigned int max_index_size;
  699. /**
  700. * Maximum amount of memory in bytes to use for buffering frames
  701. * obtained from realtime capture devices.
  702. */
  703. unsigned int max_picture_buffer;
  704. unsigned int nb_chapters;
  705. AVChapter **chapters;
  706. /**
  707. * Flags to enable debugging.
  708. */
  709. int debug;
  710. #define FF_FDEBUG_TS 0x0001
  711. /**
  712. * Raw packets from the demuxer, prior to parsing and decoding.
  713. * This buffer is used for buffering packets until the codec can
  714. * be identified, as parsing cannot be done without knowing the
  715. * codec.
  716. */
  717. struct AVPacketList *raw_packet_buffer;
  718. struct AVPacketList *raw_packet_buffer_end;
  719. struct AVPacketList *packet_buffer_end;
  720. AVMetadata *metadata;
  721. /**
  722. * Remaining size available for raw_packet_buffer, in bytes.
  723. * NOT PART OF PUBLIC API
  724. */
  725. #define RAW_PACKET_BUFFER_SIZE 2500000
  726. int raw_packet_buffer_remaining_size;
  727. /**
  728. * Start time of the stream in real world time, in microseconds
  729. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  730. * in the stream was captured at this real world time.
  731. * - encoding: Set by user.
  732. * - decoding: Unused.
  733. */
  734. int64_t start_time_realtime;
  735. } AVFormatContext;
  736. typedef struct AVPacketList {
  737. AVPacket pkt;
  738. struct AVPacketList *next;
  739. } AVPacketList;
  740. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  741. extern AVInputFormat *first_iformat;
  742. extern AVOutputFormat *first_oformat;
  743. #endif
  744. /**
  745. * If f is NULL, returns the first registered input format,
  746. * if f is non-NULL, returns the next registered input format after f
  747. * or NULL if f is the last one.
  748. */
  749. AVInputFormat *av_iformat_next(AVInputFormat *f);
  750. /**
  751. * If f is NULL, returns the first registered output format,
  752. * if f is non-NULL, returns the next registered output format after f
  753. * or NULL if f is the last one.
  754. */
  755. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  756. enum CodecID av_guess_image2_codec(const char *filename);
  757. /* XXX: Use automatic init with either ELF sections or C file parser */
  758. /* modules. */
  759. /* utils.c */
  760. void av_register_input_format(AVInputFormat *format);
  761. void av_register_output_format(AVOutputFormat *format);
  762. #if LIBAVFORMAT_VERSION_MAJOR < 53
  763. attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
  764. const char *filename,
  765. const char *mime_type);
  766. /**
  767. * @deprecated Use av_guess_format() instead.
  768. */
  769. attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
  770. const char *filename,
  771. const char *mime_type);
  772. #endif
  773. /**
  774. * Return the output format in the list of registered output formats
  775. * which best matches the provided parameters, or return NULL if
  776. * there is no match.
  777. *
  778. * @param short_name if non-NULL checks if short_name matches with the
  779. * names of the registered formats
  780. * @param filename if non-NULL checks if filename terminates with the
  781. * extensions of the registered formats
  782. * @param mime_type if non-NULL checks if mime_type matches with the
  783. * MIME type of the registered formats
  784. */
  785. AVOutputFormat *av_guess_format(const char *short_name,
  786. const char *filename,
  787. const char *mime_type);
  788. /**
  789. * Guess the codec ID based upon muxer and filename.
  790. */
  791. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  792. const char *filename, const char *mime_type,
  793. enum AVMediaType type);
  794. /**
  795. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  796. *
  797. * @param f The file stream pointer where the dump should be sent to.
  798. * @param buf buffer
  799. * @param size buffer size
  800. *
  801. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  802. */
  803. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  804. /**
  805. * Send a nice hexadecimal dump of a buffer to the log.
  806. *
  807. * @param avcl A pointer to an arbitrary struct of which the first field is a
  808. * pointer to an AVClass struct.
  809. * @param level The importance level of the message, lower values signifying
  810. * higher importance.
  811. * @param buf buffer
  812. * @param size buffer size
  813. *
  814. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  815. */
  816. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  817. /**
  818. * Send a nice dump of a packet to the specified file stream.
  819. *
  820. * @param f The file stream pointer where the dump should be sent to.
  821. * @param pkt packet to dump
  822. * @param dump_payload True if the payload must be displayed, too.
  823. */
  824. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  825. /**
  826. * Send a nice dump of a packet to the log.
  827. *
  828. * @param avcl A pointer to an arbitrary struct of which the first field is a
  829. * pointer to an AVClass struct.
  830. * @param level The importance level of the message, lower values signifying
  831. * higher importance.
  832. * @param pkt packet to dump
  833. * @param dump_payload True if the payload must be displayed, too.
  834. */
  835. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  836. /**
  837. * Initialize libavformat and register all the muxers, demuxers and
  838. * protocols. If you do not call this function, then you can select
  839. * exactly which formats you want to support.
  840. *
  841. * @see av_register_input_format()
  842. * @see av_register_output_format()
  843. * @see av_register_protocol()
  844. */
  845. void av_register_all(void);
  846. /**
  847. * Get the CodecID for the given codec tag tag.
  848. * If no codec id is found returns CODEC_ID_NONE.
  849. *
  850. * @param tags list of supported codec_id-codec_tag pairs, as stored
  851. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  852. */
  853. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  854. /**
  855. * Get the codec tag for the given codec id id.
  856. * If no codec tag is found returns 0.
  857. *
  858. * @param tags list of supported codec_id-codec_tag pairs, as stored
  859. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  860. */
  861. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  862. /* media file input */
  863. /**
  864. * Find AVInputFormat based on the short name of the input format.
  865. */
  866. AVInputFormat *av_find_input_format(const char *short_name);
  867. /**
  868. * Guess the file format.
  869. *
  870. * @param is_opened Whether the file is already opened; determines whether
  871. * demuxers with or without AVFMT_NOFILE are probed.
  872. */
  873. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  874. /**
  875. * Guess the file format.
  876. *
  877. * @param is_opened Whether the file is already opened; determines whether
  878. * demuxers with or without AVFMT_NOFILE are probed.
  879. * @param score_max A probe score larger that this is required to accept a
  880. * detection, the variable is set to the actual detection
  881. * score afterwards.
  882. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  883. * to retry with a larger probe buffer.
  884. */
  885. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  886. /**
  887. * Allocate all the structures needed to read an input stream.
  888. * This does not open the needed codecs for decoding the stream[s].
  889. */
  890. int av_open_input_stream(AVFormatContext **ic_ptr,
  891. ByteIOContext *pb, const char *filename,
  892. AVInputFormat *fmt, AVFormatParameters *ap);
  893. /**
  894. * Open a media file as input. The codecs are not opened. Only the file
  895. * header (if present) is read.
  896. *
  897. * @param ic_ptr The opened media file handle is put here.
  898. * @param filename filename to open
  899. * @param fmt If non-NULL, force the file format to use.
  900. * @param buf_size optional buffer size (zero if default is OK)
  901. * @param ap Additional parameters needed when opening the file
  902. * (NULL if default).
  903. * @return 0 if OK, AVERROR_xxx otherwise
  904. */
  905. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  906. AVInputFormat *fmt,
  907. int buf_size,
  908. AVFormatParameters *ap);
  909. #if LIBAVFORMAT_VERSION_MAJOR < 53
  910. /**
  911. * @deprecated Use avformat_alloc_context() instead.
  912. */
  913. attribute_deprecated AVFormatContext *av_alloc_format_context(void);
  914. #endif
  915. /**
  916. * Allocate an AVFormatContext.
  917. * Can be freed with av_free() but do not forget to free everything you
  918. * explicitly allocated as well!
  919. */
  920. AVFormatContext *avformat_alloc_context(void);
  921. /**
  922. * Read packets of a media file to get stream information. This
  923. * is useful for file formats with no headers such as MPEG. This
  924. * function also computes the real framerate in case of MPEG-2 repeat
  925. * frame mode.
  926. * The logical file position is not changed by this function;
  927. * examined packets may be buffered for later processing.
  928. *
  929. * @param ic media file handle
  930. * @return >=0 if OK, AVERROR_xxx on error
  931. * @todo Let the user decide somehow what information is needed so that
  932. * we do not waste time getting stuff the user does not need.
  933. */
  934. int av_find_stream_info(AVFormatContext *ic);
  935. /**
  936. * Read a transport packet from a media file.
  937. *
  938. * This function is obsolete and should never be used.
  939. * Use av_read_frame() instead.
  940. *
  941. * @param s media file handle
  942. * @param pkt is filled
  943. * @return 0 if OK, AVERROR_xxx on error
  944. */
  945. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  946. /**
  947. * Return the next frame of a stream.
  948. * This function returns what is stored in the file, and does not validate
  949. * that what is there are valid frames for the decoder. It will split what is
  950. * stored in the file into frames and return one for each call. It will not
  951. * omit invalid data between valid frames so as to give the decoder the maximum
  952. * information possible for decoding.
  953. *
  954. * The returned packet is valid
  955. * until the next av_read_frame() or until av_close_input_file() and
  956. * must be freed with av_free_packet. For video, the packet contains
  957. * exactly one frame. For audio, it contains an integer number of
  958. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  959. * data). If the audio frames have a variable size (e.g. MPEG audio),
  960. * then it contains one frame.
  961. *
  962. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  963. * values in AVStream.time_base units (and guessed if the format cannot
  964. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  965. * has B-frames, so it is better to rely on pkt->dts if you do not
  966. * decompress the payload.
  967. *
  968. * @return 0 if OK, < 0 on error or end of file
  969. */
  970. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  971. /**
  972. * Seek to the keyframe at timestamp.
  973. * 'timestamp' in 'stream_index'.
  974. * @param stream_index If stream_index is (-1), a default
  975. * stream is selected, and timestamp is automatically converted
  976. * from AV_TIME_BASE units to the stream specific time_base.
  977. * @param timestamp Timestamp in AVStream.time_base units
  978. * or, if no stream is specified, in AV_TIME_BASE units.
  979. * @param flags flags which select direction and seeking mode
  980. * @return >= 0 on success
  981. */
  982. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  983. int flags);
  984. /**
  985. * Seek to timestamp ts.
  986. * Seeking will be done so that the point from which all active streams
  987. * can be presented successfully will be closest to ts and within min/max_ts.
  988. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  989. *
  990. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  991. * are the file position (this may not be supported by all demuxers).
  992. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  993. * in the stream with stream_index (this may not be supported by all demuxers).
  994. * Otherwise all timestamps are in units of the stream selected by stream_index
  995. * or if stream_index is -1, in AV_TIME_BASE units.
  996. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  997. * keyframes (this may not be supported by all demuxers).
  998. *
  999. * @param stream_index index of the stream which is used as time base reference
  1000. * @param min_ts smallest acceptable timestamp
  1001. * @param ts target timestamp
  1002. * @param max_ts largest acceptable timestamp
  1003. * @param flags flags
  1004. * @return >=0 on success, error code otherwise
  1005. *
  1006. * @note This is part of the new seek API which is still under construction.
  1007. * Thus do not use this yet. It may change at any time, do not expect
  1008. * ABI compatibility yet!
  1009. */
  1010. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1011. /**
  1012. * Start playing a network-based stream (e.g. RTSP stream) at the
  1013. * current position.
  1014. */
  1015. int av_read_play(AVFormatContext *s);
  1016. /**
  1017. * Pause a network-based stream (e.g. RTSP stream).
  1018. *
  1019. * Use av_read_play() to resume it.
  1020. */
  1021. int av_read_pause(AVFormatContext *s);
  1022. /**
  1023. * Free a AVFormatContext allocated by av_open_input_stream.
  1024. * @param s context to free
  1025. */
  1026. void av_close_input_stream(AVFormatContext *s);
  1027. /**
  1028. * Close a media file (but not its codecs).
  1029. *
  1030. * @param s media file handle
  1031. */
  1032. void av_close_input_file(AVFormatContext *s);
  1033. /**
  1034. * Add a new stream to a media file.
  1035. *
  1036. * Can only be called in the read_header() function. If the flag
  1037. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1038. * can be added in read_packet too.
  1039. *
  1040. * @param s media file handle
  1041. * @param id file-format-dependent stream ID
  1042. */
  1043. AVStream *av_new_stream(AVFormatContext *s, int id);
  1044. AVProgram *av_new_program(AVFormatContext *s, int id);
  1045. /**
  1046. * Add a new chapter.
  1047. * This function is NOT part of the public API
  1048. * and should ONLY be used by demuxers.
  1049. *
  1050. * @param s media file handle
  1051. * @param id unique ID for this chapter
  1052. * @param start chapter start time in time_base units
  1053. * @param end chapter end time in time_base units
  1054. * @param title chapter title
  1055. *
  1056. * @return AVChapter or NULL on error
  1057. */
  1058. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
  1059. int64_t start, int64_t end, const char *title);
  1060. /**
  1061. * Set the pts for a given stream.
  1062. *
  1063. * @param s stream
  1064. * @param pts_wrap_bits number of bits effectively used by the pts
  1065. * (used for wrap control, 33 is the value for MPEG)
  1066. * @param pts_num numerator to convert to seconds (MPEG: 1)
  1067. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  1068. */
  1069. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1070. unsigned int pts_num, unsigned int pts_den);
  1071. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1072. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1073. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1074. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1075. int av_find_default_stream_index(AVFormatContext *s);
  1076. /**
  1077. * Get the index for a specific timestamp.
  1078. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1079. * to the timestamp which is <= the requested one, if backward
  1080. * is 0, then it will be >=
  1081. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1082. * @return < 0 if no such timestamp could be found
  1083. */
  1084. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1085. /**
  1086. * Ensure the index uses less memory than the maximum specified in
  1087. * AVFormatContext.max_index_size by discarding entries if it grows
  1088. * too large.
  1089. * This function is not part of the public API and should only be called
  1090. * by demuxers.
  1091. */
  1092. void ff_reduce_index(AVFormatContext *s, int stream_index);
  1093. /**
  1094. * Add an index entry into a sorted list. Update the entry if the list
  1095. * already contains it.
  1096. *
  1097. * @param timestamp timestamp in the time base of the given stream
  1098. */
  1099. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1100. int size, int distance, int flags);
  1101. /**
  1102. * Perform a binary search using av_index_search_timestamp() and
  1103. * AVInputFormat.read_timestamp().
  1104. * This is not supposed to be called directly by a user application,
  1105. * but by demuxers.
  1106. * @param target_ts target timestamp in the time base of the given stream
  1107. * @param stream_index stream number
  1108. */
  1109. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  1110. int64_t target_ts, int flags);
  1111. /**
  1112. * Update cur_dts of all streams based on the given timestamp and AVStream.
  1113. *
  1114. * Stream ref_st unchanged, others set cur_dts in their native time base.
  1115. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  1116. * @param timestamp new dts expressed in time_base of param ref_st
  1117. * @param ref_st reference stream giving time_base of param timestamp
  1118. */
  1119. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  1120. /**
  1121. * Perform a binary search using read_timestamp().
  1122. * This is not supposed to be called directly by a user application,
  1123. * but by demuxers.
  1124. * @param target_ts target timestamp in the time base of the given stream
  1125. * @param stream_index stream number
  1126. */
  1127. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  1128. int64_t target_ts, int64_t pos_min,
  1129. int64_t pos_max, int64_t pos_limit,
  1130. int64_t ts_min, int64_t ts_max,
  1131. int flags, int64_t *ts_ret,
  1132. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1133. /**
  1134. * media file output
  1135. */
  1136. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1137. /**
  1138. * Split a URL string into components.
  1139. *
  1140. * The pointers to buffers for storing individual components may be null,
  1141. * in order to ignore that component. Buffers for components not found are
  1142. * set to empty strings. If the port is not found, it is set to a negative
  1143. * value.
  1144. *
  1145. * @param proto the buffer for the protocol
  1146. * @param proto_size the size of the proto buffer
  1147. * @param authorization the buffer for the authorization
  1148. * @param authorization_size the size of the authorization buffer
  1149. * @param hostname the buffer for the host name
  1150. * @param hostname_size the size of the hostname buffer
  1151. * @param port_ptr a pointer to store the port number in
  1152. * @param path the buffer for the path
  1153. * @param path_size the size of the path buffer
  1154. * @param url the URL to split
  1155. */
  1156. void av_url_split(char *proto, int proto_size,
  1157. char *authorization, int authorization_size,
  1158. char *hostname, int hostname_size,
  1159. int *port_ptr,
  1160. char *path, int path_size,
  1161. const char *url);
  1162. /**
  1163. * Allocate the stream private data and write the stream header to an
  1164. * output media file.
  1165. *
  1166. * @param s media file handle
  1167. * @return 0 if OK, AVERROR_xxx on error
  1168. */
  1169. int av_write_header(AVFormatContext *s);
  1170. /**
  1171. * Write a packet to an output media file.
  1172. *
  1173. * The packet shall contain one audio or video frame.
  1174. * The packet must be correctly interleaved according to the container
  1175. * specification, if not then av_interleaved_write_frame must be used.
  1176. *
  1177. * @param s media file handle
  1178. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1179. dts/pts, ...
  1180. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1181. */
  1182. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1183. /**
  1184. * Write a packet to an output media file ensuring correct interleaving.
  1185. *
  1186. * The packet must contain one audio or video frame.
  1187. * If the packets are already correctly interleaved, the application should
  1188. * call av_write_frame() instead as it is slightly faster. It is also important
  1189. * to keep in mind that completely non-interleaved input will need huge amounts
  1190. * of memory to interleave with this, so it is preferable to interleave at the
  1191. * demuxer level.
  1192. *
  1193. * @param s media file handle
  1194. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1195. dts/pts, ...
  1196. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1197. */
  1198. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1199. /**
  1200. * Interleave a packet per dts in an output media file.
  1201. *
  1202. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1203. * function, so they cannot be used after it. Note that calling av_free_packet()
  1204. * on them is still safe.
  1205. *
  1206. * @param s media file handle
  1207. * @param out the interleaved packet will be output here
  1208. * @param pkt the input packet
  1209. * @param flush 1 if no further packets are available as input and all
  1210. * remaining packets should be output
  1211. * @return 1 if a packet was output, 0 if no packet could be output,
  1212. * < 0 if an error occurred
  1213. */
  1214. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1215. AVPacket *pkt, int flush);
  1216. /**
  1217. * Write the stream trailer to an output media file and free the
  1218. * file private data.
  1219. *
  1220. * May only be called after a successful call to av_write_header.
  1221. *
  1222. * @param s media file handle
  1223. * @return 0 if OK, AVERROR_xxx on error
  1224. */
  1225. int av_write_trailer(AVFormatContext *s);
  1226. void dump_format(AVFormatContext *ic,
  1227. int index,
  1228. const char *url,
  1229. int is_output);
  1230. #if LIBAVFORMAT_VERSION_MAJOR < 53
  1231. /**
  1232. * Parse width and height out of string str.
  1233. * @deprecated Use av_parse_video_frame_size instead.
  1234. */
  1235. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
  1236. const char *str);
  1237. /**
  1238. * Convert framerate from a string to a fraction.
  1239. * @deprecated Use av_parse_video_frame_rate instead.
  1240. */
  1241. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
  1242. const char *arg);
  1243. #endif
  1244. /**
  1245. * Parse datestr and return a corresponding number of microseconds.
  1246. * @param datestr String representing a date or a duration.
  1247. * - If a date the syntax is:
  1248. * @code
  1249. * now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
  1250. * @endcode
  1251. * If the value is "now" it takes the current time.
  1252. * Time is local time unless Z is appended, in which case it is
  1253. * interpreted as UTC.
  1254. * If the year-month-day part is not specified it takes the current
  1255. * year-month-day.
  1256. * @return the number of microseconds since 1st of January, 1970 up to
  1257. * the time of the parsed date or INT64_MIN if datestr cannot be
  1258. * successfully parsed.
  1259. * - If a duration the syntax is:
  1260. * @code
  1261. * [-]HH[:MM[:SS[.m...]]]
  1262. * [-]S+[.m...]
  1263. * @endcode
  1264. * @return the number of microseconds contained in a time interval
  1265. * with the specified duration or INT64_MIN if datestr cannot be
  1266. * successfully parsed.
  1267. * @param duration Flag which tells how to interpret datestr, if
  1268. * not zero datestr is interpreted as a duration, otherwise as a
  1269. * date.
  1270. */
  1271. int64_t parse_date(const char *datestr, int duration);
  1272. /**
  1273. * Get the current time in microseconds.
  1274. */
  1275. int64_t av_gettime(void);
  1276. /* ffm-specific for ffserver */
  1277. #define FFM_PACKET_SIZE 4096
  1278. int64_t ffm_read_write_index(int fd);
  1279. int ffm_write_write_index(int fd, int64_t pos);
  1280. void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
  1281. /**
  1282. * Attempt to find a specific tag in a URL.
  1283. *
  1284. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  1285. * Return 1 if found.
  1286. */
  1287. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1288. /**
  1289. * Return in 'buf' the path with '%d' replaced by a number.
  1290. *
  1291. * Also handles the '%0nd' format where 'n' is the total number
  1292. * of digits and '%%'.
  1293. *
  1294. * @param buf destination buffer
  1295. * @param buf_size destination buffer size
  1296. * @param path numbered sequence string
  1297. * @param number frame number
  1298. * @return 0 if OK, -1 on format error
  1299. */
  1300. int av_get_frame_filename(char *buf, int buf_size,
  1301. const char *path, int number);
  1302. /**
  1303. * Check whether filename actually is a numbered sequence generator.
  1304. *
  1305. * @param filename possible numbered sequence string
  1306. * @return 1 if a valid numbered sequence string, 0 otherwise
  1307. */
  1308. int av_filename_number_test(const char *filename);
  1309. /**
  1310. * Generate an SDP for an RTP session.
  1311. *
  1312. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1313. * array is composed by only one context, such context can contain
  1314. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1315. * all the contexts in the array (an AVCodecContext per RTP stream)
  1316. * must contain only one AVStream.
  1317. * @param n_files number of AVCodecContexts contained in ac
  1318. * @param buff buffer where the SDP will be stored (must be allocated by
  1319. * the caller)
  1320. * @param size the size of the buffer
  1321. * @return 0 if OK, AVERROR_xxx on error
  1322. */
  1323. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1324. /**
  1325. * Return a positive value if the given filename has one of the given
  1326. * extensions, 0 otherwise.
  1327. *
  1328. * @param extensions a comma-separated list of filename extensions
  1329. */
  1330. int av_match_ext(const char *filename, const char *extensions);
  1331. #endif /* AVFORMAT_AVFORMAT_H */