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.

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