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;
703 int64_t interleaver_chunk_size;
704 int64_t interleaver_chunk_duration;
707 * Stream informations used internally by av_find_stream_info()
709 #define MAX_STD_TIMEBASES (60*12+5)
712 int64_t duration_gcd;
714 double duration_error[2][2][MAX_STD_TIMEBASES];
715 int64_t codec_info_duration;
716 int nb_decoded_frames;
720 * flag to indicate that probing is requested
721 * NOT PART OF PUBLIC API
724 #if !FF_API_REORDER_PRIVATE
725 const uint8_t *cur_ptr;
729 // Timestamp generation support:
731 * Timestamp corresponding to the last dts sync point.
733 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
734 * a DTS is received from the underlying container. Otherwise set to
735 * AV_NOPTS_VALUE by default.
737 int64_t reference_dts;
740 int last_IP_duration;
744 * Number of packets to buffer for codec probing
746 #define MAX_PROBE_PACKETS 2500
750 * last packet in packet_buffer for this stream when muxing.
752 struct AVPacketList *last_in_packet_buffer;
753 AVProbeData probe_data;
754 #define MAX_REORDER_DELAY 16
755 int64_t pts_buffer[MAX_REORDER_DELAY+1];
756 /* av_read_frame() support */
757 enum AVStreamParseType need_parsing;
758 struct AVCodecParserContext *parser;
760 AVIndexEntry *index_entries; /**< Only used if the format does not
761 support seeking natively. */
762 int nb_index_entries;
763 unsigned int index_entries_allocated_size;
765 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
769 #define AV_PROGRAM_RUNNING 1
772 * New fields can be added to the end with minor version bumps.
773 * Removal, reordering and changes to existing fields require a major
775 * sizeof(AVProgram) must not be used outside libav*.
777 typedef struct AVProgram {
780 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
781 unsigned int *stream_index;
782 unsigned int nb_stream_indexes;
783 AVDictionary *metadata;
790 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
791 (streams are added dynamically) */
793 typedef struct AVChapter {
794 int id; ///< unique ID to identify the chapter
795 AVRational time_base; ///< time base in which the start/end timestamps are specified
796 int64_t start, end; ///< chapter start/end time in time_base units
797 AVDictionary *metadata;
801 * Format I/O context.
802 * New fields can be added to the end with minor version bumps.
803 * Removal, reordering and changes to existing fields require a major
805 * sizeof(AVFormatContext) must not be used outside libav*, use
806 * avformat_alloc_context() to create an AVFormatContext.
808 typedef struct AVFormatContext {
810 * A class for logging and AVOptions. Set by avformat_alloc_context().
811 * Exports (de)muxer private options if they exist.
813 const AVClass *av_class;
816 * Can only be iformat or oformat, not both at the same time.
818 * decoding: set by avformat_open_input().
819 * encoding: set by the user.
821 struct AVInputFormat *iformat;
822 struct AVOutputFormat *oformat;
825 * Format private data. This is an AVOptions-enabled struct
826 * if and only if iformat/oformat.priv_class is not NULL.
833 * decoding: either set by the user before avformat_open_input() (then
834 * the user must close it manually) or set by avformat_open_input().
835 * encoding: set by the user.
837 * Do NOT set this field if AVFMT_NOFILE flag is set in
838 * iformat/oformat.flags. In such a case, the (de)muxer will handle
839 * I/O in some other way and this field will be NULL.
844 * A list of all streams in the file. New streams are created with
845 * avformat_new_stream().
847 * decoding: streams are created by libavformat in avformat_open_input().
848 * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
849 * appear in av_read_frame().
850 * encoding: streams are created by the user before avformat_write_header().
852 unsigned int nb_streams;
855 char filename[1024]; /**< input or output filename */
859 * @deprecated use 'creation_time' metadata tag instead
861 attribute_deprecated int64_t timestamp;
864 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
865 #if FF_API_REORDER_PRIVATE
866 /* private data for pts handling (do not modify directly). */
868 * This buffer is only needed when packets were already buffered but
869 * not decoded, for example to get the codec parameters in MPEG
872 struct AVPacketList *packet_buffer;
876 * Decoding: position of the first frame of the component, in
877 * AV_TIME_BASE fractional seconds. NEVER set this value directly:
878 * It is deduced from the AVStream values.
883 * Decoding: duration of the stream, in AV_TIME_BASE fractional
884 * seconds. Only set this value if you know none of the individual stream
885 * durations and also dont set any of them. This is deduced from the
886 * AVStream values if not set.
892 * decoding: total file size, 0 if unknown
894 attribute_deprecated int64_t file_size;
898 * Decoding: total stream bitrate in bit/s, 0 if not
899 * available. Never set it directly if the file_size and the
900 * duration are known as FFmpeg can compute it automatically.
904 #if FF_API_REORDER_PRIVATE
905 /* av_read_frame() support */
908 /* av_seek_frame() support */
909 int64_t data_offset; /**< offset of the first packet */
914 * use mpeg muxer private options instead
916 attribute_deprecated int mux_rate;
918 unsigned int packet_size;
920 attribute_deprecated int preload;
924 #if FF_API_LOOP_OUTPUT
925 #define AVFMT_NOOUTPUTLOOP -1
926 #define AVFMT_INFINITEOUTPUTLOOP 0
928 * number of times to loop output in formats that support it
930 * @deprecated use the 'loop' private option in the gif muxer.
932 attribute_deprecated int loop_output;
936 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
937 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
938 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
939 #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
940 #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
941 #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
942 #if FF_API_FLAG_RTP_HINT
943 #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
945 #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
946 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
947 #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
948 #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
949 #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)
950 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate.
952 #if FF_API_LOOP_INPUT
954 * @deprecated, use the 'loop' img2 demuxer private option.
956 attribute_deprecated int loop_input;
960 * decoding: size of data to probe; encoding: unused.
962 unsigned int probesize;
965 * decoding: maximum time (in AV_TIME_BASE units) during which the input should
966 * be analyzed in avformat_find_stream_info().
968 int max_analyze_duration;
973 unsigned int nb_programs;
974 AVProgram **programs;
977 * Forced video codec_id.
978 * Demuxing: Set by user.
980 enum CodecID video_codec_id;
983 * Forced audio codec_id.
984 * Demuxing: Set by user.
986 enum CodecID audio_codec_id;
989 * Forced subtitle codec_id.
990 * Demuxing: Set by user.
992 enum CodecID subtitle_codec_id;
995 * Maximum amount of memory in bytes to use for the index of each stream.
996 * If the index exceeds this size, entries will be discarded as
997 * needed to maintain a smaller size. This can lead to slower or less
998 * accurate seeking (depends on demuxer).
999 * Demuxers for which a full in-memory index is mandatory will ignore
1002 * demuxing: set by user
1004 unsigned int max_index_size;
1007 * Maximum amount of memory in bytes to use for buffering frames
1008 * obtained from realtime capture devices.
1010 unsigned int max_picture_buffer;
1012 unsigned int nb_chapters;
1013 AVChapter **chapters;
1016 * Flags to enable debugging.
1019 #define FF_FDEBUG_TS 0x0001
1021 #if FF_API_REORDER_PRIVATE
1023 * Raw packets from the demuxer, prior to parsing and decoding.
1024 * This buffer is used for buffering packets until the codec can
1025 * be identified, as parsing cannot be done without knowing the
1028 struct AVPacketList *raw_packet_buffer;
1029 struct AVPacketList *raw_packet_buffer_end;
1031 struct AVPacketList *packet_buffer_end;
1034 AVDictionary *metadata;
1036 #if FF_API_REORDER_PRIVATE
1038 * Remaining size available for raw_packet_buffer, in bytes.
1039 * NOT PART OF PUBLIC API
1041 #define RAW_PACKET_BUFFER_SIZE 2500000
1042 int raw_packet_buffer_remaining_size;
1046 * Start time of the stream in real world time, in microseconds
1047 * since the unix epoch (00:00 1st January 1970). That is, pts=0
1048 * in the stream was captured at this real world time.
1049 * - encoding: Set by user.
1050 * - decoding: Unused.
1052 int64_t start_time_realtime;
1055 * decoding: number of frames used to probe fps
1060 * Error recognition; higher values will detect more errors but may
1061 * misdetect some more or less valid parts as errors.
1062 * - encoding: unused
1063 * - decoding: Set by user.
1065 int error_recognition;
1068 * Custom interrupt callbacks for the I/O layer.
1070 * decoding: set by the user before avformat_open_input().
1071 * encoding: set by the user before avformat_write_header()
1072 * (mainly useful for AVFMT_NOFILE formats). The callback
1073 * should also be passed to avio_open2() if it's used to
1076 AVIOInterruptCB interrupt_callback;
1079 * Transport stream id.
1080 * This will be moved into demuxer private options. Thus no API/ABI compatibility
1085 * Audio preload in microseconds.
1086 * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
1087 * - encoding: Set by user via AVOptions (NO direct access)
1088 * - decoding: unused
1093 * Max chunk time in microseconds.
1094 * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
1095 * - encoding: Set by user via AVOptions (NO direct access)
1096 * - decoding: unused
1098 int max_chunk_duration;
1101 * Max chunk size in bytes
1102 * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
1103 * - encoding: Set by user via AVOptions (NO direct access)
1104 * - decoding: unused
1108 /*****************************************************************
1109 * All fields below this line are not part of the public API. They
1110 * may not be used outside of libavformat and can be changed and
1112 * New public fields should be added right above.
1113 *****************************************************************
1115 #if !FF_API_REORDER_PRIVATE
1117 * Raw packets from the demuxer, prior to parsing and decoding.
1118 * This buffer is used for buffering packets until the codec can
1119 * be identified, as parsing cannot be done without knowing the
1122 struct AVPacketList *raw_packet_buffer;
1123 struct AVPacketList *raw_packet_buffer_end;
1125 * Remaining size available for raw_packet_buffer, in bytes.
1127 #define RAW_PACKET_BUFFER_SIZE 2500000
1128 int raw_packet_buffer_remaining_size;
1131 * This buffer is only needed when packets were already buffered but
1132 * not decoded, for example to get the codec parameters in MPEG
1135 struct AVPacketList *packet_buffer;
1136 struct AVPacketList *packet_buffer_end;
1138 /* av_read_frame() support */
1141 /* av_seek_frame() support */
1142 int64_t data_offset; /**< offset of the first packet */
1146 typedef struct AVPacketList {
1148 struct AVPacketList *next;
1152 * If f is NULL, returns the first registered input format,
1153 * if f is non-NULL, returns the next registered input format after f
1154 * or NULL if f is the last one.
1156 AVInputFormat *av_iformat_next(AVInputFormat *f);
1159 * If f is NULL, returns the first registered output format,
1160 * if f is non-NULL, returns the next registered output format after f
1161 * or NULL if f is the last one.
1163 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
1165 #if FF_API_GUESS_IMG2_CODEC
1166 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1169 /* XXX: Use automatic init with either ELF sections or C file parser */
1173 void av_register_input_format(AVInputFormat *format);
1174 void av_register_output_format(AVOutputFormat *format);
1177 * Return the output format in the list of registered output formats
1178 * which best matches the provided parameters, or return NULL if
1179 * there is no match.
1181 * @param short_name if non-NULL checks if short_name matches with the
1182 * names of the registered formats
1183 * @param filename if non-NULL checks if filename terminates with the
1184 * extensions of the registered formats
1185 * @param mime_type if non-NULL checks if mime_type matches with the
1186 * MIME type of the registered formats
1188 AVOutputFormat *av_guess_format(const char *short_name,
1189 const char *filename,
1190 const char *mime_type);
1193 * Guess the codec ID based upon muxer and filename.
1195 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1196 const char *filename, const char *mime_type,
1197 enum AVMediaType type);
1200 * Send a nice hexadecimal dump of a buffer to the specified file stream.
1202 * @param f The file stream pointer where the dump should be sent to.
1204 * @param size buffer size
1206 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
1208 void av_hex_dump(FILE *f, uint8_t *buf, int size);
1211 * Send a nice hexadecimal dump of a buffer to the log.
1213 * @param avcl A pointer to an arbitrary struct of which the first field is a
1214 * pointer to an AVClass struct.
1215 * @param level The importance level of the message, lower values signifying
1216 * higher importance.
1218 * @param size buffer size
1220 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
1222 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1225 * Send a nice dump of a packet to the specified file stream.
1227 * @param f The file stream pointer where the dump should be sent to.
1228 * @param pkt packet to dump
1229 * @param dump_payload True if the payload must be displayed, too.
1230 * @param st AVStream that the packet belongs to
1232 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1236 * Send a nice dump of a packet to the log.
1238 * @param avcl A pointer to an arbitrary struct of which the first field is a
1239 * pointer to an AVClass struct.
1240 * @param level The importance level of the message, lower values signifying
1241 * higher importance.
1242 * @param pkt packet to dump
1243 * @param dump_payload True if the payload must be displayed, too.
1244 * @param st AVStream that the packet belongs to
1246 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1250 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1251 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1256 * Initialize libavformat and register all the muxers, demuxers and
1257 * protocols. If you do not call this function, then you can select
1258 * exactly which formats you want to support.
1260 * @see av_register_input_format()
1261 * @see av_register_output_format()
1262 * @see av_register_protocol()
1264 void av_register_all(void);
1267 * Get the CodecID for the given codec tag tag.
1268 * If no codec id is found returns CODEC_ID_NONE.
1270 * @param tags list of supported codec_id-codec_tag pairs, as stored
1271 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1273 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1276 * Get the codec tag for the given codec id id.
1277 * If no codec tag is found returns 0.
1279 * @param tags list of supported codec_id-codec_tag pairs, as stored
1280 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1282 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1284 /* media file input */
1287 * Find AVInputFormat based on the short name of the input format.
1289 AVInputFormat *av_find_input_format(const char *short_name);
1292 * Guess the file format.
1294 * @param is_opened Whether the file is already opened; determines whether
1295 * demuxers with or without AVFMT_NOFILE are probed.
1297 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1300 * Guess the file format.
1302 * @param is_opened Whether the file is already opened; determines whether
1303 * demuxers with or without AVFMT_NOFILE are probed.
1304 * @param score_max A probe score larger that this is required to accept a
1305 * detection, the variable is set to the actual detection
1307 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1308 * to retry with a larger probe buffer.
1310 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1313 * Guess the file format.
1315 * @param is_opened Whether the file is already opened; determines whether
1316 * demuxers with or without AVFMT_NOFILE are probed.
1317 * @param score_ret The score of the best detection.
1319 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
1322 * Probe a bytestream to determine the input format. Each time a probe returns
1323 * with a score that is too low, the probe buffer size is increased and another
1324 * attempt is made. When the maximum probe size is reached, the input format
1325 * with the highest score is returned.
1327 * @param pb the bytestream to probe
1328 * @param fmt the input format is put here
1329 * @param filename the filename of the stream
1330 * @param logctx the log context
1331 * @param offset the offset within the bytestream to probe from
1332 * @param max_probe_size the maximum probe buffer size (zero for default)
1333 * @return 0 in case of success, a negative value corresponding to an
1334 * AVERROR code otherwise
1336 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
1337 const char *filename, void *logctx,
1338 unsigned int offset, unsigned int max_probe_size);
1340 #if FF_API_FORMAT_PARAMETERS
1342 * Allocate all the structures needed to read an input stream.
1343 * This does not open the needed codecs for decoding the stream[s].
1344 * @deprecated use avformat_open_input instead.
1346 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
1347 AVIOContext *pb, const char *filename,
1348 AVInputFormat *fmt, AVFormatParameters *ap);
1351 * Open a media file as input. The codecs are not opened. Only the file
1352 * header (if present) is read.
1354 * @param ic_ptr The opened media file handle is put here.
1355 * @param filename filename to open
1356 * @param fmt If non-NULL, force the file format to use.
1357 * @param buf_size optional buffer size (zero if default is OK)
1358 * @param ap Additional parameters needed when opening the file
1359 * (NULL if default).
1360 * @return 0 if OK, AVERROR_xxx otherwise
1362 * @deprecated use avformat_open_input instead.
1364 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1367 AVFormatParameters *ap);
1371 * Open an input stream and read the header. The codecs are not opened.
1372 * The stream must be closed with av_close_input_file().
1374 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1375 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1376 * function and written into ps.
1377 * Note that a user-supplied AVFormatContext will be freed on failure.
1378 * @param filename Name of the stream to open.
1379 * @param fmt If non-NULL, this parameter forces a specific input format.
1380 * Otherwise the format is autodetected.
1381 * @param options A dictionary filled with AVFormatContext and demuxer-private options.
1382 * On return this parameter will be destroyed and replaced with a dict containing
1383 * options that were not found. May be NULL.
1385 * @return 0 on success, a negative AVERROR on failure.
1387 * @note If you want to use custom IO, preallocate the format context and set its pb field.
1389 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1391 int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
1394 * Allocate an AVFormatContext.
1395 * avformat_free_context() can be used to free the context and everything
1396 * allocated by the framework within it.
1398 AVFormatContext *avformat_alloc_context(void);
1400 #if FF_API_ALLOC_OUTPUT_CONTEXT
1402 * @deprecated deprecated in favor of avformat_alloc_output_context2()
1404 attribute_deprecated
1405 AVFormatContext *avformat_alloc_output_context(const char *format,
1406 AVOutputFormat *oformat,
1407 const char *filename);
1411 * Allocate an AVFormatContext for an output format.
1412 * avformat_free_context() can be used to free the context and
1413 * everything allocated by the framework within it.
1415 * @param *ctx is set to the created format context, or to NULL in
1417 * @param oformat format to use for allocating the context, if NULL
1418 * format_name and filename are used instead
1419 * @param format_name the name of output format to use for allocating the
1420 * context, if NULL filename is used instead
1421 * @param filename the name of the filename to use for allocating the
1422 * context, may be NULL
1423 * @return >= 0 in case of success, a negative AVERROR code in case of
1426 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
1427 const char *format_name, const char *filename);
1429 #if FF_API_FORMAT_PARAMETERS
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 * @return >=0 if OK, AVERROR_xxx on error
1440 * @todo Let the user decide somehow what information is needed so that
1441 * we do not waste time getting stuff the user does not need.
1443 * @deprecated use avformat_find_stream_info.
1445 attribute_deprecated
1446 int av_find_stream_info(AVFormatContext *ic);
1450 * Read packets of a media file to get stream information. This
1451 * is useful for file formats with no headers such as MPEG. This
1452 * function also computes the real framerate in case of MPEG-2 repeat
1454 * The logical file position is not changed by this function;
1455 * examined packets may be buffered for later processing.
1457 * @param ic media file handle
1458 * @param options If non-NULL, an ic.nb_streams long array of pointers to
1459 * dictionaries, where i-th member contains options for
1460 * codec corresponding to i-th stream.
1461 * On return each dictionary will be filled with options that were not found.
1462 * @return >=0 if OK, AVERROR_xxx on error
1464 * @note this function isn't guaranteed to open all the codecs, so
1465 * options being non-empty at return is a perfectly normal behavior.
1467 * @todo Let the user decide somehow what information is needed so that
1468 * we do not waste time getting stuff the user does not need.
1470 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
1473 * Find the programs which belong to a given stream.
1475 * @param ic media file handle
1476 * @param last the last found program, the search will start after this
1477 * program, or from the beginning if it is NULL
1478 * @param s stream index
1479 * @return the next program which belongs to s, NULL if no program is found or
1480 * the last program is not among the programs of ic.
1482 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
1485 * Find the "best" stream in the file.
1486 * The best stream is determined according to various heuristics as the most
1487 * likely to be what the user expects.
1488 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1489 * default decoder for the stream's codec; streams for which no decoder can
1490 * be found are ignored.
1492 * @param ic media file handle
1493 * @param type stream type: video, audio, subtitles, etc.
1494 * @param wanted_stream_nb user-requested stream number,
1495 * or -1 for automatic selection
1496 * @param related_stream try to find a stream related (eg. in the same
1497 * program) to this one, or -1 if none
1498 * @param decoder_ret if non-NULL, returns the decoder for the
1500 * @param flags flags; none are currently defined
1501 * @return the non-negative stream number in case of success,
1502 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1504 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1505 * @note If av_find_best_stream returns successfully and decoder_ret is not
1506 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1508 int av_find_best_stream(AVFormatContext *ic,
1509 enum AVMediaType type,
1510 int wanted_stream_nb,
1512 AVCodec **decoder_ret,
1516 * Read a transport packet from a media file.
1518 * This function is obsolete and should never be used.
1519 * Use av_read_frame() instead.
1521 * @param s media file handle
1522 * @param pkt is filled
1523 * @return 0 if OK, AVERROR_xxx on error
1525 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1528 * Return the next frame of a stream.
1529 * This function returns what is stored in the file, and does not validate
1530 * that what is there are valid frames for the decoder. It will split what is
1531 * stored in the file into frames and return one for each call. It will not
1532 * omit invalid data between valid frames so as to give the decoder the maximum
1533 * information possible for decoding.
1535 * The returned packet is valid
1536 * until the next av_read_frame() or until av_close_input_file() and
1537 * must be freed with av_free_packet. For video, the packet contains
1538 * exactly one frame. For audio, it contains an integer number of
1539 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1540 * data). If the audio frames have a variable size (e.g. MPEG audio),
1541 * then it contains one frame.
1543 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1544 * values in AVStream.time_base units (and guessed if the format cannot
1545 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1546 * has B-frames, so it is better to rely on pkt->dts if you do not
1547 * decompress the payload.
1549 * @return 0 if OK, < 0 on error or end of file
1551 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1554 * Seek to the keyframe at timestamp.
1555 * 'timestamp' in 'stream_index'.
1556 * @param stream_index If stream_index is (-1), a default
1557 * stream is selected, and timestamp is automatically converted
1558 * from AV_TIME_BASE units to the stream specific time_base.
1559 * @param timestamp Timestamp in AVStream.time_base units
1560 * or, if no stream is specified, in AV_TIME_BASE units.
1561 * @param flags flags which select direction and seeking mode
1562 * @return >= 0 on success
1564 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1568 * Seek to timestamp ts.
1569 * Seeking will be done so that the point from which all active streams
1570 * can be presented successfully will be closest to ts and within min/max_ts.
1571 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1573 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1574 * are the file position (this may not be supported by all demuxers).
1575 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1576 * in the stream with stream_index (this may not be supported by all demuxers).
1577 * Otherwise all timestamps are in units of the stream selected by stream_index
1578 * or if stream_index is -1, in AV_TIME_BASE units.
1579 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1580 * keyframes (this may not be supported by all demuxers).
1582 * @param stream_index index of the stream which is used as time base reference
1583 * @param min_ts smallest acceptable timestamp
1584 * @param ts target timestamp
1585 * @param max_ts largest acceptable timestamp
1586 * @param flags flags
1587 * @return >=0 on success, error code otherwise
1589 * @note This is part of the new seek API which is still under construction.
1590 * Thus do not use this yet. It may change at any time, do not expect
1591 * ABI compatibility yet!
1593 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1596 * Start playing a network-based stream (e.g. RTSP stream) at the
1599 int av_read_play(AVFormatContext *s);
1602 * Pause a network-based stream (e.g. RTSP stream).
1604 * Use av_read_play() to resume it.
1606 int av_read_pause(AVFormatContext *s);
1609 * Free a AVFormatContext allocated by av_open_input_stream.
1610 * @param s context to free
1612 void av_close_input_stream(AVFormatContext *s);
1615 * Close a media file (but not its codecs).
1617 * @param s media file handle
1619 void av_close_input_file(AVFormatContext *s);
1622 * Free an AVFormatContext and all its streams.
1623 * @param s context to free
1625 void avformat_free_context(AVFormatContext *s);
1627 #if FF_API_NEW_STREAM
1629 * Add a new stream to a media file.
1631 * Can only be called in the read_header() function. If the flag
1632 * AVFMTCTX_NOHEADER is in the format context, then new streams
1633 * can be added in read_packet too.
1635 * @param s media file handle
1636 * @param id file-format-dependent stream ID
1638 attribute_deprecated
1639 AVStream *av_new_stream(AVFormatContext *s, int id);
1643 * Add a new stream to a media file.
1645 * When demuxing, it is called by the demuxer in read_header(). If the
1646 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1647 * be called in read_packet().
1649 * When muxing, should be called by the user before avformat_write_header().
1651 * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1652 * will be initialized to use this codec. This is needed for e.g. codec-specific
1653 * defaults to be set, so codec should be provided if it is known.
1655 * @return newly created stream or NULL on error.
1657 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1659 AVProgram *av_new_program(AVFormatContext *s, int id);
1661 #if FF_API_SET_PTS_INFO
1663 * @deprecated this function is not supposed to be called outside of lavf
1665 attribute_deprecated
1666 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1667 unsigned int pts_num, unsigned int pts_den);
1670 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1671 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
1672 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
1673 #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
1675 int av_find_default_stream_index(AVFormatContext *s);
1678 * Get the index for a specific timestamp.
1679 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1680 * to the timestamp which is <= the requested one, if backward
1681 * is 0, then it will be >=
1682 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1683 * @return < 0 if no such timestamp could be found
1685 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1688 * Add an index entry into a sorted list. Update the entry if the list
1689 * already contains it.
1691 * @param timestamp timestamp in the time base of the given stream
1693 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1694 int size, int distance, int flags);
1696 #if FF_API_SEEK_PUBLIC
1697 attribute_deprecated
1698 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1699 int64_t target_ts, int flags);
1700 attribute_deprecated
1701 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1702 attribute_deprecated
1703 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1704 int64_t target_ts, int64_t pos_min,
1705 int64_t pos_max, int64_t pos_limit,
1706 int64_t ts_min, int64_t ts_max,
1707 int flags, int64_t *ts_ret,
1708 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1714 #if FF_API_FORMAT_PARAMETERS
1716 * @deprecated pass the options to avformat_write_header directly.
1718 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1722 * Split a URL string into components.
1724 * The pointers to buffers for storing individual components may be null,
1725 * in order to ignore that component. Buffers for components not found are
1726 * set to empty strings. If the port is not found, it is set to a negative
1729 * @param proto the buffer for the protocol
1730 * @param proto_size the size of the proto buffer
1731 * @param authorization the buffer for the authorization
1732 * @param authorization_size the size of the authorization buffer
1733 * @param hostname the buffer for the host name
1734 * @param hostname_size the size of the hostname buffer
1735 * @param port_ptr a pointer to store the port number in
1736 * @param path the buffer for the path
1737 * @param path_size the size of the path buffer
1738 * @param url the URL to split
1740 void av_url_split(char *proto, int proto_size,
1741 char *authorization, int authorization_size,
1742 char *hostname, int hostname_size,
1744 char *path, int path_size,
1748 * Allocate the stream private data and write the stream header to
1749 * an output media file.
1751 * @param s Media file handle, must be allocated with avformat_alloc_context().
1752 * Its oformat field must be set to the desired output format;
1753 * Its pb field must be set to an already openened AVIOContext.
1754 * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
1755 * On return this parameter will be destroyed and replaced with a dict containing
1756 * options that were not found. May be NULL.
1758 * @return 0 on success, negative AVERROR on failure.
1760 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1762 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1764 #if FF_API_FORMAT_PARAMETERS
1766 * Allocate the stream private data and write the stream header to an
1767 * output media file.
1768 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1769 * but for some formats it might also be some other time base
1771 * @param s media file handle
1772 * @return 0 if OK, AVERROR_xxx on error
1774 * @deprecated use avformat_write_header.
1776 attribute_deprecated int av_write_header(AVFormatContext *s);
1780 * Write a packet to an output media file.
1782 * The packet shall contain one audio or video frame.
1783 * The packet must be correctly interleaved according to the container
1784 * specification, if not then av_interleaved_write_frame must be used.
1786 * @param s media file handle
1787 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1789 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1791 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1794 * Write a packet to an output media file ensuring correct interleaving.
1796 * The packet must contain one audio or video frame.
1797 * If the packets are already correctly interleaved, the application should
1798 * call av_write_frame() instead as it is slightly faster. It is also important
1799 * to keep in mind that completely non-interleaved input will need huge amounts
1800 * of memory to interleave with this, so it is preferable to interleave at the
1803 * @param s media file handle
1804 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1806 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1808 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1811 * Interleave a packet per dts in an output media file.
1813 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1814 * function, so they cannot be used after it. Note that calling av_free_packet()
1815 * on them is still safe.
1817 * @param s media file handle
1818 * @param out the interleaved packet will be output here
1819 * @param pkt the input packet
1820 * @param flush 1 if no further packets are available as input and all
1821 * remaining packets should be output
1822 * @return 1 if a packet was output, 0 if no packet could be output,
1823 * < 0 if an error occurred
1825 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1826 AVPacket *pkt, int flush);
1829 * Write the stream trailer to an output media file and free the
1830 * file private data.
1832 * May only be called after a successful call to av_write_header.
1834 * @param s media file handle
1835 * @return 0 if OK, AVERROR_xxx on error
1837 int av_write_trailer(AVFormatContext *s);
1840 * Get timing information for the data currently output.
1841 * The exact meaning of "currently output" depends on the format.
1842 * It is mostly relevant for devices that have an internal buffer and/or
1843 * work in real time.
1844 * @param s media file handle
1845 * @param stream stream in the media file
1846 * @param dts[out] DTS of the last packet output for the stream, in stream
1848 * @param wall[out] absolute time when that packet whas output,
1850 * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it
1851 * Note: some formats or devices may not allow to measure dts and wall
1854 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
1855 int64_t *dts, int64_t *wall);
1857 #if FF_API_DUMP_FORMAT
1859 * @deprecated Deprecated in favor of av_dump_format().
1861 attribute_deprecated void dump_format(AVFormatContext *ic,
1867 void av_dump_format(AVFormatContext *ic,
1872 #if FF_API_PARSE_DATE
1874 * Parse datestr and return a corresponding number of microseconds.
1876 * @param datestr String representing a date or a duration.
1877 * See av_parse_time() for the syntax of the provided string.
1878 * @deprecated in favor of av_parse_time()
1880 attribute_deprecated
1881 int64_t parse_date(const char *datestr, int duration);
1885 * Get the current time in microseconds.
1887 int64_t av_gettime(void);
1889 #if FF_API_FIND_INFO_TAG
1891 * @deprecated use av_find_info_tag in libavutil instead.
1893 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1897 * Return in 'buf' the path with '%d' replaced by a number.
1899 * Also handles the '%0nd' format where 'n' is the total number
1900 * of digits and '%%'.
1902 * @param buf destination buffer
1903 * @param buf_size destination buffer size
1904 * @param path numbered sequence string
1905 * @param number frame number
1906 * @return 0 if OK, -1 on format error
1908 int av_get_frame_filename(char *buf, int buf_size,
1909 const char *path, int number);
1912 * Check whether filename actually is a numbered sequence generator.
1914 * @param filename possible numbered sequence string
1915 * @return 1 if a valid numbered sequence string, 0 otherwise
1917 int av_filename_number_test(const char *filename);
1920 * Generate an SDP for an RTP session.
1922 * @param ac array of AVFormatContexts describing the RTP streams. If the
1923 * array is composed by only one context, such context can contain
1924 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1925 * all the contexts in the array (an AVCodecContext per RTP stream)
1926 * must contain only one AVStream.
1927 * @param n_files number of AVCodecContexts contained in ac
1928 * @param buf buffer where the SDP will be stored (must be allocated by
1930 * @param size the size of the buffer
1931 * @return 0 if OK, AVERROR_xxx on error
1933 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1935 #if FF_API_SDP_CREATE
1936 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1940 * Return a positive value if the given filename has one of the given
1941 * extensions, 0 otherwise.
1943 * @param extensions a comma-separated list of filename extensions
1945 int av_match_ext(const char *filename, const char *extensions);
1948 * Test if the given container can store a codec.
1950 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1952 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1953 * A negative number if this information is not available.
1955 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1958 * Get the AVClass for AVFormatContext. It can be used in combination with
1959 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1961 * @see av_opt_find().
1963 const AVClass *avformat_get_class(void);
1966 * Do global initialization of network components. This is optional,
1967 * but recommended, since it avoids the overhead of implicitly
1968 * doing the setup for each session.
1970 * Calling this function will become mandatory if using network
1971 * protocols at some major version bump.
1973 int avformat_network_init(void);
1976 * Undo the initialization done by avformat_network_init.
1978 int avformat_network_deinit(void);
1980 #endif /* AVFORMAT_AVFORMAT_H */