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.

1214 lines
42KB

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