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.

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