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.

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