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.

1365 lines
49KB

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