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.

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