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.

1162 lines
40KB

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