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.

1480 lines
51KB

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