yading@11: /* yading@11: * copyright (c) 2001 Fabrice Bellard yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_AVFORMAT_H yading@11: #define AVFORMAT_AVFORMAT_H yading@11: yading@11: /** yading@11: * @file yading@11: * @ingroup libavf yading@11: * Main libavformat public API header yading@11: */ yading@11: yading@11: /** yading@11: * @defgroup libavf I/O and Muxing/Demuxing Library yading@11: * @{ yading@11: * yading@11: * Libavformat (lavf) is a library for dealing with various media container yading@11: * formats. Its main two purposes are demuxing - i.e. splitting a media file yading@11: * into component streams, and the reverse process of muxing - writing supplied yading@11: * data in a specified container format. It also has an @ref lavf_io yading@11: * "I/O module" which supports a number of protocols for accessing the data (e.g. yading@11: * file, tcp, http and others). Before using lavf, you need to call yading@11: * av_register_all() to register all compiled muxers, demuxers and protocols. yading@11: * Unless you are absolutely sure you won't use libavformat's network yading@11: * capabilities, you should also call avformat_network_init(). yading@11: * yading@11: * A supported input format is described by an AVInputFormat struct, conversely yading@11: * an output format is described by AVOutputFormat. You can iterate over all yading@11: * registered input/output formats using the av_iformat_next() / yading@11: * av_oformat_next() functions. The protocols layer is not part of the public yading@11: * API, so you can only get the names of supported protocols with the yading@11: * avio_enum_protocols() function. yading@11: * yading@11: * Main lavf structure used for both muxing and demuxing is AVFormatContext, yading@11: * which exports all information about the file being read or written. As with yading@11: * most Libavformat structures, its size is not part of public ABI, so it cannot be yading@11: * allocated on stack or directly with av_malloc(). To create an yading@11: * AVFormatContext, use avformat_alloc_context() (some functions, like yading@11: * avformat_open_input() might do that for you). yading@11: * yading@11: * Most importantly an AVFormatContext contains: yading@11: * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat yading@11: * "output" format. It is either autodetected or set by user for input; yading@11: * always set by user for output. yading@11: * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all yading@11: * elementary streams stored in the file. AVStreams are typically referred to yading@11: * using their index in this array. yading@11: * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or yading@11: * set by user for input, always set by user for output (unless you are dealing yading@11: * with an AVFMT_NOFILE format). yading@11: * yading@11: * @section lavf_options Passing options to (de)muxers yading@11: * Lavf allows to configure muxers and demuxers using the @ref avoptions yading@11: * mechanism. Generic (format-independent) libavformat options are provided by yading@11: * AVFormatContext, they can be examined from a user program by calling yading@11: * av_opt_next() / av_opt_find() on an allocated AVFormatContext (or its AVClass yading@11: * from avformat_get_class()). Private (format-specific) options are provided by yading@11: * AVFormatContext.priv_data if and only if AVInputFormat.priv_class / yading@11: * AVOutputFormat.priv_class of the corresponding format struct is non-NULL. yading@11: * Further options may be provided by the @ref AVFormatContext.pb "I/O context", yading@11: * if its AVClass is non-NULL, and the protocols layer. See the discussion on yading@11: * nesting in @ref avoptions documentation to learn how to access those. yading@11: * yading@11: * @defgroup lavf_decoding Demuxing yading@11: * @{ yading@11: * Demuxers read a media file and split it into chunks of data (@em packets). A yading@11: * @ref AVPacket "packet" contains one or more encoded frames which belongs to a yading@11: * single elementary stream. In the lavf API this process is represented by the yading@11: * avformat_open_input() function for opening a file, av_read_frame() for yading@11: * reading a single packet and finally avformat_close_input(), which does the yading@11: * cleanup. yading@11: * yading@11: * @section lavf_decoding_open Opening a media file yading@11: * The minimum information required to open a file is its URL or filename, which yading@11: * is passed to avformat_open_input(), as in the following code: yading@11: * @code yading@11: * const char *url = "in.mp3"; yading@11: * AVFormatContext *s = NULL; yading@11: * int ret = avformat_open_input(&s, url, NULL, NULL); yading@11: * if (ret < 0) yading@11: * abort(); yading@11: * @endcode yading@11: * The above code attempts to allocate an AVFormatContext, open the yading@11: * specified file (autodetecting the format) and read the header, exporting the yading@11: * information stored there into s. Some formats do not have a header or do not yading@11: * store enough information there, so it is recommended that you call the yading@11: * avformat_find_stream_info() function which tries to read and decode a few yading@11: * frames to find missing information. yading@11: * yading@11: * In some cases you might want to preallocate an AVFormatContext yourself with yading@11: * avformat_alloc_context() and do some tweaking on it before passing it to yading@11: * avformat_open_input(). One such case is when you want to use custom functions yading@11: * for reading input data instead of lavf internal I/O layer. yading@11: * To do that, create your own AVIOContext with avio_alloc_context(), passing yading@11: * your reading callbacks to it. Then set the @em pb field of your yading@11: * AVFormatContext to newly created AVIOContext. yading@11: * yading@11: * Since the format of the opened file is in general not known until after yading@11: * avformat_open_input() has returned, it is not possible to set demuxer private yading@11: * options on a preallocated context. Instead, the options should be passed to yading@11: * avformat_open_input() wrapped in an AVDictionary: yading@11: * @code yading@11: * AVDictionary *options = NULL; yading@11: * av_dict_set(&options, "video_size", "640x480", 0); yading@11: * av_dict_set(&options, "pixel_format", "rgb24", 0); yading@11: * yading@11: * if (avformat_open_input(&s, url, NULL, &options) < 0) yading@11: * abort(); yading@11: * av_dict_free(&options); yading@11: * @endcode yading@11: * This code passes the private options 'video_size' and 'pixel_format' to the yading@11: * demuxer. They would be necessary for e.g. the rawvideo demuxer, since it yading@11: * cannot know how to interpret raw video data otherwise. If the format turns yading@11: * out to be something different than raw video, those options will not be yading@11: * recognized by the demuxer and therefore will not be applied. Such unrecognized yading@11: * options are then returned in the options dictionary (recognized options are yading@11: * consumed). The calling program can handle such unrecognized options as it yading@11: * wishes, e.g. yading@11: * @code yading@11: * AVDictionaryEntry *e; yading@11: * if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) { yading@11: * fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key); yading@11: * abort(); yading@11: * } yading@11: * @endcode yading@11: * yading@11: * After you have finished reading the file, you must close it with yading@11: * avformat_close_input(). It will free everything associated with the file. yading@11: * yading@11: * @section lavf_decoding_read Reading from an opened file yading@11: * Reading data from an opened AVFormatContext is done by repeatedly calling yading@11: * av_read_frame() on it. Each call, if successful, will return an AVPacket yading@11: * containing encoded data for one AVStream, identified by yading@11: * AVPacket.stream_index. This packet may be passed straight into the libavcodec yading@11: * decoding functions avcodec_decode_video2(), avcodec_decode_audio4() or yading@11: * avcodec_decode_subtitle2() if the caller wishes to decode the data. yading@11: * yading@11: * AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be yading@11: * set if known. They may also be unset (i.e. AV_NOPTS_VALUE for yading@11: * pts/dts, 0 for duration) if the stream does not provide them. The timing yading@11: * information will be in AVStream.time_base units, i.e. it has to be yading@11: * multiplied by the timebase to convert them to seconds. yading@11: * yading@11: * If AVPacket.buf is set on the returned packet, then the packet is yading@11: * allocated dynamically and the user may keep it indefinitely. yading@11: * Otherwise, if AVPacket.buf is NULL, the packet data is backed by a yading@11: * static storage somewhere inside the demuxer and the packet is only valid yading@11: * until the next av_read_frame() call or closing the file. If the caller yading@11: * requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy yading@11: * of it. yading@11: * In both cases, the packet must be freed with av_free_packet() when it is no yading@11: * longer needed. yading@11: * yading@11: * @section lavf_decoding_seek Seeking yading@11: * @} yading@11: * yading@11: * @defgroup lavf_encoding Muxing yading@11: * @{ yading@11: * @} yading@11: * yading@11: * @defgroup lavf_io I/O Read/Write yading@11: * @{ yading@11: * @} yading@11: * yading@11: * @defgroup lavf_codec Demuxers yading@11: * @{ yading@11: * @defgroup lavf_codec_native Native Demuxers yading@11: * @{ yading@11: * @} yading@11: * @defgroup lavf_codec_wrappers External library wrappers yading@11: * @{ yading@11: * @} yading@11: * @} yading@11: * @defgroup lavf_protos I/O Protocols yading@11: * @{ yading@11: * @} yading@11: * @defgroup lavf_internal Internal yading@11: * @{ yading@11: * @} yading@11: * @} yading@11: * yading@11: */ yading@11: yading@11: #include yading@11: #include /* FILE */ yading@11: #include "libavcodec/avcodec.h" yading@11: #include "libavutil/dict.h" yading@11: #include "libavutil/log.h" yading@11: yading@11: #include "avio.h" yading@11: #include "libavformat/version.h" yading@11: yading@11: struct AVFormatContext; yading@11: yading@11: yading@11: /** yading@11: * @defgroup metadata_api Public Metadata API yading@11: * @{ yading@11: * @ingroup libavf yading@11: * The metadata API allows libavformat to export metadata tags to a client yading@11: * application when demuxing. Conversely it allows a client application to yading@11: * set metadata when muxing. yading@11: * yading@11: * Metadata is exported or set as pairs of key/value strings in the 'metadata' yading@11: * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs yading@11: * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg, yading@11: * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata yading@11: * exported by demuxers isn't checked to be valid UTF-8 in most cases. yading@11: * yading@11: * Important concepts to keep in mind: yading@11: * - Keys are unique; there can never be 2 tags with the same key. This is yading@11: * also meant semantically, i.e., a demuxer should not knowingly produce yading@11: * several keys that are literally different but semantically identical. yading@11: * E.g., key=Author5, key=Author6. In this example, all authors must be yading@11: * placed in the same tag. yading@11: * - Metadata is flat, not hierarchical; there are no subtags. If you yading@11: * want to store, e.g., the email address of the child of producer Alice yading@11: * and actor Bob, that could have key=alice_and_bobs_childs_email_address. yading@11: * - Several modifiers can be applied to the tag name. This is done by yading@11: * appending a dash character ('-') and the modifier name in the order yading@11: * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng. yading@11: * - language -- a tag whose value is localized for a particular language yading@11: * is appended with the ISO 639-2/B 3-letter language code. yading@11: * For example: Author-ger=Michael, Author-eng=Mike yading@11: * The original/default language is in the unqualified "Author" tag. yading@11: * A demuxer should set a default if it sets any translated tag. yading@11: * - sorting -- a modified version of a tag that should be used for yading@11: * sorting will have '-sort' appended. E.g. artist="The Beatles", yading@11: * artist-sort="Beatles, The". yading@11: * yading@11: * - Demuxers attempt to export metadata in a generic format, however tags yading@11: * with no generic equivalents are left as they are stored in the container. yading@11: * Follows a list of generic tag names: yading@11: * yading@11: @verbatim yading@11: album -- name of the set this work belongs to yading@11: album_artist -- main creator of the set/album, if different from artist. yading@11: e.g. "Various Artists" for compilation albums. yading@11: artist -- main creator of the work yading@11: comment -- any additional description of the file. yading@11: composer -- who composed the work, if different from artist. yading@11: copyright -- name of copyright holder. yading@11: creation_time-- date when the file was created, preferably in ISO 8601. yading@11: date -- date when the work was created, preferably in ISO 8601. yading@11: disc -- number of a subset, e.g. disc in a multi-disc collection. yading@11: encoder -- name/settings of the software/hardware that produced the file. yading@11: encoded_by -- person/group who created the file. yading@11: filename -- original name of the file. yading@11: genre -- . yading@11: language -- main language in which the work is performed, preferably yading@11: in ISO 639-2 format. Multiple languages can be specified by yading@11: separating them with commas. yading@11: performer -- artist who performed the work, if different from artist. yading@11: E.g for "Also sprach Zarathustra", artist would be "Richard yading@11: Strauss" and performer "London Philharmonic Orchestra". yading@11: publisher -- name of the label/publisher. yading@11: service_name -- name of the service in broadcasting (channel name). yading@11: service_provider -- name of the service provider in broadcasting. yading@11: title -- name of the work. yading@11: track -- number of this work in the set, can be in form current/total. yading@11: variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of yading@11: @endverbatim yading@11: * yading@11: * Look in the examples section for an application example how to use the Metadata API. yading@11: * yading@11: * @} yading@11: */ yading@11: yading@11: /* packet functions */ yading@11: yading@11: yading@11: /** yading@11: * Allocate and read the payload of a packet and initialize its yading@11: * fields with default values. yading@11: * yading@11: * @param pkt packet yading@11: * @param size desired payload size yading@11: * @return >0 (read size) if OK, AVERROR_xxx otherwise yading@11: */ yading@11: int av_get_packet(AVIOContext *s, AVPacket *pkt, int size); yading@11: yading@11: yading@11: /** yading@11: * Read data and append it to the current content of the AVPacket. yading@11: * If pkt->size is 0 this is identical to av_get_packet. yading@11: * Note that this uses av_grow_packet and thus involves a realloc yading@11: * which is inefficient. Thus this function should only be used yading@11: * when there is no reasonable way to know (an upper bound of) yading@11: * the final size. yading@11: * yading@11: * @param pkt packet yading@11: * @param size amount of data to read yading@11: * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data yading@11: * will not be lost even if an error occurs. yading@11: */ yading@11: int av_append_packet(AVIOContext *s, AVPacket *pkt, int size); yading@11: yading@11: /*************************************************/ yading@11: /* fractional numbers for exact pts handling */ yading@11: yading@11: /** yading@11: * The exact value of the fractional number is: 'val + num / den'. yading@11: * num is assumed to be 0 <= num < den. yading@11: */ yading@11: typedef struct AVFrac { yading@11: int64_t val, num, den; yading@11: } AVFrac; yading@11: yading@11: /*************************************************/ yading@11: /* input/output formats */ yading@11: yading@11: struct AVCodecTag; yading@11: yading@11: /** yading@11: * This structure contains the data a format has to probe a file. yading@11: */ yading@11: typedef struct AVProbeData { yading@11: const char *filename; yading@11: unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */ yading@11: int buf_size; /**< Size of buf except extra allocated bytes */ yading@11: } AVProbeData; yading@11: yading@11: #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection yading@11: #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4) yading@11: #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer yading@11: yading@11: /// Demuxer will use avio_open, no opened file should be provided by the caller. yading@11: #define AVFMT_NOFILE 0x0001 yading@11: #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */ yading@11: #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */ yading@11: #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for yading@11: raw picture data. */ yading@11: #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */ yading@11: #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */ yading@11: #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */ yading@11: #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */ yading@11: #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */ yading@11: #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */ yading@11: #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */ yading@11: #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */ yading@11: #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */ yading@11: #define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */ yading@11: #define AVFMT_ALLOW_FLUSH 0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */ yading@11: #if LIBAVFORMAT_VERSION_MAJOR <= 54 yading@11: #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks yading@11: #else yading@11: #define AVFMT_TS_NONSTRICT 0x20000 yading@11: #endif yading@11: /**< Format does not require strictly yading@11: increasing timestamps, but they must yading@11: still be monotonic */ yading@11: yading@11: #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */ yading@11: yading@11: /** yading@11: * @addtogroup lavf_encoding yading@11: * @{ yading@11: */ yading@11: typedef struct AVOutputFormat { yading@11: const char *name; yading@11: /** yading@11: * Descriptive name for the format, meant to be more human-readable yading@11: * than name. You should use the NULL_IF_CONFIG_SMALL() macro yading@11: * to define it. yading@11: */ yading@11: const char *long_name; yading@11: const char *mime_type; yading@11: const char *extensions; /**< comma-separated filename extensions */ yading@11: /* output support */ yading@11: enum AVCodecID audio_codec; /**< default audio codec */ yading@11: enum AVCodecID video_codec; /**< default video codec */ yading@11: enum AVCodecID subtitle_codec; /**< default subtitle codec */ yading@11: /** yading@11: * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, yading@11: * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, yading@11: * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, yading@11: * AVFMT_TS_NONSTRICT yading@11: */ yading@11: int flags; yading@11: yading@11: /** yading@11: * List of supported codec_id-codec_tag pairs, ordered by "better yading@11: * choice first". The arrays are all terminated by AV_CODEC_ID_NONE. yading@11: */ yading@11: const struct AVCodecTag * const *codec_tag; yading@11: yading@11: yading@11: const AVClass *priv_class; ///< AVClass for the private context yading@11: yading@11: /***************************************************************** yading@11: * No fields below this line are part of the public API. They yading@11: * may not be used outside of libavformat and can be changed and yading@11: * removed at will. yading@11: * New public fields should be added right above. yading@11: ***************************************************************** yading@11: */ yading@11: struct AVOutputFormat *next; yading@11: /** yading@11: * size of private data so that it can be allocated in the wrapper yading@11: */ yading@11: int priv_data_size; yading@11: yading@11: int (*write_header)(struct AVFormatContext *); yading@11: /** yading@11: * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags, yading@11: * pkt can be NULL in order to flush data buffered in the muxer. yading@11: * When flushing, return 0 if there still is more data to flush, yading@11: * or 1 if everything was flushed and there is no more buffered yading@11: * data. yading@11: */ yading@11: int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); yading@11: int (*write_trailer)(struct AVFormatContext *); yading@11: /** yading@11: * Currently only used to set pixel format if not YUV420P. yading@11: */ yading@11: int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, yading@11: AVPacket *in, int flush); yading@11: /** yading@11: * Test if the given codec can be stored in this container. yading@11: * yading@11: * @return 1 if the codec is supported, 0 if it is not. yading@11: * A negative number if unknown. yading@11: * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC yading@11: */ yading@11: int (*query_codec)(enum AVCodecID id, int std_compliance); yading@11: yading@11: void (*get_output_timestamp)(struct AVFormatContext *s, int stream, yading@11: int64_t *dts, int64_t *wall); yading@11: } AVOutputFormat; yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: /** yading@11: * @addtogroup lavf_decoding yading@11: * @{ yading@11: */ yading@11: typedef struct AVInputFormat { yading@11: /** yading@11: * A comma separated list of short names for the format. New names yading@11: * may be appended with a minor bump. yading@11: */ yading@11: const char *name; yading@11: yading@11: /** yading@11: * Descriptive name for the format, meant to be more human-readable yading@11: * than name. You should use the NULL_IF_CONFIG_SMALL() macro yading@11: * to define it. yading@11: */ yading@11: const char *long_name; yading@11: yading@11: /** yading@11: * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, yading@11: * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, yading@11: * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS. yading@11: */ yading@11: int flags; yading@11: yading@11: /** yading@11: * If extensions are defined, then no probe is done. You should yading@11: * usually not use extension format guessing because it is not yading@11: * reliable enough yading@11: */ yading@11: const char *extensions; yading@11: yading@11: const struct AVCodecTag * const *codec_tag; yading@11: yading@11: const AVClass *priv_class; ///< AVClass for the private context yading@11: yading@11: /***************************************************************** yading@11: * No fields below this line are part of the public API. They yading@11: * may not be used outside of libavformat and can be changed and yading@11: * removed at will. yading@11: * New public fields should be added right above. yading@11: ***************************************************************** yading@11: */ yading@11: struct AVInputFormat *next; yading@11: yading@11: /** yading@11: * Raw demuxers store their codec ID here. yading@11: */ yading@11: int raw_codec_id; yading@11: yading@11: /** yading@11: * Size of private data so that it can be allocated in the wrapper. yading@11: */ yading@11: int priv_data_size; yading@11: yading@11: /** yading@11: * Tell if a given file has a chance of being parsed as this format. yading@11: * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes yading@11: * big so you do not have to check for that unless you need more. yading@11: */ yading@11: int (*read_probe)(AVProbeData *); yading@11: yading@11: /** yading@11: * Read the format header and initialize the AVFormatContext yading@11: * structure. Return 0 if OK. Only used in raw format right yading@11: * now. 'avformat_new_stream' should be called to create new streams. yading@11: */ yading@11: int (*read_header)(struct AVFormatContext *); yading@11: yading@11: /** yading@11: * Read one packet and put it in 'pkt'. pts and flags are also yading@11: * set. 'avformat_new_stream' can be called only if the flag yading@11: * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a yading@11: * background thread). yading@11: * @return 0 on success, < 0 on error. yading@11: * When returning an error, pkt must not have been allocated yading@11: * or must be freed before returning yading@11: */ yading@11: int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Close the stream. The AVFormatContext and AVStreams are not yading@11: * freed by this function yading@11: */ yading@11: int (*read_close)(struct AVFormatContext *); yading@11: yading@11: /** yading@11: * Seek to a given timestamp relative to the frames in yading@11: * stream component stream_index. yading@11: * @param stream_index Must not be -1. yading@11: * @param flags Selects which direction should be preferred if no exact yading@11: * match is available. yading@11: * @return >= 0 on success (but not necessarily the new offset) yading@11: */ yading@11: int (*read_seek)(struct AVFormatContext *, yading@11: int stream_index, int64_t timestamp, int flags); yading@11: yading@11: /** yading@11: * Get the next timestamp in stream[stream_index].time_base units. yading@11: * @return the timestamp or AV_NOPTS_VALUE if an error occurred yading@11: */ yading@11: int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, yading@11: int64_t *pos, int64_t pos_limit); yading@11: yading@11: /** yading@11: * Start/resume playing - only meaningful if using a network-based format yading@11: * (RTSP). yading@11: */ yading@11: int (*read_play)(struct AVFormatContext *); yading@11: yading@11: /** yading@11: * Pause playing - only meaningful if using a network-based format yading@11: * (RTSP). yading@11: */ yading@11: int (*read_pause)(struct AVFormatContext *); yading@11: yading@11: /** yading@11: * Seek to timestamp ts. yading@11: * Seeking will be done so that the point from which all active streams yading@11: * can be presented successfully will be closest to ts and within min/max_ts. yading@11: * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. yading@11: */ yading@11: int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); yading@11: } AVInputFormat; yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: enum AVStreamParseType { yading@11: AVSTREAM_PARSE_NONE, yading@11: AVSTREAM_PARSE_FULL, /**< full parsing and repack */ yading@11: AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */ yading@11: AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */ yading@11: AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */ yading@11: AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'), /**< full parsing and repack with timestamp and position generation by parser for raw yading@11: this assumes that each packet in the file contains no demuxer level headers and yading@11: just codec level data, otherwise position generation would fail */ yading@11: }; yading@11: yading@11: typedef struct AVIndexEntry { yading@11: int64_t pos; yading@11: int64_t timestamp; /**< yading@11: * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available yading@11: * when seeking to this entry. That means preferable PTS on keyframe based formats. yading@11: * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better yading@11: * is known yading@11: */ yading@11: #define AVINDEX_KEYFRAME 0x0001 yading@11: int flags:2; yading@11: 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). yading@11: int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */ yading@11: } AVIndexEntry; yading@11: yading@11: #define AV_DISPOSITION_DEFAULT 0x0001 yading@11: #define AV_DISPOSITION_DUB 0x0002 yading@11: #define AV_DISPOSITION_ORIGINAL 0x0004 yading@11: #define AV_DISPOSITION_COMMENT 0x0008 yading@11: #define AV_DISPOSITION_LYRICS 0x0010 yading@11: #define AV_DISPOSITION_KARAOKE 0x0020 yading@11: yading@11: /** yading@11: * Track should be used during playback by default. yading@11: * Useful for subtitle track that should be displayed yading@11: * even when user did not explicitly ask for subtitles. yading@11: */ yading@11: #define AV_DISPOSITION_FORCED 0x0040 yading@11: #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */ yading@11: #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */ yading@11: #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */ yading@11: /** yading@11: * The stream is stored in the file as an attached picture/"cover art" (e.g. yading@11: * APIC frame in ID3v2). The single packet associated with it will be returned yading@11: * among the first few packets read from the file unless seeking takes place. yading@11: * It can also be accessed at any time in AVStream.attached_pic. yading@11: */ yading@11: #define AV_DISPOSITION_ATTACHED_PIC 0x0400 yading@11: yading@11: /** yading@11: * Options for behavior on timestamp wrap detection. yading@11: */ yading@11: #define AV_PTS_WRAP_IGNORE 0 ///< ignore the wrap yading@11: #define AV_PTS_WRAP_ADD_OFFSET 1 ///< add the format specific offset on wrap detection yading@11: #define AV_PTS_WRAP_SUB_OFFSET -1 ///< subtract the format specific offset on wrap detection yading@11: yading@11: /** yading@11: * Stream structure. yading@11: * New fields can be added to the end with minor version bumps. yading@11: * Removal, reordering and changes to existing fields require a major yading@11: * version bump. yading@11: * sizeof(AVStream) must not be used outside libav*. yading@11: */ yading@11: typedef struct AVStream { yading@11: int index; /**< stream index in AVFormatContext */ yading@11: /** yading@11: * Format-specific stream ID. yading@11: * decoding: set by libavformat yading@11: * encoding: set by the user, replaced by libavformat if left unset yading@11: */ yading@11: int id; yading@11: /** yading@11: * Codec context associated with this stream. Allocated and freed by yading@11: * libavformat. yading@11: * yading@11: * - decoding: The demuxer exports codec information stored in the headers yading@11: * here. yading@11: * - encoding: The user sets codec information, the muxer writes it to the yading@11: * output. Mandatory fields as specified in AVCodecContext yading@11: * documentation must be set even if this AVCodecContext is yading@11: * not actually used for encoding. yading@11: */ yading@11: AVCodecContext *codec; yading@11: void *priv_data; yading@11: yading@11: /** yading@11: * encoding: pts generation when outputting stream yading@11: */ yading@11: struct AVFrac pts; yading@11: yading@11: /** yading@11: * This is the fundamental unit of time (in seconds) in terms yading@11: * of which frame timestamps are represented. yading@11: * yading@11: * decoding: set by libavformat yading@11: * encoding: set by libavformat in avformat_write_header. The muxer may use the yading@11: * user-provided value of @ref AVCodecContext.time_base "codec->time_base" yading@11: * as a hint. yading@11: */ yading@11: AVRational time_base; yading@11: yading@11: /** yading@11: * Decoding: pts of the first frame of the stream in presentation order, in stream time base. yading@11: * Only set this if you are absolutely 100% sure that the value you set yading@11: * it to really is the pts of the first frame. yading@11: * This may be undefined (AV_NOPTS_VALUE). yading@11: * @note The ASF header does NOT contain a correct start_time the ASF yading@11: * demuxer must NOT set this. yading@11: */ yading@11: int64_t start_time; yading@11: yading@11: /** yading@11: * Decoding: duration of the stream, in stream time base. yading@11: * If a source file does not specify a duration, but does specify yading@11: * a bitrate, this value will be estimated from bitrate and file size. yading@11: */ yading@11: int64_t duration; yading@11: yading@11: int64_t nb_frames; ///< number of frames in this stream if known or 0 yading@11: yading@11: int disposition; /**< AV_DISPOSITION_* bit field */ yading@11: yading@11: enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed. yading@11: yading@11: /** yading@11: * sample aspect ratio (0 if unknown) yading@11: * - encoding: Set by user. yading@11: * - decoding: Set by libavformat. yading@11: */ yading@11: AVRational sample_aspect_ratio; yading@11: yading@11: AVDictionary *metadata; yading@11: yading@11: /** yading@11: * Average framerate yading@11: */ yading@11: AVRational avg_frame_rate; yading@11: yading@11: /** yading@11: * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet yading@11: * will contain the attached picture. yading@11: * yading@11: * decoding: set by libavformat, must not be modified by the caller. yading@11: * encoding: unused yading@11: */ yading@11: AVPacket attached_pic; yading@11: yading@11: /** yading@11: * Real base framerate of the stream. yading@11: * This is the lowest framerate with which all timestamps can be yading@11: * represented accurately (it is the least common multiple of all yading@11: * framerates in the stream). Note, this value is just a guess! yading@11: * For example, if the time base is 1/90000 and all frames have either yading@11: * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1. yading@11: * yading@11: * Code outside avformat should access this field using: yading@11: * av_stream_get/set_r_frame_rate(stream) yading@11: */ yading@11: AVRational r_frame_rate; yading@11: yading@11: /***************************************************************** yading@11: * All fields below this line are not part of the public API. They yading@11: * may not be used outside of libavformat and can be changed and yading@11: * removed at will. yading@11: * New public fields should be added right above. yading@11: ***************************************************************** yading@11: */ yading@11: yading@11: /** yading@11: * Stream information used internally by av_find_stream_info() yading@11: */ yading@11: #define MAX_STD_TIMEBASES (60*12+6) yading@11: struct { yading@11: int64_t last_dts; yading@11: int64_t duration_gcd; yading@11: int duration_count; yading@11: double (*duration_error)[2][MAX_STD_TIMEBASES]; yading@11: int64_t codec_info_duration; yading@11: int64_t codec_info_duration_fields; yading@11: int found_decoder; yading@11: yading@11: int64_t last_duration; yading@11: yading@11: /** yading@11: * Those are used for average framerate estimation. yading@11: */ yading@11: int64_t fps_first_dts; yading@11: int fps_first_dts_idx; yading@11: int64_t fps_last_dts; yading@11: int fps_last_dts_idx; yading@11: yading@11: } *info; yading@11: yading@11: int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ yading@11: yading@11: // Timestamp generation support: yading@11: /** yading@11: * Timestamp corresponding to the last dts sync point. yading@11: * yading@11: * Initialized when AVCodecParserContext.dts_sync_point >= 0 and yading@11: * a DTS is received from the underlying container. Otherwise set to yading@11: * AV_NOPTS_VALUE by default. yading@11: */ yading@11: int64_t reference_dts; yading@11: int64_t first_dts; yading@11: int64_t cur_dts; yading@11: int64_t last_IP_pts; yading@11: int last_IP_duration; yading@11: yading@11: /** yading@11: * Number of packets to buffer for codec probing yading@11: */ yading@11: #define MAX_PROBE_PACKETS 2500 yading@11: int probe_packets; yading@11: yading@11: /** yading@11: * Number of frames that have been demuxed during av_find_stream_info() yading@11: */ yading@11: int codec_info_nb_frames; yading@11: yading@11: /** yading@11: * Stream Identifier yading@11: * This is the MPEG-TS stream identifier +1 yading@11: * 0 means unknown yading@11: */ yading@11: int stream_identifier; yading@11: yading@11: int64_t interleaver_chunk_size; yading@11: int64_t interleaver_chunk_duration; yading@11: yading@11: /* av_read_frame() support */ yading@11: enum AVStreamParseType need_parsing; yading@11: struct AVCodecParserContext *parser; yading@11: yading@11: /** yading@11: * last packet in packet_buffer for this stream when muxing. yading@11: */ yading@11: struct AVPacketList *last_in_packet_buffer; yading@11: AVProbeData probe_data; yading@11: #define MAX_REORDER_DELAY 16 yading@11: int64_t pts_buffer[MAX_REORDER_DELAY+1]; yading@11: yading@11: AVIndexEntry *index_entries; /**< Only used if the format does not yading@11: support seeking natively. */ yading@11: int nb_index_entries; yading@11: unsigned int index_entries_allocated_size; yading@11: yading@11: /** yading@11: * stream probing state yading@11: * -1 -> probing finished yading@11: * 0 -> no probing requested yading@11: * rest -> perform probing with request_probe being the minimum score to accept. yading@11: * NOT PART OF PUBLIC API yading@11: */ yading@11: int request_probe; yading@11: /** yading@11: * Indicates that everything up to the next keyframe yading@11: * should be discarded. yading@11: */ yading@11: int skip_to_keyframe; yading@11: yading@11: /** yading@11: * Number of samples to skip at the start of the frame decoded from the next packet. yading@11: */ yading@11: int skip_samples; yading@11: yading@11: /** yading@11: * Number of internally decoded frames, used internally in libavformat, do not access yading@11: * its lifetime differs from info which is why it is not in that structure. yading@11: */ yading@11: int nb_decoded_frames; yading@11: yading@11: /** yading@11: * Timestamp offset added to timestamps before muxing yading@11: * NOT PART OF PUBLIC API yading@11: */ yading@11: int64_t mux_ts_offset; yading@11: yading@11: /** yading@11: * Internal data to check for wrapping of the time stamp yading@11: */ yading@11: int64_t pts_wrap_reference; yading@11: yading@11: /** yading@11: * Options for behavior, when a wrap is detected. yading@11: * yading@11: * Defined by AV_PTS_WRAP_ values. yading@11: * yading@11: * If correction is enabled, there are two possibilities: yading@11: * If the first time stamp is near the wrap point, the wrap offset yading@11: * will be subtracted, which will create negative time stamps. yading@11: * Otherwise the offset will be added. yading@11: */ yading@11: int pts_wrap_behavior; yading@11: yading@11: } AVStream; yading@11: yading@11: AVRational av_stream_get_r_frame_rate(const AVStream *s); yading@11: void av_stream_set_r_frame_rate(AVStream *s, AVRational r); yading@11: yading@11: #define AV_PROGRAM_RUNNING 1 yading@11: yading@11: /** yading@11: * New fields can be added to the end with minor version bumps. yading@11: * Removal, reordering and changes to existing fields require a major yading@11: * version bump. yading@11: * sizeof(AVProgram) must not be used outside libav*. yading@11: */ yading@11: typedef struct AVProgram { yading@11: int id; yading@11: int flags; yading@11: enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller yading@11: unsigned int *stream_index; yading@11: unsigned int nb_stream_indexes; yading@11: AVDictionary *metadata; yading@11: yading@11: int program_num; yading@11: int pmt_pid; yading@11: int pcr_pid; yading@11: yading@11: /***************************************************************** yading@11: * All fields below this line are not part of the public API. They yading@11: * may not be used outside of libavformat and can be changed and yading@11: * removed at will. yading@11: * New public fields should be added right above. yading@11: ***************************************************************** yading@11: */ yading@11: int64_t start_time; yading@11: int64_t end_time; yading@11: yading@11: int64_t pts_wrap_reference; ///< reference dts for wrap detection yading@11: int pts_wrap_behavior; ///< behavior on wrap detection yading@11: } AVProgram; yading@11: yading@11: #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present yading@11: (streams are added dynamically) */ yading@11: yading@11: typedef struct AVChapter { yading@11: int id; ///< unique ID to identify the chapter yading@11: AVRational time_base; ///< time base in which the start/end timestamps are specified yading@11: int64_t start, end; ///< chapter start/end time in time_base units yading@11: AVDictionary *metadata; yading@11: } AVChapter; yading@11: yading@11: yading@11: /** yading@11: * The duration of a video can be estimated through various ways, and this enum can be used yading@11: * to know how the duration was estimated. yading@11: */ yading@11: enum AVDurationEstimationMethod { yading@11: AVFMT_DURATION_FROM_PTS, ///< Duration accurately estimated from PTSes yading@11: AVFMT_DURATION_FROM_STREAM, ///< Duration estimated from a stream with a known duration yading@11: AVFMT_DURATION_FROM_BITRATE ///< Duration estimated from bitrate (less accurate) yading@11: }; yading@11: yading@11: /** yading@11: * Format I/O context. yading@11: * New fields can be added to the end with minor version bumps. yading@11: * Removal, reordering and changes to existing fields require a major yading@11: * version bump. yading@11: * sizeof(AVFormatContext) must not be used outside libav*, use yading@11: * avformat_alloc_context() to create an AVFormatContext. yading@11: */ yading@11: typedef struct AVFormatContext { yading@11: /** yading@11: * A class for logging and AVOptions. Set by avformat_alloc_context(). yading@11: * Exports (de)muxer private options if they exist. yading@11: */ yading@11: const AVClass *av_class; yading@11: yading@11: /** yading@11: * Can only be iformat or oformat, not both at the same time. yading@11: * yading@11: * decoding: set by avformat_open_input(). yading@11: * encoding: set by the user. yading@11: */ yading@11: struct AVInputFormat *iformat; yading@11: struct AVOutputFormat *oformat; yading@11: yading@11: /** yading@11: * Format private data. This is an AVOptions-enabled struct yading@11: * if and only if iformat/oformat.priv_class is not NULL. yading@11: */ yading@11: void *priv_data; yading@11: yading@11: /** yading@11: * I/O context. yading@11: * yading@11: * decoding: either set by the user before avformat_open_input() (then yading@11: * the user must close it manually) or set by avformat_open_input(). yading@11: * encoding: set by the user. yading@11: * yading@11: * Do NOT set this field if AVFMT_NOFILE flag is set in yading@11: * iformat/oformat.flags. In such a case, the (de)muxer will handle yading@11: * I/O in some other way and this field will be NULL. yading@11: */ yading@11: AVIOContext *pb; yading@11: yading@11: /* stream info */ yading@11: int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */ yading@11: yading@11: /** yading@11: * A list of all streams in the file. New streams are created with yading@11: * avformat_new_stream(). yading@11: * yading@11: * decoding: streams are created by libavformat in avformat_open_input(). yading@11: * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also yading@11: * appear in av_read_frame(). yading@11: * encoding: streams are created by the user before avformat_write_header(). yading@11: */ yading@11: unsigned int nb_streams; yading@11: AVStream **streams; yading@11: yading@11: char filename[1024]; /**< input or output filename */ yading@11: yading@11: /** yading@11: * Decoding: position of the first frame of the component, in yading@11: * AV_TIME_BASE fractional seconds. NEVER set this value directly: yading@11: * It is deduced from the AVStream values. yading@11: */ yading@11: int64_t start_time; yading@11: yading@11: /** yading@11: * Decoding: duration of the stream, in AV_TIME_BASE fractional yading@11: * seconds. Only set this value if you know none of the individual stream yading@11: * durations and also do not set any of them. This is deduced from the yading@11: * AVStream values if not set. yading@11: */ yading@11: int64_t duration; yading@11: yading@11: /** yading@11: * Decoding: total stream bitrate in bit/s, 0 if not yading@11: * available. Never set it directly if the file_size and the yading@11: * duration are known as FFmpeg can compute it automatically. yading@11: */ yading@11: int bit_rate; yading@11: yading@11: unsigned int packet_size; yading@11: int max_delay; yading@11: yading@11: int flags; yading@11: #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames. yading@11: #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index. yading@11: #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input. yading@11: #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS yading@11: #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container yading@11: #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 yading@11: #define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible yading@11: #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it. yading@11: #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted yading@11: #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload yading@11: #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down) yading@11: #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) yading@11: #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Don't merge side data but keep it separate. yading@11: yading@11: /** yading@11: * decoding: size of data to probe; encoding: unused. yading@11: */ yading@11: unsigned int probesize; yading@11: yading@11: /** yading@11: * decoding: maximum time (in AV_TIME_BASE units) during which the input should yading@11: * be analyzed in avformat_find_stream_info(). yading@11: */ yading@11: int max_analyze_duration; yading@11: yading@11: const uint8_t *key; yading@11: int keylen; yading@11: yading@11: unsigned int nb_programs; yading@11: AVProgram **programs; yading@11: yading@11: /** yading@11: * Forced video codec_id. yading@11: * Demuxing: Set by user. yading@11: */ yading@11: enum AVCodecID video_codec_id; yading@11: yading@11: /** yading@11: * Forced audio codec_id. yading@11: * Demuxing: Set by user. yading@11: */ yading@11: enum AVCodecID audio_codec_id; yading@11: yading@11: /** yading@11: * Forced subtitle codec_id. yading@11: * Demuxing: Set by user. yading@11: */ yading@11: enum AVCodecID subtitle_codec_id; yading@11: yading@11: /** yading@11: * Maximum amount of memory in bytes to use for the index of each stream. yading@11: * If the index exceeds this size, entries will be discarded as yading@11: * needed to maintain a smaller size. This can lead to slower or less yading@11: * accurate seeking (depends on demuxer). yading@11: * Demuxers for which a full in-memory index is mandatory will ignore yading@11: * this. yading@11: * muxing : unused yading@11: * demuxing: set by user yading@11: */ yading@11: unsigned int max_index_size; yading@11: yading@11: /** yading@11: * Maximum amount of memory in bytes to use for buffering frames yading@11: * obtained from realtime capture devices. yading@11: */ yading@11: unsigned int max_picture_buffer; yading@11: yading@11: unsigned int nb_chapters; yading@11: AVChapter **chapters; yading@11: yading@11: AVDictionary *metadata; yading@11: yading@11: /** yading@11: * Start time of the stream in real world time, in microseconds yading@11: * since the unix epoch (00:00 1st January 1970). That is, pts=0 yading@11: * in the stream was captured at this real world time. yading@11: * - encoding: Set by user. yading@11: * - decoding: Unused. yading@11: */ yading@11: int64_t start_time_realtime; yading@11: yading@11: /** yading@11: * decoding: number of frames used to probe fps yading@11: */ yading@11: int fps_probe_size; yading@11: yading@11: /** yading@11: * Error recognition; higher values will detect more errors but may yading@11: * misdetect some more or less valid parts as errors. yading@11: * - encoding: unused yading@11: * - decoding: Set by user. yading@11: */ yading@11: int error_recognition; yading@11: yading@11: /** yading@11: * Custom interrupt callbacks for the I/O layer. yading@11: * yading@11: * decoding: set by the user before avformat_open_input(). yading@11: * encoding: set by the user before avformat_write_header() yading@11: * (mainly useful for AVFMT_NOFILE formats). The callback yading@11: * should also be passed to avio_open2() if it's used to yading@11: * open the file. yading@11: */ yading@11: AVIOInterruptCB interrupt_callback; yading@11: yading@11: /** yading@11: * Flags to enable debugging. yading@11: */ yading@11: int debug; yading@11: #define FF_FDEBUG_TS 0x0001 yading@11: yading@11: /** yading@11: * Transport stream id. yading@11: * This will be moved into demuxer private options. Thus no API/ABI compatibility yading@11: */ yading@11: int ts_id; yading@11: yading@11: /** yading@11: * Audio preload in microseconds. yading@11: * Note, not all formats support this and unpredictable things may happen if it is used when not supported. yading@11: * - encoding: Set by user via AVOptions (NO direct access) yading@11: * - decoding: unused yading@11: */ yading@11: int audio_preload; yading@11: yading@11: /** yading@11: * Max chunk time in microseconds. yading@11: * Note, not all formats support this and unpredictable things may happen if it is used when not supported. yading@11: * - encoding: Set by user via AVOptions (NO direct access) yading@11: * - decoding: unused yading@11: */ yading@11: int max_chunk_duration; yading@11: yading@11: /** yading@11: * Max chunk size in bytes yading@11: * Note, not all formats support this and unpredictable things may happen if it is used when not supported. yading@11: * - encoding: Set by user via AVOptions (NO direct access) yading@11: * - decoding: unused yading@11: */ yading@11: int max_chunk_size; yading@11: yading@11: /** yading@11: * forces the use of wallclock timestamps as pts/dts of packets yading@11: * This has undefined results in the presence of B frames. yading@11: * - encoding: unused yading@11: * - decoding: Set by user via AVOptions (NO direct access) yading@11: */ yading@11: int use_wallclock_as_timestamps; yading@11: yading@11: /** yading@11: * Avoid negative timestamps during muxing. yading@11: * 0 -> allow negative timestamps yading@11: * 1 -> avoid negative timestamps yading@11: * -1 -> choose automatically (default) yading@11: * Note, this only works when interleave_packet_per_dts is in use. yading@11: * - encoding: Set by user via AVOptions (NO direct access) yading@11: * - decoding: unused yading@11: */ yading@11: int avoid_negative_ts; yading@11: yading@11: /** yading@11: * avio flags, used to force AVIO_FLAG_DIRECT. yading@11: * - encoding: unused yading@11: * - decoding: Set by user via AVOptions (NO direct access) yading@11: */ yading@11: int avio_flags; yading@11: yading@11: /** yading@11: * The duration field can be estimated through various ways, and this field can be used yading@11: * to know how the duration was estimated. yading@11: * - encoding: unused yading@11: * - decoding: Read by user via AVOptions (NO direct access) yading@11: */ yading@11: enum AVDurationEstimationMethod duration_estimation_method; yading@11: yading@11: /** yading@11: * Skip initial bytes when opening stream yading@11: * - encoding: unused yading@11: * - decoding: Set by user via AVOptions (NO direct access) yading@11: */ yading@11: unsigned int skip_initial_bytes; yading@11: yading@11: /** yading@11: * Correct single timestamp overflows yading@11: * - encoding: unused yading@11: * - decoding: Set by user via AVOPtions (NO direct access) yading@11: */ yading@11: unsigned int correct_ts_overflow; yading@11: yading@11: /** yading@11: * Force seeking to any (also non key) frames. yading@11: * - encoding: unused yading@11: * - decoding: Set by user via AVOPtions (NO direct access) yading@11: */ yading@11: int seek2any; yading@11: yading@11: /** yading@11: * Flush the I/O context after each packet. yading@11: * - encoding: Set by user via AVOptions (NO direct access) yading@11: * - decoding: unused yading@11: */ yading@11: int flush_packets; yading@11: yading@11: /***************************************************************** yading@11: * All fields below this line are not part of the public API. They yading@11: * may not be used outside of libavformat and can be changed and yading@11: * removed at will. yading@11: * New public fields should be added right above. yading@11: ***************************************************************** yading@11: */ yading@11: yading@11: /** yading@11: * This buffer is only needed when packets were already buffered but yading@11: * not decoded, for example to get the codec parameters in MPEG yading@11: * streams. yading@11: */ yading@11: struct AVPacketList *packet_buffer; yading@11: struct AVPacketList *packet_buffer_end; yading@11: yading@11: /* av_seek_frame() support */ yading@11: int64_t data_offset; /**< offset of the first packet */ yading@11: yading@11: /** yading@11: * Raw packets from the demuxer, prior to parsing and decoding. yading@11: * This buffer is used for buffering packets until the codec can yading@11: * be identified, as parsing cannot be done without knowing the yading@11: * codec. yading@11: */ yading@11: struct AVPacketList *raw_packet_buffer; yading@11: struct AVPacketList *raw_packet_buffer_end; yading@11: /** yading@11: * Packets split by the parser get queued here. yading@11: */ yading@11: struct AVPacketList *parse_queue; yading@11: struct AVPacketList *parse_queue_end; yading@11: /** yading@11: * Remaining size available for raw_packet_buffer, in bytes. yading@11: */ yading@11: #define RAW_PACKET_BUFFER_SIZE 2500000 yading@11: int raw_packet_buffer_remaining_size; yading@11: yading@11: /** yading@11: * IO repositioned flag. yading@11: * This is set by avformat when the underlaying IO context read pointer yading@11: * is repositioned, for example when doing byte based seeking. yading@11: * Demuxers can use the flag to detect such changes. yading@11: */ yading@11: int io_repositioned; yading@11: } AVFormatContext; yading@11: yading@11: /** yading@11: * Returns the method used to set ctx->duration. yading@11: * yading@11: * @return AVFMT_DURATION_FROM_PTS, AVFMT_DURATION_FROM_STREAM, or AVFMT_DURATION_FROM_BITRATE. yading@11: */ yading@11: enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx); yading@11: yading@11: typedef struct AVPacketList { yading@11: AVPacket pkt; yading@11: struct AVPacketList *next; yading@11: } AVPacketList; yading@11: yading@11: yading@11: /** yading@11: * @defgroup lavf_core Core functions yading@11: * @ingroup libavf yading@11: * yading@11: * Functions for querying libavformat capabilities, allocating core structures, yading@11: * etc. yading@11: * @{ yading@11: */ yading@11: yading@11: /** yading@11: * Return the LIBAVFORMAT_VERSION_INT constant. yading@11: */ yading@11: unsigned avformat_version(void); yading@11: yading@11: /** yading@11: * Return the libavformat build-time configuration. yading@11: */ yading@11: const char *avformat_configuration(void); yading@11: yading@11: /** yading@11: * Return the libavformat license. yading@11: */ yading@11: const char *avformat_license(void); yading@11: yading@11: /** yading@11: * Initialize libavformat and register all the muxers, demuxers and yading@11: * protocols. If you do not call this function, then you can select yading@11: * exactly which formats you want to support. yading@11: * yading@11: * @see av_register_input_format() yading@11: * @see av_register_output_format() yading@11: */ yading@11: void av_register_all(void); yading@11: yading@11: void av_register_input_format(AVInputFormat *format); yading@11: void av_register_output_format(AVOutputFormat *format); yading@11: yading@11: /** yading@11: * Do global initialization of network components. This is optional, yading@11: * but recommended, since it avoids the overhead of implicitly yading@11: * doing the setup for each session. yading@11: * yading@11: * Calling this function will become mandatory if using network yading@11: * protocols at some major version bump. yading@11: */ yading@11: int avformat_network_init(void); yading@11: yading@11: /** yading@11: * Undo the initialization done by avformat_network_init. yading@11: */ yading@11: int avformat_network_deinit(void); yading@11: yading@11: /** yading@11: * If f is NULL, returns the first registered input format, yading@11: * if f is non-NULL, returns the next registered input format after f yading@11: * or NULL if f is the last one. yading@11: */ yading@11: AVInputFormat *av_iformat_next(AVInputFormat *f); yading@11: yading@11: /** yading@11: * If f is NULL, returns the first registered output format, yading@11: * if f is non-NULL, returns the next registered output format after f yading@11: * or NULL if f is the last one. yading@11: */ yading@11: AVOutputFormat *av_oformat_next(AVOutputFormat *f); yading@11: yading@11: /** yading@11: * Allocate an AVFormatContext. yading@11: * avformat_free_context() can be used to free the context and everything yading@11: * allocated by the framework within it. yading@11: */ yading@11: AVFormatContext *avformat_alloc_context(void); yading@11: yading@11: /** yading@11: * Free an AVFormatContext and all its streams. yading@11: * @param s context to free yading@11: */ yading@11: void avformat_free_context(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Get the AVClass for AVFormatContext. It can be used in combination with yading@11: * AV_OPT_SEARCH_FAKE_OBJ for examining options. yading@11: * yading@11: * @see av_opt_find(). yading@11: */ yading@11: const AVClass *avformat_get_class(void); yading@11: yading@11: /** yading@11: * Add a new stream to a media file. yading@11: * yading@11: * When demuxing, it is called by the demuxer in read_header(). If the yading@11: * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also yading@11: * be called in read_packet(). yading@11: * yading@11: * When muxing, should be called by the user before avformat_write_header(). yading@11: * yading@11: * @param c If non-NULL, the AVCodecContext corresponding to the new stream yading@11: * will be initialized to use this codec. This is needed for e.g. codec-specific yading@11: * defaults to be set, so codec should be provided if it is known. yading@11: * yading@11: * @return newly created stream or NULL on error. yading@11: */ yading@11: AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c); yading@11: yading@11: AVProgram *av_new_program(AVFormatContext *s, int id); yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: yading@11: #if FF_API_PKT_DUMP yading@11: attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); yading@11: attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, yading@11: int dump_payload); yading@11: #endif yading@11: yading@11: #if FF_API_ALLOC_OUTPUT_CONTEXT yading@11: /** yading@11: * @deprecated deprecated in favor of avformat_alloc_output_context2() yading@11: */ yading@11: attribute_deprecated yading@11: AVFormatContext *avformat_alloc_output_context(const char *format, yading@11: AVOutputFormat *oformat, yading@11: const char *filename); yading@11: #endif yading@11: yading@11: /** yading@11: * Allocate an AVFormatContext for an output format. yading@11: * avformat_free_context() can be used to free the context and yading@11: * everything allocated by the framework within it. yading@11: * yading@11: * @param *ctx is set to the created format context, or to NULL in yading@11: * case of failure yading@11: * @param oformat format to use for allocating the context, if NULL yading@11: * format_name and filename are used instead yading@11: * @param format_name the name of output format to use for allocating the yading@11: * context, if NULL filename is used instead yading@11: * @param filename the name of the filename to use for allocating the yading@11: * context, may be NULL yading@11: * @return >= 0 in case of success, a negative AVERROR code in case of yading@11: * failure yading@11: */ yading@11: int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, yading@11: const char *format_name, const char *filename); yading@11: yading@11: /** yading@11: * @addtogroup lavf_decoding yading@11: * @{ yading@11: */ yading@11: yading@11: /** yading@11: * Find AVInputFormat based on the short name of the input format. yading@11: */ yading@11: AVInputFormat *av_find_input_format(const char *short_name); yading@11: yading@11: /** yading@11: * Guess the file format. yading@11: * yading@11: * @param is_opened Whether the file is already opened; determines whether yading@11: * demuxers with or without AVFMT_NOFILE are probed. yading@11: */ yading@11: AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened); yading@11: yading@11: /** yading@11: * Guess the file format. yading@11: * yading@11: * @param is_opened Whether the file is already opened; determines whether yading@11: * demuxers with or without AVFMT_NOFILE are probed. yading@11: * @param score_max A probe score larger that this is required to accept a yading@11: * detection, the variable is set to the actual detection yading@11: * score afterwards. yading@11: * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended yading@11: * to retry with a larger probe buffer. yading@11: */ yading@11: AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max); yading@11: yading@11: /** yading@11: * Guess the file format. yading@11: * yading@11: * @param is_opened Whether the file is already opened; determines whether yading@11: * demuxers with or without AVFMT_NOFILE are probed. yading@11: * @param score_ret The score of the best detection. yading@11: */ yading@11: AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret); yading@11: yading@11: /** yading@11: * Probe a bytestream to determine the input format. Each time a probe returns yading@11: * with a score that is too low, the probe buffer size is increased and another yading@11: * attempt is made. When the maximum probe size is reached, the input format yading@11: * with the highest score is returned. yading@11: * yading@11: * @param pb the bytestream to probe yading@11: * @param fmt the input format is put here yading@11: * @param filename the filename of the stream yading@11: * @param logctx the log context yading@11: * @param offset the offset within the bytestream to probe from yading@11: * @param max_probe_size the maximum probe buffer size (zero for default) yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code otherwise yading@11: */ yading@11: int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, yading@11: const char *filename, void *logctx, yading@11: unsigned int offset, unsigned int max_probe_size); yading@11: yading@11: /** yading@11: * Open an input stream and read the header. The codecs are not opened. yading@11: * The stream must be closed with av_close_input_file(). yading@11: * yading@11: * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). yading@11: * May be a pointer to NULL, in which case an AVFormatContext is allocated by this yading@11: * function and written into ps. yading@11: * Note that a user-supplied AVFormatContext will be freed on failure. yading@11: * @param filename Name of the stream to open. yading@11: * @param fmt If non-NULL, this parameter forces a specific input format. yading@11: * Otherwise the format is autodetected. yading@11: * @param options A dictionary filled with AVFormatContext and demuxer-private options. yading@11: * On return this parameter will be destroyed and replaced with a dict containing yading@11: * options that were not found. May be NULL. yading@11: * yading@11: * @return 0 on success, a negative AVERROR on failure. yading@11: * yading@11: * @note If you want to use custom IO, preallocate the format context and set its pb field. yading@11: */ yading@11: int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options); yading@11: yading@11: attribute_deprecated yading@11: int av_demuxer_open(AVFormatContext *ic); yading@11: yading@11: #if FF_API_FORMAT_PARAMETERS yading@11: /** yading@11: * Read packets of a media file to get stream information. This yading@11: * is useful for file formats with no headers such as MPEG. This yading@11: * function also computes the real framerate in case of MPEG-2 repeat yading@11: * frame mode. yading@11: * The logical file position is not changed by this function; yading@11: * examined packets may be buffered for later processing. yading@11: * yading@11: * @param ic media file handle yading@11: * @return >=0 if OK, AVERROR_xxx on error yading@11: * @todo Let the user decide somehow what information is needed so that yading@11: * we do not waste time getting stuff the user does not need. yading@11: * yading@11: * @deprecated use avformat_find_stream_info. yading@11: */ yading@11: attribute_deprecated yading@11: int av_find_stream_info(AVFormatContext *ic); yading@11: #endif yading@11: yading@11: /** yading@11: * Read packets of a media file to get stream information. This yading@11: * is useful for file formats with no headers such as MPEG. This yading@11: * function also computes the real framerate in case of MPEG-2 repeat yading@11: * frame mode. yading@11: * The logical file position is not changed by this function; yading@11: * examined packets may be buffered for later processing. yading@11: * yading@11: * @param ic media file handle yading@11: * @param options If non-NULL, an ic.nb_streams long array of pointers to yading@11: * dictionaries, where i-th member contains options for yading@11: * codec corresponding to i-th stream. yading@11: * On return each dictionary will be filled with options that were not found. yading@11: * @return >=0 if OK, AVERROR_xxx on error yading@11: * yading@11: * @note this function isn't guaranteed to open all the codecs, so yading@11: * options being non-empty at return is a perfectly normal behavior. yading@11: * yading@11: * @todo Let the user decide somehow what information is needed so that yading@11: * we do not waste time getting stuff the user does not need. yading@11: */ yading@11: int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options); yading@11: yading@11: /** yading@11: * Find the programs which belong to a given stream. yading@11: * yading@11: * @param ic media file handle yading@11: * @param last the last found program, the search will start after this yading@11: * program, or from the beginning if it is NULL yading@11: * @param s stream index yading@11: * @return the next program which belongs to s, NULL if no program is found or yading@11: * the last program is not among the programs of ic. yading@11: */ yading@11: AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s); yading@11: yading@11: /** yading@11: * Find the "best" stream in the file. yading@11: * The best stream is determined according to various heuristics as the most yading@11: * likely to be what the user expects. yading@11: * If the decoder parameter is non-NULL, av_find_best_stream will find the yading@11: * default decoder for the stream's codec; streams for which no decoder can yading@11: * be found are ignored. yading@11: * yading@11: * @param ic media file handle yading@11: * @param type stream type: video, audio, subtitles, etc. yading@11: * @param wanted_stream_nb user-requested stream number, yading@11: * or -1 for automatic selection yading@11: * @param related_stream try to find a stream related (eg. in the same yading@11: * program) to this one, or -1 if none yading@11: * @param decoder_ret if non-NULL, returns the decoder for the yading@11: * selected stream yading@11: * @param flags flags; none are currently defined yading@11: * @return the non-negative stream number in case of success, yading@11: * AVERROR_STREAM_NOT_FOUND if no stream with the requested type yading@11: * could be found, yading@11: * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder yading@11: * @note If av_find_best_stream returns successfully and decoder_ret is not yading@11: * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec. yading@11: */ yading@11: int av_find_best_stream(AVFormatContext *ic, yading@11: enum AVMediaType type, yading@11: int wanted_stream_nb, yading@11: int related_stream, yading@11: AVCodec **decoder_ret, yading@11: int flags); yading@11: yading@11: #if FF_API_READ_PACKET yading@11: /** yading@11: * @deprecated use AVFMT_FLAG_NOFILLIN | AVFMT_FLAG_NOPARSE to read raw yading@11: * unprocessed packets yading@11: * yading@11: * Read a transport packet from a media file. yading@11: * yading@11: * This function is obsolete and should never be used. yading@11: * Use av_read_frame() instead. yading@11: * yading@11: * @param s media file handle yading@11: * @param pkt is filled yading@11: * @return 0 if OK, AVERROR_xxx on error yading@11: */ yading@11: attribute_deprecated yading@11: int av_read_packet(AVFormatContext *s, AVPacket *pkt); yading@11: #endif yading@11: yading@11: /** yading@11: * Return the next frame of a stream. yading@11: * This function returns what is stored in the file, and does not validate yading@11: * that what is there are valid frames for the decoder. It will split what is yading@11: * stored in the file into frames and return one for each call. It will not yading@11: * omit invalid data between valid frames so as to give the decoder the maximum yading@11: * information possible for decoding. yading@11: * yading@11: * If pkt->buf is NULL, then the packet is valid until the next yading@11: * av_read_frame() or until av_close_input_file(). Otherwise the packet is valid yading@11: * indefinitely. In both cases the packet must be freed with yading@11: * av_free_packet when it is no longer needed. For video, the packet contains yading@11: * exactly one frame. For audio, it contains an integer number of frames if each yading@11: * frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames yading@11: * have a variable size (e.g. MPEG audio), then it contains one frame. yading@11: * yading@11: * pkt->pts, pkt->dts and pkt->duration are always set to correct yading@11: * values in AVStream.time_base units (and guessed if the format cannot yading@11: * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format yading@11: * has B-frames, so it is better to rely on pkt->dts if you do not yading@11: * decompress the payload. yading@11: * yading@11: * @return 0 if OK, < 0 on error or end of file yading@11: */ yading@11: int av_read_frame(AVFormatContext *s, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Seek to the keyframe at timestamp. yading@11: * 'timestamp' in 'stream_index'. yading@11: * @param stream_index If stream_index is (-1), a default yading@11: * stream is selected, and timestamp is automatically converted yading@11: * from AV_TIME_BASE units to the stream specific time_base. yading@11: * @param timestamp Timestamp in AVStream.time_base units yading@11: * or, if no stream is specified, in AV_TIME_BASE units. yading@11: * @param flags flags which select direction and seeking mode yading@11: * @return >= 0 on success yading@11: */ yading@11: int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, yading@11: int flags); yading@11: yading@11: /** yading@11: * Seek to timestamp ts. yading@11: * Seeking will be done so that the point from which all active streams yading@11: * can be presented successfully will be closest to ts and within min/max_ts. yading@11: * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. yading@11: * yading@11: * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and yading@11: * are the file position (this may not be supported by all demuxers). yading@11: * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames yading@11: * in the stream with stream_index (this may not be supported by all demuxers). yading@11: * Otherwise all timestamps are in units of the stream selected by stream_index yading@11: * or if stream_index is -1, in AV_TIME_BASE units. yading@11: * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as yading@11: * keyframes (this may not be supported by all demuxers). yading@11: * yading@11: * @param stream_index index of the stream which is used as time base reference yading@11: * @param min_ts smallest acceptable timestamp yading@11: * @param ts target timestamp yading@11: * @param max_ts largest acceptable timestamp yading@11: * @param flags flags yading@11: * @return >=0 on success, error code otherwise yading@11: * yading@11: * @note This is part of the new seek API which is still under construction. yading@11: * Thus do not use this yet. It may change at any time, do not expect yading@11: * ABI compatibility yet! yading@11: */ yading@11: int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); yading@11: yading@11: /** yading@11: * Start playing a network-based stream (e.g. RTSP stream) at the yading@11: * current position. yading@11: */ yading@11: int av_read_play(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Pause a network-based stream (e.g. RTSP stream). yading@11: * yading@11: * Use av_read_play() to resume it. yading@11: */ yading@11: int av_read_pause(AVFormatContext *s); yading@11: yading@11: #if FF_API_CLOSE_INPUT_FILE yading@11: /** yading@11: * @deprecated use avformat_close_input() yading@11: * Close a media file (but not its codecs). yading@11: * yading@11: * @param s media file handle yading@11: */ yading@11: attribute_deprecated yading@11: void av_close_input_file(AVFormatContext *s); yading@11: #endif yading@11: yading@11: /** yading@11: * Close an opened input AVFormatContext. Free it and all its contents yading@11: * and set *s to NULL. yading@11: */ yading@11: void avformat_close_input(AVFormatContext **s); yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #if FF_API_NEW_STREAM yading@11: /** yading@11: * Add a new stream to a media file. yading@11: * yading@11: * Can only be called in the read_header() function. If the flag yading@11: * AVFMTCTX_NOHEADER is in the format context, then new streams yading@11: * can be added in read_packet too. yading@11: * yading@11: * @param s media file handle yading@11: * @param id file-format-dependent stream ID yading@11: */ yading@11: attribute_deprecated yading@11: AVStream *av_new_stream(AVFormatContext *s, int id); yading@11: #endif yading@11: yading@11: #if FF_API_SET_PTS_INFO yading@11: /** yading@11: * @deprecated this function is not supposed to be called outside of lavf yading@11: */ yading@11: attribute_deprecated yading@11: void av_set_pts_info(AVStream *s, int pts_wrap_bits, yading@11: unsigned int pts_num, unsigned int pts_den); yading@11: #endif yading@11: yading@11: #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward yading@11: #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes yading@11: #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes yading@11: #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number yading@11: yading@11: /** yading@11: * @addtogroup lavf_encoding yading@11: * @{ yading@11: */ yading@11: /** yading@11: * Allocate the stream private data and write the stream header to yading@11: * an output media file. yading@11: * yading@11: * @param s Media file handle, must be allocated with avformat_alloc_context(). yading@11: * Its oformat field must be set to the desired output format; yading@11: * Its pb field must be set to an already openened AVIOContext. yading@11: * @param options An AVDictionary filled with AVFormatContext and muxer-private options. yading@11: * On return this parameter will be destroyed and replaced with a dict containing yading@11: * options that were not found. May be NULL. yading@11: * yading@11: * @return 0 on success, negative AVERROR on failure. yading@11: * yading@11: * @see av_opt_find, av_dict_set, avio_open, av_oformat_next. yading@11: */ yading@11: int avformat_write_header(AVFormatContext *s, AVDictionary **options); yading@11: yading@11: /** yading@11: * Write a packet to an output media file. yading@11: * yading@11: * The packet shall contain one audio or video frame. yading@11: * The packet must be correctly interleaved according to the container yading@11: * specification, if not then av_interleaved_write_frame must be used. yading@11: * yading@11: * @param s media file handle yading@11: * @param pkt The packet, which contains the stream_index, buf/buf_size, yading@11: * dts/pts, ... yading@11: * This can be NULL (at any time, not just at the end), in yading@11: * order to immediately flush data buffered within the muxer, yading@11: * for muxers that buffer up data internally before writing it yading@11: * to the output. yading@11: * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush yading@11: */ yading@11: int av_write_frame(AVFormatContext *s, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Write a packet to an output media file ensuring correct interleaving. yading@11: * yading@11: * The packet must contain one audio or video frame. yading@11: * If the packets are already correctly interleaved, the application should yading@11: * call av_write_frame() instead as it is slightly faster. It is also important yading@11: * to keep in mind that completely non-interleaved input will need huge amounts yading@11: * of memory to interleave with this, so it is preferable to interleave at the yading@11: * demuxer level. yading@11: * yading@11: * @param s media file handle yading@11: * @param pkt The packet containing the data to be written. pkt->buf must be set yading@11: * to a valid AVBufferRef describing the packet data. Libavformat takes yading@11: * ownership of this reference and will unref it when it sees fit. The caller yading@11: * must not access the data through this reference after this function returns. yading@11: * This can be NULL (at any time, not just at the end), to flush the yading@11: * interleaving queues. yading@11: * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the yading@11: * index of the corresponding stream in @ref AVFormatContext.streams yading@11: * "s.streams". yading@11: * It is very strongly recommended that timing information (@ref AVPacket.pts yading@11: * "pts", @ref AVPacket.dts "dts" @ref AVPacket.duration "duration") is set to yading@11: * correct values. yading@11: * yading@11: * @return 0 on success, a negative AVERROR on error. yading@11: */ yading@11: int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Write the stream trailer to an output media file and free the yading@11: * file private data. yading@11: * yading@11: * May only be called after a successful call to avformat_write_header. yading@11: * yading@11: * @param s media file handle yading@11: * @return 0 if OK, AVERROR_xxx on error yading@11: */ yading@11: int av_write_trailer(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Return the output format in the list of registered output formats yading@11: * which best matches the provided parameters, or return NULL if yading@11: * there is no match. yading@11: * yading@11: * @param short_name if non-NULL checks if short_name matches with the yading@11: * names of the registered formats yading@11: * @param filename if non-NULL checks if filename terminates with the yading@11: * extensions of the registered formats yading@11: * @param mime_type if non-NULL checks if mime_type matches with the yading@11: * MIME type of the registered formats yading@11: */ yading@11: AVOutputFormat *av_guess_format(const char *short_name, yading@11: const char *filename, yading@11: const char *mime_type); yading@11: yading@11: /** yading@11: * Guess the codec ID based upon muxer and filename. yading@11: */ yading@11: enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, yading@11: const char *filename, const char *mime_type, yading@11: enum AVMediaType type); yading@11: yading@11: /** yading@11: * Get timing information for the data currently output. yading@11: * The exact meaning of "currently output" depends on the format. yading@11: * It is mostly relevant for devices that have an internal buffer and/or yading@11: * work in real time. yading@11: * @param s media file handle yading@11: * @param stream stream in the media file yading@11: * @param[out] dts DTS of the last packet output for the stream, in stream yading@11: * time_base units yading@11: * @param[out] wall absolute time when that packet whas output, yading@11: * in microsecond yading@11: * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it yading@11: * Note: some formats or devices may not allow to measure dts and wall yading@11: * atomically. yading@11: */ yading@11: int av_get_output_timestamp(struct AVFormatContext *s, int stream, yading@11: int64_t *dts, int64_t *wall); yading@11: yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: yading@11: /** yading@11: * @defgroup lavf_misc Utility functions yading@11: * @ingroup libavf yading@11: * @{ yading@11: * yading@11: * Miscellaneous utility functions related to both muxing and demuxing yading@11: * (or neither). yading@11: */ yading@11: yading@11: /** yading@11: * Send a nice hexadecimal dump of a buffer to the specified file stream. yading@11: * yading@11: * @param f The file stream pointer where the dump should be sent to. yading@11: * @param buf buffer yading@11: * @param size buffer size yading@11: * yading@11: * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2 yading@11: */ yading@11: void av_hex_dump(FILE *f, const uint8_t *buf, int size); yading@11: yading@11: /** yading@11: * Send a nice hexadecimal dump of a buffer to the log. yading@11: * yading@11: * @param avcl A pointer to an arbitrary struct of which the first field is a yading@11: * pointer to an AVClass struct. yading@11: * @param level The importance level of the message, lower values signifying yading@11: * higher importance. yading@11: * @param buf buffer yading@11: * @param size buffer size yading@11: * yading@11: * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2 yading@11: */ yading@11: void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size); yading@11: yading@11: /** yading@11: * Send a nice dump of a packet to the specified file stream. yading@11: * yading@11: * @param f The file stream pointer where the dump should be sent to. yading@11: * @param pkt packet to dump yading@11: * @param dump_payload True if the payload must be displayed, too. yading@11: * @param st AVStream that the packet belongs to yading@11: */ yading@11: void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st); yading@11: yading@11: yading@11: /** yading@11: * Send a nice dump of a packet to the log. yading@11: * yading@11: * @param avcl A pointer to an arbitrary struct of which the first field is a yading@11: * pointer to an AVClass struct. yading@11: * @param level The importance level of the message, lower values signifying yading@11: * higher importance. yading@11: * @param pkt packet to dump yading@11: * @param dump_payload True if the payload must be displayed, too. yading@11: * @param st AVStream that the packet belongs to yading@11: */ yading@11: void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, yading@11: AVStream *st); yading@11: yading@11: /** yading@11: * Get the AVCodecID for the given codec tag tag. yading@11: * If no codec id is found returns AV_CODEC_ID_NONE. yading@11: * yading@11: * @param tags list of supported codec_id-codec_tag pairs, as stored yading@11: * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag yading@11: */ yading@11: enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag); yading@11: yading@11: /** yading@11: * Get the codec tag for the given codec id id. yading@11: * If no codec tag is found returns 0. yading@11: * yading@11: * @param tags list of supported codec_id-codec_tag pairs, as stored yading@11: * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag yading@11: */ yading@11: unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id); yading@11: yading@11: /** yading@11: * Get the codec tag for the given codec id. yading@11: * yading@11: * @param tags list of supported codec_id - codec_tag pairs, as stored yading@11: * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag yading@11: * @param id codec id that should be searched for in the list yading@11: * @param tag A pointer to the found tag yading@11: * @return 0 if id was not found in tags, > 0 if it was found yading@11: */ yading@11: int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id, yading@11: unsigned int *tag); yading@11: yading@11: int av_find_default_stream_index(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Get the index for a specific timestamp. yading@11: * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond yading@11: * to the timestamp which is <= the requested one, if backward yading@11: * is 0, then it will be >= yading@11: * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise yading@11: * @return < 0 if no such timestamp could be found yading@11: */ yading@11: int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); yading@11: yading@11: /** yading@11: * Add an index entry into a sorted list. Update the entry if the list yading@11: * already contains it. yading@11: * yading@11: * @param timestamp timestamp in the time base of the given stream yading@11: */ yading@11: int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, yading@11: int size, int distance, int flags); yading@11: yading@11: yading@11: /** yading@11: * Split a URL string into components. yading@11: * yading@11: * The pointers to buffers for storing individual components may be null, yading@11: * in order to ignore that component. Buffers for components not found are yading@11: * set to empty strings. If the port is not found, it is set to a negative yading@11: * value. yading@11: * yading@11: * @param proto the buffer for the protocol yading@11: * @param proto_size the size of the proto buffer yading@11: * @param authorization the buffer for the authorization yading@11: * @param authorization_size the size of the authorization buffer yading@11: * @param hostname the buffer for the host name yading@11: * @param hostname_size the size of the hostname buffer yading@11: * @param port_ptr a pointer to store the port number in yading@11: * @param path the buffer for the path yading@11: * @param path_size the size of the path buffer yading@11: * @param url the URL to split yading@11: */ yading@11: void av_url_split(char *proto, int proto_size, yading@11: char *authorization, int authorization_size, yading@11: char *hostname, int hostname_size, yading@11: int *port_ptr, yading@11: char *path, int path_size, yading@11: const char *url); yading@11: yading@11: yading@11: void av_dump_format(AVFormatContext *ic, yading@11: int index, yading@11: const char *url, yading@11: int is_output); yading@11: yading@11: /** yading@11: * Return in 'buf' the path with '%d' replaced by a number. yading@11: * yading@11: * Also handles the '%0nd' format where 'n' is the total number yading@11: * of digits and '%%'. yading@11: * yading@11: * @param buf destination buffer yading@11: * @param buf_size destination buffer size yading@11: * @param path numbered sequence string yading@11: * @param number frame number yading@11: * @return 0 if OK, -1 on format error yading@11: */ yading@11: int av_get_frame_filename(char *buf, int buf_size, yading@11: const char *path, int number); yading@11: yading@11: /** yading@11: * Check whether filename actually is a numbered sequence generator. yading@11: * yading@11: * @param filename possible numbered sequence string yading@11: * @return 1 if a valid numbered sequence string, 0 otherwise yading@11: */ yading@11: int av_filename_number_test(const char *filename); yading@11: yading@11: /** yading@11: * Generate an SDP for an RTP session. yading@11: * yading@11: * Note, this overwrites the id values of AVStreams in the muxer contexts yading@11: * for getting unique dynamic payload types. yading@11: * yading@11: * @param ac array of AVFormatContexts describing the RTP streams. If the yading@11: * array is composed by only one context, such context can contain yading@11: * multiple AVStreams (one AVStream per RTP stream). Otherwise, yading@11: * all the contexts in the array (an AVCodecContext per RTP stream) yading@11: * must contain only one AVStream. yading@11: * @param n_files number of AVCodecContexts contained in ac yading@11: * @param buf buffer where the SDP will be stored (must be allocated by yading@11: * the caller) yading@11: * @param size the size of the buffer yading@11: * @return 0 if OK, AVERROR_xxx on error yading@11: */ yading@11: int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size); yading@11: yading@11: /** yading@11: * Return a positive value if the given filename has one of the given yading@11: * extensions, 0 otherwise. yading@11: * yading@11: * @param extensions a comma-separated list of filename extensions yading@11: */ yading@11: int av_match_ext(const char *filename, const char *extensions); yading@11: yading@11: /** yading@11: * Test if the given container can store a codec. yading@11: * yading@11: * @param std_compliance standards compliance level, one of FF_COMPLIANCE_* yading@11: * yading@11: * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot. yading@11: * A negative number if this information is not available. yading@11: */ yading@11: int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance); yading@11: yading@11: /** yading@11: * @defgroup riff_fourcc RIFF FourCCs yading@11: * @{ yading@11: * Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs. The tables are yading@11: * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the yading@11: * following code: yading@11: * @code yading@11: * uint32_t tag = MKTAG('H', '2', '6', '4'); yading@11: * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 }; yading@11: * enum AVCodecID id = av_codec_get_id(table, tag); yading@11: * @endcode yading@11: */ yading@11: /** yading@11: * @return the table mapping RIFF FourCCs for video to libavcodec AVCodecID. yading@11: */ yading@11: const struct AVCodecTag *avformat_get_riff_video_tags(void); yading@11: /** yading@11: * @return the table mapping RIFF FourCCs for audio to AVCodecID. yading@11: */ yading@11: const struct AVCodecTag *avformat_get_riff_audio_tags(void); yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: /** yading@11: * Guess the sample aspect ratio of a frame, based on both the stream and the yading@11: * frame aspect ratio. yading@11: * yading@11: * Since the frame aspect ratio is set by the codec but the stream aspect ratio yading@11: * is set by the demuxer, these two may not be equal. This function tries to yading@11: * return the value that you should use if you would like to display the frame. yading@11: * yading@11: * Basic logic is to use the stream aspect ratio if it is set to something sane yading@11: * otherwise use the frame aspect ratio. This way a container setting, which is yading@11: * usually easy to modify can override the coded value in the frames. yading@11: * yading@11: * @param format the format context which the stream is part of yading@11: * @param stream the stream which the frame is part of yading@11: * @param frame the frame with the aspect ratio to be determined yading@11: * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea yading@11: */ yading@11: AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame); yading@11: yading@11: /** yading@11: * Guess the frame rate, based on both the container and codec information. yading@11: * yading@11: * @param ctx the format context which the stream is part of yading@11: * @param stream the stream which the frame is part of yading@11: * @param frame the frame for which the frame rate should be determined, may be NULL yading@11: * @return the guessed (valid) frame rate, 0/1 if no idea yading@11: */ yading@11: AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame); yading@11: yading@11: /** yading@11: * Check if the stream st contained in s is matched by the stream specifier yading@11: * spec. yading@11: * yading@11: * See the "stream specifiers" chapter in the documentation for the syntax yading@11: * of spec. yading@11: * yading@11: * @return >0 if st is matched by spec; yading@11: * 0 if st is not matched by spec; yading@11: * AVERROR code if spec is invalid yading@11: * yading@11: * @note A stream specifier can match several streams in the format. yading@11: */ yading@11: int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, yading@11: const char *spec); yading@11: yading@11: int avformat_queue_attached_pictures(AVFormatContext *s); yading@11: yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #endif /* AVFORMAT_AVFORMAT_H */