2 * copyright (c) 2001 Fabrice Bellard
4 * This file is part of Libav.
6 * Libav 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 * Libav 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 Libav; 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 Libav,
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 */
313 typedef struct AVOutputFormat {
316 * Descriptive name for the format, meant to be more human-readable
317 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
320 const char *long_name;
321 const char *mime_type;
322 const char *extensions; /**< comma-separated filename extensions */
324 * size of private data so that it can be allocated in the wrapper
328 enum CodecID audio_codec; /**< default audio codec */
329 enum CodecID video_codec; /**< default video codec */
330 int (*write_header)(struct AVFormatContext *);
331 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
332 int (*write_trailer)(struct AVFormatContext *);
334 * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
335 * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
336 * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
340 * Currently only used to set pixel format if not YUV420P.
342 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
343 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
344 AVPacket *in, int flush);
347 * List of supported codec_id-codec_tag pairs, ordered by "better
348 * choice first". The arrays are all terminated by CODEC_ID_NONE.
350 const struct AVCodecTag * const *codec_tag;
352 enum CodecID subtitle_codec; /**< default subtitle codec */
354 #if FF_API_OLD_METADATA2
355 const AVMetadataConv *metadata_conv;
358 const AVClass *priv_class; ///< AVClass for the private context
361 * Test if the given codec can be stored in this container.
363 * @return 1 if the codec is supported, 0 if it is not.
364 * A negative number if unknown.
366 int (*query_codec)(enum CodecID id, int std_compliance);
369 struct AVOutputFormat *next;
372 typedef struct AVInputFormat {
374 * A comma separated list of short names for the format. New names
375 * may be appended with a minor bump.
380 * Descriptive name for the format, meant to be more human-readable
381 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
384 const char *long_name;
387 * Size of private data so that it can be allocated in the wrapper.
392 * Tell if a given file has a chance of being parsed as this format.
393 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
394 * big so you do not have to check for that unless you need more.
396 int (*read_probe)(AVProbeData *);
399 * Read the format header and initialize the AVFormatContext
400 * structure. Return 0 if OK. 'ap' if non-NULL contains
401 * additional parameters. Only used in raw format right
402 * now. 'av_new_stream' should be called to create new streams.
404 int (*read_header)(struct AVFormatContext *,
405 AVFormatParameters *ap);
408 * Read one packet and put it in 'pkt'. pts and flags are also
409 * set. 'av_new_stream' can be called only if the flag
410 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
411 * background thread).
412 * @return 0 on success, < 0 on error.
413 * When returning an error, pkt must not have been allocated
414 * or must be freed before returning
416 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
419 * Close the stream. The AVFormatContext and AVStreams are not
420 * freed by this function
422 int (*read_close)(struct AVFormatContext *);
426 * Seek to a given timestamp relative to the frames in
427 * stream component stream_index.
428 * @param stream_index Must not be -1.
429 * @param flags Selects which direction should be preferred if no exact
430 * match is available.
431 * @return >= 0 on success (but not necessarily the new offset)
433 attribute_deprecated int (*read_seek)(struct AVFormatContext *,
434 int stream_index, int64_t timestamp, int flags);
437 * Gets the next timestamp in stream[stream_index].time_base units.
438 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
440 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
441 int64_t *pos, int64_t pos_limit);
444 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
445 * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
446 * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
451 * If extensions are defined, then no probe is done. You should
452 * usually not use extension format guessing because it is not
455 const char *extensions;
458 * General purpose read-only value that the format can use.
463 * Start/resume playing - only meaningful if using a network-based format
466 int (*read_play)(struct AVFormatContext *);
469 * Pause playing - only meaningful if using a network-based format
472 int (*read_pause)(struct AVFormatContext *);
474 const struct AVCodecTag * const *codec_tag;
477 * Seek to timestamp ts.
478 * Seeking will be done so that the point from which all active streams
479 * can be presented successfully will be closest to ts and within min/max_ts.
480 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
482 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
484 #if FF_API_OLD_METADATA2
485 const AVMetadataConv *metadata_conv;
488 const AVClass *priv_class; ///< AVClass for the private context
491 struct AVInputFormat *next;
494 enum AVStreamParseType {
496 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
497 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
498 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
499 AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
502 typedef struct AVIndexEntry {
505 #define AVINDEX_KEYFRAME 0x0001
507 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).
508 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
511 #define AV_DISPOSITION_DEFAULT 0x0001
512 #define AV_DISPOSITION_DUB 0x0002
513 #define AV_DISPOSITION_ORIGINAL 0x0004
514 #define AV_DISPOSITION_COMMENT 0x0008
515 #define AV_DISPOSITION_LYRICS 0x0010
516 #define AV_DISPOSITION_KARAOKE 0x0020
519 * Track should be used during playback by default.
520 * Useful for subtitle track that should be displayed
521 * even when user did not explicitly ask for subtitles.
523 #define AV_DISPOSITION_FORCED 0x0040
524 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
525 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
526 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
530 * New fields can be added to the end with minor version bumps.
531 * Removal, reordering and changes to existing fields require a major
533 * sizeof(AVStream) must not be used outside libav*.
535 typedef struct AVStream {
536 int index; /**< stream index in AVFormatContext */
537 int id; /**< format-specific stream ID */
538 AVCodecContext *codec; /**< codec context */
540 * Real base framerate of the stream.
541 * This is the lowest framerate with which all timestamps can be
542 * represented accurately (it is the least common multiple of all
543 * framerates in the stream). Note, this value is just a guess!
544 * For example, if the time base is 1/90000 and all frames have either
545 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
547 AVRational r_frame_rate;
550 #if FF_API_REORDER_PRIVATE
551 /* internal data used in av_find_stream_info() */
556 * encoding: pts generation when outputting stream
561 * This is the fundamental unit of time (in seconds) in terms
562 * of which frame timestamps are represented. For fixed-fps content,
563 * time base should be 1/framerate and timestamp increments should be 1.
564 * decoding: set by libavformat
565 * encoding: set by libavformat in av_write_header
567 AVRational time_base;
568 #if FF_API_REORDER_PRIVATE
569 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
571 #if FF_API_STREAM_COPY
572 /* ffmpeg.c private use */
573 attribute_deprecated int stream_copy; /**< If set, just copy stream. */
575 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
577 #if FF_API_AVSTREAM_QUALITY
578 //FIXME move stuff to a flags field?
580 * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
581 * MN: dunno if that is the right place for it
583 attribute_deprecated float quality;
587 * Decoding: pts of the first frame of the stream, in stream time base.
588 * Only set this if you are absolutely 100% sure that the value you set
589 * it to really is the pts of the first frame.
590 * This may be undefined (AV_NOPTS_VALUE).
595 * Decoding: duration of the stream, in stream time base.
596 * If a source file does not specify a duration, but does specify
597 * a bitrate, this value will be estimated from bitrate and file size.
601 #if FF_API_REORDER_PRIVATE
602 /* av_read_frame() support */
603 enum AVStreamParseType need_parsing;
604 struct AVCodecParserContext *parser;
607 int last_IP_duration;
609 /* av_seek_frame() support */
610 AVIndexEntry *index_entries; /**< Only used if the format does not
611 support seeking natively. */
612 int nb_index_entries;
613 unsigned int index_entries_allocated_size;
616 int64_t nb_frames; ///< number of frames in this stream if known or 0
618 int disposition; /**< AV_DISPOSITION_* bit field */
620 #if FF_API_REORDER_PRIVATE
621 AVProbeData probe_data;
622 #define MAX_REORDER_DELAY 16
623 int64_t pts_buffer[MAX_REORDER_DELAY+1];
627 * sample aspect ratio (0 if unknown)
628 * - encoding: Set by user.
629 * - decoding: Set by libavformat.
631 AVRational sample_aspect_ratio;
633 AVDictionary *metadata;
635 #if FF_API_REORDER_PRIVATE
636 /* Intended mostly for av_read_frame() support. Not supposed to be used by */
637 /* external applications; try to use something else if at all possible. */
638 const uint8_t *cur_ptr;
642 // Timestamp generation support:
644 * Timestamp corresponding to the last dts sync point.
646 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
647 * a DTS is received from the underlying container. Otherwise set to
648 * AV_NOPTS_VALUE by default.
650 int64_t reference_dts;
653 * Number of packets to buffer for codec probing
654 * NOT PART OF PUBLIC API
656 #define MAX_PROBE_PACKETS 2500
660 * last packet in packet_buffer for this stream when muxing.
661 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
663 struct AVPacketList *last_in_packet_buffer;
669 AVRational avg_frame_rate;
671 /*****************************************************************
672 * All fields below this line are not part of the public API. They
673 * may not be used outside of libavformat and can be changed and
675 * New public fields should be added right above.
676 *****************************************************************
680 * Number of frames that have been demuxed during av_find_stream_info()
682 int codec_info_nb_frames;
685 * Stream informations used internally by av_find_stream_info()
687 #define MAX_STD_TIMEBASES (60*12+5)
690 int64_t duration_gcd;
692 double duration_error[MAX_STD_TIMEBASES];
693 int64_t codec_info_duration;
694 int nb_decoded_frames;
696 #if !FF_API_REORDER_PRIVATE
697 const uint8_t *cur_ptr;
701 // Timestamp generation support:
703 * Timestamp corresponding to the last dts sync point.
705 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
706 * a DTS is received from the underlying container. Otherwise set to
707 * AV_NOPTS_VALUE by default.
709 int64_t reference_dts;
712 int last_IP_duration;
716 * Number of packets to buffer for codec probing
718 #define MAX_PROBE_PACKETS 2500
722 * last packet in packet_buffer for this stream when muxing.
724 struct AVPacketList *last_in_packet_buffer;
725 AVProbeData probe_data;
726 #define MAX_REORDER_DELAY 16
727 int64_t pts_buffer[MAX_REORDER_DELAY+1];
728 /* av_read_frame() support */
729 enum AVStreamParseType need_parsing;
730 struct AVCodecParserContext *parser;
732 AVIndexEntry *index_entries; /**< Only used if the format does not
733 support seeking natively. */
734 int nb_index_entries;
735 unsigned int index_entries_allocated_size;
737 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
741 #define AV_PROGRAM_RUNNING 1
744 * New fields can be added to the end with minor version bumps.
745 * Removal, reordering and changes to existing fields require a major
747 * sizeof(AVProgram) must not be used outside libav*.
749 typedef struct AVProgram {
752 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
753 unsigned int *stream_index;
754 unsigned int nb_stream_indexes;
755 AVDictionary *metadata;
758 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
759 (streams are added dynamically) */
761 typedef struct AVChapter {
762 int id; ///< unique ID to identify the chapter
763 AVRational time_base; ///< time base in which the start/end timestamps are specified
764 int64_t start, end; ///< chapter start/end time in time_base units
765 AVDictionary *metadata;
769 * Format I/O context.
770 * New fields can be added to the end with minor version bumps.
771 * Removal, reordering and changes to existing fields require a major
773 * sizeof(AVFormatContext) must not be used outside libav*, use
774 * avformat_alloc_context() to create an AVFormatContext.
776 typedef struct AVFormatContext {
778 * A class for logging and AVOptions. Set by avformat_alloc_context().
779 * Exports (de)muxer private options if they exist.
781 const AVClass *av_class;
784 * Can only be iformat or oformat, not both at the same time.
786 * decoding: set by avformat_open_input().
787 * encoding: set by the user.
789 struct AVInputFormat *iformat;
790 struct AVOutputFormat *oformat;
793 * Format private data. This is an AVOptions-enabled struct
794 * if and only if iformat/oformat.priv_class is not NULL.
801 * decoding: either set by the user before avformat_open_input() (then
802 * the user must close it manually) or set by avformat_open_input().
803 * encoding: set by the user.
805 * Do NOT set this field if AVFMT_NOFILE flag is set in
806 * iformat/oformat.flags. In such a case, the (de)muxer will handle
807 * I/O in some other way and this field will be NULL.
812 * A list of all streams in the file. New streams are created with
813 * avformat_new_stream().
815 * decoding: streams are created by libavformat in avformat_open_input().
816 * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
817 * appear in av_read_frame().
818 * encoding: streams are created by the user before avformat_write_header().
820 unsigned int nb_streams;
823 char filename[1024]; /**< input or output filename */
827 * @deprecated use 'creation_time' metadata tag instead
829 attribute_deprecated int64_t timestamp;
832 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
833 #if FF_API_REORDER_PRIVATE
834 /* private data for pts handling (do not modify directly). */
836 * This buffer is only needed when packets were already buffered but
837 * not decoded, for example to get the codec parameters in MPEG
840 struct AVPacketList *packet_buffer;
844 * Decoding: position of the first frame of the component, in
845 * AV_TIME_BASE fractional seconds. NEVER set this value directly:
846 * It is deduced from the AVStream values.
851 * Decoding: duration of the stream, in AV_TIME_BASE fractional
852 * seconds. Only set this value if you know none of the individual stream
853 * durations and also dont set any of them. This is deduced from the
854 * AVStream values if not set.
860 * decoding: total file size, 0 if unknown
862 attribute_deprecated int64_t file_size;
866 * Decoding: total stream bitrate in bit/s, 0 if not
867 * available. Never set it directly if the file_size and the
868 * duration are known as Libav can compute it automatically.
872 #if FF_API_REORDER_PRIVATE
873 /* av_read_frame() support */
876 /* av_seek_frame() support */
877 int64_t data_offset; /**< offset of the first packet */
882 * use mpeg muxer private options instead
884 attribute_deprecated int mux_rate;
886 unsigned int packet_size;
888 attribute_deprecated int preload;
892 #if FF_API_LOOP_OUTPUT
893 #define AVFMT_NOOUTPUTLOOP -1
894 #define AVFMT_INFINITEOUTPUTLOOP 0
896 * number of times to loop output in formats that support it
898 * @deprecated use the 'loop' private option in the gif muxer.
900 attribute_deprecated int loop_output;
904 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
905 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
906 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
907 #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
908 #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
909 #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
910 #if FF_API_FLAG_RTP_HINT
911 #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
913 #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
914 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
916 #if FF_API_LOOP_INPUT
918 * @deprecated, use the 'loop' img2 demuxer private option.
920 attribute_deprecated int loop_input;
924 * decoding: size of data to probe; encoding: unused.
926 unsigned int probesize;
929 * decoding: maximum time (in AV_TIME_BASE units) during which the input should
930 * be analyzed in avformat_find_stream_info().
932 int max_analyze_duration;
937 unsigned int nb_programs;
938 AVProgram **programs;
941 * Forced video codec_id.
942 * Demuxing: Set by user.
944 enum CodecID video_codec_id;
947 * Forced audio codec_id.
948 * Demuxing: Set by user.
950 enum CodecID audio_codec_id;
953 * Forced subtitle codec_id.
954 * Demuxing: Set by user.
956 enum CodecID subtitle_codec_id;
959 * Maximum amount of memory in bytes to use for the index of each stream.
960 * If the index exceeds this size, entries will be discarded as
961 * needed to maintain a smaller size. This can lead to slower or less
962 * accurate seeking (depends on demuxer).
963 * Demuxers for which a full in-memory index is mandatory will ignore
966 * demuxing: set by user
968 unsigned int max_index_size;
971 * Maximum amount of memory in bytes to use for buffering frames
972 * obtained from realtime capture devices.
974 unsigned int max_picture_buffer;
976 unsigned int nb_chapters;
977 AVChapter **chapters;
980 * Flags to enable debugging.
983 #define FF_FDEBUG_TS 0x0001
985 #if FF_API_REORDER_PRIVATE
987 * Raw packets from the demuxer, prior to parsing and decoding.
988 * This buffer is used for buffering packets until the codec can
989 * be identified, as parsing cannot be done without knowing the
992 struct AVPacketList *raw_packet_buffer;
993 struct AVPacketList *raw_packet_buffer_end;
995 struct AVPacketList *packet_buffer_end;
998 AVDictionary *metadata;
1000 #if FF_API_REORDER_PRIVATE
1002 * Remaining size available for raw_packet_buffer, in bytes.
1003 * NOT PART OF PUBLIC API
1005 #define RAW_PACKET_BUFFER_SIZE 2500000
1006 int raw_packet_buffer_remaining_size;
1010 * Start time of the stream in real world time, in microseconds
1011 * since the unix epoch (00:00 1st January 1970). That is, pts=0
1012 * in the stream was captured at this real world time.
1013 * - encoding: Set by user.
1014 * - decoding: Unused.
1016 int64_t start_time_realtime;
1019 * decoding: number of frames used to probe fps
1024 * Error recognition; higher values will detect more errors but may
1025 * misdetect some more or less valid parts as errors.
1026 * - encoding: unused
1027 * - decoding: Set by user.
1029 int error_recognition;
1032 * Custom interrupt callbacks for the I/O layer.
1034 * decoding: set by the user before avformat_open_input().
1035 * encoding: set by the user before avformat_write_header()
1036 * (mainly useful for AVFMT_NOFILE formats). The callback
1037 * should also be passed to avio_open2() if it's used to
1040 AVIOInterruptCB interrupt_callback;
1042 /*****************************************************************
1043 * All fields below this line are not part of the public API. They
1044 * may not be used outside of libavformat and can be changed and
1046 * New public fields should be added right above.
1047 *****************************************************************
1049 #if !FF_API_REORDER_PRIVATE
1051 * Raw packets from the demuxer, prior to parsing and decoding.
1052 * This buffer is used for buffering packets until the codec can
1053 * be identified, as parsing cannot be done without knowing the
1056 struct AVPacketList *raw_packet_buffer;
1057 struct AVPacketList *raw_packet_buffer_end;
1059 * Remaining size available for raw_packet_buffer, in bytes.
1061 #define RAW_PACKET_BUFFER_SIZE 2500000
1062 int raw_packet_buffer_remaining_size;
1065 * This buffer is only needed when packets were already buffered but
1066 * not decoded, for example to get the codec parameters in MPEG
1069 struct AVPacketList *packet_buffer;
1070 struct AVPacketList *packet_buffer_end;
1072 /* av_read_frame() support */
1075 /* av_seek_frame() support */
1076 int64_t data_offset; /**< offset of the first packet */
1080 typedef struct AVPacketList {
1082 struct AVPacketList *next;
1086 * If f is NULL, returns the first registered input format,
1087 * if f is non-NULL, returns the next registered input format after f
1088 * or NULL if f is the last one.
1090 AVInputFormat *av_iformat_next(AVInputFormat *f);
1093 * If f is NULL, returns the first registered output format,
1094 * if f is non-NULL, returns the next registered output format after f
1095 * or NULL if f is the last one.
1097 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
1099 #if FF_API_GUESS_IMG2_CODEC
1100 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1103 /* XXX: Use automatic init with either ELF sections or C file parser */
1107 void av_register_input_format(AVInputFormat *format);
1108 void av_register_output_format(AVOutputFormat *format);
1111 * Return the output format in the list of registered output formats
1112 * which best matches the provided parameters, or return NULL if
1113 * there is no match.
1115 * @param short_name if non-NULL checks if short_name matches with the
1116 * names of the registered formats
1117 * @param filename if non-NULL checks if filename terminates with the
1118 * extensions of the registered formats
1119 * @param mime_type if non-NULL checks if mime_type matches with the
1120 * MIME type of the registered formats
1122 AVOutputFormat *av_guess_format(const char *short_name,
1123 const char *filename,
1124 const char *mime_type);
1127 * Guess the codec ID based upon muxer and filename.
1129 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1130 const char *filename, const char *mime_type,
1131 enum AVMediaType type);
1134 * Send a nice hexadecimal dump of a buffer to the specified file stream.
1136 * @param f The file stream pointer where the dump should be sent to.
1138 * @param size buffer size
1140 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
1142 void av_hex_dump(FILE *f, uint8_t *buf, int size);
1145 * Send a nice hexadecimal dump of a buffer to the log.
1147 * @param avcl A pointer to an arbitrary struct of which the first field is a
1148 * pointer to an AVClass struct.
1149 * @param level The importance level of the message, lower values signifying
1150 * higher importance.
1152 * @param size buffer size
1154 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
1156 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1159 * Send a nice dump of a packet to the specified file stream.
1161 * @param f The file stream pointer where the dump should be sent to.
1162 * @param pkt packet to dump
1163 * @param dump_payload True if the payload must be displayed, too.
1164 * @param st AVStream that the packet belongs to
1166 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1170 * Send a nice dump of a packet to the log.
1172 * @param avcl A pointer to an arbitrary struct of which the first field is a
1173 * pointer to an AVClass struct.
1174 * @param level The importance level of the message, lower values signifying
1175 * higher importance.
1176 * @param pkt packet to dump
1177 * @param dump_payload True if the payload must be displayed, too.
1178 * @param st AVStream that the packet belongs to
1180 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1184 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1185 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1190 * Initialize libavformat and register all the muxers, demuxers and
1191 * protocols. If you do not call this function, then you can select
1192 * exactly which formats you want to support.
1194 * @see av_register_input_format()
1195 * @see av_register_output_format()
1196 * @see av_register_protocol()
1198 void av_register_all(void);
1201 * Get the CodecID for the given codec tag tag.
1202 * If no codec id is found returns CODEC_ID_NONE.
1204 * @param tags list of supported codec_id-codec_tag pairs, as stored
1205 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1207 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1210 * Get the codec tag for the given codec id id.
1211 * If no codec tag is found returns 0.
1213 * @param tags list of supported codec_id-codec_tag pairs, as stored
1214 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1216 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1218 /* media file input */
1221 * Find AVInputFormat based on the short name of the input format.
1223 AVInputFormat *av_find_input_format(const char *short_name);
1226 * Guess the file format.
1228 * @param is_opened Whether the file is already opened; determines whether
1229 * demuxers with or without AVFMT_NOFILE are probed.
1231 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1234 * Guess the file format.
1236 * @param is_opened Whether the file is already opened; determines whether
1237 * demuxers with or without AVFMT_NOFILE are probed.
1238 * @param score_max A probe score larger that this is required to accept a
1239 * detection, the variable is set to the actual detection
1241 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1242 * to retry with a larger probe buffer.
1244 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1247 * Probe a bytestream to determine the input format. Each time a probe returns
1248 * with a score that is too low, the probe buffer size is increased and another
1249 * attempt is made. When the maximum probe size is reached, the input format
1250 * with the highest score is returned.
1252 * @param pb the bytestream to probe
1253 * @param fmt the input format is put here
1254 * @param filename the filename of the stream
1255 * @param logctx the log context
1256 * @param offset the offset within the bytestream to probe from
1257 * @param max_probe_size the maximum probe buffer size (zero for default)
1258 * @return 0 in case of success, a negative value corresponding to an
1259 * AVERROR code otherwise
1261 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
1262 const char *filename, void *logctx,
1263 unsigned int offset, unsigned int max_probe_size);
1265 #if FF_API_FORMAT_PARAMETERS
1267 * Allocate all the structures needed to read an input stream.
1268 * This does not open the needed codecs for decoding the stream[s].
1269 * @deprecated use avformat_open_input instead.
1271 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
1272 AVIOContext *pb, const char *filename,
1273 AVInputFormat *fmt, AVFormatParameters *ap);
1276 * Open a media file as input. The codecs are not opened. Only the file
1277 * header (if present) is read.
1279 * @param ic_ptr The opened media file handle is put here.
1280 * @param filename filename to open
1281 * @param fmt If non-NULL, force the file format to use.
1282 * @param buf_size optional buffer size (zero if default is OK)
1283 * @param ap Additional parameters needed when opening the file
1284 * (NULL if default).
1285 * @return 0 if OK, AVERROR_xxx otherwise
1287 * @deprecated use avformat_open_input instead.
1289 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1292 AVFormatParameters *ap);
1296 * Open an input stream and read the header. The codecs are not opened.
1297 * The stream must be closed with av_close_input_file().
1299 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1300 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1301 * function and written into ps.
1302 * Note that a user-supplied AVFormatContext will be freed on failure.
1303 * @param filename Name of the stream to open.
1304 * @param fmt If non-NULL, this parameter forces a specific input format.
1305 * Otherwise the format is autodetected.
1306 * @param options A dictionary filled with AVFormatContext and demuxer-private options.
1307 * On return this parameter will be destroyed and replaced with a dict containing
1308 * options that were not found. May be NULL.
1310 * @return 0 on success, a negative AVERROR on failure.
1312 * @note If you want to use custom IO, preallocate the format context and set its pb field.
1314 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1317 * Allocate an AVFormatContext.
1318 * avformat_free_context() can be used to free the context and everything
1319 * allocated by the framework within it.
1321 AVFormatContext *avformat_alloc_context(void);
1323 #if FF_API_FORMAT_PARAMETERS
1325 * Read packets of a media file to get stream information. This
1326 * is useful for file formats with no headers such as MPEG. This
1327 * function also computes the real framerate in case of MPEG-2 repeat
1329 * The logical file position is not changed by this function;
1330 * examined packets may be buffered for later processing.
1332 * @param ic media file handle
1333 * @return >=0 if OK, AVERROR_xxx on error
1334 * @todo Let the user decide somehow what information is needed so that
1335 * we do not waste time getting stuff the user does not need.
1337 * @deprecated use avformat_find_stream_info.
1339 attribute_deprecated
1340 int av_find_stream_info(AVFormatContext *ic);
1344 * Read packets of a media file to get stream information. This
1345 * is useful for file formats with no headers such as MPEG. This
1346 * function also computes the real framerate in case of MPEG-2 repeat
1348 * The logical file position is not changed by this function;
1349 * examined packets may be buffered for later processing.
1351 * @param ic media file handle
1352 * @param options If non-NULL, an ic.nb_streams long array of pointers to
1353 * dictionaries, where i-th member contains options for
1354 * codec corresponding to i-th stream.
1355 * On return each dictionary will be filled with options that were not found.
1356 * @return >=0 if OK, AVERROR_xxx on error
1358 * @note this function isn't guaranteed to open all the codecs, so
1359 * options being non-empty at return is a perfectly normal behavior.
1361 * @todo Let the user decide somehow what information is needed so that
1362 * we do not waste time getting stuff the user does not need.
1364 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
1367 * Find the "best" stream in the file.
1368 * The best stream is determined according to various heuristics as the most
1369 * likely to be what the user expects.
1370 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1371 * default decoder for the stream's codec; streams for which no decoder can
1372 * be found are ignored.
1374 * @param ic media file handle
1375 * @param type stream type: video, audio, subtitles, etc.
1376 * @param wanted_stream_nb user-requested stream number,
1377 * or -1 for automatic selection
1378 * @param related_stream try to find a stream related (eg. in the same
1379 * program) to this one, or -1 if none
1380 * @param decoder_ret if non-NULL, returns the decoder for the
1382 * @param flags flags; none are currently defined
1383 * @return the non-negative stream number in case of success,
1384 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1386 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1387 * @note If av_find_best_stream returns successfully and decoder_ret is not
1388 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1390 int av_find_best_stream(AVFormatContext *ic,
1391 enum AVMediaType type,
1392 int wanted_stream_nb,
1394 AVCodec **decoder_ret,
1398 * Read a transport packet from a media file.
1400 * This function is obsolete and should never be used.
1401 * Use av_read_frame() instead.
1403 * @param s media file handle
1404 * @param pkt is filled
1405 * @return 0 if OK, AVERROR_xxx on error
1407 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1410 * Return the next frame of a stream.
1411 * This function returns what is stored in the file, and does not validate
1412 * that what is there are valid frames for the decoder. It will split what is
1413 * stored in the file into frames and return one for each call. It will not
1414 * omit invalid data between valid frames so as to give the decoder the maximum
1415 * information possible for decoding.
1417 * The returned packet is valid
1418 * until the next av_read_frame() or until av_close_input_file() and
1419 * must be freed with av_free_packet. For video, the packet contains
1420 * exactly one frame. For audio, it contains an integer number of
1421 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1422 * data). If the audio frames have a variable size (e.g. MPEG audio),
1423 * then it contains one frame.
1425 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1426 * values in AVStream.time_base units (and guessed if the format cannot
1427 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1428 * has B-frames, so it is better to rely on pkt->dts if you do not
1429 * decompress the payload.
1431 * @return 0 if OK, < 0 on error or end of file
1433 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1436 * Seek to the keyframe at timestamp.
1437 * 'timestamp' in 'stream_index'.
1438 * @param stream_index If stream_index is (-1), a default
1439 * stream is selected, and timestamp is automatically converted
1440 * from AV_TIME_BASE units to the stream specific time_base.
1441 * @param timestamp Timestamp in AVStream.time_base units
1442 * or, if no stream is specified, in AV_TIME_BASE units.
1443 * @param flags flags which select direction and seeking mode
1444 * @return >= 0 on success
1446 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1450 * Seek to timestamp ts.
1451 * Seeking will be done so that the point from which all active streams
1452 * can be presented successfully will be closest to ts and within min/max_ts.
1453 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1455 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1456 * are the file position (this may not be supported by all demuxers).
1457 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1458 * in the stream with stream_index (this may not be supported by all demuxers).
1459 * Otherwise all timestamps are in units of the stream selected by stream_index
1460 * or if stream_index is -1, in AV_TIME_BASE units.
1461 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1462 * keyframes (this may not be supported by all demuxers).
1464 * @param stream_index index of the stream which is used as time base reference
1465 * @param min_ts smallest acceptable timestamp
1466 * @param ts target timestamp
1467 * @param max_ts largest acceptable timestamp
1468 * @param flags flags
1469 * @return >=0 on success, error code otherwise
1471 * @note This is part of the new seek API which is still under construction.
1472 * Thus do not use this yet. It may change at any time, do not expect
1473 * ABI compatibility yet!
1475 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1478 * Start playing a network-based stream (e.g. RTSP stream) at the
1481 int av_read_play(AVFormatContext *s);
1484 * Pause a network-based stream (e.g. RTSP stream).
1486 * Use av_read_play() to resume it.
1488 int av_read_pause(AVFormatContext *s);
1491 * Free a AVFormatContext allocated by av_open_input_stream.
1492 * @param s context to free
1494 void av_close_input_stream(AVFormatContext *s);
1497 * Close a media file (but not its codecs).
1499 * @param s media file handle
1501 void av_close_input_file(AVFormatContext *s);
1504 * Free an AVFormatContext and all its streams.
1505 * @param s context to free
1507 void avformat_free_context(AVFormatContext *s);
1509 #if FF_API_NEW_STREAM
1511 * Add a new stream to a media file.
1513 * Can only be called in the read_header() function. If the flag
1514 * AVFMTCTX_NOHEADER is in the format context, then new streams
1515 * can be added in read_packet too.
1517 * @param s media file handle
1518 * @param id file-format-dependent stream ID
1520 attribute_deprecated
1521 AVStream *av_new_stream(AVFormatContext *s, int id);
1525 * Add a new stream to a media file.
1527 * When demuxing, it is called by the demuxer in read_header(). If the
1528 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1529 * be called in read_packet().
1531 * When muxing, should be called by the user before avformat_write_header().
1533 * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1534 * will be initialized to use this codec. This is needed for e.g. codec-specific
1535 * defaults to be set, so codec should be provided if it is known.
1537 * @return newly created stream or NULL on error.
1539 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1541 AVProgram *av_new_program(AVFormatContext *s, int id);
1543 #if FF_API_SET_PTS_INFO
1545 * @deprecated this function is not supposed to be called outside of lavf
1547 attribute_deprecated
1548 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1549 unsigned int pts_num, unsigned int pts_den);
1552 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1553 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
1554 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
1555 #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
1557 int av_find_default_stream_index(AVFormatContext *s);
1560 * Get the index for a specific timestamp.
1561 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1562 * to the timestamp which is <= the requested one, if backward
1563 * is 0, then it will be >=
1564 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1565 * @return < 0 if no such timestamp could be found
1567 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1570 * Add an index entry into a sorted list. Update the entry if the list
1571 * already contains it.
1573 * @param timestamp timestamp in the time base of the given stream
1575 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1576 int size, int distance, int flags);
1578 #if FF_API_SEEK_PUBLIC
1579 attribute_deprecated
1580 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1581 int64_t target_ts, int flags);
1582 attribute_deprecated
1583 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1584 attribute_deprecated
1585 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1586 int64_t target_ts, int64_t pos_min,
1587 int64_t pos_max, int64_t pos_limit,
1588 int64_t ts_min, int64_t ts_max,
1589 int flags, int64_t *ts_ret,
1590 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1596 #if FF_API_FORMAT_PARAMETERS
1598 * @deprecated pass the options to avformat_write_header directly.
1600 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1604 * Split a URL string into components.
1606 * The pointers to buffers for storing individual components may be null,
1607 * in order to ignore that component. Buffers for components not found are
1608 * set to empty strings. If the port is not found, it is set to a negative
1611 * @param proto the buffer for the protocol
1612 * @param proto_size the size of the proto buffer
1613 * @param authorization the buffer for the authorization
1614 * @param authorization_size the size of the authorization buffer
1615 * @param hostname the buffer for the host name
1616 * @param hostname_size the size of the hostname buffer
1617 * @param port_ptr a pointer to store the port number in
1618 * @param path the buffer for the path
1619 * @param path_size the size of the path buffer
1620 * @param url the URL to split
1622 void av_url_split(char *proto, int proto_size,
1623 char *authorization, int authorization_size,
1624 char *hostname, int hostname_size,
1626 char *path, int path_size,
1630 * Allocate the stream private data and write the stream header to
1631 * an output media file.
1633 * @param s Media file handle, must be allocated with avformat_alloc_context().
1634 * Its oformat field must be set to the desired output format;
1635 * Its pb field must be set to an already openened AVIOContext.
1636 * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
1637 * On return this parameter will be destroyed and replaced with a dict containing
1638 * options that were not found. May be NULL.
1640 * @return 0 on success, negative AVERROR on failure.
1642 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1644 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1646 #if FF_API_FORMAT_PARAMETERS
1648 * Allocate the stream private data and write the stream header to an
1649 * output media file.
1650 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1651 * but for some formats it might also be some other time base
1653 * @param s media file handle
1654 * @return 0 if OK, AVERROR_xxx on error
1656 * @deprecated use avformat_write_header.
1658 attribute_deprecated int av_write_header(AVFormatContext *s);
1662 * Write a packet to an output media file.
1664 * The packet shall contain one audio or video frame.
1665 * The packet must be correctly interleaved according to the container
1666 * specification, if not then av_interleaved_write_frame must be used.
1668 * @param s media file handle
1669 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1671 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1673 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1676 * Write a packet to an output media file ensuring correct interleaving.
1678 * The packet must contain one audio or video frame.
1679 * If the packets are already correctly interleaved, the application should
1680 * call av_write_frame() instead as it is slightly faster. It is also important
1681 * to keep in mind that completely non-interleaved input will need huge amounts
1682 * of memory to interleave with this, so it is preferable to interleave at the
1685 * @param s media file handle
1686 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1688 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1690 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1693 * Interleave a packet per dts in an output media file.
1695 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1696 * function, so they cannot be used after it. Note that calling av_free_packet()
1697 * on them is still safe.
1699 * @param s media file handle
1700 * @param out the interleaved packet will be output here
1701 * @param pkt the input packet
1702 * @param flush 1 if no further packets are available as input and all
1703 * remaining packets should be output
1704 * @return 1 if a packet was output, 0 if no packet could be output,
1705 * < 0 if an error occurred
1707 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1708 AVPacket *pkt, int flush);
1711 * Write the stream trailer to an output media file and free the
1712 * file private data.
1714 * May only be called after a successful call to av_write_header.
1716 * @param s media file handle
1717 * @return 0 if OK, AVERROR_xxx on error
1719 int av_write_trailer(AVFormatContext *s);
1721 #if FF_API_DUMP_FORMAT
1722 attribute_deprecated void dump_format(AVFormatContext *ic,
1728 void av_dump_format(AVFormatContext *ic,
1733 #if FF_API_PARSE_DATE
1735 * Parse datestr and return a corresponding number of microseconds.
1737 * @param datestr String representing a date or a duration.
1738 * See av_parse_time() for the syntax of the provided string.
1739 * @deprecated in favor of av_parse_time()
1741 attribute_deprecated
1742 int64_t parse_date(const char *datestr, int duration);
1746 * Get the current time in microseconds.
1748 int64_t av_gettime(void);
1750 #if FF_API_FIND_INFO_TAG
1752 * @deprecated use av_find_info_tag in libavutil instead.
1754 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1758 * Return in 'buf' the path with '%d' replaced by a number.
1760 * Also handles the '%0nd' format where 'n' is the total number
1761 * of digits and '%%'.
1763 * @param buf destination buffer
1764 * @param buf_size destination buffer size
1765 * @param path numbered sequence string
1766 * @param number frame number
1767 * @return 0 if OK, -1 on format error
1769 int av_get_frame_filename(char *buf, int buf_size,
1770 const char *path, int number);
1773 * Check whether filename actually is a numbered sequence generator.
1775 * @param filename possible numbered sequence string
1776 * @return 1 if a valid numbered sequence string, 0 otherwise
1778 int av_filename_number_test(const char *filename);
1781 * Generate an SDP for an RTP session.
1783 * @param ac array of AVFormatContexts describing the RTP streams. If the
1784 * array is composed by only one context, such context can contain
1785 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1786 * all the contexts in the array (an AVCodecContext per RTP stream)
1787 * must contain only one AVStream.
1788 * @param n_files number of AVCodecContexts contained in ac
1789 * @param buf buffer where the SDP will be stored (must be allocated by
1791 * @param size the size of the buffer
1792 * @return 0 if OK, AVERROR_xxx on error
1794 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1796 #if FF_API_SDP_CREATE
1797 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1801 * Return a positive value if the given filename has one of the given
1802 * extensions, 0 otherwise.
1804 * @param extensions a comma-separated list of filename extensions
1806 int av_match_ext(const char *filename, const char *extensions);
1809 * Test if the given container can store a codec.
1811 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1813 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1814 * A negative number if this information is not available.
1816 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1819 * Get the AVClass for AVFormatContext. It can be used in combination with
1820 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1822 * @see av_opt_find().
1824 const AVClass *avformat_get_class(void);
1827 * Do global initialization of network components. This is optional,
1828 * but recommended, since it avoids the overhead of implicitly
1829 * doing the setup for each session.
1831 * Calling this function will become mandatory if using network
1832 * protocols at some major version bump.
1834 int avformat_network_init(void);
1837 * Undo the initialization done by avformat_network_init.
1839 int avformat_network_deinit(void);
1841 #endif /* AVFORMAT_AVFORMAT_H */