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.

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