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.

1364 lines
48KB

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