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.

1101 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 20
  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. } AVStream;
  358. #define AV_PROGRAM_RUNNING 1
  359. /**
  360. * New fields can be added to the end with minor version bumps.
  361. * Removal, reordering and changes to existing fields require a major
  362. * version bump.
  363. * sizeof(AVProgram) must not be used outside libav*.
  364. */
  365. typedef struct AVProgram {
  366. int id;
  367. char *provider_name; ///< Network name for DVB streams
  368. char *name; ///< Service name for DVB streams
  369. int flags;
  370. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  371. unsigned int *stream_index;
  372. unsigned int nb_stream_indexes;
  373. } AVProgram;
  374. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  375. (streams are added dynamically) */
  376. typedef struct AVChapter {
  377. int id; ///< Unique id to identify the chapter
  378. AVRational time_base; ///< Timebase in which the start/end timestamps are specified
  379. int64_t start, end; ///< chapter start/end time in time_base units
  380. char *title; ///< chapter title
  381. } AVChapter;
  382. #define MAX_STREAMS 20
  383. /**
  384. * format I/O context.
  385. * New fields can be added to the end with minor version bumps.
  386. * Removal, reordering and changes to existing fields require a major
  387. * version bump.
  388. * sizeof(AVFormatContext) must not be used outside libav*.
  389. */
  390. typedef struct AVFormatContext {
  391. const AVClass *av_class; /**< set by av_alloc_format_context */
  392. /* can only be iformat or oformat, not both at the same time */
  393. struct AVInputFormat *iformat;
  394. struct AVOutputFormat *oformat;
  395. void *priv_data;
  396. ByteIOContext *pb;
  397. unsigned int nb_streams;
  398. AVStream *streams[MAX_STREAMS];
  399. char filename[1024]; /**< input or output filename */
  400. /* stream info */
  401. int64_t timestamp;
  402. char title[512];
  403. char author[512];
  404. char copyright[512];
  405. char comment[512];
  406. char album[512];
  407. int year; /**< ID3 year, 0 if none */
  408. int track; /**< track number, 0 if none */
  409. char genre[32]; /**< ID3 genre */
  410. int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
  411. /* private data for pts handling (do not modify directly) */
  412. /** This buffer is only needed when packets were already buffered but
  413. not decoded, for example to get the codec parameters in mpeg
  414. streams */
  415. struct AVPacketList *packet_buffer;
  416. /** decoding: position of the first frame of the component, in
  417. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  418. it is deduced from the AVStream values. */
  419. int64_t start_time;
  420. /** decoding: duration of the stream, in AV_TIME_BASE fractional
  421. seconds. NEVER set this value directly: it is deduced from the
  422. AVStream values. */
  423. int64_t duration;
  424. /** decoding: total file size. 0 if unknown */
  425. int64_t file_size;
  426. /** decoding: total stream bitrate in bit/s, 0 if not
  427. available. Never set it directly if the file_size and the
  428. duration are known as ffmpeg can compute it automatically. */
  429. int bit_rate;
  430. /* av_read_frame() support */
  431. AVStream *cur_st;
  432. const uint8_t *cur_ptr;
  433. int cur_len;
  434. AVPacket cur_pkt;
  435. /* av_seek_frame() support */
  436. int64_t data_offset; /** offset of the first packet */
  437. int index_built;
  438. int mux_rate;
  439. int packet_size;
  440. int preload;
  441. int max_delay;
  442. #define AVFMT_NOOUTPUTLOOP -1
  443. #define AVFMT_INFINITEOUTPUTLOOP 0
  444. /** number of times to loop output in formats that support it */
  445. int loop_output;
  446. int flags;
  447. #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
  448. #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
  449. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input
  450. int loop_input;
  451. /** decoding: size of data to probe; encoding unused */
  452. unsigned int probesize;
  453. /**
  454. * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
  455. */
  456. int max_analyze_duration;
  457. const uint8_t *key;
  458. int keylen;
  459. unsigned int nb_programs;
  460. AVProgram **programs;
  461. /**
  462. * Forced video codec_id.
  463. * demuxing: set by user
  464. */
  465. enum CodecID video_codec_id;
  466. /**
  467. * Forced audio codec_id.
  468. * demuxing: set by user
  469. */
  470. enum CodecID audio_codec_id;
  471. /**
  472. * Forced subtitle codec_id.
  473. * demuxing: set by user
  474. */
  475. enum CodecID subtitle_codec_id;
  476. /**
  477. * Maximum amount of memory in bytes to use per stream for the index.
  478. * If the needed index exceeds this size entries will be discarded as
  479. * needed to maintain a smaller size. This can lead to slower or less
  480. * accurate seeking (depends on demuxer).
  481. * Demuxers for which a full in memory index is mandatory will ignore
  482. * this.
  483. * muxing : unused
  484. * demuxing: set by user
  485. */
  486. unsigned int max_index_size;
  487. /**
  488. * Maximum amount of memory in bytes to use for buffering frames
  489. * obtained from real-time capture devices.
  490. */
  491. unsigned int max_picture_buffer;
  492. unsigned int nb_chapters;
  493. AVChapter **chapters;
  494. /**
  495. * Flags to enable debuging.
  496. */
  497. int debug;
  498. #define FF_FDEBUG_TS 0x0001
  499. /**
  500. * raw packets from the demuxer, prior to parsing and decoding.
  501. * This buffer is used for buffering packets until the codec can
  502. * be identified, as parsing cannot be done without knowing the
  503. * codec.
  504. */
  505. struct AVPacketList *raw_packet_buffer;
  506. struct AVPacketList *raw_packet_buffer_end;
  507. struct AVPacketList *packet_buffer_end;
  508. } AVFormatContext;
  509. typedef struct AVPacketList {
  510. AVPacket pkt;
  511. struct AVPacketList *next;
  512. } AVPacketList;
  513. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  514. extern AVInputFormat *first_iformat;
  515. extern AVOutputFormat *first_oformat;
  516. #endif
  517. AVInputFormat *av_iformat_next(AVInputFormat *f);
  518. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  519. enum CodecID av_guess_image2_codec(const char *filename);
  520. /* XXX: use automatic init with either ELF sections or C file parser */
  521. /* modules */
  522. /* utils.c */
  523. void av_register_input_format(AVInputFormat *format);
  524. void av_register_output_format(AVOutputFormat *format);
  525. AVOutputFormat *guess_stream_format(const char *short_name,
  526. const char *filename, const char *mime_type);
  527. AVOutputFormat *guess_format(const char *short_name,
  528. const char *filename, const char *mime_type);
  529. /**
  530. * Guesses the codec id based upon muxer and filename.
  531. */
  532. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  533. const char *filename, const char *mime_type, enum CodecType type);
  534. /**
  535. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  536. *
  537. * @param f The file stream pointer where the dump should be sent to.
  538. * @param buf buffer
  539. * @param size buffer size
  540. *
  541. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  542. */
  543. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  544. /**
  545. * Send a nice hexadecimal dump of a buffer to the log.
  546. *
  547. * @param avcl A pointer to an arbitrary struct of which the first field is a
  548. * pointer to an AVClass struct.
  549. * @param level The importance level of the message, lower values signifying
  550. * higher importance.
  551. * @param buf buffer
  552. * @param size buffer size
  553. *
  554. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  555. */
  556. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  557. /**
  558. * Send a nice dump of a packet to the specified file stream.
  559. *
  560. * @param f The file stream pointer where the dump should be sent to.
  561. * @param pkt packet to dump
  562. * @param dump_payload true if the payload must be displayed too
  563. */
  564. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  565. /**
  566. * Send a nice dump of a packet to the log.
  567. *
  568. * @param avcl A pointer to an arbitrary struct of which the first field is a
  569. * pointer to an AVClass struct.
  570. * @param level The importance level of the message, lower values signifying
  571. * higher importance.
  572. * @param pkt packet to dump
  573. * @param dump_payload true if the payload must be displayed too
  574. */
  575. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  576. void av_register_all(void);
  577. /** codec tag <-> codec id */
  578. enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
  579. unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
  580. /* media file input */
  581. /**
  582. * finds AVInputFormat based on input format's short name.
  583. */
  584. AVInputFormat *av_find_input_format(const char *short_name);
  585. /**
  586. * Guess file format.
  587. *
  588. * @param is_opened whether the file is already opened, determines whether
  589. * demuxers with or without AVFMT_NOFILE are probed
  590. */
  591. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  592. /**
  593. * Allocates all the structures needed to read an input stream.
  594. * This does not open the needed codecs for decoding the stream[s].
  595. */
  596. int av_open_input_stream(AVFormatContext **ic_ptr,
  597. ByteIOContext *pb, const char *filename,
  598. AVInputFormat *fmt, AVFormatParameters *ap);
  599. /**
  600. * Open a media file as input. The codecs are not opened. Only the file
  601. * header (if present) is read.
  602. *
  603. * @param ic_ptr the opened media file handle is put here
  604. * @param filename filename to open.
  605. * @param fmt if non NULL, force the file format to use
  606. * @param buf_size optional buffer size (zero if default is OK)
  607. * @param ap additional parameters needed when opening the file (NULL if default)
  608. * @return 0 if OK. AVERROR_xxx otherwise.
  609. */
  610. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  611. AVInputFormat *fmt,
  612. int buf_size,
  613. AVFormatParameters *ap);
  614. /**
  615. * Allocate an AVFormatContext.
  616. * Can be freed with av_free() but do not forget to free everything you
  617. * explicitly allocated as well!
  618. */
  619. AVFormatContext *av_alloc_format_context(void);
  620. /**
  621. * Read packets of a media file to get stream information. This
  622. * is useful for file formats with no headers such as MPEG. This
  623. * function also computes the real frame rate in case of mpeg2 repeat
  624. * frame mode.
  625. * The logical file position is not changed by this function;
  626. * examined packets may be buffered for later processing.
  627. *
  628. * @param ic media file handle
  629. * @return >=0 if OK. AVERROR_xxx if error.
  630. * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
  631. */
  632. int av_find_stream_info(AVFormatContext *ic);
  633. /**
  634. * Read a transport packet from a media file.
  635. *
  636. * This function is obsolete and should never be used.
  637. * Use av_read_frame() instead.
  638. *
  639. * @param s media file handle
  640. * @param pkt is filled
  641. * @return 0 if OK. AVERROR_xxx if error.
  642. */
  643. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  644. /**
  645. * Return the next frame of a stream.
  646. *
  647. * The returned packet is valid
  648. * until the next av_read_frame() or until av_close_input_file() and
  649. * must be freed with av_free_packet. For video, the packet contains
  650. * exactly one frame. For audio, it contains an integer number of
  651. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  652. * data). If the audio frames have a variable size (e.g. MPEG audio),
  653. * then it contains one frame.
  654. *
  655. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  656. * values in AVStream.timebase units (and guessed if the format cannot
  657. * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
  658. * has B frames, so it is better to rely on pkt->dts if you do not
  659. * decompress the payload.
  660. *
  661. * @return 0 if OK, < 0 if error or end of file.
  662. */
  663. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  664. /**
  665. * Seek to the key frame at timestamp.
  666. * 'timestamp' in 'stream_index'.
  667. * @param stream_index If stream_index is (-1), a default
  668. * stream is selected, and timestamp is automatically converted
  669. * from AV_TIME_BASE units to the stream specific time_base.
  670. * @param timestamp timestamp in AVStream.time_base units
  671. * or if there is no stream specified then in AV_TIME_BASE units
  672. * @param flags flags which select direction and seeking mode
  673. * @return >= 0 on success
  674. */
  675. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
  676. /**
  677. * start playing a network based stream (e.g. RTSP stream) at the
  678. * current position
  679. */
  680. int av_read_play(AVFormatContext *s);
  681. /**
  682. * Pause a network based stream (e.g. RTSP stream).
  683. *
  684. * Use av_read_play() to resume it.
  685. */
  686. int av_read_pause(AVFormatContext *s);
  687. /**
  688. * Free a AVFormatContext allocated by av_open_input_stream.
  689. * @param s context to free
  690. */
  691. void av_close_input_stream(AVFormatContext *s);
  692. /**
  693. * Close a media file (but not its codecs).
  694. *
  695. * @param s media file handle
  696. */
  697. void av_close_input_file(AVFormatContext *s);
  698. /**
  699. * Add a new stream to a media file.
  700. *
  701. * Can only be called in the read_header() function. If the flag
  702. * AVFMTCTX_NOHEADER is in the format context, then new streams
  703. * can be added in read_packet too.
  704. *
  705. * @param s media file handle
  706. * @param id file format dependent stream id
  707. */
  708. AVStream *av_new_stream(AVFormatContext *s, int id);
  709. AVProgram *av_new_program(AVFormatContext *s, int id);
  710. /**
  711. * Add a new chapter.
  712. * This function is NOT part of the public API
  713. * and should be ONLY used by demuxers.
  714. *
  715. * @param s media file handle
  716. * @param id unique id for this chapter
  717. * @param start chapter start time in time_base units
  718. * @param end chapter end time in time_base units
  719. * @param title chapter title
  720. *
  721. * @return AVChapter or NULL if error.
  722. */
  723. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
  724. /**
  725. * Set the pts for a given stream.
  726. *
  727. * @param s stream
  728. * @param pts_wrap_bits number of bits effectively used by the pts
  729. * (used for wrap control, 33 is the value for MPEG)
  730. * @param pts_num numerator to convert to seconds (MPEG: 1)
  731. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  732. */
  733. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  734. int pts_num, int pts_den);
  735. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  736. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  737. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
  738. int av_find_default_stream_index(AVFormatContext *s);
  739. /**
  740. * Gets the index for a specific timestamp.
  741. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
  742. * the timestamp which is <= the requested one, if backward is 0
  743. * then it will be >=
  744. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  745. * @return < 0 if no such timestamp could be found
  746. */
  747. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  748. /**
  749. * Ensures the index uses less memory than the maximum specified in
  750. * AVFormatContext.max_index_size, by discarding entries if it grows
  751. * too large.
  752. * This function is not part of the public API and should only be called
  753. * by demuxers.
  754. */
  755. void ff_reduce_index(AVFormatContext *s, int stream_index);
  756. /**
  757. * Add a index entry into a sorted list updateing if it is already there.
  758. *
  759. * @param timestamp timestamp in the timebase of the given stream
  760. */
  761. int av_add_index_entry(AVStream *st,
  762. int64_t pos, int64_t timestamp, int size, int distance, int flags);
  763. /**
  764. * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
  765. * This is not supposed to be called directly by a user application, but by demuxers.
  766. * @param target_ts target timestamp in the time base of the given stream
  767. * @param stream_index stream number
  768. */
  769. int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
  770. /**
  771. * Updates cur_dts of all streams based on given timestamp and AVStream.
  772. *
  773. * Stream ref_st unchanged, others set cur_dts in their native timebase
  774. * only needed for timestamp wrapping or if (dts not set and pts!=dts).
  775. * @param timestamp new dts expressed in time_base of param ref_st
  776. * @param ref_st reference stream giving time_base of param timestamp
  777. */
  778. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  779. /**
  780. * Does a binary search using read_timestamp().
  781. * This is not supposed to be called directly by a user application, but by demuxers.
  782. * @param target_ts target timestamp in the time base of the given stream
  783. * @param stream_index stream number
  784. */
  785. 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 ));
  786. /** media file output */
  787. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  788. /**
  789. * Allocate the stream private data and write the stream header to an
  790. * output media file.
  791. *
  792. * @param s media file handle
  793. * @return 0 if OK. AVERROR_xxx if error.
  794. */
  795. int av_write_header(AVFormatContext *s);
  796. /**
  797. * Write a packet to an output media file.
  798. *
  799. * The packet shall contain one audio or video frame.
  800. * The packet must be correctly interleaved according to the container specification,
  801. * if not then av_interleaved_write_frame must be used
  802. *
  803. * @param s media file handle
  804. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  805. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  806. */
  807. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  808. /**
  809. * Writes a packet to an output media file ensuring correct interleaving.
  810. *
  811. * The packet must contain one audio or video frame.
  812. * If the packets are already correctly interleaved the application should
  813. * call av_write_frame() instead as it is slightly faster. It is also important
  814. * to keep in mind that completely non-interleaved input will need huge amounts
  815. * of memory to interleave with this, so it is preferable to interleave at the
  816. * demuxer level.
  817. *
  818. * @param s media file handle
  819. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  820. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  821. */
  822. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  823. /**
  824. * Interleave a packet per DTS in an output media file.
  825. *
  826. * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
  827. * so they cannot be used after it, note calling av_free_packet() on them is still safe.
  828. *
  829. * @param s media file handle
  830. * @param out the interleaved packet will be output here
  831. * @param in the input packet
  832. * @param flush 1 if no further packets are available as input and all
  833. * remaining packets should be output
  834. * @return 1 if a packet was output, 0 if no packet could be output,
  835. * < 0 if an error occurred
  836. */
  837. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
  838. /**
  839. * @brief Write the stream trailer to an output media file and
  840. * free the file private data.
  841. *
  842. * @param s media file handle
  843. * @return 0 if OK. AVERROR_xxx if error.
  844. */
  845. int av_write_trailer(AVFormatContext *s);
  846. void dump_format(AVFormatContext *ic,
  847. int index,
  848. const char *url,
  849. int is_output);
  850. /**
  851. * parses width and height out of string str.
  852. * @deprecated Use av_parse_video_frame_size instead.
  853. */
  854. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  855. /**
  856. * Converts frame rate from string to a fraction.
  857. * @deprecated Use av_parse_video_frame_rate instead.
  858. */
  859. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  860. /**
  861. * Parses \p datestr and returns a corresponding number of microseconds.
  862. * @param datestr String representing a date or a duration.
  863. * - If a date the syntax is:
  864. * @code
  865. * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
  866. * @endcode
  867. * Time is localtime unless Z is appended, in which case it is
  868. * interpreted as UTC.
  869. * If the year-month-day part isn't specified it takes the current
  870. * year-month-day.
  871. * Returns the number of microseconds since 1st of January, 1970 up to
  872. * the time of the parsed date or INT64_MIN if \p datestr cannot be
  873. * successfully parsed.
  874. * - If a duration the syntax is:
  875. * @code
  876. * [-]HH[:MM[:SS[.m...]]]
  877. * [-]S+[.m...]
  878. * @endcode
  879. * Returns the number of microseconds contained in a time interval
  880. * with the specified duration or INT64_MIN if \p datestr cannot be
  881. * successfully parsed.
  882. * @param duration Flag which tells how to interpret \p datestr, if
  883. * not zero \p datestr is interpreted as a duration, otherwise as a
  884. * date.
  885. */
  886. int64_t parse_date(const char *datestr, int duration);
  887. int64_t av_gettime(void);
  888. /* ffm specific for ffserver */
  889. #define FFM_PACKET_SIZE 4096
  890. offset_t ffm_read_write_index(int fd);
  891. void ffm_write_write_index(int fd, offset_t pos);
  892. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  893. /**
  894. * Attempts to find a specific tag in a URL.
  895. *
  896. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  897. * Return 1 if found.
  898. */
  899. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  900. /**
  901. * Returns in 'buf' the path with '%d' replaced by number.
  902. * Also handles the '%0nd' format where 'n' is the total number
  903. * of digits and '%%'.
  904. *
  905. * @param buf destination buffer
  906. * @param buf_size destination buffer size
  907. * @param path numbered sequence string
  908. * @param number frame number
  909. * @return 0 if OK, -1 if format error.
  910. */
  911. int av_get_frame_filename(char *buf, int buf_size,
  912. const char *path, int number);
  913. /**
  914. * Check whether filename actually is a numbered sequence generator.
  915. *
  916. * @param filename possible numbered sequence string
  917. * @return 1 if a valid numbered sequence string, 0 otherwise.
  918. */
  919. int av_filename_number_test(const char *filename);
  920. /**
  921. * Generate an SDP for an RTP session.
  922. *
  923. * @param ac array of AVFormatContexts describing the RTP streams. If the
  924. * array is composed by only one context, such context can contain
  925. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  926. * all the contexts in the array (an AVCodecContext per RTP stream)
  927. * must contain only one AVStream
  928. * @param n_files number of AVCodecContexts contained in ac
  929. * @param buff buffer where the SDP will be stored (must be allocated by
  930. * the caller
  931. * @param size the size of the buffer
  932. * @return 0 if OK. AVERROR_xxx if error.
  933. */
  934. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  935. #ifdef HAVE_AV_CONFIG_H
  936. void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  937. #ifdef __GNUC__
  938. #define dynarray_add(tab, nb_ptr, elem)\
  939. do {\
  940. typeof(tab) _tab = (tab);\
  941. typeof(elem) _elem = (elem);\
  942. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  943. ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  944. } while(0)
  945. #else
  946. #define dynarray_add(tab, nb_ptr, elem)\
  947. do {\
  948. ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
  949. } while(0)
  950. #endif
  951. time_t mktimegm(struct tm *tm);
  952. struct tm *brktimegm(time_t secs, struct tm *tm);
  953. const char *small_strptime(const char *p, const char *fmt,
  954. struct tm *dt);
  955. struct in_addr;
  956. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  957. void url_split(char *proto, int proto_size,
  958. char *authorization, int authorization_size,
  959. char *hostname, int hostname_size,
  960. int *port_ptr,
  961. char *path, int path_size,
  962. const char *url);
  963. int match_ext(const char *filename, const char *extensions);
  964. #endif /* HAVE_AV_CONFIG_H */
  965. #endif /* FFMPEG_AVFORMAT_H */