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.

1108 lines
38KB

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