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.

1131 lines
39KB

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