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
25 * @defgroup libavf I/O and Muxing/Demuxing Library
28 * @defgroup lavf_decoding Demuxing
32 * @defgroup lavf_encoding Muxing
36 * @defgroup lavf_proto I/O Read/Write
40 * @defgroup lavf_codec Demuxers
42 * @defgroup lavf_codec_native Native Demuxers
45 * @defgroup lavf_codec_wrappers External library wrappers
49 * @defgroup lavf_protos I/O Protocols
52 * @defgroup lavf_internal Internal
60 * Return the LIBAVFORMAT_VERSION_INT constant.
62 unsigned avformat_version(void);
65 * Return the libavformat build-time configuration.
67 const char *avformat_configuration(void);
70 * Return the libavformat license.
72 const char *avformat_license(void);
75 #include <stdio.h> /* FILE */
76 #include "libavcodec/avcodec.h"
77 #include "libavutil/dict.h"
78 #include "libavutil/log.h"
81 #include "libavformat/version.h"
83 struct AVFormatContext;
87 * @defgroup metadata_api Public Metadata API
89 * The metadata API allows libavformat to export metadata tags to a client
90 * application using a sequence of key/value pairs. Like all strings in FFmpeg,
91 * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
92 * exported by demuxers isn't checked to be valid UTF-8 in most cases.
93 * Important concepts to keep in mind:
94 * - Keys are unique; there can never be 2 tags with the same key. This is
95 * also meant semantically, i.e., a demuxer should not knowingly produce
96 * several keys that are literally different but semantically identical.
97 * E.g., key=Author5, key=Author6. In this example, all authors must be
98 * placed in the same tag.
99 * - Metadata is flat, not hierarchical; there are no subtags. If you
100 * want to store, e.g., the email address of the child of producer Alice
101 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
102 * - Several modifiers can be applied to the tag name. This is done by
103 * appending a dash character ('-') and the modifier name in the order
104 * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
105 * - language -- a tag whose value is localized for a particular language
106 * is appended with the ISO 639-2/B 3-letter language code.
107 * For example: Author-ger=Michael, Author-eng=Mike
108 * The original/default language is in the unqualified "Author" tag.
109 * A demuxer should set a default if it sets any translated tag.
110 * - sorting -- a modified version of a tag that should be used for
111 * sorting will have '-sort' appended. E.g. artist="The Beatles",
112 * artist-sort="Beatles, The".
114 * - Demuxers attempt to export metadata in a generic format, however tags
115 * with no generic equivalents are left as they are stored in the container.
116 * Follows a list of generic tag names:
119 album -- name of the set this work belongs to
120 album_artist -- main creator of the set/album, if different from artist.
121 e.g. "Various Artists" for compilation albums.
122 artist -- main creator of the work
123 comment -- any additional description of the file.
124 composer -- who composed the work, if different from artist.
125 copyright -- name of copyright holder.
126 creation_time-- date when the file was created, preferably in ISO 8601.
127 date -- date when the work was created, preferably in ISO 8601.
128 disc -- number of a subset, e.g. disc in a multi-disc collection.
129 encoder -- name/settings of the software/hardware that produced the file.
130 encoded_by -- person/group who created the file.
131 filename -- original name of the file.
132 genre -- <self-evident>.
133 language -- main language in which the work is performed, preferably
134 in ISO 639-2 format. Multiple languages can be specified by
135 separating them with commas.
136 performer -- artist who performed the work, if different from artist.
137 E.g for "Also sprach Zarathustra", artist would be "Richard
138 Strauss" and performer "London Philharmonic Orchestra".
139 publisher -- name of the label/publisher.
140 service_name -- name of the service in broadcasting (channel name).
141 service_provider -- name of the service provider in broadcasting.
142 title -- name of the work.
143 track -- number of this work in the set, can be in form current/total.
144 variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
147 * Look in the examples section for an application example how to use the Metadata API.
152 #if FF_API_OLD_METADATA2
154 * @defgroup old_metadata Old metadata API
155 * The following functions are deprecated, use
156 * their equivalents from libavutil/dict.h instead.
160 #define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
161 #define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
162 #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
163 #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
164 #define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
166 typedef attribute_deprecated AVDictionary AVMetadata;
167 typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
169 typedef struct AVMetadataConv AVMetadataConv;
172 * Get a metadata element with matching key.
174 * @param prev Set to the previous matching element to find the next.
175 * If set to NULL the first matching element is returned.
176 * @param flags Allows case as well as suffix-insensitive comparisons.
177 * @return Found tag or NULL, changing key or value leads to undefined behavior.
179 attribute_deprecated AVDictionaryEntry *
180 av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
183 * Set the given tag in *pm, overwriting an existing tag.
185 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
186 * a metadata struct is allocated and put in *pm.
187 * @param key tag key to add to *pm (will be av_strduped depending on flags)
188 * @param value tag value to add to *pm (will be av_strduped depending on flags).
189 * Passing a NULL value will cause an existing tag to be deleted.
190 * @return >= 0 on success otherwise an error code <0
192 attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
195 * This function is provided for compatibility reason and currently does nothing.
197 attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
198 const AVMetadataConv *s_conv);
201 * Copy metadata from one AVDictionary struct into another.
202 * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
203 * this function will allocate a struct for you and put it in *dst
204 * @param src pointer to source AVDictionary struct
205 * @param flags flags to use when setting metadata in *dst
206 * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
208 attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
211 * Free all the memory allocated for an AVDictionary struct.
213 attribute_deprecated void av_metadata_free(AVDictionary **m);
220 /* packet functions */
224 * Allocate and read the payload of a packet and initialize its
225 * fields with default values.
228 * @param size desired payload size
229 * @return >0 (read size) if OK, AVERROR_xxx otherwise
231 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
235 * Read data and append it to the current content of the AVPacket.
236 * If pkt->size is 0 this is identical to av_get_packet.
237 * Note that this uses av_grow_packet and thus involves a realloc
238 * which is inefficient. Thus this function should only be used
239 * when there is no reasonable way to know (an upper bound of)
243 * @param size amount of data to read
244 * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
245 * will not be lost even if an error occurs.
247 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
249 /*************************************************/
250 /* fractional numbers for exact pts handling */
253 * The exact value of the fractional number is: 'val + num / den'.
254 * num is assumed to be 0 <= num < den.
256 typedef struct AVFrac {
257 int64_t val, num, den;
260 /*************************************************/
261 /* input/output formats */
266 * This structure contains the data a format has to probe a file.
268 typedef struct AVProbeData {
269 const char *filename;
270 unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
271 int buf_size; /**< Size of buf except extra allocated bytes */
274 #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
275 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
277 typedef struct AVFormatParameters {
278 #if FF_API_FORMAT_PARAMETERS
279 attribute_deprecated AVRational time_base;
280 attribute_deprecated int sample_rate;
281 attribute_deprecated int channels;
282 attribute_deprecated int width;
283 attribute_deprecated int height;
284 attribute_deprecated enum PixelFormat pix_fmt;
285 attribute_deprecated int channel; /**< Used to select DV channel. */
286 attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
287 attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */
288 /**< deprecated, use mpegtsraw demuxer-specific options instead */
289 attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
290 attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream
291 immediately (RTSP only). */
292 attribute_deprecated unsigned int prealloced_context:1;
294 } AVFormatParameters;
296 //! Demuxer will use avio_open, no opened file should be provided by the caller.
297 #define AVFMT_NOFILE 0x0001
298 #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
299 #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
300 #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
302 #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
303 #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
304 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
305 #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
306 #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
307 #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
308 #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
309 #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
310 #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
311 #define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */
312 #define AVFMT_TS_NONSTRICT 0x8000000 /**< Format does not require strictly
313 increasing timestamps, but they must
314 still be monotonic */
316 typedef struct AVOutputFormat {
319 * Descriptive name for the format, meant to be more human-readable
320 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
323 const char *long_name;
324 const char *mime_type;
325 const char *extensions; /**< comma-separated filename extensions */
327 * size of private data so that it can be allocated in the wrapper
331 enum CodecID audio_codec; /**< default audio codec */
332 enum CodecID video_codec; /**< default video codec */
333 int (*write_header)(struct AVFormatContext *);
334 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
335 int (*write_trailer)(struct AVFormatContext *);
337 * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
338 * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
339 * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
345 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
346 AVPacket *in, int flush);
349 * List of supported codec_id-codec_tag pairs, ordered by "better
350 * choice first". The arrays are all terminated by CODEC_ID_NONE.
352 const struct AVCodecTag * const *codec_tag;
354 enum CodecID subtitle_codec; /**< default subtitle codec */
356 #if FF_API_OLD_METADATA2
357 const AVMetadataConv *metadata_conv;
360 const AVClass *priv_class; ///< AVClass for the private context
363 * Test if the given codec can be stored in this container.
365 * @return 1 if the codec is supported, 0 if it is not.
366 * A negative number if unknown.
368 int (*query_codec)(enum CodecID id, int std_compliance);
370 void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
371 int64_t *dts, int64_t *wall);
374 struct AVOutputFormat *next;
377 typedef struct AVInputFormat {
379 * A comma separated list of short names for the format. New names
380 * may be appended with a minor bump.
385 * Descriptive name for the format, meant to be more human-readable
386 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
389 const char *long_name;
392 * Size of private data so that it can be allocated in the wrapper.
397 * Tell if a given file has a chance of being parsed as this format.
398 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
399 * big so you do not have to check for that unless you need more.
401 int (*read_probe)(AVProbeData *);
404 * Read the format header and initialize the AVFormatContext
405 * structure. Return 0 if OK. 'ap' if non-NULL contains
406 * additional parameters. Only used in raw format right
407 * now. 'av_new_stream' should be called to create new streams.
409 int (*read_header)(struct AVFormatContext *,
410 AVFormatParameters *ap);
413 * Read one packet and put it in 'pkt'. pts and flags are also
414 * set. 'av_new_stream' can be called only if the flag
415 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
416 * background thread).
417 * @return 0 on success, < 0 on error.
418 * When returning an error, pkt must not have been allocated
419 * or must be freed before returning
421 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
424 * Close the stream. The AVFormatContext and AVStreams are not
425 * freed by this function
427 int (*read_close)(struct AVFormatContext *);
431 * Seek to a given timestamp relative to the frames in
432 * stream component stream_index.
433 * @param stream_index Must not be -1.
434 * @param flags Selects which direction should be preferred if no exact
435 * match is available.
436 * @return >= 0 on success (but not necessarily the new offset)
438 attribute_deprecated int (*read_seek)(struct AVFormatContext *,
439 int stream_index, int64_t timestamp, int flags);
442 * Gets the next timestamp in stream[stream_index].time_base units.
443 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
445 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
446 int64_t *pos, int64_t pos_limit);
449 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
450 * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
451 * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
456 * If extensions are defined, then no probe is done. You should
457 * usually not use extension format guessing because it is not
460 const char *extensions;
463 * General purpose read-only value that the format can use.
468 * Start/resume playing - only meaningful if using a network-based format
471 int (*read_play)(struct AVFormatContext *);
474 * Pause playing - only meaningful if using a network-based format
477 int (*read_pause)(struct AVFormatContext *);
479 const struct AVCodecTag * const *codec_tag;
482 * Seek to timestamp ts.
483 * Seeking will be done so that the point from which all active streams
484 * can be presented successfully will be closest to ts and within min/max_ts.
485 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
487 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
489 #if FF_API_OLD_METADATA2
490 const AVMetadataConv *metadata_conv;
493 const AVClass *priv_class; ///< AVClass for the private context
496 struct AVInputFormat *next;
499 enum AVStreamParseType {
501 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
502 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
503 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
504 AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
507 typedef struct AVIndexEntry {
509 int64_t timestamp; /**<
510 * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available
511 * when seeking to this entry. That means preferable PTS on keyframe based formats.
512 * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better
515 #define AVINDEX_KEYFRAME 0x0001
517 int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
518 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
521 #define AV_DISPOSITION_DEFAULT 0x0001
522 #define AV_DISPOSITION_DUB 0x0002
523 #define AV_DISPOSITION_ORIGINAL 0x0004
524 #define AV_DISPOSITION_COMMENT 0x0008
525 #define AV_DISPOSITION_LYRICS 0x0010
526 #define AV_DISPOSITION_KARAOKE 0x0020
529 * Track should be used during playback by default.
530 * Useful for subtitle track that should be displayed
531 * even when user did not explicitly ask for subtitles.
533 #define AV_DISPOSITION_FORCED 0x0040
534 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
535 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
536 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
540 * New fields can be added to the end with minor version bumps.
541 * Removal, reordering and changes to existing fields require a major
543 * sizeof(AVStream) must not be used outside libav*.
545 typedef struct AVStream {
546 int index; /**< stream index in AVFormatContext */
547 int id; /**< format-specific stream ID */
548 AVCodecContext *codec; /**< codec context */
550 * Real base framerate of the stream.
551 * This is the lowest framerate with which all timestamps can be
552 * represented accurately (it is the least common multiple of all
553 * framerates in the stream). Note, this value is just a guess!
554 * For example, if the time base is 1/90000 and all frames have either
555 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
557 AVRational r_frame_rate;
560 #if FF_API_REORDER_PRIVATE
561 /* internal data used in av_find_stream_info() */
566 * encoding: pts generation when outputting stream
571 * This is the fundamental unit of time (in seconds) in terms
572 * of which frame timestamps are represented. For fixed-fps content,
573 * time base should be 1/framerate and timestamp increments should be 1.
574 * decoding: set by libavformat
575 * encoding: set by libavformat in av_write_header
577 AVRational time_base;
578 #if FF_API_REORDER_PRIVATE
579 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
581 #if FF_API_STREAM_COPY
582 /* ffmpeg.c private use */
583 attribute_deprecated int stream_copy; /**< If set, just copy stream. */
585 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
587 #if FF_API_AVSTREAM_QUALITY
588 //FIXME move stuff to a flags field?
590 * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
591 * MN: dunno if that is the right place for it
593 attribute_deprecated float quality;
597 * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
598 * Only set this if you are absolutely 100% sure that the value you set
599 * it to really is the pts of the first frame.
600 * This may be undefined (AV_NOPTS_VALUE).
601 * @note The ASF header does NOT contain a correct start_time the ASF
602 * demuxer must NOT set this.
607 * Decoding: duration of the stream, in stream time base.
608 * If a source file does not specify a duration, but does specify
609 * a bitrate, this value will be estimated from bitrate and file size.
613 #if FF_API_REORDER_PRIVATE
614 /* av_read_frame() support */
615 enum AVStreamParseType need_parsing;
616 struct AVCodecParserContext *parser;
619 int last_IP_duration;
621 /* av_seek_frame() support */
622 AVIndexEntry *index_entries; /**< Only used if the format does not
623 support seeking natively. */
624 int nb_index_entries;
625 unsigned int index_entries_allocated_size;
628 int64_t nb_frames; ///< number of frames in this stream if known or 0
630 int disposition; /**< AV_DISPOSITION_* bit field */
632 #if FF_API_REORDER_PRIVATE
633 AVProbeData probe_data;
634 #define MAX_REORDER_DELAY 16
635 int64_t pts_buffer[MAX_REORDER_DELAY+1];
639 * sample aspect ratio (0 if unknown)
640 * - encoding: Set by user.
641 * - decoding: Set by libavformat.
643 AVRational sample_aspect_ratio;
645 AVDictionary *metadata;
647 #if FF_API_REORDER_PRIVATE
648 /* Intended mostly for av_read_frame() support. Not supposed to be used by */
649 /* external applications; try to use something else if at all possible. */
650 const uint8_t *cur_ptr;
654 // Timestamp generation support:
656 * Timestamp corresponding to the last dts sync point.
658 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
659 * a DTS is received from the underlying container. Otherwise set to
660 * AV_NOPTS_VALUE by default.
662 int64_t reference_dts;
665 * Number of packets to buffer for codec probing
666 * NOT PART OF PUBLIC API
668 #define MAX_PROBE_PACKETS 2500
672 * last packet in packet_buffer for this stream when muxing.
673 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
675 struct AVPacketList *last_in_packet_buffer;
681 AVRational avg_frame_rate;
683 /*****************************************************************
684 * All fields below this line are not part of the public API. They
685 * may not be used outside of libavformat and can be changed and
687 * New public fields should be added right above.
688 *****************************************************************
692 * Number of frames that have been demuxed during av_find_stream_info()
694 int codec_info_nb_frames;
698 * This is the MPEG-TS stream identifier +1
701 int stream_identifier;
704 * Stream informations used internally by av_find_stream_info()
706 #define MAX_STD_TIMEBASES (60*12+5)
709 int64_t duration_gcd;
711 double duration_error[2][2][MAX_STD_TIMEBASES];
712 int64_t codec_info_duration;
713 int nb_decoded_frames;
717 * flag to indicate that probing is requested
718 * NOT PART OF PUBLIC API
721 #if !FF_API_REORDER_PRIVATE
722 const uint8_t *cur_ptr;
726 // Timestamp generation support:
728 * Timestamp corresponding to the last dts sync point.
730 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
731 * a DTS is received from the underlying container. Otherwise set to
732 * AV_NOPTS_VALUE by default.
734 int64_t reference_dts;
737 int last_IP_duration;
741 * Number of packets to buffer for codec probing
743 #define MAX_PROBE_PACKETS 2500
747 * last packet in packet_buffer for this stream when muxing.
749 struct AVPacketList *last_in_packet_buffer;
750 AVProbeData probe_data;
751 #define MAX_REORDER_DELAY 16
752 int64_t pts_buffer[MAX_REORDER_DELAY+1];
753 /* av_read_frame() support */
754 enum AVStreamParseType need_parsing;
755 struct AVCodecParserContext *parser;
757 AVIndexEntry *index_entries; /**< Only used if the format does not
758 support seeking natively. */
759 int nb_index_entries;
760 unsigned int index_entries_allocated_size;
762 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
766 #define AV_PROGRAM_RUNNING 1
769 * New fields can be added to the end with minor version bumps.
770 * Removal, reordering and changes to existing fields require a major
772 * sizeof(AVProgram) must not be used outside libav*.
774 typedef struct AVProgram {
777 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
778 unsigned int *stream_index;
779 unsigned int nb_stream_indexes;
780 AVDictionary *metadata;
787 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
788 (streams are added dynamically) */
790 typedef struct AVChapter {
791 int id; ///< unique ID to identify the chapter
792 AVRational time_base; ///< time base in which the start/end timestamps are specified
793 int64_t start, end; ///< chapter start/end time in time_base units
794 AVDictionary *metadata;
798 * Format I/O context.
799 * New fields can be added to the end with minor version bumps.
800 * Removal, reordering and changes to existing fields require a major
802 * sizeof(AVFormatContext) must not be used outside libav*, use
803 * avformat_alloc_context() to create an AVFormatContext.
805 typedef struct AVFormatContext {
807 * A class for logging and AVOptions. Set by avformat_alloc_context().
808 * Exports (de)muxer private options if they exist.
810 const AVClass *av_class;
813 * Can only be iformat or oformat, not both at the same time.
815 * decoding: set by avformat_open_input().
816 * encoding: set by the user.
818 struct AVInputFormat *iformat;
819 struct AVOutputFormat *oformat;
822 * Format private data. This is an AVOptions-enabled struct
823 * if and only if iformat/oformat.priv_class is not NULL.
830 * decoding: either set by the user before avformat_open_input() (then
831 * the user must close it manually) or set by avformat_open_input().
832 * encoding: set by the user.
834 * Do NOT set this field if AVFMT_NOFILE flag is set in
835 * iformat/oformat.flags. In such a case, the (de)muxer will handle
836 * I/O in some other way and this field will be NULL.
841 * A list of all streams in the file. New streams are created with
842 * avformat_new_stream().
844 * decoding: streams are created by libavformat in avformat_open_input().
845 * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
846 * appear in av_read_frame().
847 * encoding: streams are created by the user before avformat_write_header().
849 unsigned int nb_streams;
852 char filename[1024]; /**< input or output filename */
856 * @deprecated use 'creation_time' metadata tag instead
858 attribute_deprecated int64_t timestamp;
861 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
862 #if FF_API_REORDER_PRIVATE
863 /* private data for pts handling (do not modify directly). */
865 * This buffer is only needed when packets were already buffered but
866 * not decoded, for example to get the codec parameters in MPEG
869 struct AVPacketList *packet_buffer;
873 * Decoding: position of the first frame of the component, in
874 * AV_TIME_BASE fractional seconds. NEVER set this value directly:
875 * It is deduced from the AVStream values.
880 * Decoding: duration of the stream, in AV_TIME_BASE fractional
881 * seconds. Only set this value if you know none of the individual stream
882 * durations and also dont set any of them. This is deduced from the
883 * AVStream values if not set.
889 * decoding: total file size, 0 if unknown
891 attribute_deprecated int64_t file_size;
895 * Decoding: total stream bitrate in bit/s, 0 if not
896 * available. Never set it directly if the file_size and the
897 * duration are known as FFmpeg can compute it automatically.
901 #if FF_API_REORDER_PRIVATE
902 /* av_read_frame() support */
905 /* av_seek_frame() support */
906 int64_t data_offset; /**< offset of the first packet */
911 * use mpeg muxer private options instead
913 attribute_deprecated int mux_rate;
915 unsigned int packet_size;
917 attribute_deprecated int preload;
921 #if FF_API_LOOP_OUTPUT
922 #define AVFMT_NOOUTPUTLOOP -1
923 #define AVFMT_INFINITEOUTPUTLOOP 0
925 * number of times to loop output in formats that support it
927 * @deprecated use the 'loop' private option in the gif muxer.
929 attribute_deprecated int loop_output;
933 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
934 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
935 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
936 #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
937 #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
938 #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
939 #if FF_API_FLAG_RTP_HINT
940 #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
942 #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
943 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
944 #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
945 #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
946 #define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
947 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate.
949 #if FF_API_LOOP_INPUT
951 * @deprecated, use the 'loop' img2 demuxer private option.
953 attribute_deprecated int loop_input;
957 * decoding: size of data to probe; encoding: unused.
959 unsigned int probesize;
962 * decoding: maximum time (in AV_TIME_BASE units) during which the input should
963 * be analyzed in avformat_find_stream_info().
965 int max_analyze_duration;
970 unsigned int nb_programs;
971 AVProgram **programs;
974 * Forced video codec_id.
975 * Demuxing: Set by user.
977 enum CodecID video_codec_id;
980 * Forced audio codec_id.
981 * Demuxing: Set by user.
983 enum CodecID audio_codec_id;
986 * Forced subtitle codec_id.
987 * Demuxing: Set by user.
989 enum CodecID subtitle_codec_id;
992 * Maximum amount of memory in bytes to use for the index of each stream.
993 * If the index exceeds this size, entries will be discarded as
994 * needed to maintain a smaller size. This can lead to slower or less
995 * accurate seeking (depends on demuxer).
996 * Demuxers for which a full in-memory index is mandatory will ignore
999 * demuxing: set by user
1001 unsigned int max_index_size;
1004 * Maximum amount of memory in bytes to use for buffering frames
1005 * obtained from realtime capture devices.
1007 unsigned int max_picture_buffer;
1009 unsigned int nb_chapters;
1010 AVChapter **chapters;
1013 * Flags to enable debugging.
1016 #define FF_FDEBUG_TS 0x0001
1018 #if FF_API_REORDER_PRIVATE
1020 * Raw packets from the demuxer, prior to parsing and decoding.
1021 * This buffer is used for buffering packets until the codec can
1022 * be identified, as parsing cannot be done without knowing the
1025 struct AVPacketList *raw_packet_buffer;
1026 struct AVPacketList *raw_packet_buffer_end;
1028 struct AVPacketList *packet_buffer_end;
1031 AVDictionary *metadata;
1033 #if FF_API_REORDER_PRIVATE
1035 * Remaining size available for raw_packet_buffer, in bytes.
1036 * NOT PART OF PUBLIC API
1038 #define RAW_PACKET_BUFFER_SIZE 2500000
1039 int raw_packet_buffer_remaining_size;
1043 * Start time of the stream in real world time, in microseconds
1044 * since the unix epoch (00:00 1st January 1970). That is, pts=0
1045 * in the stream was captured at this real world time.
1046 * - encoding: Set by user.
1047 * - decoding: Unused.
1049 int64_t start_time_realtime;
1052 * decoding: number of frames used to probe fps
1057 * Error recognition; higher values will detect more errors but may
1058 * misdetect some more or less valid parts as errors.
1059 * - encoding: unused
1060 * - decoding: Set by user.
1062 int error_recognition;
1065 * Custom interrupt callbacks for the I/O layer.
1067 * decoding: set by the user before avformat_open_input().
1068 * encoding: set by the user before avformat_write_header()
1069 * (mainly useful for AVFMT_NOFILE formats). The callback
1070 * should also be passed to avio_open2() if it's used to
1073 AVIOInterruptCB interrupt_callback;
1076 * Transport stream id.
1077 * This will be moved into demuxer private options. Thus no API/ABI compatibility
1082 * Audio preload in microseconds.
1083 * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
1084 * - encoding: Set by user via AVOptions (NO direct access)
1085 * - decoding: unused
1089 /*****************************************************************
1090 * All fields below this line are not part of the public API. They
1091 * may not be used outside of libavformat and can be changed and
1093 * New public fields should be added right above.
1094 *****************************************************************
1096 #if !FF_API_REORDER_PRIVATE
1098 * Raw packets from the demuxer, prior to parsing and decoding.
1099 * This buffer is used for buffering packets until the codec can
1100 * be identified, as parsing cannot be done without knowing the
1103 struct AVPacketList *raw_packet_buffer;
1104 struct AVPacketList *raw_packet_buffer_end;
1106 * Remaining size available for raw_packet_buffer, in bytes.
1108 #define RAW_PACKET_BUFFER_SIZE 2500000
1109 int raw_packet_buffer_remaining_size;
1112 * This buffer is only needed when packets were already buffered but
1113 * not decoded, for example to get the codec parameters in MPEG
1116 struct AVPacketList *packet_buffer;
1117 struct AVPacketList *packet_buffer_end;
1119 /* av_read_frame() support */
1122 /* av_seek_frame() support */
1123 int64_t data_offset; /**< offset of the first packet */
1127 typedef struct AVPacketList {
1129 struct AVPacketList *next;
1133 * If f is NULL, returns the first registered input format,
1134 * if f is non-NULL, returns the next registered input format after f
1135 * or NULL if f is the last one.
1137 AVInputFormat *av_iformat_next(AVInputFormat *f);
1140 * If f is NULL, returns the first registered output format,
1141 * if f is non-NULL, returns the next registered output format after f
1142 * or NULL if f is the last one.
1144 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
1146 #if FF_API_GUESS_IMG2_CODEC
1147 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1150 /* XXX: Use automatic init with either ELF sections or C file parser */
1154 void av_register_input_format(AVInputFormat *format);
1155 void av_register_output_format(AVOutputFormat *format);
1158 * Return the output format in the list of registered output formats
1159 * which best matches the provided parameters, or return NULL if
1160 * there is no match.
1162 * @param short_name if non-NULL checks if short_name matches with the
1163 * names of the registered formats
1164 * @param filename if non-NULL checks if filename terminates with the
1165 * extensions of the registered formats
1166 * @param mime_type if non-NULL checks if mime_type matches with the
1167 * MIME type of the registered formats
1169 AVOutputFormat *av_guess_format(const char *short_name,
1170 const char *filename,
1171 const char *mime_type);
1174 * Guess the codec ID based upon muxer and filename.
1176 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1177 const char *filename, const char *mime_type,
1178 enum AVMediaType type);
1181 * Send a nice hexadecimal dump of a buffer to the specified file stream.
1183 * @param f The file stream pointer where the dump should be sent to.
1185 * @param size buffer size
1187 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
1189 void av_hex_dump(FILE *f, uint8_t *buf, int size);
1192 * Send a nice hexadecimal dump of a buffer to the log.
1194 * @param avcl A pointer to an arbitrary struct of which the first field is a
1195 * pointer to an AVClass struct.
1196 * @param level The importance level of the message, lower values signifying
1197 * higher importance.
1199 * @param size buffer size
1201 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
1203 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1206 * Send a nice dump of a packet to the specified file stream.
1208 * @param f The file stream pointer where the dump should be sent to.
1209 * @param pkt packet to dump
1210 * @param dump_payload True if the payload must be displayed, too.
1211 * @param st AVStream that the packet belongs to
1213 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1217 * Send a nice dump of a packet to the log.
1219 * @param avcl A pointer to an arbitrary struct of which the first field is a
1220 * pointer to an AVClass struct.
1221 * @param level The importance level of the message, lower values signifying
1222 * higher importance.
1223 * @param pkt packet to dump
1224 * @param dump_payload True if the payload must be displayed, too.
1225 * @param st AVStream that the packet belongs to
1227 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1231 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1232 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1237 * Initialize libavformat and register all the muxers, demuxers and
1238 * protocols. If you do not call this function, then you can select
1239 * exactly which formats you want to support.
1241 * @see av_register_input_format()
1242 * @see av_register_output_format()
1243 * @see av_register_protocol()
1245 void av_register_all(void);
1248 * Get the CodecID for the given codec tag tag.
1249 * If no codec id is found returns CODEC_ID_NONE.
1251 * @param tags list of supported codec_id-codec_tag pairs, as stored
1252 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1254 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1257 * Get the codec tag for the given codec id id.
1258 * If no codec tag is found returns 0.
1260 * @param tags list of supported codec_id-codec_tag pairs, as stored
1261 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1263 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1265 /* media file input */
1268 * Find AVInputFormat based on the short name of the input format.
1270 AVInputFormat *av_find_input_format(const char *short_name);
1273 * Guess the file format.
1275 * @param is_opened Whether the file is already opened; determines whether
1276 * demuxers with or without AVFMT_NOFILE are probed.
1278 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1281 * Guess the file format.
1283 * @param is_opened Whether the file is already opened; determines whether
1284 * demuxers with or without AVFMT_NOFILE are probed.
1285 * @param score_max A probe score larger that this is required to accept a
1286 * detection, the variable is set to the actual detection
1288 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1289 * to retry with a larger probe buffer.
1291 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1294 * Guess the file format.
1296 * @param is_opened Whether the file is already opened; determines whether
1297 * demuxers with or without AVFMT_NOFILE are probed.
1298 * @param score_ret The score of the best detection.
1300 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
1303 * Probe a bytestream to determine the input format. Each time a probe returns
1304 * with a score that is too low, the probe buffer size is increased and another
1305 * attempt is made. When the maximum probe size is reached, the input format
1306 * with the highest score is returned.
1308 * @param pb the bytestream to probe
1309 * @param fmt the input format is put here
1310 * @param filename the filename of the stream
1311 * @param logctx the log context
1312 * @param offset the offset within the bytestream to probe from
1313 * @param max_probe_size the maximum probe buffer size (zero for default)
1314 * @return 0 in case of success, a negative value corresponding to an
1315 * AVERROR code otherwise
1317 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
1318 const char *filename, void *logctx,
1319 unsigned int offset, unsigned int max_probe_size);
1321 #if FF_API_FORMAT_PARAMETERS
1323 * Allocate all the structures needed to read an input stream.
1324 * This does not open the needed codecs for decoding the stream[s].
1325 * @deprecated use avformat_open_input instead.
1327 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
1328 AVIOContext *pb, const char *filename,
1329 AVInputFormat *fmt, AVFormatParameters *ap);
1332 * Open a media file as input. The codecs are not opened. Only the file
1333 * header (if present) is read.
1335 * @param ic_ptr The opened media file handle is put here.
1336 * @param filename filename to open
1337 * @param fmt If non-NULL, force the file format to use.
1338 * @param buf_size optional buffer size (zero if default is OK)
1339 * @param ap Additional parameters needed when opening the file
1340 * (NULL if default).
1341 * @return 0 if OK, AVERROR_xxx otherwise
1343 * @deprecated use avformat_open_input instead.
1345 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1348 AVFormatParameters *ap);
1352 * Open an input stream and read the header. The codecs are not opened.
1353 * The stream must be closed with av_close_input_file().
1355 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1356 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1357 * function and written into ps.
1358 * Note that a user-supplied AVFormatContext will be freed on failure.
1359 * @param filename Name of the stream to open.
1360 * @param fmt If non-NULL, this parameter forces a specific input format.
1361 * Otherwise the format is autodetected.
1362 * @param options A dictionary filled with AVFormatContext and demuxer-private options.
1363 * On return this parameter will be destroyed and replaced with a dict containing
1364 * options that were not found. May be NULL.
1366 * @return 0 on success, a negative AVERROR on failure.
1368 * @note If you want to use custom IO, preallocate the format context and set its pb field.
1370 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1372 int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
1375 * Allocate an AVFormatContext.
1376 * avformat_free_context() can be used to free the context and everything
1377 * allocated by the framework within it.
1379 AVFormatContext *avformat_alloc_context(void);
1381 #if FF_API_ALLOC_OUTPUT_CONTEXT
1383 * @deprecated deprecated in favor of avformat_alloc_output_context2()
1385 attribute_deprecated
1386 AVFormatContext *avformat_alloc_output_context(const char *format,
1387 AVOutputFormat *oformat,
1388 const char *filename);
1392 * Allocate an AVFormatContext for an output format.
1393 * avformat_free_context() can be used to free the context and
1394 * everything allocated by the framework within it.
1396 * @param *ctx is set to the created format context, or to NULL in
1398 * @param oformat format to use for allocating the context, if NULL
1399 * format_name and filename are used instead
1400 * @param format_name the name of output format to use for allocating the
1401 * context, if NULL filename is used instead
1402 * @param filename the name of the filename to use for allocating the
1403 * context, may be NULL
1404 * @return >= 0 in case of success, a negative AVERROR code in case of
1407 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
1408 const char *format_name, const char *filename);
1410 #if FF_API_FORMAT_PARAMETERS
1412 * Read packets of a media file to get stream information. This
1413 * is useful for file formats with no headers such as MPEG. This
1414 * function also computes the real framerate in case of MPEG-2 repeat
1416 * The logical file position is not changed by this function;
1417 * examined packets may be buffered for later processing.
1419 * @param ic media file handle
1420 * @return >=0 if OK, AVERROR_xxx on error
1421 * @todo Let the user decide somehow what information is needed so that
1422 * we do not waste time getting stuff the user does not need.
1424 * @deprecated use avformat_find_stream_info.
1426 attribute_deprecated
1427 int av_find_stream_info(AVFormatContext *ic);
1431 * Read packets of a media file to get stream information. This
1432 * is useful for file formats with no headers such as MPEG. This
1433 * function also computes the real framerate in case of MPEG-2 repeat
1435 * The logical file position is not changed by this function;
1436 * examined packets may be buffered for later processing.
1438 * @param ic media file handle
1439 * @param options If non-NULL, an ic.nb_streams long array of pointers to
1440 * dictionaries, where i-th member contains options for
1441 * codec corresponding to i-th stream.
1442 * On return each dictionary will be filled with options that were not found.
1443 * @return >=0 if OK, AVERROR_xxx on error
1445 * @note this function isn't guaranteed to open all the codecs, so
1446 * options being non-empty at return is a perfectly normal behavior.
1448 * @todo Let the user decide somehow what information is needed so that
1449 * we do not waste time getting stuff the user does not need.
1451 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
1454 * Find the programs which belong to a given stream.
1456 * @param ic media file handle
1457 * @param last the last found program, the search will start after this
1458 * program, or from the beginning if it is NULL
1459 * @param s stream index
1460 * @return the next program which belongs to s, NULL if no program is found or
1461 * the last program is not among the programs of ic.
1463 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
1466 * Find the "best" stream in the file.
1467 * The best stream is determined according to various heuristics as the most
1468 * likely to be what the user expects.
1469 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1470 * default decoder for the stream's codec; streams for which no decoder can
1471 * be found are ignored.
1473 * @param ic media file handle
1474 * @param type stream type: video, audio, subtitles, etc.
1475 * @param wanted_stream_nb user-requested stream number,
1476 * or -1 for automatic selection
1477 * @param related_stream try to find a stream related (eg. in the same
1478 * program) to this one, or -1 if none
1479 * @param decoder_ret if non-NULL, returns the decoder for the
1481 * @param flags flags; none are currently defined
1482 * @return the non-negative stream number in case of success,
1483 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1485 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1486 * @note If av_find_best_stream returns successfully and decoder_ret is not
1487 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1489 int av_find_best_stream(AVFormatContext *ic,
1490 enum AVMediaType type,
1491 int wanted_stream_nb,
1493 AVCodec **decoder_ret,
1497 * Read a transport packet from a media file.
1499 * This function is obsolete and should never be used.
1500 * Use av_read_frame() instead.
1502 * @param s media file handle
1503 * @param pkt is filled
1504 * @return 0 if OK, AVERROR_xxx on error
1506 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1509 * Return the next frame of a stream.
1510 * This function returns what is stored in the file, and does not validate
1511 * that what is there are valid frames for the decoder. It will split what is
1512 * stored in the file into frames and return one for each call. It will not
1513 * omit invalid data between valid frames so as to give the decoder the maximum
1514 * information possible for decoding.
1516 * The returned packet is valid
1517 * until the next av_read_frame() or until av_close_input_file() and
1518 * must be freed with av_free_packet. For video, the packet contains
1519 * exactly one frame. For audio, it contains an integer number of
1520 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1521 * data). If the audio frames have a variable size (e.g. MPEG audio),
1522 * then it contains one frame.
1524 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1525 * values in AVStream.time_base units (and guessed if the format cannot
1526 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1527 * has B-frames, so it is better to rely on pkt->dts if you do not
1528 * decompress the payload.
1530 * @return 0 if OK, < 0 on error or end of file
1532 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1535 * Seek to the keyframe at timestamp.
1536 * 'timestamp' in 'stream_index'.
1537 * @param stream_index If stream_index is (-1), a default
1538 * stream is selected, and timestamp is automatically converted
1539 * from AV_TIME_BASE units to the stream specific time_base.
1540 * @param timestamp Timestamp in AVStream.time_base units
1541 * or, if no stream is specified, in AV_TIME_BASE units.
1542 * @param flags flags which select direction and seeking mode
1543 * @return >= 0 on success
1545 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1549 * Seek to timestamp ts.
1550 * Seeking will be done so that the point from which all active streams
1551 * can be presented successfully will be closest to ts and within min/max_ts.
1552 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1554 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1555 * are the file position (this may not be supported by all demuxers).
1556 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1557 * in the stream with stream_index (this may not be supported by all demuxers).
1558 * Otherwise all timestamps are in units of the stream selected by stream_index
1559 * or if stream_index is -1, in AV_TIME_BASE units.
1560 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1561 * keyframes (this may not be supported by all demuxers).
1563 * @param stream_index index of the stream which is used as time base reference
1564 * @param min_ts smallest acceptable timestamp
1565 * @param ts target timestamp
1566 * @param max_ts largest acceptable timestamp
1567 * @param flags flags
1568 * @return >=0 on success, error code otherwise
1570 * @note This is part of the new seek API which is still under construction.
1571 * Thus do not use this yet. It may change at any time, do not expect
1572 * ABI compatibility yet!
1574 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1577 * Start playing a network-based stream (e.g. RTSP stream) at the
1580 int av_read_play(AVFormatContext *s);
1583 * Pause a network-based stream (e.g. RTSP stream).
1585 * Use av_read_play() to resume it.
1587 int av_read_pause(AVFormatContext *s);
1590 * Free a AVFormatContext allocated by av_open_input_stream.
1591 * @param s context to free
1593 void av_close_input_stream(AVFormatContext *s);
1596 * Close a media file (but not its codecs).
1598 * @param s media file handle
1600 void av_close_input_file(AVFormatContext *s);
1603 * Free an AVFormatContext and all its streams.
1604 * @param s context to free
1606 void avformat_free_context(AVFormatContext *s);
1608 #if FF_API_NEW_STREAM
1610 * Add a new stream to a media file.
1612 * Can only be called in the read_header() function. If the flag
1613 * AVFMTCTX_NOHEADER is in the format context, then new streams
1614 * can be added in read_packet too.
1616 * @param s media file handle
1617 * @param id file-format-dependent stream ID
1619 attribute_deprecated
1620 AVStream *av_new_stream(AVFormatContext *s, int id);
1624 * Add a new stream to a media file.
1626 * When demuxing, it is called by the demuxer in read_header(). If the
1627 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1628 * be called in read_packet().
1630 * When muxing, should be called by the user before avformat_write_header().
1632 * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1633 * will be initialized to use this codec. This is needed for e.g. codec-specific
1634 * defaults to be set, so codec should be provided if it is known.
1636 * @return newly created stream or NULL on error.
1638 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1640 AVProgram *av_new_program(AVFormatContext *s, int id);
1642 #if FF_API_SET_PTS_INFO
1644 * @deprecated this function is not supposed to be called outside of lavf
1646 attribute_deprecated
1647 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1648 unsigned int pts_num, unsigned int pts_den);
1651 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1652 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
1653 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
1654 #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
1656 int av_find_default_stream_index(AVFormatContext *s);
1659 * Get the index for a specific timestamp.
1660 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1661 * to the timestamp which is <= the requested one, if backward
1662 * is 0, then it will be >=
1663 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1664 * @return < 0 if no such timestamp could be found
1666 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1669 * Add an index entry into a sorted list. Update the entry if the list
1670 * already contains it.
1672 * @param timestamp timestamp in the time base of the given stream
1674 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1675 int size, int distance, int flags);
1677 #if FF_API_SEEK_PUBLIC
1678 attribute_deprecated
1679 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1680 int64_t target_ts, int flags);
1681 attribute_deprecated
1682 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1683 attribute_deprecated
1684 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1685 int64_t target_ts, int64_t pos_min,
1686 int64_t pos_max, int64_t pos_limit,
1687 int64_t ts_min, int64_t ts_max,
1688 int flags, int64_t *ts_ret,
1689 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1695 #if FF_API_FORMAT_PARAMETERS
1697 * @deprecated pass the options to avformat_write_header directly.
1699 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1703 * Split a URL string into components.
1705 * The pointers to buffers for storing individual components may be null,
1706 * in order to ignore that component. Buffers for components not found are
1707 * set to empty strings. If the port is not found, it is set to a negative
1710 * @param proto the buffer for the protocol
1711 * @param proto_size the size of the proto buffer
1712 * @param authorization the buffer for the authorization
1713 * @param authorization_size the size of the authorization buffer
1714 * @param hostname the buffer for the host name
1715 * @param hostname_size the size of the hostname buffer
1716 * @param port_ptr a pointer to store the port number in
1717 * @param path the buffer for the path
1718 * @param path_size the size of the path buffer
1719 * @param url the URL to split
1721 void av_url_split(char *proto, int proto_size,
1722 char *authorization, int authorization_size,
1723 char *hostname, int hostname_size,
1725 char *path, int path_size,
1729 * Allocate the stream private data and write the stream header to
1730 * an output media file.
1732 * @param s Media file handle, must be allocated with avformat_alloc_context().
1733 * Its oformat field must be set to the desired output format;
1734 * Its pb field must be set to an already openened AVIOContext.
1735 * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
1736 * On return this parameter will be destroyed and replaced with a dict containing
1737 * options that were not found. May be NULL.
1739 * @return 0 on success, negative AVERROR on failure.
1741 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1743 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1745 #if FF_API_FORMAT_PARAMETERS
1747 * Allocate the stream private data and write the stream header to an
1748 * output media file.
1749 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1750 * but for some formats it might also be some other time base
1752 * @param s media file handle
1753 * @return 0 if OK, AVERROR_xxx on error
1755 * @deprecated use avformat_write_header.
1757 attribute_deprecated int av_write_header(AVFormatContext *s);
1761 * Write a packet to an output media file.
1763 * The packet shall contain one audio or video frame.
1764 * The packet must be correctly interleaved according to the container
1765 * specification, if not then av_interleaved_write_frame must be used.
1767 * @param s media file handle
1768 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1770 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1772 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1775 * Write a packet to an output media file ensuring correct interleaving.
1777 * The packet must contain one audio or video frame.
1778 * If the packets are already correctly interleaved, the application should
1779 * call av_write_frame() instead as it is slightly faster. It is also important
1780 * to keep in mind that completely non-interleaved input will need huge amounts
1781 * of memory to interleave with this, so it is preferable to interleave at the
1784 * @param s media file handle
1785 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1787 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1789 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1792 * Interleave a packet per dts in an output media file.
1794 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1795 * function, so they cannot be used after it. Note that calling av_free_packet()
1796 * on them is still safe.
1798 * @param s media file handle
1799 * @param out the interleaved packet will be output here
1800 * @param pkt the input packet
1801 * @param flush 1 if no further packets are available as input and all
1802 * remaining packets should be output
1803 * @return 1 if a packet was output, 0 if no packet could be output,
1804 * < 0 if an error occurred
1806 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1807 AVPacket *pkt, int flush);
1810 * Write the stream trailer to an output media file and free the
1811 * file private data.
1813 * May only be called after a successful call to av_write_header.
1815 * @param s media file handle
1816 * @return 0 if OK, AVERROR_xxx on error
1818 int av_write_trailer(AVFormatContext *s);
1821 * Get timing information for the data currently output.
1822 * The exact meaning of "currently output" depends on the format.
1823 * It is mostly relevant for devices that have an internal buffer and/or
1824 * work in real time.
1825 * @param s media file handle
1826 * @param stream stream in the media file
1827 * @param dts[out] DTS of the last packet output for the stream, in stream
1829 * @param wall[out] absolute time when that packet whas output,
1831 * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it
1832 * Note: some formats or devices may not allow to measure dts and wall
1835 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
1836 int64_t *dts, int64_t *wall);
1838 #if FF_API_DUMP_FORMAT
1840 * @deprecated Deprecated in favor of av_dump_format().
1842 attribute_deprecated void dump_format(AVFormatContext *ic,
1848 void av_dump_format(AVFormatContext *ic,
1853 #if FF_API_PARSE_DATE
1855 * Parse datestr and return a corresponding number of microseconds.
1857 * @param datestr String representing a date or a duration.
1858 * See av_parse_time() for the syntax of the provided string.
1859 * @deprecated in favor of av_parse_time()
1861 attribute_deprecated
1862 int64_t parse_date(const char *datestr, int duration);
1866 * Get the current time in microseconds.
1868 int64_t av_gettime(void);
1870 #if FF_API_FIND_INFO_TAG
1872 * @deprecated use av_find_info_tag in libavutil instead.
1874 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1878 * Return in 'buf' the path with '%d' replaced by a number.
1880 * Also handles the '%0nd' format where 'n' is the total number
1881 * of digits and '%%'.
1883 * @param buf destination buffer
1884 * @param buf_size destination buffer size
1885 * @param path numbered sequence string
1886 * @param number frame number
1887 * @return 0 if OK, -1 on format error
1889 int av_get_frame_filename(char *buf, int buf_size,
1890 const char *path, int number);
1893 * Check whether filename actually is a numbered sequence generator.
1895 * @param filename possible numbered sequence string
1896 * @return 1 if a valid numbered sequence string, 0 otherwise
1898 int av_filename_number_test(const char *filename);
1901 * Generate an SDP for an RTP session.
1903 * @param ac array of AVFormatContexts describing the RTP streams. If the
1904 * array is composed by only one context, such context can contain
1905 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1906 * all the contexts in the array (an AVCodecContext per RTP stream)
1907 * must contain only one AVStream.
1908 * @param n_files number of AVCodecContexts contained in ac
1909 * @param buf buffer where the SDP will be stored (must be allocated by
1911 * @param size the size of the buffer
1912 * @return 0 if OK, AVERROR_xxx on error
1914 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1916 #if FF_API_SDP_CREATE
1917 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1921 * Return a positive value if the given filename has one of the given
1922 * extensions, 0 otherwise.
1924 * @param extensions a comma-separated list of filename extensions
1926 int av_match_ext(const char *filename, const char *extensions);
1929 * Test if the given container can store a codec.
1931 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1933 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1934 * A negative number if this information is not available.
1936 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1939 * Get the AVClass for AVFormatContext. It can be used in combination with
1940 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1942 * @see av_opt_find().
1944 const AVClass *avformat_get_class(void);
1947 * Do global initialization of network components. This is optional,
1948 * but recommended, since it avoids the overhead of implicitly
1949 * doing the setup for each session.
1951 * Calling this function will become mandatory if using network
1952 * protocols at some major version bump.
1954 int avformat_network_init(void);
1957 * Undo the initialization done by avformat_network_init.
1959 int avformat_network_deinit(void);
1961 #endif /* AVFORMAT_AVFORMAT_H */