2 * copyright (c) 2001 Fabrice Bellard
4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVFORMAT_AVFORMAT_H
22 #define AVFORMAT_AVFORMAT_H
24 #define LIBAVFORMAT_VERSION_MAJOR 52
25 #define LIBAVFORMAT_VERSION_MINOR 22
26 #define LIBAVFORMAT_VERSION_MICRO 1
28 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
29 LIBAVFORMAT_VERSION_MINOR, \
30 LIBAVFORMAT_VERSION_MICRO)
31 #define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
32 LIBAVFORMAT_VERSION_MINOR, \
33 LIBAVFORMAT_VERSION_MICRO)
34 #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
36 #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
39 * Returns the LIBAVFORMAT_VERSION_INT constant.
41 unsigned avformat_version(void);
44 #include <stdio.h> /* FILE */
45 #include "libavcodec/avcodec.h"
49 /* packet functions */
51 typedef struct AVPacket {
53 * Presentation time stamp in time_base units.
54 * This is the time at which the decompressed packet will be presented
56 * Can be AV_NOPTS_VALUE if it is not stored in the file.
57 * pts MUST be larger or equal to dts as presentation can not happen before
58 * decompression, unless one wants to view hex dumps. Some formats misuse
59 * the terms dts and pts/cts to mean something different, these timestamps
60 * must be converted to true pts/dts before they are stored in AVPacket.
64 * Decompression time stamp in time_base units.
65 * This is the time at which the packet is decompressed.
66 * Can be AV_NOPTS_VALUE if it is not stored in the file.
74 * Duration of this packet in time_base units, 0 if unknown.
75 * Equals next_pts - this_pts in presentation order.
78 void (*destruct)(struct AVPacket *);
80 int64_t pos; ///< byte position in stream, -1 if unknown
83 * This is the time difference in stream timebase units from the pts at which
84 * the output from the decoder has converged independent from the availability
85 * of previous frames (that is the frames are virtually identical no matter
86 * if decoding started from the very first frame or from this keyframe).
87 * is AV_NOPTS_VALUE if unknown.
89 * The purpose of this field is to allow seeking in streams that have no
90 * keyframes in the conventional sense. It corresponds to the
91 * recovery point SEI in H.264 and match_time_delta in nut. It also is
92 * essential for some types of subtitle streams to ensure that all
93 * subtitles are correctly displayed after seeking.
95 int64_t convergence_duration;
97 #define PKT_FLAG_KEY 0x0001
99 void av_destruct_packet_nofree(AVPacket *pkt);
102 * Default packet destructor.
104 void av_destruct_packet(AVPacket *pkt);
107 * Initialize optional fields of a packet to default values.
111 void av_init_packet(AVPacket *pkt);
114 * Allocate the payload of a packet and initialize its fields to default values.
117 * @param size wanted payload size
118 * @return 0 if OK. AVERROR_xxx otherwise.
120 int av_new_packet(AVPacket *pkt, int size);
123 * Allocate and read the payload of a packet and initialize its fields to default values.
126 * @param size wanted payload size
127 * @return >0 (read size) if OK. AVERROR_xxx otherwise.
129 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
132 * @warning This is a hack - the packet memory allocation stuff is broken. The
133 * packet is allocated if it was not really allocated
135 int av_dup_packet(AVPacket *pkt);
140 * @param pkt packet to free
142 static inline void av_free_packet(AVPacket *pkt)
144 if (pkt && pkt->destruct) {
149 /*************************************************/
150 /* fractional numbers for exact pts handling */
153 * the exact value of the fractional number is: 'val + num / den'.
154 * num is assumed to be such as 0 <= num < den
155 * @deprecated Use AVRational instead
157 typedef struct AVFrac {
158 int64_t val, num, den;
159 } AVFrac attribute_deprecated;
161 /*************************************************/
162 /* input/output formats */
166 struct AVFormatContext;
168 /** this structure contains the data a format has to probe a file */
169 typedef struct AVProbeData {
170 const char *filename;
175 #define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
176 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
178 typedef struct AVFormatParameters {
179 AVRational time_base;
184 enum PixelFormat pix_fmt;
185 int channel; /**< used to select dv channel */
186 const char *standard; /**< tv standard, NTSC, PAL, SECAM */
187 unsigned int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
188 unsigned int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
189 stream packet (only meaningful if
190 mpeg2ts_raw is TRUE) */
191 unsigned int initial_pause:1; /**< do not begin to play the stream
192 immediately (RTSP only) */
193 unsigned int prealloced_context:1;
194 #if LIBAVFORMAT_VERSION_INT < (53<<16)
195 enum CodecID video_codec_id;
196 enum CodecID audio_codec_id;
198 } AVFormatParameters;
200 //! demuxer will use url_fopen, no opened file should be provided by the caller
201 #define AVFMT_NOFILE 0x0001
202 #define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
203 #define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
204 #define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
206 #define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
207 #define AVFMT_NOTIMESTAMPS 0x0080 /**< format does not need / have any timestamps */
208 #define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
209 #define AVFMT_TS_DISCONT 0x0200 /**< format allows timestamo discontinuities */
211 typedef struct AVOutputFormat {
214 * Descriptive name for the format, meant to be more human-readable
215 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
218 const char *long_name;
219 const char *mime_type;
220 const char *extensions; /**< comma separated filename extensions */
221 /** size of private data so that it can be allocated in the wrapper */
224 enum CodecID audio_codec; /**< default audio codec */
225 enum CodecID video_codec; /**< default video codec */
226 int (*write_header)(struct AVFormatContext *);
227 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
228 int (*write_trailer)(struct AVFormatContext *);
229 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
231 /** currently only used to set pixel format if not YUV420P */
232 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
233 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
236 * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
237 * the arrays are all CODEC_ID_NONE terminated
239 const struct AVCodecTag * const *codec_tag;
241 enum CodecID subtitle_codec; /**< default subtitle codec */
244 struct AVOutputFormat *next;
247 typedef struct AVInputFormat {
250 * Descriptive name for the format, meant to be more human-readable
251 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
254 const char *long_name;
255 /** size of private data so that it can be allocated in the wrapper */
258 * Tell if a given file has a chance of being parsed by this format.
259 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
260 * big so you do not have to check for that unless you need more.
262 int (*read_probe)(AVProbeData *);
263 /** read the format header and initialize the AVFormatContext
264 structure. Return 0 if OK. 'ap' if non NULL contains
265 additional paramters. Only used in raw format right
266 now. 'av_new_stream' should be called to create new streams. */
267 int (*read_header)(struct AVFormatContext *,
268 AVFormatParameters *ap);
269 /** read one packet and put it in 'pkt'. pts and flags are also
270 set. 'av_new_stream' can be called only if the flag
271 AVFMTCTX_NOHEADER is used. */
272 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
273 /** close the stream. The AVFormatContext and AVStreams are not
274 freed by this function */
275 int (*read_close)(struct AVFormatContext *);
277 * seek to a given timestamp relative to the frames in
278 * stream component stream_index
279 * @param stream_index must not be -1
280 * @param flags selects which direction should be preferred if no exact
282 * @return >= 0 on success (but not necessarily the new offset)
284 int (*read_seek)(struct AVFormatContext *,
285 int stream_index, int64_t timestamp, int flags);
287 * gets the next timestamp in stream[stream_index].time_base units.
288 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
290 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
291 int64_t *pos, int64_t pos_limit);
292 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
294 /** if extensions are defined, then no probe is done. You should
295 usually not use extension format guessing because it is not
297 const char *extensions;
298 /** general purpose read only value that the format can use */
301 /** start/resume playing - only meaningful if using a network based format
303 int (*read_play)(struct AVFormatContext *);
305 /** pause playing - only meaningful if using a network based format
307 int (*read_pause)(struct AVFormatContext *);
309 const struct AVCodecTag * const *codec_tag;
312 struct AVInputFormat *next;
315 enum AVStreamParseType {
317 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
318 AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */
319 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */
322 typedef struct AVIndexEntry {
325 #define AVINDEX_KEYFRAME 0x0001
327 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).
328 int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
331 #define AV_DISPOSITION_DEFAULT 0x0001
332 #define AV_DISPOSITION_DUB 0x0002
333 #define AV_DISPOSITION_ORIGINAL 0x0004
334 #define AV_DISPOSITION_COMMENT 0x0008
335 #define AV_DISPOSITION_LYRICS 0x0010
336 #define AV_DISPOSITION_KARAOKE 0x0020
340 * New fields can be added to the end with minor version bumps.
341 * Removal, reordering and changes to existing fields require a major
343 * sizeof(AVStream) must not be used outside libav*.
345 typedef struct AVStream {
346 int index; /**< stream index in AVFormatContext */
347 int id; /**< format specific stream id */
348 AVCodecContext *codec; /**< codec context */
350 * Real base frame rate of the stream.
351 * This is the lowest frame rate with which all timestamps can be
352 * represented accurately (it is the least common multiple of all
353 * frame rates in the stream), Note, this value is just a guess!
354 * For example if the timebase is 1/90000 and all frames have either
355 * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1.
357 AVRational r_frame_rate;
360 /* internal data used in av_find_stream_info() */
362 /** encoding: PTS generation when outputing stream */
366 * This is the fundamental unit of time (in seconds) in terms
367 * of which frame timestamps are represented. For fixed-fps content,
368 * timebase should be 1/frame rate and timestamp increments should be
371 AVRational time_base;
372 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
373 /* ffmpeg.c private use */
374 int stream_copy; /**< if set, just copy stream */
375 enum AVDiscard discard; ///< selects which packets can be discarded at will and do not need to be demuxed
376 //FIXME move stuff to a flags field?
377 /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
378 * MN: dunno if that is the right place for it */
381 * Decoding: pts of the first frame of the stream, in stream time base.
382 * Only set this if you are absolutely 100% sure that the value you set
383 * it to really is the pts of the first frame.
384 * This may be undefined (AV_NOPTS_VALUE).
385 * @note The ASF header does NOT contain a correct start_time the ASF
386 * demuxer must NOT set this.
390 * Decoding: duration of the stream, in stream time base.
391 * If a source file does not specify a duration, but does specify
392 * a bitrate, this value will be estimates from bit rate and file size.
396 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
398 /* av_read_frame() support */
399 enum AVStreamParseType need_parsing;
400 struct AVCodecParserContext *parser;
403 int last_IP_duration;
405 /* av_seek_frame() support */
406 AVIndexEntry *index_entries; /**< only used if the format does not
407 support seeking natively */
408 int nb_index_entries;
409 unsigned int index_entries_allocated_size;
411 int64_t nb_frames; ///< number of frames in this stream if known or 0
413 #if LIBAVFORMAT_VERSION_INT < (53<<16)
417 char *filename; /**< source filename of the stream */
419 int disposition; /**< AV_DISPOSITION_* bitfield */
421 AVProbeData probe_data;
422 #define MAX_REORDER_DELAY 16
423 int64_t pts_buffer[MAX_REORDER_DELAY+1];
426 * sample aspect ratio (0 if unknown)
427 * - encoding: Set by user.
428 * - decoding: Set by libavformat.
430 AVRational sample_aspect_ratio;
433 #define AV_PROGRAM_RUNNING 1
436 * New fields can be added to the end with minor version bumps.
437 * Removal, reordering and changes to existing fields require a major
439 * sizeof(AVProgram) must not be used outside libav*.
441 typedef struct AVProgram {
443 char *provider_name; ///< Network name for DVB streams
444 char *name; ///< Service name for DVB streams
446 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
447 unsigned int *stream_index;
448 unsigned int nb_stream_indexes;
451 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
452 (streams are added dynamically) */
454 typedef struct AVChapter {
455 int id; ///< Unique id to identify the chapter
456 AVRational time_base; ///< Timebase in which the start/end timestamps are specified
457 int64_t start, end; ///< chapter start/end time in time_base units
458 char *title; ///< chapter title
461 #define MAX_STREAMS 20
464 * format I/O context.
465 * New fields can be added to the end with minor version bumps.
466 * Removal, reordering and changes to existing fields require a major
468 * sizeof(AVFormatContext) must not be used outside libav*.
470 typedef struct AVFormatContext {
471 const AVClass *av_class; /**< set by av_alloc_format_context */
472 /* can only be iformat or oformat, not both at the same time */
473 struct AVInputFormat *iformat;
474 struct AVOutputFormat *oformat;
477 unsigned int nb_streams;
478 AVStream *streams[MAX_STREAMS];
479 char filename[1024]; /**< input or output filename */
487 int year; /**< ID3 year, 0 if none */
488 int track; /**< track number, 0 if none */
489 char genre[32]; /**< ID3 genre */
491 int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
492 /* private data for pts handling (do not modify directly) */
493 /** This buffer is only needed when packets were already buffered but
494 not decoded, for example to get the codec parameters in mpeg
496 struct AVPacketList *packet_buffer;
498 /** decoding: position of the first frame of the component, in
499 AV_TIME_BASE fractional seconds. NEVER set this value directly:
500 it is deduced from the AVStream values. */
502 /** decoding: duration of the stream, in AV_TIME_BASE fractional
503 seconds. NEVER set this value directly: it is deduced from the
506 /** decoding: total file size. 0 if unknown */
508 /** decoding: total stream bitrate in bit/s, 0 if not
509 available. Never set it directly if the file_size and the
510 duration are known as ffmpeg can compute it automatically. */
513 /* av_read_frame() support */
515 const uint8_t *cur_ptr;
519 /* av_seek_frame() support */
520 int64_t data_offset; /** offset of the first packet */
528 #define AVFMT_NOOUTPUTLOOP -1
529 #define AVFMT_INFINITEOUTPUTLOOP 0
530 /** number of times to loop output in formats that support it */
534 #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
535 #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
536 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input
539 /** decoding: size of data to probe; encoding unused */
540 unsigned int probesize;
543 * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
545 int max_analyze_duration;
550 unsigned int nb_programs;
551 AVProgram **programs;
554 * Forced video codec_id.
555 * demuxing: set by user
557 enum CodecID video_codec_id;
559 * Forced audio codec_id.
560 * demuxing: set by user
562 enum CodecID audio_codec_id;
564 * Forced subtitle codec_id.
565 * demuxing: set by user
567 enum CodecID subtitle_codec_id;
570 * Maximum amount of memory in bytes to use per stream for the index.
571 * If the needed index exceeds this size entries will be discarded as
572 * needed to maintain a smaller size. This can lead to slower or less
573 * accurate seeking (depends on demuxer).
574 * Demuxers for which a full in memory index is mandatory will ignore
577 * demuxing: set by user
579 unsigned int max_index_size;
582 * Maximum amount of memory in bytes to use for buffering frames
583 * obtained from real-time capture devices.
585 unsigned int max_picture_buffer;
587 unsigned int nb_chapters;
588 AVChapter **chapters;
591 * Flags to enable debuging.
594 #define FF_FDEBUG_TS 0x0001
597 * raw packets from the demuxer, prior to parsing and decoding.
598 * This buffer is used for buffering packets until the codec can
599 * be identified, as parsing cannot be done without knowing the
602 struct AVPacketList *raw_packet_buffer;
603 struct AVPacketList *raw_packet_buffer_end;
605 struct AVPacketList *packet_buffer_end;
608 typedef struct AVPacketList {
610 struct AVPacketList *next;
613 #if LIBAVFORMAT_VERSION_INT < (53<<16)
614 extern AVInputFormat *first_iformat;
615 extern AVOutputFormat *first_oformat;
618 AVInputFormat *av_iformat_next(AVInputFormat *f);
619 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
621 enum CodecID av_guess_image2_codec(const char *filename);
623 /* XXX: use automatic init with either ELF sections or C file parser */
627 void av_register_input_format(AVInputFormat *format);
628 void av_register_output_format(AVOutputFormat *format);
629 AVOutputFormat *guess_stream_format(const char *short_name,
630 const char *filename, const char *mime_type);
631 AVOutputFormat *guess_format(const char *short_name,
632 const char *filename, const char *mime_type);
635 * Guesses the codec id based upon muxer and filename.
637 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
638 const char *filename, const char *mime_type, enum CodecType type);
641 * Send a nice hexadecimal dump of a buffer to the specified file stream.
643 * @param f The file stream pointer where the dump should be sent to.
645 * @param size buffer size
647 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
649 void av_hex_dump(FILE *f, uint8_t *buf, int size);
652 * Send a nice hexadecimal dump of a buffer to the log.
654 * @param avcl A pointer to an arbitrary struct of which the first field is a
655 * pointer to an AVClass struct.
656 * @param level The importance level of the message, lower values signifying
659 * @param size buffer size
661 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
663 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
666 * Send a nice dump of a packet to the specified file stream.
668 * @param f The file stream pointer where the dump should be sent to.
669 * @param pkt packet to dump
670 * @param dump_payload true if the payload must be displayed too
672 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
675 * Send a nice dump of a packet to the log.
677 * @param avcl A pointer to an arbitrary struct of which the first field is a
678 * pointer to an AVClass struct.
679 * @param level The importance level of the message, lower values signifying
681 * @param pkt packet to dump
682 * @param dump_payload true if the payload must be displayed too
684 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
686 void av_register_all(void);
688 /** codec tag <-> codec id */
689 enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
690 unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
692 /* media file input */
695 * finds AVInputFormat based on input format's short name.
697 AVInputFormat *av_find_input_format(const char *short_name);
702 * @param is_opened whether the file is already opened, determines whether
703 * demuxers with or without AVFMT_NOFILE are probed
705 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
708 * Allocates all the structures needed to read an input stream.
709 * This does not open the needed codecs for decoding the stream[s].
711 int av_open_input_stream(AVFormatContext **ic_ptr,
712 ByteIOContext *pb, const char *filename,
713 AVInputFormat *fmt, AVFormatParameters *ap);
716 * Open a media file as input. The codecs are not opened. Only the file
717 * header (if present) is read.
719 * @param ic_ptr the opened media file handle is put here
720 * @param filename filename to open.
721 * @param fmt if non NULL, force the file format to use
722 * @param buf_size optional buffer size (zero if default is OK)
723 * @param ap additional parameters needed when opening the file (NULL if default)
724 * @return 0 if OK. AVERROR_xxx otherwise.
726 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
729 AVFormatParameters *ap);
731 * Allocate an AVFormatContext.
732 * Can be freed with av_free() but do not forget to free everything you
733 * explicitly allocated as well!
735 AVFormatContext *av_alloc_format_context(void);
738 * Read packets of a media file to get stream information. This
739 * is useful for file formats with no headers such as MPEG. This
740 * function also computes the real frame rate in case of mpeg2 repeat
742 * The logical file position is not changed by this function;
743 * examined packets may be buffered for later processing.
745 * @param ic media file handle
746 * @return >=0 if OK. AVERROR_xxx if error.
747 * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
749 int av_find_stream_info(AVFormatContext *ic);
752 * Read a transport packet from a media file.
754 * This function is obsolete and should never be used.
755 * Use av_read_frame() instead.
757 * @param s media file handle
758 * @param pkt is filled
759 * @return 0 if OK. AVERROR_xxx if error.
761 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
764 * Return the next frame of a stream.
766 * The returned packet is valid
767 * until the next av_read_frame() or until av_close_input_file() and
768 * must be freed with av_free_packet. For video, the packet contains
769 * exactly one frame. For audio, it contains an integer number of
770 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
771 * data). If the audio frames have a variable size (e.g. MPEG audio),
772 * then it contains one frame.
774 * pkt->pts, pkt->dts and pkt->duration are always set to correct
775 * values in AVStream.timebase units (and guessed if the format cannot
776 * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
777 * has B frames, so it is better to rely on pkt->dts if you do not
778 * decompress the payload.
780 * @return 0 if OK, < 0 if error or end of file.
782 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
785 * Seek to the key frame at timestamp.
786 * 'timestamp' in 'stream_index'.
787 * @param stream_index If stream_index is (-1), a default
788 * stream is selected, and timestamp is automatically converted
789 * from AV_TIME_BASE units to the stream specific time_base.
790 * @param timestamp timestamp in AVStream.time_base units
791 * or if there is no stream specified then in AV_TIME_BASE units
792 * @param flags flags which select direction and seeking mode
793 * @return >= 0 on success
795 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
798 * start playing a network based stream (e.g. RTSP stream) at the
801 int av_read_play(AVFormatContext *s);
804 * Pause a network based stream (e.g. RTSP stream).
806 * Use av_read_play() to resume it.
808 int av_read_pause(AVFormatContext *s);
811 * Free a AVFormatContext allocated by av_open_input_stream.
812 * @param s context to free
814 void av_close_input_stream(AVFormatContext *s);
817 * Close a media file (but not its codecs).
819 * @param s media file handle
821 void av_close_input_file(AVFormatContext *s);
824 * Add a new stream to a media file.
826 * Can only be called in the read_header() function. If the flag
827 * AVFMTCTX_NOHEADER is in the format context, then new streams
828 * can be added in read_packet too.
830 * @param s media file handle
831 * @param id file format dependent stream id
833 AVStream *av_new_stream(AVFormatContext *s, int id);
834 AVProgram *av_new_program(AVFormatContext *s, int id);
838 * This function is NOT part of the public API
839 * and should be ONLY used by demuxers.
841 * @param s media file handle
842 * @param id unique id for this chapter
843 * @param start chapter start time in time_base units
844 * @param end chapter end time in time_base units
845 * @param title chapter title
847 * @return AVChapter or NULL if error.
849 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
852 * Set the pts for a given stream.
855 * @param pts_wrap_bits number of bits effectively used by the pts
856 * (used for wrap control, 33 is the value for MPEG)
857 * @param pts_num numerator to convert to seconds (MPEG: 1)
858 * @param pts_den denominator to convert to seconds (MPEG: 90000)
860 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
861 int pts_num, int pts_den);
863 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
864 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
865 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
867 int av_find_default_stream_index(AVFormatContext *s);
870 * Gets the index for a specific timestamp.
871 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
872 * the timestamp which is <= the requested one, if backward is 0
874 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
875 * @return < 0 if no such timestamp could be found
877 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
880 * Ensures the index uses less memory than the maximum specified in
881 * AVFormatContext.max_index_size, by discarding entries if it grows
883 * This function is not part of the public API and should only be called
886 void ff_reduce_index(AVFormatContext *s, int stream_index);
889 * Add a index entry into a sorted list updateing if it is already there.
891 * @param timestamp timestamp in the timebase of the given stream
893 int av_add_index_entry(AVStream *st,
894 int64_t pos, int64_t timestamp, int size, int distance, int flags);
897 * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
898 * This is not supposed to be called directly by a user application, but by demuxers.
899 * @param target_ts target timestamp in the time base of the given stream
900 * @param stream_index stream number
902 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
905 * Updates cur_dts of all streams based on given timestamp and AVStream.
907 * Stream ref_st unchanged, others set cur_dts in their native timebase
908 * only needed for timestamp wrapping or if (dts not set and pts!=dts).
909 * @param timestamp new dts expressed in time_base of param ref_st
910 * @param ref_st reference stream giving time_base of param timestamp
912 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
915 * Does a binary search using read_timestamp().
916 * This is not supposed to be called directly by a user application, but by demuxers.
917 * @param target_ts target timestamp in the time base of the given stream
918 * @param stream_index stream number
920 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 ));
922 /** media file output */
923 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
926 * Allocate the stream private data and write the stream header to an
929 * @param s media file handle
930 * @return 0 if OK. AVERROR_xxx if error.
932 int av_write_header(AVFormatContext *s);
935 * Write a packet to an output media file.
937 * The packet shall contain one audio or video frame.
938 * The packet must be correctly interleaved according to the container specification,
939 * if not then av_interleaved_write_frame must be used
941 * @param s media file handle
942 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
943 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
945 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
948 * Writes a packet to an output media file ensuring correct interleaving.
950 * The packet must contain one audio or video frame.
951 * If the packets are already correctly interleaved the application should
952 * call av_write_frame() instead as it is slightly faster. It is also important
953 * to keep in mind that completely non-interleaved input will need huge amounts
954 * of memory to interleave with this, so it is preferable to interleave at the
957 * @param s media file handle
958 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
959 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
961 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
964 * Interleave a packet per DTS in an output media file.
966 * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
967 * so they cannot be used after it, note calling av_free_packet() on them is still safe.
969 * @param s media file handle
970 * @param out the interleaved packet will be output here
971 * @param in the input packet
972 * @param flush 1 if no further packets are available as input and all
973 * remaining packets should be output
974 * @return 1 if a packet was output, 0 if no packet could be output,
975 * < 0 if an error occurred
977 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
980 * @brief Write the stream trailer to an output media file and
981 * free the file private data.
983 * May only be called after a successful call to av_write_header.
985 * @param s media file handle
986 * @return 0 if OK. AVERROR_xxx if error.
988 int av_write_trailer(AVFormatContext *s);
990 void dump_format(AVFormatContext *ic,
996 * parses width and height out of string str.
997 * @deprecated Use av_parse_video_frame_size instead.
999 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
1002 * Converts frame rate from string to a fraction.
1003 * @deprecated Use av_parse_video_frame_rate instead.
1005 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
1008 * Parses \p datestr and returns a corresponding number of microseconds.
1009 * @param datestr String representing a date or a duration.
1010 * - If a date the syntax is:
1012 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1014 * Time is localtime unless Z is appended, in which case it is
1015 * interpreted as UTC.
1016 * If the year-month-day part isn't specified it takes the current
1018 * Returns the number of microseconds since 1st of January, 1970 up to
1019 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1020 * successfully parsed.
1021 * - If a duration the syntax is:
1023 * [-]HH[:MM[:SS[.m...]]]
1026 * Returns the number of microseconds contained in a time interval
1027 * with the specified duration or INT64_MIN if \p datestr cannot be
1028 * successfully parsed.
1029 * @param duration Flag which tells how to interpret \p datestr, if
1030 * not zero \p datestr is interpreted as a duration, otherwise as a
1033 int64_t parse_date(const char *datestr, int duration);
1035 int64_t av_gettime(void);
1037 /* ffm specific for ffserver */
1038 #define FFM_PACKET_SIZE 4096
1039 offset_t ffm_read_write_index(int fd);
1040 void ffm_write_write_index(int fd, offset_t pos);
1041 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
1044 * Attempts to find a specific tag in a URL.
1046 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1047 * Return 1 if found.
1049 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1052 * Returns in 'buf' the path with '%d' replaced by number.
1054 * Also handles the '%0nd' format where 'n' is the total number
1055 * of digits and '%%'.
1057 * @param buf destination buffer
1058 * @param buf_size destination buffer size
1059 * @param path numbered sequence string
1060 * @param number frame number
1061 * @return 0 if OK, -1 if format error.
1063 int av_get_frame_filename(char *buf, int buf_size,
1064 const char *path, int number);
1067 * Check whether filename actually is a numbered sequence generator.
1069 * @param filename possible numbered sequence string
1070 * @return 1 if a valid numbered sequence string, 0 otherwise.
1072 int av_filename_number_test(const char *filename);
1075 * Generate an SDP for an RTP session.
1077 * @param ac array of AVFormatContexts describing the RTP streams. If the
1078 * array is composed by only one context, such context can contain
1079 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1080 * all the contexts in the array (an AVCodecContext per RTP stream)
1081 * must contain only one AVStream
1082 * @param n_files number of AVCodecContexts contained in ac
1083 * @param buff buffer where the SDP will be stored (must be allocated by
1085 * @param size the size of the buffer
1086 * @return 0 if OK. AVERROR_xxx if error.
1088 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1090 #ifdef HAVE_AV_CONFIG_H
1092 void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1095 #define dynarray_add(tab, nb_ptr, elem)\
1097 typeof(tab) _tab = (tab);\
1098 typeof(elem) _elem = (elem);\
1099 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1100 ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1103 #define dynarray_add(tab, nb_ptr, elem)\
1105 ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1109 time_t mktimegm(struct tm *tm);
1110 struct tm *brktimegm(time_t secs, struct tm *tm);
1111 const char *small_strptime(const char *p, const char *fmt,
1115 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1117 void url_split(char *proto, int proto_size,
1118 char *authorization, int authorization_size,
1119 char *hostname, int hostname_size,
1121 char *path, int path_size,
1124 int match_ext(const char *filename, const char *extensions);
1126 #endif /* HAVE_AV_CONFIG_H */
1128 #endif /* AVFORMAT_AVFORMAT_H */