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.

1129 lines
39KB

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