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.

1236 lines
43KB

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