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 of this
84 * packet to the point at which the output from the decoder has converged
85 * independent from the availability
86 * of previous frames (that is the frames are virtually identical no matter
87 * if decoding started from the very first frame or from this keyframe).
88 * is AV_NOPTS_VALUE if unknown.
89 * This field is not the display duration of the current packet.
91 * The purpose of this field is to allow seeking in streams that have no
92 * keyframes in the conventional sense. It corresponds to the
93 * recovery point SEI in H.264 and match_time_delta in nut. It also is
94 * essential for some types of subtitle streams to ensure that all
95 * subtitles are correctly displayed after seeking.
97 int64_t convergence_duration;
99 #define PKT_FLAG_KEY 0x0001
101 void av_destruct_packet_nofree(AVPacket *pkt);
104 * Default packet destructor.
106 void av_destruct_packet(AVPacket *pkt);
109 * Initialize optional fields of a packet to default values.
113 void av_init_packet(AVPacket *pkt);
116 * Allocate the payload of a packet and initialize its fields to default values.
119 * @param size wanted payload size
120 * @return 0 if OK. AVERROR_xxx otherwise.
122 int av_new_packet(AVPacket *pkt, int size);
125 * Allocate and read the payload of a packet and initialize its fields to default values.
128 * @param size wanted payload size
129 * @return >0 (read size) if OK. AVERROR_xxx otherwise.
131 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
134 * @warning This is a hack - the packet memory allocation stuff is broken. The
135 * packet is allocated if it was not really allocated
137 int av_dup_packet(AVPacket *pkt);
142 * @param pkt packet to free
144 static inline void av_free_packet(AVPacket *pkt)
146 if (pkt && pkt->destruct) {
151 /*************************************************/
152 /* fractional numbers for exact pts handling */
155 * the exact value of the fractional number is: 'val + num / den'.
156 * num is assumed to be such as 0 <= num < den
157 * @deprecated Use AVRational instead
159 typedef struct AVFrac {
160 int64_t val, num, den;
161 } AVFrac attribute_deprecated;
163 /*************************************************/
164 /* input/output formats */
168 struct AVFormatContext;
170 /** this structure contains the data a format has to probe a file */
171 typedef struct AVProbeData {
172 const char *filename;
177 #define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
178 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
180 typedef struct AVFormatParameters {
181 AVRational time_base;
186 enum PixelFormat pix_fmt;
187 int channel; /**< used to select dv channel */
188 const char *standard; /**< tv standard, NTSC, PAL, SECAM */
189 unsigned int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
190 unsigned int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
191 stream packet (only meaningful if
192 mpeg2ts_raw is TRUE) */
193 unsigned int initial_pause:1; /**< do not begin to play the stream
194 immediately (RTSP only) */
195 unsigned int prealloced_context:1;
196 #if LIBAVFORMAT_VERSION_INT < (53<<16)
197 enum CodecID video_codec_id;
198 enum CodecID audio_codec_id;
200 } AVFormatParameters;
202 //! demuxer will use url_fopen, no opened file should be provided by the caller
203 #define AVFMT_NOFILE 0x0001
204 #define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
205 #define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
206 #define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
208 #define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
209 #define AVFMT_NOTIMESTAMPS 0x0080 /**< format does not need / have any timestamps */
210 #define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
211 #define AVFMT_TS_DISCONT 0x0200 /**< format allows timestamo discontinuities */
213 typedef struct AVOutputFormat {
216 * Descriptive name for the format, meant to be more human-readable
217 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
220 const char *long_name;
221 const char *mime_type;
222 const char *extensions; /**< comma separated filename extensions */
223 /** size of private data so that it can be allocated in the wrapper */
226 enum CodecID audio_codec; /**< default audio codec */
227 enum CodecID video_codec; /**< default video codec */
228 int (*write_header)(struct AVFormatContext *);
229 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
230 int (*write_trailer)(struct AVFormatContext *);
231 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
233 /** currently only used to set pixel format if not YUV420P */
234 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
235 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
238 * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
239 * the arrays are all CODEC_ID_NONE terminated
241 const struct AVCodecTag * const *codec_tag;
243 enum CodecID subtitle_codec; /**< default subtitle codec */
246 struct AVOutputFormat *next;
249 typedef struct AVInputFormat {
252 * Descriptive name for the format, meant to be more human-readable
253 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
256 const char *long_name;
257 /** size of private data so that it can be allocated in the wrapper */
260 * Tell if a given file has a chance of being parsed by this format.
261 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
262 * big so you do not have to check for that unless you need more.
264 int (*read_probe)(AVProbeData *);
265 /** read the format header and initialize the AVFormatContext
266 structure. Return 0 if OK. 'ap' if non NULL contains
267 additional paramters. Only used in raw format right
268 now. 'av_new_stream' should be called to create new streams. */
269 int (*read_header)(struct AVFormatContext *,
270 AVFormatParameters *ap);
271 /** read one packet and put it in 'pkt'. pts and flags are also
272 set. 'av_new_stream' can be called only if the flag
273 AVFMTCTX_NOHEADER is used. */
274 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
275 /** close the stream. The AVFormatContext and AVStreams are not
276 freed by this function */
277 int (*read_close)(struct AVFormatContext *);
279 * seek to a given timestamp relative to the frames in
280 * stream component stream_index
281 * @param stream_index must not be -1
282 * @param flags selects which direction should be preferred if no exact
284 * @return >= 0 on success (but not necessarily the new offset)
286 int (*read_seek)(struct AVFormatContext *,
287 int stream_index, int64_t timestamp, int flags);
289 * gets the next timestamp in stream[stream_index].time_base units.
290 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
292 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
293 int64_t *pos, int64_t pos_limit);
294 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
296 /** if extensions are defined, then no probe is done. You should
297 usually not use extension format guessing because it is not
299 const char *extensions;
300 /** general purpose read only value that the format can use */
303 /** start/resume playing - only meaningful if using a network based format
305 int (*read_play)(struct AVFormatContext *);
307 /** pause playing - only meaningful if using a network based format
309 int (*read_pause)(struct AVFormatContext *);
311 const struct AVCodecTag * const *codec_tag;
314 struct AVInputFormat *next;
317 enum AVStreamParseType {
319 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
320 AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */
321 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */
324 typedef struct AVIndexEntry {
327 #define AVINDEX_KEYFRAME 0x0001
329 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).
330 int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
333 #define AV_DISPOSITION_DEFAULT 0x0001
334 #define AV_DISPOSITION_DUB 0x0002
335 #define AV_DISPOSITION_ORIGINAL 0x0004
336 #define AV_DISPOSITION_COMMENT 0x0008
337 #define AV_DISPOSITION_LYRICS 0x0010
338 #define AV_DISPOSITION_KARAOKE 0x0020
342 * New fields can be added to the end with minor version bumps.
343 * Removal, reordering and changes to existing fields require a major
345 * sizeof(AVStream) must not be used outside libav*.
347 typedef struct AVStream {
348 int index; /**< stream index in AVFormatContext */
349 int id; /**< format specific stream id */
350 AVCodecContext *codec; /**< codec context */
352 * Real base frame rate of the stream.
353 * This is the lowest frame rate with which all timestamps can be
354 * represented accurately (it is the least common multiple of all
355 * frame rates in the stream), Note, this value is just a guess!
356 * For example if the timebase is 1/90000 and all frames have either
357 * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1.
359 AVRational r_frame_rate;
362 /* internal data used in av_find_stream_info() */
364 /** encoding: PTS generation when outputing stream */
368 * This is the fundamental unit of time (in seconds) in terms
369 * of which frame timestamps are represented. For fixed-fps content,
370 * timebase should be 1/frame rate and timestamp increments should be
373 AVRational time_base;
374 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
375 /* ffmpeg.c private use */
376 int stream_copy; /**< if set, just copy stream */
377 enum AVDiscard discard; ///< selects which packets can be discarded at will and do not need to be demuxed
378 //FIXME move stuff to a flags field?
379 /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
380 * MN: dunno if that is the right place for it */
383 * Decoding: pts of the first frame of the stream, in stream time base.
384 * Only set this if you are absolutely 100% sure that the value you set
385 * it to really is the pts of the first frame.
386 * This may be undefined (AV_NOPTS_VALUE).
387 * @note The ASF header does NOT contain a correct start_time the ASF
388 * demuxer must NOT set this.
392 * Decoding: duration of the stream, in stream time base.
393 * If a source file does not specify a duration, but does specify
394 * a bitrate, this value will be estimates from bit rate and file size.
398 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
400 /* av_read_frame() support */
401 enum AVStreamParseType need_parsing;
402 struct AVCodecParserContext *parser;
405 int last_IP_duration;
407 /* av_seek_frame() support */
408 AVIndexEntry *index_entries; /**< only used if the format does not
409 support seeking natively */
410 int nb_index_entries;
411 unsigned int index_entries_allocated_size;
413 int64_t nb_frames; ///< number of frames in this stream if known or 0
415 #if LIBAVFORMAT_VERSION_INT < (53<<16)
419 char *filename; /**< source filename of the stream */
421 int disposition; /**< AV_DISPOSITION_* bitfield */
423 AVProbeData probe_data;
424 #define MAX_REORDER_DELAY 16
425 int64_t pts_buffer[MAX_REORDER_DELAY+1];
428 * sample aspect ratio (0 if unknown)
429 * - encoding: Set by user.
430 * - decoding: Set by libavformat.
432 AVRational sample_aspect_ratio;
435 #define AV_PROGRAM_RUNNING 1
438 * New fields can be added to the end with minor version bumps.
439 * Removal, reordering and changes to existing fields require a major
441 * sizeof(AVProgram) must not be used outside libav*.
443 typedef struct AVProgram {
445 char *provider_name; ///< Network name for DVB streams
446 char *name; ///< Service name for DVB streams
448 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
449 unsigned int *stream_index;
450 unsigned int nb_stream_indexes;
453 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
454 (streams are added dynamically) */
456 typedef struct AVChapter {
457 int id; ///< Unique id to identify the chapter
458 AVRational time_base; ///< Timebase in which the start/end timestamps are specified
459 int64_t start, end; ///< chapter start/end time in time_base units
460 char *title; ///< chapter title
463 #define MAX_STREAMS 20
466 * format I/O context.
467 * New fields can be added to the end with minor version bumps.
468 * Removal, reordering and changes to existing fields require a major
470 * sizeof(AVFormatContext) must not be used outside libav*.
472 typedef struct AVFormatContext {
473 const AVClass *av_class; /**< set by av_alloc_format_context */
474 /* can only be iformat or oformat, not both at the same time */
475 struct AVInputFormat *iformat;
476 struct AVOutputFormat *oformat;
479 unsigned int nb_streams;
480 AVStream *streams[MAX_STREAMS];
481 char filename[1024]; /**< input or output filename */
489 int year; /**< ID3 year, 0 if none */
490 int track; /**< track number, 0 if none */
491 char genre[32]; /**< ID3 genre */
493 int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
494 /* private data for pts handling (do not modify directly) */
495 /** This buffer is only needed when packets were already buffered but
496 not decoded, for example to get the codec parameters in mpeg
498 struct AVPacketList *packet_buffer;
500 /** decoding: position of the first frame of the component, in
501 AV_TIME_BASE fractional seconds. NEVER set this value directly:
502 it is deduced from the AVStream values. */
504 /** decoding: duration of the stream, in AV_TIME_BASE fractional
505 seconds. NEVER set this value directly: it is deduced from the
508 /** decoding: total file size. 0 if unknown */
510 /** decoding: total stream bitrate in bit/s, 0 if not
511 available. Never set it directly if the file_size and the
512 duration are known as ffmpeg can compute it automatically. */
515 /* av_read_frame() support */
517 const uint8_t *cur_ptr;
521 /* av_seek_frame() support */
522 int64_t data_offset; /** offset of the first packet */
530 #define AVFMT_NOOUTPUTLOOP -1
531 #define AVFMT_INFINITEOUTPUTLOOP 0
532 /** number of times to loop output in formats that support it */
536 #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
537 #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
538 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input
541 /** decoding: size of data to probe; encoding unused */
542 unsigned int probesize;
545 * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
547 int max_analyze_duration;
552 unsigned int nb_programs;
553 AVProgram **programs;
556 * Forced video codec_id.
557 * demuxing: set by user
559 enum CodecID video_codec_id;
561 * Forced audio codec_id.
562 * demuxing: set by user
564 enum CodecID audio_codec_id;
566 * Forced subtitle codec_id.
567 * demuxing: set by user
569 enum CodecID subtitle_codec_id;
572 * Maximum amount of memory in bytes to use per stream for the index.
573 * If the needed index exceeds this size entries will be discarded as
574 * needed to maintain a smaller size. This can lead to slower or less
575 * accurate seeking (depends on demuxer).
576 * Demuxers for which a full in memory index is mandatory will ignore
579 * demuxing: set by user
581 unsigned int max_index_size;
584 * Maximum amount of memory in bytes to use for buffering frames
585 * obtained from real-time capture devices.
587 unsigned int max_picture_buffer;
589 unsigned int nb_chapters;
590 AVChapter **chapters;
593 * Flags to enable debuging.
596 #define FF_FDEBUG_TS 0x0001
599 * raw packets from the demuxer, prior to parsing and decoding.
600 * This buffer is used for buffering packets until the codec can
601 * be identified, as parsing cannot be done without knowing the
604 struct AVPacketList *raw_packet_buffer;
605 struct AVPacketList *raw_packet_buffer_end;
607 struct AVPacketList *packet_buffer_end;
610 typedef struct AVPacketList {
612 struct AVPacketList *next;
615 #if LIBAVFORMAT_VERSION_INT < (53<<16)
616 extern AVInputFormat *first_iformat;
617 extern AVOutputFormat *first_oformat;
620 AVInputFormat *av_iformat_next(AVInputFormat *f);
621 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
623 enum CodecID av_guess_image2_codec(const char *filename);
625 /* XXX: use automatic init with either ELF sections or C file parser */
629 void av_register_input_format(AVInputFormat *format);
630 void av_register_output_format(AVOutputFormat *format);
631 AVOutputFormat *guess_stream_format(const char *short_name,
632 const char *filename, const char *mime_type);
633 AVOutputFormat *guess_format(const char *short_name,
634 const char *filename, const char *mime_type);
637 * Guesses the codec id based upon muxer and filename.
639 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
640 const char *filename, const char *mime_type, enum CodecType type);
643 * Send a nice hexadecimal dump of a buffer to the specified file stream.
645 * @param f The file stream pointer where the dump should be sent to.
647 * @param size buffer size
649 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
651 void av_hex_dump(FILE *f, uint8_t *buf, int size);
654 * Send a nice hexadecimal dump of a buffer to the log.
656 * @param avcl A pointer to an arbitrary struct of which the first field is a
657 * pointer to an AVClass struct.
658 * @param level The importance level of the message, lower values signifying
661 * @param size buffer size
663 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
665 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
668 * Send a nice dump of a packet to the specified file stream.
670 * @param f The file stream pointer where the dump should be sent to.
671 * @param pkt packet to dump
672 * @param dump_payload true if the payload must be displayed too
674 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
677 * Send a nice dump of a packet to the log.
679 * @param avcl A pointer to an arbitrary struct of which the first field is a
680 * pointer to an AVClass struct.
681 * @param level The importance level of the message, lower values signifying
683 * @param pkt packet to dump
684 * @param dump_payload true if the payload must be displayed too
686 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
688 void av_register_all(void);
690 /** codec tag <-> codec id */
691 enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
692 unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
694 /* media file input */
697 * finds AVInputFormat based on input format's short name.
699 AVInputFormat *av_find_input_format(const char *short_name);
704 * @param is_opened whether the file is already opened, determines whether
705 * demuxers with or without AVFMT_NOFILE are probed
707 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
710 * Allocates all the structures needed to read an input stream.
711 * This does not open the needed codecs for decoding the stream[s].
713 int av_open_input_stream(AVFormatContext **ic_ptr,
714 ByteIOContext *pb, const char *filename,
715 AVInputFormat *fmt, AVFormatParameters *ap);
718 * Open a media file as input. The codecs are not opened. Only the file
719 * header (if present) is read.
721 * @param ic_ptr the opened media file handle is put here
722 * @param filename filename to open.
723 * @param fmt if non NULL, force the file format to use
724 * @param buf_size optional buffer size (zero if default is OK)
725 * @param ap additional parameters needed when opening the file (NULL if default)
726 * @return 0 if OK. AVERROR_xxx otherwise.
728 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
731 AVFormatParameters *ap);
733 * Allocate an AVFormatContext.
734 * Can be freed with av_free() but do not forget to free everything you
735 * explicitly allocated as well!
737 AVFormatContext *av_alloc_format_context(void);
740 * Read packets of a media file to get stream information. This
741 * is useful for file formats with no headers such as MPEG. This
742 * function also computes the real frame rate in case of mpeg2 repeat
744 * The logical file position is not changed by this function;
745 * examined packets may be buffered for later processing.
747 * @param ic media file handle
748 * @return >=0 if OK. AVERROR_xxx if error.
749 * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
751 int av_find_stream_info(AVFormatContext *ic);
754 * Read a transport packet from a media file.
756 * This function is obsolete and should never be used.
757 * Use av_read_frame() instead.
759 * @param s media file handle
760 * @param pkt is filled
761 * @return 0 if OK. AVERROR_xxx if error.
763 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
766 * Return the next frame of a stream.
768 * The returned packet is valid
769 * until the next av_read_frame() or until av_close_input_file() and
770 * must be freed with av_free_packet. For video, the packet contains
771 * exactly one frame. For audio, it contains an integer number of
772 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
773 * data). If the audio frames have a variable size (e.g. MPEG audio),
774 * then it contains one frame.
776 * pkt->pts, pkt->dts and pkt->duration are always set to correct
777 * values in AVStream.timebase units (and guessed if the format cannot
778 * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
779 * has B frames, so it is better to rely on pkt->dts if you do not
780 * decompress the payload.
782 * @return 0 if OK, < 0 if error or end of file.
784 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
787 * Seek to the key frame at timestamp.
788 * 'timestamp' in 'stream_index'.
789 * @param stream_index If stream_index is (-1), a default
790 * stream is selected, and timestamp is automatically converted
791 * from AV_TIME_BASE units to the stream specific time_base.
792 * @param timestamp timestamp in AVStream.time_base units
793 * or if there is no stream specified then in AV_TIME_BASE units
794 * @param flags flags which select direction and seeking mode
795 * @return >= 0 on success
797 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
800 * start playing a network based stream (e.g. RTSP stream) at the
803 int av_read_play(AVFormatContext *s);
806 * Pause a network based stream (e.g. RTSP stream).
808 * Use av_read_play() to resume it.
810 int av_read_pause(AVFormatContext *s);
813 * Free a AVFormatContext allocated by av_open_input_stream.
814 * @param s context to free
816 void av_close_input_stream(AVFormatContext *s);
819 * Close a media file (but not its codecs).
821 * @param s media file handle
823 void av_close_input_file(AVFormatContext *s);
826 * Add a new stream to a media file.
828 * Can only be called in the read_header() function. If the flag
829 * AVFMTCTX_NOHEADER is in the format context, then new streams
830 * can be added in read_packet too.
832 * @param s media file handle
833 * @param id file format dependent stream id
835 AVStream *av_new_stream(AVFormatContext *s, int id);
836 AVProgram *av_new_program(AVFormatContext *s, int id);
840 * This function is NOT part of the public API
841 * and should be ONLY used by demuxers.
843 * @param s media file handle
844 * @param id unique id for this chapter
845 * @param start chapter start time in time_base units
846 * @param end chapter end time in time_base units
847 * @param title chapter title
849 * @return AVChapter or NULL if error.
851 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
854 * Set the pts for a given stream.
857 * @param pts_wrap_bits number of bits effectively used by the pts
858 * (used for wrap control, 33 is the value for MPEG)
859 * @param pts_num numerator to convert to seconds (MPEG: 1)
860 * @param pts_den denominator to convert to seconds (MPEG: 90000)
862 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
863 int pts_num, int pts_den);
865 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
866 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
867 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
869 int av_find_default_stream_index(AVFormatContext *s);
872 * Gets the index for a specific timestamp.
873 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
874 * the timestamp which is <= the requested one, if backward is 0
876 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
877 * @return < 0 if no such timestamp could be found
879 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
882 * Ensures the index uses less memory than the maximum specified in
883 * AVFormatContext.max_index_size, by discarding entries if it grows
885 * This function is not part of the public API and should only be called
888 void ff_reduce_index(AVFormatContext *s, int stream_index);
891 * Add a index entry into a sorted list updateing if it is already there.
893 * @param timestamp timestamp in the timebase of the given stream
895 int av_add_index_entry(AVStream *st,
896 int64_t pos, int64_t timestamp, int size, int distance, int flags);
899 * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
900 * This is not supposed to be called directly by a user application, but by demuxers.
901 * @param target_ts target timestamp in the time base of the given stream
902 * @param stream_index stream number
904 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
907 * Updates cur_dts of all streams based on given timestamp and AVStream.
909 * Stream ref_st unchanged, others set cur_dts in their native timebase
910 * only needed for timestamp wrapping or if (dts not set and pts!=dts).
911 * @param timestamp new dts expressed in time_base of param ref_st
912 * @param ref_st reference stream giving time_base of param timestamp
914 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
917 * Does a binary search using read_timestamp().
918 * This is not supposed to be called directly by a user application, but by demuxers.
919 * @param target_ts target timestamp in the time base of the given stream
920 * @param stream_index stream number
922 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 ));
924 /** media file output */
925 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
928 * Allocate the stream private data and write the stream header to an
931 * @param s media file handle
932 * @return 0 if OK. AVERROR_xxx if error.
934 int av_write_header(AVFormatContext *s);
937 * Write a packet to an output media file.
939 * The packet shall contain one audio or video frame.
940 * The packet must be correctly interleaved according to the container specification,
941 * if not then av_interleaved_write_frame must be used
943 * @param s media file handle
944 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
945 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
947 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
950 * Writes a packet to an output media file ensuring correct interleaving.
952 * The packet must contain one audio or video frame.
953 * If the packets are already correctly interleaved the application should
954 * call av_write_frame() instead as it is slightly faster. It is also important
955 * to keep in mind that completely non-interleaved input will need huge amounts
956 * of memory to interleave with this, so it is preferable to interleave at the
959 * @param s media file handle
960 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
961 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
963 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
966 * Interleave a packet per DTS in an output media file.
968 * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
969 * so they cannot be used after it, note calling av_free_packet() on them is still safe.
971 * @param s media file handle
972 * @param out the interleaved packet will be output here
973 * @param in the input packet
974 * @param flush 1 if no further packets are available as input and all
975 * remaining packets should be output
976 * @return 1 if a packet was output, 0 if no packet could be output,
977 * < 0 if an error occurred
979 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
982 * @brief Write the stream trailer to an output media file and
983 * free the file private data.
985 * May only be called after a successful call to av_write_header.
987 * @param s media file handle
988 * @return 0 if OK. AVERROR_xxx if error.
990 int av_write_trailer(AVFormatContext *s);
992 void dump_format(AVFormatContext *ic,
998 * parses width and height out of string str.
999 * @deprecated Use av_parse_video_frame_size instead.
1001 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
1004 * Converts frame rate from string to a fraction.
1005 * @deprecated Use av_parse_video_frame_rate instead.
1007 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
1010 * Parses \p datestr and returns a corresponding number of microseconds.
1011 * @param datestr String representing a date or a duration.
1012 * - If a date the syntax is:
1014 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1016 * Time is localtime unless Z is appended, in which case it is
1017 * interpreted as UTC.
1018 * If the year-month-day part isn't specified it takes the current
1020 * Returns the number of microseconds since 1st of January, 1970 up to
1021 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1022 * successfully parsed.
1023 * - If a duration the syntax is:
1025 * [-]HH[:MM[:SS[.m...]]]
1028 * Returns the number of microseconds contained in a time interval
1029 * with the specified duration or INT64_MIN if \p datestr cannot be
1030 * successfully parsed.
1031 * @param duration Flag which tells how to interpret \p datestr, if
1032 * not zero \p datestr is interpreted as a duration, otherwise as a
1035 int64_t parse_date(const char *datestr, int duration);
1037 /** Gets the current time in microseconds. */
1038 int64_t av_gettime(void);
1040 /* ffm specific for ffserver */
1041 #define FFM_PACKET_SIZE 4096
1042 offset_t ffm_read_write_index(int fd);
1043 void ffm_write_write_index(int fd, offset_t pos);
1044 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
1047 * Attempts to find a specific tag in a URL.
1049 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1050 * Return 1 if found.
1052 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1055 * Returns in 'buf' the path with '%d' replaced by number.
1057 * Also handles the '%0nd' format where 'n' is the total number
1058 * of digits and '%%'.
1060 * @param buf destination buffer
1061 * @param buf_size destination buffer size
1062 * @param path numbered sequence string
1063 * @param number frame number
1064 * @return 0 if OK, -1 if format error.
1066 int av_get_frame_filename(char *buf, int buf_size,
1067 const char *path, int number);
1070 * Check whether filename actually is a numbered sequence generator.
1072 * @param filename possible numbered sequence string
1073 * @return 1 if a valid numbered sequence string, 0 otherwise.
1075 int av_filename_number_test(const char *filename);
1078 * Generate an SDP for an RTP session.
1080 * @param ac array of AVFormatContexts describing the RTP streams. If the
1081 * array is composed by only one context, such context can contain
1082 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1083 * all the contexts in the array (an AVCodecContext per RTP stream)
1084 * must contain only one AVStream
1085 * @param n_files number of AVCodecContexts contained in ac
1086 * @param buff buffer where the SDP will be stored (must be allocated by
1088 * @param size the size of the buffer
1089 * @return 0 if OK. AVERROR_xxx if error.
1091 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1093 #ifdef HAVE_AV_CONFIG_H
1095 void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1098 #define dynarray_add(tab, nb_ptr, elem)\
1100 typeof(tab) _tab = (tab);\
1101 typeof(elem) _elem = (elem);\
1102 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1103 ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1106 #define dynarray_add(tab, nb_ptr, elem)\
1108 ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1112 time_t mktimegm(struct tm *tm);
1113 struct tm *brktimegm(time_t secs, struct tm *tm);
1114 const char *small_strptime(const char *p, const char *fmt,
1118 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1120 void url_split(char *proto, int proto_size,
1121 char *authorization, int authorization_size,
1122 char *hostname, int hostname_size,
1124 char *path, int path_size,
1127 int match_ext(const char *filename, const char *extensions);
1129 #endif /* HAVE_AV_CONFIG_H */
1131 #endif /* AVFORMAT_AVFORMAT_H */