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.

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