lavf doxy: add some general lavf information.
[libav.git] / libavformat / avformat.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2001 Fabrice Bellard
3 *
2912e87a 4 * This file is part of Libav.
b78e7197 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
04d7f601
DB
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
2912e87a 17 * License along with Libav; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
98790382
SS
21#ifndef AVFORMAT_AVFORMAT_H
22#define AVFORMAT_AVFORMAT_H
de6d9b64 23
e361b508 24/**
eca06cbe
AK
25 * @file
26 * @ingroup libavf
27 * Main libavformat public API header
28 */
29
30/**
e361b508
LB
31 * @defgroup libavf I/O and Muxing/Demuxing Library
32 * @{
33 *
ccbc1068
AK
34 * Libavformat (lavf) is a library for dealing with various media container
35 * formats. Its main two purposes are demuxing - i.e. splitting a media file
36 * into component streams, and the reverse process of muxing - writing supplied
37 * data in a specified container format. It also has an @ref lavf_io
38 * "I/O module" which supports a number of protocols for accessing the data (e.g.
39 * file, tcp, http and others). Before using lavf, you need to call
40 * av_register_all() to register all compiled muxers, demuxers and protocols.
41 * Unless you are absolutely sure you won't use libavformat's network
42 * capabilities, you should also call avformat_network_init().
43 *
44 * A supported input format is described by an AVInputFormat struct, conversely
45 * an output format is described by AVOutputFormat. You can iterate over all
46 * registered input/output formats using the av_iformat_next() /
47 * av_oformat_next() functions. The protocols layer is not part of the public
48 * API, so you can only get the names of supported protocols with the
49 * avio_enum_protocols() function.
50 *
51 * Main lavf structure used for both muxing and demuxing is AVFormatContext,
52 * which exports all information about the file being read or written. As with
53 * most Libav structures, its size is not part of public ABI, so it cannot be
54 * allocated on stack or directly with av_malloc(). To create an
55 * AVFormatContext, use avformat_alloc_context() (some functions, like
56 * avformat_open_input() might do that for you).
57 *
58 * Most importantly an AVFormatContext contains:
59 * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat
60 * "output" format. It is either autodetected or set by user for input;
61 * always set by user for output.
62 * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all
63 * elementary streams stored in the file. AVStreams are typically referred to
64 * using their index in this array.
65 * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or
66 * set by user for input, always set by user for output (unless you are dealing
67 * with an AVFMT_NOFILE format).
68 *
e361b508
LB
69 * @defgroup lavf_decoding Demuxing
70 * @{
71 * @}
72 *
73 * @defgroup lavf_encoding Muxing
74 * @{
75 * @}
76 *
e4f4a1f9 77 * @defgroup lavf_io I/O Read/Write
e361b508
LB
78 * @{
79 * @}
80 *
81 * @defgroup lavf_codec Demuxers
82 * @{
83 * @defgroup lavf_codec_native Native Demuxers
84 * @{
85 * @}
86 * @defgroup lavf_codec_wrappers External library wrappers
87 * @{
88 * @}
89 * @}
90 * @defgroup lavf_protos I/O Protocols
91 * @{
92 * @}
93 * @defgroup lavf_internal Internal
94 * @{
95 * @}
96 * @}
97 *
98 */
072e3efd 99
f71869a4 100#include <time.h>
67070e4f 101#include <stdio.h> /* FILE */
76a448ed 102#include "libavcodec/avcodec.h"
d9f80ea2 103#include "libavutil/dict.h"
abc78a5a 104#include "libavutil/log.h"
de6d9b64 105
de6d9b64 106#include "avio.h"
50196a98 107#include "libavformat/version.h"
de6d9b64 108
f610a9f2
AJ
109struct AVFormatContext;
110
a6d18a0e 111
1a53a438
RT
112/**
113 * @defgroup metadata_api Public Metadata API
114 * @{
b262a059 115 * @ingroup libavf
ea29242c 116 * The metadata API allows libavformat to export metadata tags to a client
28b4c06b
AK
117 * application when demuxing. Conversely it allows a client application to
118 * set metadata when muxing.
119 *
120 * Metadata is exported or set as pairs of key/value strings in the 'metadata'
121 * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs
122 * using the @ref lavu_dict "AVDictionary" API. Like all strings in Libav,
123 * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata
61648423 124 * exported by demuxers isn't checked to be valid UTF-8 in most cases.
28b4c06b 125 *
ea29242c 126 * Important concepts to keep in mind:
1a53a438 127 * - Keys are unique; there can never be 2 tags with the same key. This is
ea29242c
MM
128 * also meant semantically, i.e., a demuxer should not knowingly produce
129 * several keys that are literally different but semantically identical.
130 * E.g., key=Author5, key=Author6. In this example, all authors must be
131 * placed in the same tag.
1a53a438 132 * - Metadata is flat, not hierarchical; there are no subtags. If you
ea29242c
MM
133 * want to store, e.g., the email address of the child of producer Alice
134 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
1a53a438 135 * - Several modifiers can be applied to the tag name. This is done by
ca76a119
AK
136 * appending a dash character ('-') and the modifier name in the order
137 * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
1a53a438 138 * - language -- a tag whose value is localized for a particular language
ca76a119
AK
139 * is appended with the ISO 639-2/B 3-letter language code.
140 * For example: Author-ger=Michael, Author-eng=Mike
141 * The original/default language is in the unqualified "Author" tag.
142 * A demuxer should set a default if it sets any translated tag.
1a53a438 143 * - sorting -- a modified version of a tag that should be used for
ca76a119
AK
144 * sorting will have '-sort' appended. E.g. artist="The Beatles",
145 * artist-sort="Beatles, The".
146 *
1a53a438 147 * - Demuxers attempt to export metadata in a generic format, however tags
03700d39
AK
148 * with no generic equivalents are left as they are stored in the container.
149 * Follows a list of generic tag names:
ca76a119 150 *
1a53a438
RT
151 @verbatim
152 album -- name of the set this work belongs to
153 album_artist -- main creator of the set/album, if different from artist.
154 e.g. "Various Artists" for compilation albums.
155 artist -- main creator of the work
156 comment -- any additional description of the file.
157 composer -- who composed the work, if different from artist.
158 copyright -- name of copyright holder.
159 creation_time-- date when the file was created, preferably in ISO 8601.
160 date -- date when the work was created, preferably in ISO 8601.
161 disc -- number of a subset, e.g. disc in a multi-disc collection.
162 encoder -- name/settings of the software/hardware that produced the file.
163 encoded_by -- person/group who created the file.
164 filename -- original name of the file.
165 genre -- <self-evident>.
166 language -- main language in which the work is performed, preferably
167 in ISO 639-2 format. Multiple languages can be specified by
168 separating them with commas.
169 performer -- artist who performed the work, if different from artist.
170 E.g for "Also sprach Zarathustra", artist would be "Richard
171 Strauss" and performer "London Philharmonic Orchestra".
172 publisher -- name of the label/publisher.
173 service_name -- name of the service in broadcasting (channel name).
174 service_provider -- name of the service provider in broadcasting.
175 title -- name of the work.
176 track -- number of this work in the set, can be in form current/total.
177 variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
178 @endverbatim
179 *
12489443
RT
180 * Look in the examples section for an application example how to use the Metadata API.
181 *
1a53a438 182 * @}
a6d18a0e
MN
183 */
184
d9f80ea2
AK
185#if FF_API_OLD_METADATA2
186/**
187 * @defgroup old_metadata Old metadata API
188 * The following functions are deprecated, use
189 * their equivalents from libavutil/dict.h instead.
190 * @{
191 */
a6d18a0e 192
d9f80ea2
AK
193#define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
194#define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
195#define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
196#define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
197#define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
198
199typedef attribute_deprecated AVDictionary AVMetadata;
200typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
a6d18a0e 201
f610a9f2 202typedef struct AVMetadataConv AVMetadataConv;
a6d18a0e
MN
203
204/**
49bd8e4b 205 * Get a metadata element with matching key.
26cc5310 206 *
22e77e44 207 * @param prev Set to the previous matching element to find the next.
66b6c745 208 * If set to NULL the first matching element is returned.
22e77e44
DB
209 * @param flags Allows case as well as suffix-insensitive comparisons.
210 * @return Found tag or NULL, changing key or value leads to undefined behavior.
a6d18a0e 211 */
d9f80ea2
AK
212attribute_deprecated AVDictionaryEntry *
213av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
a6d18a0e 214
a181981e 215/**
32e6f246 216 * Set the given tag in *pm, overwriting an existing tag.
26cc5310 217 *
983ec304
SS
218 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
219 * a metadata struct is allocated and put in *pm.
32e6f246
SS
220 * @param key tag key to add to *pm (will be av_strduped depending on flags)
221 * @param value tag value to add to *pm (will be av_strduped depending on flags).
160c896c 222 * Passing a NULL value will cause an existing tag to be deleted.
a181981e
MN
223 * @return >= 0 on success otherwise an error code <0
224 */
d9f80ea2 225attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
a6d18a0e 226
094d9df7 227/**
03700d39 228 * This function is provided for compatibility reason and currently does nothing.
f610a9f2 229 */
03700d39
AK
230attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
231 const AVMetadataConv *s_conv);
f610a9f2
AJ
232
233/**
d9f80ea2
AK
234 * Copy metadata from one AVDictionary struct into another.
235 * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
7f88a5bf 236 * this function will allocate a struct for you and put it in *dst
d9f80ea2 237 * @param src pointer to source AVDictionary struct
7f88a5bf 238 * @param flags flags to use when setting metadata in *dst
d2d67e42 239 * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
7f88a5bf 240 */
d9f80ea2 241attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
7f88a5bf
RB
242
243/**
d9f80ea2 244 * Free all the memory allocated for an AVDictionary struct.
094d9df7 245 */
d9f80ea2
AK
246attribute_deprecated void av_metadata_free(AVDictionary **m);
247/**
248 * @}
249 */
250#endif
094d9df7 251
a6d18a0e 252
de6d9b64
FB
253/* packet functions */
254
3217cb42
PI
255
256/**
49bd8e4b 257 * Allocate and read the payload of a packet and initialize its
d1b9adf2 258 * fields with default values.
3217cb42
PI
259 *
260 * @param pkt packet
4f57fa8c
DB
261 * @param size desired payload size
262 * @return >0 (read size) if OK, AVERROR_xxx otherwise
3217cb42 263 */
ae628ec1 264int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
3217cb42 265
de6d9b64 266
6bfc2683 267/**
fa8cc126
RD
268 * Read data and append it to the current content of the AVPacket.
269 * If pkt->size is 0 this is identical to av_get_packet.
6bfc2683
RD
270 * Note that this uses av_grow_packet and thus involves a realloc
271 * which is inefficient. Thus this function should only be used
272 * when there is no reasonable way to know (an upper bound of)
273 * the final size.
274 *
275 * @param pkt packet
276 * @param size amount of data to read
277 * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
278 * will not be lost even if an error occurs.
279 */
ae628ec1 280int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
6bfc2683 281
de6d9b64 282/*************************************************/
916c80e9
FB
283/* fractional numbers for exact pts handling */
284
671adb17 285/**
4f57fa8c
DB
286 * The exact value of the fractional number is: 'val + num / den'.
287 * num is assumed to be 0 <= num < den.
4c08b2bd 288 */
916c80e9 289typedef struct AVFrac {
115329f1 290 int64_t val, num, den;
52e57500 291} AVFrac;
916c80e9 292
916c80e9 293/*************************************************/
b9a281db 294/* input/output formats */
de6d9b64 295
7caf0cc6
MN
296struct AVCodecTag;
297
76c56376
MN
298/**
299 * This structure contains the data a format has to probe a file.
300 */
b9a281db 301typedef struct AVProbeData {
5c91a675 302 const char *filename;
e5f58f81 303 unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
304 int buf_size; /**< Size of buf except extra allocated bytes */
b9a281db
FB
305} AVProbeData;
306
22e77e44 307#define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
87e87886 308#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
de6d9b64
FB
309
310typedef struct AVFormatParameters {
bffd4dd1 311#if FF_API_FORMAT_PARAMETERS
b2592ea4 312 attribute_deprecated AVRational time_base;
bffd4dd1
AK
313 attribute_deprecated int sample_rate;
314 attribute_deprecated int channels;
89d1b7f4
AK
315 attribute_deprecated int width;
316 attribute_deprecated int height;
f91ccb1d 317 attribute_deprecated enum PixelFormat pix_fmt;
d20576d0 318 attribute_deprecated int channel; /**< Used to select DV channel. */
fc68a8f7 319 attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
fb37d573 320 attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */
17a5556d
AK
321 /**< deprecated, use mpegtsraw demuxer-specific options instead */
322 attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
4779f593
AK
323 attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream
324 immediately (RTSP only). */
603b8bc2 325 attribute_deprecated unsigned int prealloced_context:1;
17a5556d 326#endif
de6d9b64
FB
327} AVFormatParameters;
328
c68fafe0 329/// Demuxer will use avio_open, no opened file should be provided by the caller.
40d9c544 330#define AVFMT_NOFILE 0x0001
4f57fa8c
DB
331#define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
332#define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
333#define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
334 raw picture data. */
335#define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
336#define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
337#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
58ec7e00 338#define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
25918212 339#define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
ab5a0175 340#define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
bb62d5c1 341#define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
69fa2396
VP
342#define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
343#define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
b631fba9 344#define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */
b9a281db 345
489a7b07
AK
346/**
347 * @addtogroup lavf_encoding
348 * @{
349 */
b9a281db 350typedef struct AVOutputFormat {
de6d9b64 351 const char *name;
bde15e74
SS
352 /**
353 * Descriptive name for the format, meant to be more human-readable
819174fa 354 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
355 * to define it.
356 */
de6d9b64
FB
357 const char *long_name;
358 const char *mime_type;
4f57fa8c 359 const char *extensions; /**< comma-separated filename extensions */
76c56376
MN
360 /**
361 * size of private data so that it can be allocated in the wrapper
362 */
b9a281db 363 int priv_data_size;
de6d9b64 364 /* output support */
43d414ba
PI
365 enum CodecID audio_codec; /**< default audio codec */
366 enum CodecID video_codec; /**< default video codec */
de6d9b64 367 int (*write_header)(struct AVFormatContext *);
e928649b 368 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
de6d9b64 369 int (*write_trailer)(struct AVFormatContext *);
76c56376 370 /**
89e568fe
AH
371 * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
372 * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
373 * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
76c56376 374 */
b9a281db 375 int flags;
76c56376
MN
376 /**
377 * Currently only used to set pixel format if not YUV420P.
378 */
290c5fa6 379 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
78cb7273
DB
380 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
381 AVPacket *in, int flush);
7caf0cc6
MN
382
383 /**
78cb7273 384 * List of supported codec_id-codec_tag pairs, ordered by "better
22e77e44 385 * choice first". The arrays are all terminated by CODEC_ID_NONE.
7caf0cc6 386 */
c1854592 387 const struct AVCodecTag * const *codec_tag;
7caf0cc6 388
11bf3847
AJ
389 enum CodecID subtitle_codec; /**< default subtitle codec */
390
451d566f 391#if FF_API_OLD_METADATA2
719e721a 392 const AVMetadataConv *metadata_conv;
03700d39 393#endif
f610a9f2 394
cf99e4aa
AH
395 const AVClass *priv_class; ///< AVClass for the private context
396
48f9e457
AK
397 /**
398 * Test if the given codec can be stored in this container.
399 *
400 * @return 1 if the codec is supported, 0 if it is not.
401 * A negative number if unknown.
402 */
403 int (*query_codec)(enum CodecID id, int std_compliance);
404
b9a281db
FB
405 /* private fields */
406 struct AVOutputFormat *next;
407} AVOutputFormat;
489a7b07
AK
408/**
409 * @}
410 */
de6d9b64 411
370f27de
AK
412/**
413 * @addtogroup lavf_decoding
414 * @{
415 */
b9a281db 416typedef struct AVInputFormat {
76c56376
MN
417 /**
418 * A comma separated list of short names for the format. New names
ac3ccbc0
AC
419 * may be appended with a minor bump.
420 */
b9a281db 421 const char *name;
76c56376 422
bde15e74
SS
423 /**
424 * Descriptive name for the format, meant to be more human-readable
819174fa 425 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
426 * to define it.
427 */
b9a281db 428 const char *long_name;
76c56376
MN
429
430 /**
431 * Size of private data so that it can be allocated in the wrapper.
432 */
b9a281db 433 int priv_data_size;
76c56376 434
65d7d68b 435 /**
22e77e44 436 * Tell if a given file has a chance of being parsed as this format.
5d81d641
DB
437 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
438 * big so you do not have to check for that unless you need more.
65d7d68b 439 */
b9a281db 440 int (*read_probe)(AVProbeData *);
76c56376
MN
441
442 /**
443 * Read the format header and initialize the AVFormatContext
444 * structure. Return 0 if OK. 'ap' if non-NULL contains
445 * additional parameters. Only used in raw format right
446 * now. 'av_new_stream' should be called to create new streams.
447 */
de6d9b64
FB
448 int (*read_header)(struct AVFormatContext *,
449 AVFormatParameters *ap);
76c56376
MN
450
451 /**
452 * Read one packet and put it in 'pkt'. pts and flags are also
453 * set. 'av_new_stream' can be called only if the flag
2899a28c
AJ
454 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
455 * background thread).
76c56376
MN
456 * @return 0 on success, < 0 on error.
457 * When returning an error, pkt must not have been allocated
458 * or must be freed before returning
459 */
de6d9b64 460 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
76c56376
MN
461
462 /**
463 * Close the stream. The AVFormatContext and AVStreams are not
464 * freed by this function
465 */
de6d9b64 466 int (*read_close)(struct AVFormatContext *);
1de2db8f 467
634e0304 468#if FF_API_READ_SEEK
115329f1 469 /**
4f57fa8c
DB
470 * Seek to a given timestamp relative to the frames in
471 * stream component stream_index.
22e77e44
DB
472 * @param stream_index Must not be -1.
473 * @param flags Selects which direction should be preferred if no exact
474 * match is available.
05ce0f11 475 * @return >= 0 on success (but not necessarily the new offset)
3ba1438d 476 */
a15c7fd6
AK
477 attribute_deprecated int (*read_seek)(struct AVFormatContext *,
478 int stream_index, int64_t timestamp, int flags);
1de2db8f 479#endif
8d14a25c 480 /**
4f57fa8c 481 * Gets the next timestamp in stream[stream_index].time_base units.
d9526386 482 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
8d14a25c
MN
483 */
484 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
485 int64_t *pos, int64_t pos_limit);
76c56376
MN
486
487 /**
050e20ae
JR
488 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
489 * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
b631fba9 490 * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
76c56376 491 */
de6d9b64 492 int flags;
76c56376
MN
493
494 /**
495 * If extensions are defined, then no probe is done. You should
496 * usually not use extension format guessing because it is not
497 * reliable enough
498 */
b9a281db 499 const char *extensions;
76c56376
MN
500
501 /**
502 * General purpose read-only value that the format can use.
503 */
b9a281db 504 int value;
fb2758c8 505
76c56376
MN
506 /**
507 * Start/resume playing - only meaningful if using a network-based format
508 * (RTSP).
509 */
fb2758c8
FB
510 int (*read_play)(struct AVFormatContext *);
511
76c56376
MN
512 /**
513 * Pause playing - only meaningful if using a network-based format
514 * (RTSP).
515 */
fb2758c8
FB
516 int (*read_pause)(struct AVFormatContext *);
517
c1854592 518 const struct AVCodecTag * const *codec_tag;
7caf0cc6 519
1de2db8f 520 /**
49bd8e4b 521 * Seek to timestamp ts.
1de2db8f
MN
522 * Seeking will be done so that the point from which all active streams
523 * can be presented successfully will be closest to ts and within min/max_ts.
524 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
525 */
882fb0a3 526 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1de2db8f 527
451d566f 528#if FF_API_OLD_METADATA2
719e721a 529 const AVMetadataConv *metadata_conv;
03700d39 530#endif
f610a9f2 531
5dc82144
AK
532 const AVClass *priv_class; ///< AVClass for the private context
533
b9a281db
FB
534 /* private fields */
535 struct AVInputFormat *next;
536} AVInputFormat;
370f27de
AK
537/**
538 * @}
539 */
de6d9b64 540
57004ff1
AJ
541enum AVStreamParseType {
542 AVSTREAM_PARSE_NONE,
543 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
4f57fa8c 544 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
78cb7273 545 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
74a6df59 546 AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
57004ff1
AJ
547};
548
fb2758c8
FB
549typedef struct AVIndexEntry {
550 int64_t pos;
551 int64_t timestamp;
552#define AVINDEX_KEYFRAME 0x0001
30a43f2d 553 int flags:2;
4f57fa8c
DB
554 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).
555 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
fb2758c8
FB
556} AVIndexEntry;
557
90c2295b
ES
558#define AV_DISPOSITION_DEFAULT 0x0001
559#define AV_DISPOSITION_DUB 0x0002
560#define AV_DISPOSITION_ORIGINAL 0x0004
561#define AV_DISPOSITION_COMMENT 0x0008
562#define AV_DISPOSITION_LYRICS 0x0010
563#define AV_DISPOSITION_KARAOKE 0x0020
76c56376
MN
564
565/**
566 * Track should be used during playback by default.
567 * Useful for subtitle track that should be displayed
568 * even when user did not explicitly ask for subtitles.
569 */
7a617a86 570#define AV_DISPOSITION_FORCED 0x0040
12c14cd4
PR
571#define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
572#define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
24a83bd1 573#define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
90c2295b 574
ba66ae94
MN
575/**
576 * Stream structure.
577 * New fields can be added to the end with minor version bumps.
8bfb108b 578 * Removal, reordering and changes to existing fields require a major
ba66ae94 579 * version bump.
8bfb108b 580 * sizeof(AVStream) must not be used outside libav*.
ba66ae94 581 */
de6d9b64 582typedef struct AVStream {
43d414ba 583 int index; /**< stream index in AVFormatContext */
4f57fa8c 584 int id; /**< format-specific stream ID */
43d414ba 585 AVCodecContext *codec; /**< codec context */
b4b87d48 586 /**
22e77e44
DB
587 * Real base framerate of the stream.
588 * This is the lowest framerate with which all timestamps can be
864ff8c1 589 * represented accurately (it is the least common multiple of all
22e77e44
DB
590 * framerates in the stream). Note, this value is just a guess!
591 * For example, if the time base is 1/90000 and all frames have either
4f57fa8c 592 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
b4b87d48
MN
593 */
594 AVRational r_frame_rate;
de6d9b64 595 void *priv_data;
82583548 596
9a174562 597#if FF_API_REORDER_PRIVATE
b9a281db 598 /* internal data used in av_find_stream_info() */
82583548 599 int64_t first_dts;
9a174562 600#endif
76c56376
MN
601
602 /**
603 * encoding: pts generation when outputting stream
604 */
a9fd2b19 605 struct AVFrac pts;
5b28c8c3
MN
606
607 /**
8bfb108b
DB
608 * This is the fundamental unit of time (in seconds) in terms
609 * of which frame timestamps are represented. For fixed-fps content,
22e77e44 610 * time base should be 1/framerate and timestamp increments should be 1.
5d820db2
RD
611 * decoding: set by libavformat
612 * encoding: set by libavformat in av_write_header
5b28c8c3 613 */
9ee91c2f 614 AVRational time_base;
9a174562 615#if FF_API_REORDER_PRIVATE
43d414ba 616 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
9a174562 617#endif
3d813e4c 618#if FF_API_STREAM_COPY
a48b7a6b 619 /* ffmpeg.c private use */
3d813e4c
AK
620 attribute_deprecated int stream_copy; /**< If set, just copy stream. */
621#endif
4f57fa8c 622 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
76c56376 623
5e8d2e33 624#if FF_API_AVSTREAM_QUALITY
b4aea108 625 //FIXME move stuff to a flags field?
76c56376
MN
626 /**
627 * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
628 * MN: dunno if that is the right place for it
629 */
5e8d2e33
AK
630 attribute_deprecated float quality;
631#endif
76c56376 632
6d96a9b9 633 /**
8bfb108b
DB
634 * Decoding: pts of the first frame of the stream, in stream time base.
635 * Only set this if you are absolutely 100% sure that the value you set
636 * it to really is the pts of the first frame.
4854c253 637 * This may be undefined (AV_NOPTS_VALUE).
6d96a9b9 638 */
115329f1 639 int64_t start_time;
76c56376 640
e26381b6 641 /**
8bfb108b 642 * Decoding: duration of the stream, in stream time base.
e26381b6 643 * If a source file does not specify a duration, but does specify
4f57fa8c 644 * a bitrate, this value will be estimated from bitrate and file size.
e26381b6 645 */
ee404803 646 int64_t duration;
fb2758c8 647
9a174562 648#if FF_API_REORDER_PRIVATE
fb2758c8 649 /* av_read_frame() support */
57004ff1 650 enum AVStreamParseType need_parsing;
fb2758c8 651 struct AVCodecParserContext *parser;
6ec87caa 652
fb2758c8 653 int64_t cur_dts;
635fbcb1
MN
654 int last_IP_duration;
655 int64_t last_IP_pts;
fb2758c8 656 /* av_seek_frame() support */
4f57fa8c
DB
657 AVIndexEntry *index_entries; /**< Only used if the format does not
658 support seeking natively. */
fb2758c8 659 int nb_index_entries;
191e8ca7 660 unsigned int index_entries_allocated_size;
9a174562 661#endif
115329f1 662
b4b87d48 663 int64_t nb_frames; ///< number of frames in this stream if known or 0
504ee036 664
4f57fa8c 665 int disposition; /**< AV_DISPOSITION_* bit field */
0bef08e5 666
9a174562 667#if FF_API_REORDER_PRIVATE
0bef08e5 668 AVProbeData probe_data;
0d84a8f6
BC
669#define MAX_REORDER_DELAY 16
670 int64_t pts_buffer[MAX_REORDER_DELAY+1];
9a174562 671#endif
c30a4489
AJ
672
673 /**
674 * sample aspect ratio (0 if unknown)
675 * - encoding: Set by user.
676 * - decoding: Set by libavformat.
677 */
678 AVRational sample_aspect_ratio;
f526adaf 679
d2d67e42 680 AVDictionary *metadata;
3a41c2f7 681
9a174562 682#if FF_API_REORDER_PRIVATE
31769dad
VP
683 /* Intended mostly for av_read_frame() support. Not supposed to be used by */
684 /* external applications; try to use something else if at all possible. */
3a41c2f7
MN
685 const uint8_t *cur_ptr;
686 int cur_len;
687 AVPacket cur_pkt;
27ca0a79
IS
688
689 // Timestamp generation support:
690 /**
691 * Timestamp corresponding to the last dts sync point.
692 *
693 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
694 * a DTS is received from the underlying container. Otherwise set to
695 * AV_NOPTS_VALUE by default.
696 */
697 int64_t reference_dts;
86cb7e33
BC
698
699 /**
700 * Number of packets to buffer for codec probing
701 * NOT PART OF PUBLIC API
702 */
48616887 703#define MAX_PROBE_PACKETS 2500
86cb7e33 704 int probe_packets;
ddce56ef
MN
705
706 /**
e07b882b 707 * last packet in packet_buffer for this stream when muxing.
da9cea77
DB
708 * Used internally, NOT PART OF PUBLIC API, do not read or
709 * write from outside of libav*
ddce56ef 710 */
e07b882b 711 struct AVPacketList *last_in_packet_buffer;
9a174562 712#endif
02b398ef
MN
713
714 /**
715 * Average framerate
716 */
717 AVRational avg_frame_rate;
6c6e6ef5 718
9a174562
AK
719 /*****************************************************************
720 * All fields below this line are not part of the public API. They
721 * may not be used outside of libavformat and can be changed and
722 * removed at will.
723 * New public fields should be added right above.
724 *****************************************************************
725 */
726
6c6e6ef5
MN
727 /**
728 * Number of frames that have been demuxed during av_find_stream_info()
729 */
730 int codec_info_nb_frames;
fd0368e7
AJ
731
732 /**
da9cea77 733 * Stream information used internally by av_find_stream_info()
fd0368e7
AJ
734 */
735#define MAX_STD_TIMEBASES (60*12+5)
736 struct {
737 int64_t last_dts;
738 int64_t duration_gcd;
739 int duration_count;
740 double duration_error[MAX_STD_TIMEBASES];
741 int64_t codec_info_duration;
38a4be3f 742 int nb_decoded_frames;
fd0368e7 743 } *info;
9a174562
AK
744#if !FF_API_REORDER_PRIVATE
745 const uint8_t *cur_ptr;
746 int cur_len;
747 AVPacket cur_pkt;
748
749 // Timestamp generation support:
750 /**
751 * Timestamp corresponding to the last dts sync point.
752 *
753 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
754 * a DTS is received from the underlying container. Otherwise set to
755 * AV_NOPTS_VALUE by default.
756 */
757 int64_t reference_dts;
758 int64_t first_dts;
759 int64_t cur_dts;
760 int last_IP_duration;
761 int64_t last_IP_pts;
762
763 /**
764 * Number of packets to buffer for codec probing
765 */
766#define MAX_PROBE_PACKETS 2500
767 int probe_packets;
768
769 /**
770 * last packet in packet_buffer for this stream when muxing.
771 */
772 struct AVPacketList *last_in_packet_buffer;
773 AVProbeData probe_data;
774#define MAX_REORDER_DELAY 16
775 int64_t pts_buffer[MAX_REORDER_DELAY+1];
776 /* av_read_frame() support */
777 enum AVStreamParseType need_parsing;
778 struct AVCodecParserContext *parser;
779
780 AVIndexEntry *index_entries; /**< Only used if the format does not
781 support seeking natively. */
782 int nb_index_entries;
783 unsigned int index_entries_allocated_size;
784
785 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
786#endif
de6d9b64
FB
787} AVStream;
788
15afa396
NS
789#define AV_PROGRAM_RUNNING 1
790
ba66ae94 791/**
ba66ae94 792 * New fields can be added to the end with minor version bumps.
8bfb108b 793 * Removal, reordering and changes to existing fields require a major
ba66ae94 794 * version bump.
8bfb108b 795 * sizeof(AVProgram) must not be used outside libav*.
ba66ae94 796 */
15afa396
NS
797typedef struct AVProgram {
798 int id;
15afa396
NS
799 int flags;
800 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
526efa10
NS
801 unsigned int *stream_index;
802 unsigned int nb_stream_indexes;
d2d67e42 803 AVDictionary *metadata;
15afa396
NS
804} AVProgram;
805
43d414ba 806#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
da24c5e3
FB
807 (streams are added dynamically) */
808
79d7836a 809typedef struct AVChapter {
4f57fa8c
DB
810 int id; ///< unique ID to identify the chapter
811 AVRational time_base; ///< time base in which the start/end timestamps are specified
8931e7b4 812 int64_t start, end; ///< chapter start/end time in time_base units
d2d67e42 813 AVDictionary *metadata;
79d7836a
AK
814} AVChapter;
815
252f17e2 816/**
4f57fa8c 817 * Format I/O context.
252f17e2 818 * New fields can be added to the end with minor version bumps.
8bfb108b 819 * Removal, reordering and changes to existing fields require a major
252f17e2 820 * version bump.
83daced0
AK
821 * sizeof(AVFormatContext) must not be used outside libav*, use
822 * avformat_alloc_context() to create an AVFormatContext.
252f17e2 823 */
de6d9b64 824typedef struct AVFormatContext {
83daced0
AK
825 /**
826 * A class for logging and AVOptions. Set by avformat_alloc_context().
827 * Exports (de)muxer private options if they exist.
828 */
829 const AVClass *av_class;
830
831 /**
832 * Can only be iformat or oformat, not both at the same time.
833 *
834 * decoding: set by avformat_open_input().
835 * encoding: set by the user.
836 */
b9a281db
FB
837 struct AVInputFormat *iformat;
838 struct AVOutputFormat *oformat;
83daced0
AK
839
840 /**
841 * Format private data. This is an AVOptions-enabled struct
842 * if and only if iformat/oformat.priv_class is not NULL.
843 */
de6d9b64 844 void *priv_data;
83daced0
AK
845
846 /*
847 * I/O context.
848 *
849 * decoding: either set by the user before avformat_open_input() (then
850 * the user must close it manually) or set by avformat_open_input().
851 * encoding: set by the user.
852 *
853 * Do NOT set this field if AVFMT_NOFILE flag is set in
854 * iformat/oformat.flags. In such a case, the (de)muxer will handle
855 * I/O in some other way and this field will be NULL.
856 */
ae628ec1 857 AVIOContext *pb;
83daced0
AK
858
859 /**
860 * A list of all streams in the file. New streams are created with
861 * avformat_new_stream().
862 *
863 * decoding: streams are created by libavformat in avformat_open_input().
864 * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
865 * appear in av_read_frame().
866 * encoding: streams are created by the user before avformat_write_header().
867 */
db69c2e5 868 unsigned int nb_streams;
38aab35f 869 AVStream **streams;
83daced0 870
43d414ba 871 char filename[1024]; /**< input or output filename */
de6d9b64 872 /* stream info */
5f847bf6
AK
873#if FF_API_TIMESTAMP
874 /**
875 * @deprecated use 'creation_time' metadata tag instead
876 */
877 attribute_deprecated int64_t timestamp;
878#endif
6a58e151 879
4f57fa8c 880 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
df968050 881#if FF_API_REORDER_PRIVATE
4f57fa8c 882 /* private data for pts handling (do not modify directly). */
76c56376
MN
883 /**
884 * This buffer is only needed when packets were already buffered but
885 * not decoded, for example to get the codec parameters in MPEG
886 * streams.
887 */
ee404803 888 struct AVPacketList *packet_buffer;
df968050 889#endif
ee404803 890
76c56376
MN
891 /**
892 * Decoding: position of the first frame of the component, in
893 * AV_TIME_BASE fractional seconds. NEVER set this value directly:
894 * It is deduced from the AVStream values.
895 */
115329f1 896 int64_t start_time;
76c56376
MN
897
898 /**
899 * Decoding: duration of the stream, in AV_TIME_BASE fractional
900 * seconds. Only set this value if you know none of the individual stream
da9cea77 901 * durations and also do not set any of them. This is deduced from the
76c56376
MN
902 * AVStream values if not set.
903 */
ee404803 904 int64_t duration;
76c56376 905
c10731e7 906#if FF_API_FILESIZE
76c56376
MN
907 /**
908 * decoding: total file size, 0 if unknown
909 */
c10731e7
AK
910 attribute_deprecated int64_t file_size;
911#endif
76c56376
MN
912
913 /**
914 * Decoding: total stream bitrate in bit/s, 0 if not
915 * available. Never set it directly if the file_size and the
6001dad6 916 * duration are known as Libav can compute it automatically.
76c56376 917 */
ee404803 918 int bit_rate;
fb2758c8 919
df968050 920#if FF_API_REORDER_PRIVATE
fb2758c8
FB
921 /* av_read_frame() support */
922 AVStream *cur_st;
fb2758c8 923
fb2758c8 924 /* av_seek_frame() support */
ec906fcd 925 int64_t data_offset; /**< offset of the first packet */
df968050 926#endif
115329f1 927
5a9ee315
AK
928#if FF_API_MUXRATE
929 /**
930 * use mpeg muxer private options instead
931 */
932 attribute_deprecated int mux_rate;
933#endif
92400be2 934 unsigned int packet_size;
f172132f
AK
935#if FF_API_PRELOAD
936 attribute_deprecated int preload;
937#endif
17c88cb0 938 int max_delay;
8108551a 939
d31e3f7c 940#if FF_API_LOOP_OUTPUT
115329f1
DB
941#define AVFMT_NOOUTPUTLOOP -1
942#define AVFMT_INFINITEOUTPUTLOOP 0
76c56376
MN
943 /**
944 * number of times to loop output in formats that support it
d31e3f7c
AK
945 *
946 * @deprecated use the 'loop' private option in the gif muxer.
76c56376 947 */
d31e3f7c
AK
948 attribute_deprecated int loop_output;
949#endif
115329f1 950
30bc6613 951 int flags;
22e77e44 952#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
4f57fa8c
DB
953#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
954#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
c55806e3 955#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
fe8344a2
MN
956#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
957#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
28734ac9
MS
958#if FF_API_FLAG_RTP_HINT
959#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
960#endif
05e84c95 961#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
73e8e8db 962#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
5894e1bb 963
6002fdef
AK
964#if FF_API_LOOP_INPUT
965 /**
966 * @deprecated, use the 'loop' img2 demuxer private option.
967 */
968 attribute_deprecated int loop_input;
969#endif
76c56376
MN
970
971 /**
972 * decoding: size of data to probe; encoding: unused.
973 */
9e6c9470 974 unsigned int probesize;
a44b3c4d
MN
975
976 /**
83daced0
AK
977 * decoding: maximum time (in AV_TIME_BASE units) during which the input should
978 * be analyzed in avformat_find_stream_info().
a44b3c4d
MN
979 */
980 int max_analyze_duration;
c964c2c7
RD
981
982 const uint8_t *key;
983 int keylen;
15afa396
NS
984
985 unsigned int nb_programs;
986 AVProgram **programs;
62600469
MN
987
988 /**
989 * Forced video codec_id.
4f57fa8c 990 * Demuxing: Set by user.
62600469
MN
991 */
992 enum CodecID video_codec_id;
76c56376 993
62600469
MN
994 /**
995 * Forced audio codec_id.
4f57fa8c 996 * Demuxing: Set by user.
62600469
MN
997 */
998 enum CodecID audio_codec_id;
76c56376 999
62600469
MN
1000 /**
1001 * Forced subtitle codec_id.
4f57fa8c 1002 * Demuxing: Set by user.
62600469
MN
1003 */
1004 enum CodecID subtitle_codec_id;
3dea63bd
PK
1005
1006 /**
22e77e44
DB
1007 * Maximum amount of memory in bytes to use for the index of each stream.
1008 * If the index exceeds this size, entries will be discarded as
3dea63bd
PK
1009 * needed to maintain a smaller size. This can lead to slower or less
1010 * accurate seeking (depends on demuxer).
4f57fa8c 1011 * Demuxers for which a full in-memory index is mandatory will ignore
3dea63bd
PK
1012 * this.
1013 * muxing : unused
1014 * demuxing: set by user
1015 */
1016 unsigned int max_index_size;
ab8ab30c
RP
1017
1018 /**
ffa71b2b 1019 * Maximum amount of memory in bytes to use for buffering frames
4f57fa8c 1020 * obtained from realtime capture devices.
ab8ab30c
RP
1021 */
1022 unsigned int max_picture_buffer;
79d7836a 1023
fbabf1e9 1024 unsigned int nb_chapters;
79d7836a 1025 AVChapter **chapters;
45b2b05f
MN
1026
1027 /**
4f57fa8c 1028 * Flags to enable debugging.
45b2b05f
MN
1029 */
1030 int debug;
1031#define FF_FDEBUG_TS 0x0001
0bef08e5 1032
df968050 1033#if FF_API_REORDER_PRIVATE
0bef08e5 1034 /**
4f57fa8c 1035 * Raw packets from the demuxer, prior to parsing and decoding.
0bef08e5
MN
1036 * This buffer is used for buffering packets until the codec can
1037 * be identified, as parsing cannot be done without knowing the
1038 * codec.
1039 */
1040 struct AVPacketList *raw_packet_buffer;
5c5b1731
MR
1041 struct AVPacketList *raw_packet_buffer_end;
1042
1043 struct AVPacketList *packet_buffer_end;
df968050 1044#endif
47146dfb 1045
d2d67e42 1046 AVDictionary *metadata;
af122d6a 1047
df968050 1048#if FF_API_REORDER_PRIVATE
af122d6a
BC
1049 /**
1050 * Remaining size available for raw_packet_buffer, in bytes.
1051 * NOT PART OF PUBLIC API
1052 */
48616887 1053#define RAW_PACKET_BUFFER_SIZE 2500000
af122d6a 1054 int raw_packet_buffer_remaining_size;
df968050 1055#endif
b8819c85
MS
1056
1057 /**
1058 * Start time of the stream in real world time, in microseconds
1059 * since the unix epoch (00:00 1st January 1970). That is, pts=0
1060 * in the stream was captured at this real world time.
1061 * - encoding: Set by user.
1062 * - decoding: Unused.
1063 */
1064 int64_t start_time_realtime;
30315a8d
AC
1065
1066 /**
1067 * decoding: number of frames used to probe fps
1068 */
1069 int fps_probe_size;
2f63440c
DB
1070
1071 /**
1072 * Error recognition; higher values will detect more errors but may
1073 * misdetect some more or less valid parts as errors.
1074 * - encoding: unused
1075 * - decoding: Set by user.
1076 */
1077 int error_recognition;
df968050 1078
6aa0b98f
MS
1079 /**
1080 * Custom interrupt callbacks for the I/O layer.
1081 *
1082 * decoding: set by the user before avformat_open_input().
1083 * encoding: set by the user before avformat_write_header()
1084 * (mainly useful for AVFMT_NOFILE formats). The callback
1085 * should also be passed to avio_open2() if it's used to
1086 * open the file.
1087 */
1088 AVIOInterruptCB interrupt_callback;
1089
df968050
AK
1090 /*****************************************************************
1091 * All fields below this line are not part of the public API. They
1092 * may not be used outside of libavformat and can be changed and
1093 * removed at will.
1094 * New public fields should be added right above.
1095 *****************************************************************
1096 */
1097#if !FF_API_REORDER_PRIVATE
1098 /**
1099 * Raw packets from the demuxer, prior to parsing and decoding.
1100 * This buffer is used for buffering packets until the codec can
1101 * be identified, as parsing cannot be done without knowing the
1102 * codec.
1103 */
1104 struct AVPacketList *raw_packet_buffer;
1105 struct AVPacketList *raw_packet_buffer_end;
1106 /**
1107 * Remaining size available for raw_packet_buffer, in bytes.
1108 */
1109#define RAW_PACKET_BUFFER_SIZE 2500000
1110 int raw_packet_buffer_remaining_size;
1111
1112 /**
1113 * This buffer is only needed when packets were already buffered but
1114 * not decoded, for example to get the codec parameters in MPEG
1115 * streams.
1116 */
1117 struct AVPacketList *packet_buffer;
1118 struct AVPacketList *packet_buffer_end;
1119
1120 /* av_read_frame() support */
1121 AVStream *cur_st;
1122
1123 /* av_seek_frame() support */
1124 int64_t data_offset; /**< offset of the first packet */
1125#endif
de6d9b64
FB
1126} AVFormatContext;
1127
1128typedef struct AVPacketList {
1129 AVPacket pkt;
1130 struct AVPacketList *next;
1131} AVPacketList;
1132
469c62d0
AK
1133
1134/**
1135 * @defgroup lavf_core Core functions
1136 * @ingroup libavf
1137 *
1138 * Functions for querying libavformat capabilities, allocating core structures,
1139 * etc.
1140 * @{
1141 */
1142
1143/**
1144 * Return the LIBAVFORMAT_VERSION_INT constant.
1145 */
1146unsigned avformat_version(void);
1147
1148/**
1149 * Return the libavformat build-time configuration.
1150 */
1151const char *avformat_configuration(void);
1152
1153/**
1154 * Return the libavformat license.
1155 */
1156const char *avformat_license(void);
1157
1158/**
1159 * Initialize libavformat and register all the muxers, demuxers and
1160 * protocols. If you do not call this function, then you can select
1161 * exactly which formats you want to support.
1162 *
1163 * @see av_register_input_format()
1164 * @see av_register_output_format()
1165 * @see av_register_protocol()
1166 */
1167void av_register_all(void);
1168
1169void av_register_input_format(AVInputFormat *format);
1170void av_register_output_format(AVOutputFormat *format);
1171
1172/**
1173 * Do global initialization of network components. This is optional,
1174 * but recommended, since it avoids the overhead of implicitly
1175 * doing the setup for each session.
1176 *
1177 * Calling this function will become mandatory if using network
1178 * protocols at some major version bump.
1179 */
1180int avformat_network_init(void);
1181
1182/**
1183 * Undo the initialization done by avformat_network_init.
1184 */
1185int avformat_network_deinit(void);
1186
aeedac95
SS
1187/**
1188 * If f is NULL, returns the first registered input format,
22e77e44 1189 * if f is non-NULL, returns the next registered input format after f
aeedac95
SS
1190 * or NULL if f is the last one.
1191 */
84be6e72 1192AVInputFormat *av_iformat_next(AVInputFormat *f);
aeedac95
SS
1193
1194/**
1195 * If f is NULL, returns the first registered output format,
22e77e44 1196 * if f is non-NULL, returns the next registered output format after f
aeedac95
SS
1197 * or NULL if f is the last one.
1198 */
84be6e72 1199AVOutputFormat *av_oformat_next(AVOutputFormat *f);
de6d9b64 1200
469c62d0
AK
1201/**
1202 * Allocate an AVFormatContext.
1203 * avformat_free_context() can be used to free the context and everything
1204 * allocated by the framework within it.
1205 */
1206AVFormatContext *avformat_alloc_context(void);
1207
1208/**
1209 * Free an AVFormatContext and all its streams.
1210 * @param s context to free
1211 */
1212void avformat_free_context(AVFormatContext *s);
1213
1214/**
1215 * Get the AVClass for AVFormatContext. It can be used in combination with
1216 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1217 *
1218 * @see av_opt_find().
1219 */
1220const AVClass *avformat_get_class(void);
1221
1222/**
1223 * Add a new stream to a media file.
1224 *
1225 * When demuxing, it is called by the demuxer in read_header(). If the
1226 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1227 * be called in read_packet().
1228 *
1229 * When muxing, should be called by the user before avformat_write_header().
1230 *
1231 * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1232 * will be initialized to use this codec. This is needed for e.g. codec-specific
1233 * defaults to be set, so codec should be provided if it is known.
1234 *
1235 * @return newly created stream or NULL on error.
1236 */
1237AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1238
1239AVProgram *av_new_program(AVFormatContext *s, int id);
1240
1241/**
1242 * @}
1243 */
1244
1245
a9bf9d8e
AK
1246#if FF_API_GUESS_IMG2_CODEC
1247attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1248#endif
290c5fa6 1249
c5704b2b
AK
1250#if FF_API_PKT_DUMP
1251attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
863c4716
MS
1252attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1253 int dump_payload);
17ca374c 1254#endif
750f0e1f 1255
7caf0cc6 1256
370f27de 1257/**
370f27de
AK
1258 * @addtogroup lavf_decoding
1259 * @{
1260 */
3217cb42
PI
1261
1262/**
49bd8e4b 1263 * Find AVInputFormat based on the short name of the input format.
3217cb42 1264 */
b9a281db 1265AVInputFormat *av_find_input_format(const char *short_name);
3217cb42
PI
1266
1267/**
49bd8e4b 1268 * Guess the file format.
3217cb42 1269 *
4f57fa8c
DB
1270 * @param is_opened Whether the file is already opened; determines whether
1271 * demuxers with or without AVFMT_NOFILE are probed.
3217cb42 1272 */
94988531 1273AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
3217cb42
PI
1274
1275/**
49bd8e4b 1276 * Guess the file format.
8e2ee182
RD
1277 *
1278 * @param is_opened Whether the file is already opened; determines whether
1279 * demuxers with or without AVFMT_NOFILE are probed.
c99d506b
RD
1280 * @param score_max A probe score larger that this is required to accept a
1281 * detection, the variable is set to the actual detection
1282 * score afterwards.
1283 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
8e2ee182
RD
1284 * to retry with a larger probe buffer.
1285 */
1286AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1287
1288/**
3940caad
AH
1289 * Probe a bytestream to determine the input format. Each time a probe returns
1290 * with a score that is too low, the probe buffer size is increased and another
1291 * attempt is made. When the maximum probe size is reached, the input format
1292 * with the highest score is returned.
1293 *
1294 * @param pb the bytestream to probe
1295 * @param fmt the input format is put here
1296 * @param filename the filename of the stream
1297 * @param logctx the log context
1298 * @param offset the offset within the bytestream to probe from
1299 * @param max_probe_size the maximum probe buffer size (zero for default)
1300 * @return 0 in case of success, a negative value corresponding to an
1301 * AVERROR code otherwise
1302 */
ae628ec1 1303int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
3940caad
AH
1304 const char *filename, void *logctx,
1305 unsigned int offset, unsigned int max_probe_size);
1306
603b8bc2 1307#if FF_API_FORMAT_PARAMETERS
3940caad 1308/**
49bd8e4b 1309 * Allocate all the structures needed to read an input stream.
3217cb42 1310 * This does not open the needed codecs for decoding the stream[s].
603b8bc2 1311 * @deprecated use avformat_open_input instead.
3217cb42 1312 */
603b8bc2 1313attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
ae628ec1 1314 AVIOContext *pb, const char *filename,
da24c5e3 1315 AVInputFormat *fmt, AVFormatParameters *ap);
3217cb42
PI
1316
1317/**
49bd8e4b 1318 * Open a media file as input. The codecs are not opened. Only the file
3217cb42
PI
1319 * header (if present) is read.
1320 *
4f57fa8c
DB
1321 * @param ic_ptr The opened media file handle is put here.
1322 * @param filename filename to open
1323 * @param fmt If non-NULL, force the file format to use.
3217cb42 1324 * @param buf_size optional buffer size (zero if default is OK)
78cb7273
DB
1325 * @param ap Additional parameters needed when opening the file
1326 * (NULL if default).
4f57fa8c 1327 * @return 0 if OK, AVERROR_xxx otherwise
603b8bc2
AK
1328 *
1329 * @deprecated use avformat_open_input instead.
3217cb42 1330 */
603b8bc2 1331attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
b9a281db
FB
1332 AVInputFormat *fmt,
1333 int buf_size,
1334 AVFormatParameters *ap);
603b8bc2 1335#endif
88a28965 1336
88808c60 1337/**
05e84c95
AK
1338 * Open an input stream and read the header. The codecs are not opened.
1339 * The stream must be closed with av_close_input_file().
1340 *
1341 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1342 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1343 * function and written into ps.
1344 * Note that a user-supplied AVFormatContext will be freed on failure.
1345 * @param filename Name of the stream to open.
1346 * @param fmt If non-NULL, this parameter forces a specific input format.
1347 * Otherwise the format is autodetected.
1348 * @param options A dictionary filled with AVFormatContext and demuxer-private options.
1349 * On return this parameter will be destroyed and replaced with a dict containing
1350 * options that were not found. May be NULL.
1351 *
1352 * @return 0 on success, a negative AVERROR on failure.
1353 *
1354 * @note If you want to use custom IO, preallocate the format context and set its pb field.
1355 */
1356int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1357
a67c061e 1358#if FF_API_FORMAT_PARAMETERS
3217cb42 1359/**
49bd8e4b 1360 * Read packets of a media file to get stream information. This
3217cb42 1361 * is useful for file formats with no headers such as MPEG. This
22e77e44 1362 * function also computes the real framerate in case of MPEG-2 repeat
3217cb42
PI
1363 * frame mode.
1364 * The logical file position is not changed by this function;
1365 * examined packets may be buffered for later processing.
1366 *
1367 * @param ic media file handle
4f57fa8c
DB
1368 * @return >=0 if OK, AVERROR_xxx on error
1369 * @todo Let the user decide somehow what information is needed so that
1370 * we do not waste time getting stuff the user does not need.
a67c061e
AK
1371 *
1372 * @deprecated use avformat_find_stream_info.
3217cb42 1373 */
3c7fa664 1374attribute_deprecated
b9a281db 1375int av_find_stream_info(AVFormatContext *ic);
a67c061e
AK
1376#endif
1377
1378/**
1379 * Read packets of a media file to get stream information. This
1380 * is useful for file formats with no headers such as MPEG. This
1381 * function also computes the real framerate in case of MPEG-2 repeat
1382 * frame mode.
1383 * The logical file position is not changed by this function;
1384 * examined packets may be buffered for later processing.
1385 *
1386 * @param ic media file handle
1387 * @param options If non-NULL, an ic.nb_streams long array of pointers to
1388 * dictionaries, where i-th member contains options for
1389 * codec corresponding to i-th stream.
1390 * On return each dictionary will be filled with options that were not found.
1391 * @return >=0 if OK, AVERROR_xxx on error
1392 *
1393 * @note this function isn't guaranteed to open all the codecs, so
1394 * options being non-empty at return is a perfectly normal behavior.
1395 *
1396 * @todo Let the user decide somehow what information is needed so that
1397 * we do not waste time getting stuff the user does not need.
1398 */
1399int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
3217cb42
PI
1400
1401/**
9128ae08
NG
1402 * Find the "best" stream in the file.
1403 * The best stream is determined according to various heuristics as the most
1404 * likely to be what the user expects.
1405 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1406 * default decoder for the stream's codec; streams for which no decoder can
1407 * be found are ignored.
1408 *
1409 * @param ic media file handle
1410 * @param type stream type: video, audio, subtitles, etc.
1411 * @param wanted_stream_nb user-requested stream number,
1412 * or -1 for automatic selection
1413 * @param related_stream try to find a stream related (eg. in the same
1414 * program) to this one, or -1 if none
1415 * @param decoder_ret if non-NULL, returns the decoder for the
1416 * selected stream
1417 * @param flags flags; none are currently defined
1418 * @return the non-negative stream number in case of success,
1419 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1420 * could be found,
1421 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1422 * @note If av_find_best_stream returns successfully and decoder_ret is not
1423 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1424 */
1425int av_find_best_stream(AVFormatContext *ic,
1426 enum AVMediaType type,
1427 int wanted_stream_nb,
1428 int related_stream,
1429 AVCodec **decoder_ret,
1430 int flags);
1431
1432/**
49bd8e4b 1433 * Read a transport packet from a media file.
3217cb42 1434 *
864ff8c1 1435 * This function is obsolete and should never be used.
3217cb42
PI
1436 * Use av_read_frame() instead.
1437 *
1438 * @param s media file handle
1439 * @param pkt is filled
4f57fa8c 1440 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1441 */
de6d9b64 1442int av_read_packet(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1443
1444/**
49bd8e4b 1445 * Return the next frame of a stream.
4faf628f
MN
1446 * This function returns what is stored in the file, and does not validate
1447 * that what is there are valid frames for the decoder. It will split what is
1448 * stored in the file into frames and return one for each call. It will not
1449 * omit invalid data between valid frames so as to give the decoder the maximum
1450 * information possible for decoding.
3217cb42
PI
1451 *
1452 * The returned packet is valid
1453 * until the next av_read_frame() or until av_close_input_file() and
1454 * must be freed with av_free_packet. For video, the packet contains
1455 * exactly one frame. For audio, it contains an integer number of
1456 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1457 * data). If the audio frames have a variable size (e.g. MPEG audio),
1458 * then it contains one frame.
1459 *
1460 * pkt->pts, pkt->dts and pkt->duration are always set to correct
22e77e44 1461 * values in AVStream.time_base units (and guessed if the format cannot
4f57fa8c
DB
1462 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1463 * has B-frames, so it is better to rely on pkt->dts if you do not
3217cb42
PI
1464 * decompress the payload.
1465 *
4f57fa8c 1466 * @return 0 if OK, < 0 on error or end of file
3217cb42 1467 */
fb2758c8 1468int av_read_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1469
1470/**
49bd8e4b 1471 * Seek to the keyframe at timestamp.
3217cb42
PI
1472 * 'timestamp' in 'stream_index'.
1473 * @param stream_index If stream_index is (-1), a default
1474 * stream is selected, and timestamp is automatically converted
1475 * from AV_TIME_BASE units to the stream specific time_base.
4f57fa8c
DB
1476 * @param timestamp Timestamp in AVStream.time_base units
1477 * or, if no stream is specified, in AV_TIME_BASE units.
3217cb42
PI
1478 * @param flags flags which select direction and seeking mode
1479 * @return >= 0 on success
1480 */
78cb7273
DB
1481int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1482 int flags);
3217cb42
PI
1483
1484/**
49bd8e4b 1485 * Seek to timestamp ts.
d04768fa
MN
1486 * Seeking will be done so that the point from which all active streams
1487 * can be presented successfully will be closest to ts and within min/max_ts.
1488 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1489 *
22e77e44 1490 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
d04768fa 1491 * are the file position (this may not be supported by all demuxers).
22e77e44 1492 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
d04768fa 1493 * in the stream with stream_index (this may not be supported by all demuxers).
22e77e44
DB
1494 * Otherwise all timestamps are in units of the stream selected by stream_index
1495 * or if stream_index is -1, in AV_TIME_BASE units.
1496 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
d04768fa
MN
1497 * keyframes (this may not be supported by all demuxers).
1498 *
22e77e44 1499 * @param stream_index index of the stream which is used as time base reference
d04768fa
MN
1500 * @param min_ts smallest acceptable timestamp
1501 * @param ts target timestamp
1502 * @param max_ts largest acceptable timestamp
1503 * @param flags flags
32e543f8 1504 * @return >=0 on success, error code otherwise
998b6f7c 1505 *
8a4d7a30 1506 * @note This is part of the new seek API which is still under construction.
22e77e44
DB
1507 * Thus do not use this yet. It may change at any time, do not expect
1508 * ABI compatibility yet!
d04768fa
MN
1509 */
1510int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1511
1512/**
49bd8e4b 1513 * Start playing a network-based stream (e.g. RTSP stream) at the
4f57fa8c 1514 * current position.
3217cb42 1515 */
fb2758c8 1516int av_read_play(AVFormatContext *s);
3217cb42
PI
1517
1518/**
49bd8e4b 1519 * Pause a network-based stream (e.g. RTSP stream).
3217cb42
PI
1520 *
1521 * Use av_read_play() to resume it.
1522 */
fb2758c8 1523int av_read_pause(AVFormatContext *s);
3217cb42
PI
1524
1525/**
49bd8e4b 1526 * Free a AVFormatContext allocated by av_open_input_stream.
2506fd54
RD
1527 * @param s context to free
1528 */
1529void av_close_input_stream(AVFormatContext *s);
1530
1531/**
49bd8e4b 1532 * Close a media file (but not its codecs).
3217cb42
PI
1533 *
1534 * @param s media file handle
1535 */
de6d9b64 1536void av_close_input_file(AVFormatContext *s);
370f27de
AK
1537/**
1538 * @}
1539 */
3217cb42 1540
569129a6 1541#if FF_API_NEW_STREAM
f124b087 1542/**
49bd8e4b 1543 * Add a new stream to a media file.
3217cb42
PI
1544 *
1545 * Can only be called in the read_header() function. If the flag
1546 * AVFMTCTX_NOHEADER is in the format context, then new streams
1547 * can be added in read_packet too.
1548 *
1549 * @param s media file handle
4f57fa8c 1550 * @param id file-format-dependent stream ID
3217cb42 1551 */
569129a6 1552attribute_deprecated
b9a281db 1553AVStream *av_new_stream(AVFormatContext *s, int id);
569129a6
AK
1554#endif
1555
c3f9ebf7 1556#if FF_API_SET_PTS_INFO
3217cb42 1557/**
c3f9ebf7 1558 * @deprecated this function is not supposed to be called outside of lavf
3217cb42 1559 */
c3f9ebf7 1560attribute_deprecated
9ee91c2f 1561void av_set_pts_info(AVStream *s, int pts_wrap_bits,
dec14949 1562 unsigned int pts_num, unsigned int pts_den);
c3f9ebf7 1563#endif
de6d9b64 1564
3ba1438d
MN
1565#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1566#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
4f57fa8c 1567#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
2bf74f49 1568#define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
3ba1438d 1569
a2faa951
AK
1570#if FF_API_SEEK_PUBLIC
1571attribute_deprecated
78cb7273
DB
1572int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1573 int64_t target_ts, int flags);
a2faa951 1574attribute_deprecated
22ffac70 1575void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
a2faa951 1576attribute_deprecated
78cb7273
DB
1577int64_t av_gen_search(AVFormatContext *s, int stream_index,
1578 int64_t target_ts, int64_t pos_min,
1579 int64_t pos_max, int64_t pos_limit,
1580 int64_t ts_min, int64_t ts_max,
1581 int flags, int64_t *ts_ret,
1582 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
a2faa951 1583#endif
b754978a 1584
25de5958
AK
1585#if FF_API_FORMAT_PARAMETERS
1586/**
1587 * @deprecated pass the options to avformat_write_header directly.
1588 */
1589attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1590#endif
3217cb42
PI
1591
1592/**
489a7b07
AK
1593 * @addtogroup lavf_encoding
1594 * @{
1595 */
f3bfe388 1596/**
25de5958
AK
1597 * Allocate the stream private data and write the stream header to
1598 * an output media file.
1599 *
1600 * @param s Media file handle, must be allocated with avformat_alloc_context().
1601 * Its oformat field must be set to the desired output format;
1602 * Its pb field must be set to an already openened AVIOContext.
1603 * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
1604 * On return this parameter will be destroyed and replaced with a dict containing
1605 * options that were not found. May be NULL.
1606 *
1607 * @return 0 on success, negative AVERROR on failure.
1608 *
1609 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1610 */
1611int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1612
1613#if FF_API_FORMAT_PARAMETERS
1614/**
49bd8e4b 1615 * Allocate the stream private data and write the stream header to an
755bfeab 1616 * output media file.
5d820db2
RD
1617 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1618 * but for some formats it might also be some other time base
3217cb42
PI
1619 *
1620 * @param s media file handle
4f57fa8c 1621 * @return 0 if OK, AVERROR_xxx on error
25de5958
AK
1622 *
1623 * @deprecated use avformat_write_header.
3217cb42 1624 */
25de5958
AK
1625attribute_deprecated int av_write_header(AVFormatContext *s);
1626#endif
3217cb42
PI
1627
1628/**
49bd8e4b 1629 * Write a packet to an output media file.
3217cb42
PI
1630 *
1631 * The packet shall contain one audio or video frame.
78cb7273
DB
1632 * The packet must be correctly interleaved according to the container
1633 * specification, if not then av_interleaved_write_frame must be used.
3217cb42
PI
1634 *
1635 * @param s media file handle
78cb7273
DB
1636 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1637 dts/pts, ...
4f57fa8c 1638 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1639 */
e928649b 1640int av_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1641
1642/**
49bd8e4b 1643 * Write a packet to an output media file ensuring correct interleaving.
3217cb42
PI
1644 *
1645 * The packet must contain one audio or video frame.
22e77e44 1646 * If the packets are already correctly interleaved, the application should
90b5b51e
DB
1647 * call av_write_frame() instead as it is slightly faster. It is also important
1648 * to keep in mind that completely non-interleaved input will need huge amounts
1649 * of memory to interleave with this, so it is preferable to interleave at the
1650 * demuxer level.
3217cb42
PI
1651 *
1652 * @param s media file handle
78cb7273
DB
1653 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1654 dts/pts, ...
4f57fa8c 1655 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1656 */
3c895fc0 1657int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1658
1659/**
49bd8e4b 1660 * Interleave a packet per dts in an output media file.
3217cb42 1661 *
78cb7273 1662 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
22e77e44 1663 * function, so they cannot be used after it. Note that calling av_free_packet()
78cb7273 1664 * on them is still safe.
3217cb42
PI
1665 *
1666 * @param s media file handle
1667 * @param out the interleaved packet will be output here
9a58234f 1668 * @param pkt the input packet
3217cb42
PI
1669 * @param flush 1 if no further packets are available as input and all
1670 * remaining packets should be output
1671 * @return 1 if a packet was output, 0 if no packet could be output,
d9526386 1672 * < 0 if an error occurred
3217cb42 1673 */
78cb7273
DB
1674int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1675 AVPacket *pkt, int flush);
e928649b 1676
3217cb42 1677/**
49bd8e4b 1678 * Write the stream trailer to an output media file and free the
2b75bde6 1679 * file private data.
3217cb42 1680 *
dc76fe13
RD
1681 * May only be called after a successful call to av_write_header.
1682 *
3217cb42 1683 * @param s media file handle
4f57fa8c 1684 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1685 */
b9a281db 1686int av_write_trailer(AVFormatContext *s);
c8dffc02
AK
1687
1688/**
1689 * Return the output format in the list of registered output formats
1690 * which best matches the provided parameters, or return NULL if
1691 * there is no match.
1692 *
1693 * @param short_name if non-NULL checks if short_name matches with the
1694 * names of the registered formats
1695 * @param filename if non-NULL checks if filename terminates with the
1696 * extensions of the registered formats
1697 * @param mime_type if non-NULL checks if mime_type matches with the
1698 * MIME type of the registered formats
1699 */
1700AVOutputFormat *av_guess_format(const char *short_name,
1701 const char *filename,
1702 const char *mime_type);
1703
1704/**
1705 * Guess the codec ID based upon muxer and filename.
1706 */
1707enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1708 const char *filename, const char *mime_type,
1709 enum AVMediaType type);
1710
489a7b07
AK
1711/**
1712 * @}
1713 */
de6d9b64 1714
abf2c2d7
AK
1715
1716/**
1717 * @defgroup lavf_misc Utility functions
1718 * @ingroup libavf
1719 * @{
1720 *
1721 * Miscelaneous utility functions related to both muxing and demuxing
1722 * (or neither).
1723 */
1724
1725/**
1726 * Send a nice hexadecimal dump of a buffer to the specified file stream.
1727 *
1728 * @param f The file stream pointer where the dump should be sent to.
1729 * @param buf buffer
1730 * @param size buffer size
1731 *
1732 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
1733 */
1734void av_hex_dump(FILE *f, uint8_t *buf, int size);
1735
1736/**
1737 * Send a nice hexadecimal dump of a buffer to the log.
1738 *
1739 * @param avcl A pointer to an arbitrary struct of which the first field is a
1740 * pointer to an AVClass struct.
1741 * @param level The importance level of the message, lower values signifying
1742 * higher importance.
1743 * @param buf buffer
1744 * @param size buffer size
1745 *
1746 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
1747 */
1748void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1749
1750/**
1751 * Send a nice dump of a packet to the specified file stream.
1752 *
1753 * @param f The file stream pointer where the dump should be sent to.
1754 * @param pkt packet to dump
1755 * @param dump_payload True if the payload must be displayed, too.
1756 * @param st AVStream that the packet belongs to
1757 */
1758void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1759
1760
1761/**
1762 * Send a nice dump of a packet to the log.
1763 *
1764 * @param avcl A pointer to an arbitrary struct of which the first field is a
1765 * pointer to an AVClass struct.
1766 * @param level The importance level of the message, lower values signifying
1767 * higher importance.
1768 * @param pkt packet to dump
1769 * @param dump_payload True if the payload must be displayed, too.
1770 * @param st AVStream that the packet belongs to
1771 */
1772void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1773 AVStream *st);
1774
1775/**
1776 * Get the CodecID for the given codec tag tag.
1777 * If no codec id is found returns CODEC_ID_NONE.
1778 *
1779 * @param tags list of supported codec_id-codec_tag pairs, as stored
1780 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1781 */
1782enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1783
1784/**
1785 * Get the codec tag for the given codec id id.
1786 * If no codec tag is found returns 0.
1787 *
1788 * @param tags list of supported codec_id-codec_tag pairs, as stored
1789 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1790 */
1791unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1792
1793int av_find_default_stream_index(AVFormatContext *s);
1794
1795/**
1796 * Get the index for a specific timestamp.
1797 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1798 * to the timestamp which is <= the requested one, if backward
1799 * is 0, then it will be >=
1800 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1801 * @return < 0 if no such timestamp could be found
1802 */
1803int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1804
1805/**
1806 * Add an index entry into a sorted list. Update the entry if the list
1807 * already contains it.
1808 *
1809 * @param timestamp timestamp in the time base of the given stream
1810 */
1811int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1812 int size, int distance, int flags);
1813
1814
1815/**
1816 * Split a URL string into components.
1817 *
1818 * The pointers to buffers for storing individual components may be null,
1819 * in order to ignore that component. Buffers for components not found are
1820 * set to empty strings. If the port is not found, it is set to a negative
1821 * value.
1822 *
1823 * @param proto the buffer for the protocol
1824 * @param proto_size the size of the proto buffer
1825 * @param authorization the buffer for the authorization
1826 * @param authorization_size the size of the authorization buffer
1827 * @param hostname the buffer for the host name
1828 * @param hostname_size the size of the hostname buffer
1829 * @param port_ptr a pointer to store the port number in
1830 * @param path the buffer for the path
1831 * @param path_size the size of the path buffer
1832 * @param url the URL to split
1833 */
1834void av_url_split(char *proto, int proto_size,
1835 char *authorization, int authorization_size,
1836 char *hostname, int hostname_size,
1837 int *port_ptr,
1838 char *path, int path_size,
1839 const char *url);
1840
610219a5
AK
1841#if FF_API_DUMP_FORMAT
1842attribute_deprecated void dump_format(AVFormatContext *ic,
1843 int index,
1844 const char *url,
1845 int is_output);
1846#endif
1847
1848void av_dump_format(AVFormatContext *ic,
1849 int index,
1850 const char *url,
1851 int is_output);
3217cb42 1852
f6c7375a 1853#if FF_API_PARSE_DATE
3217cb42 1854/**
49bd8e4b 1855 * Parse datestr and return a corresponding number of microseconds.
f6c7375a 1856 *
f9436161 1857 * @param datestr String representing a date or a duration.
f6c7375a
SS
1858 * See av_parse_time() for the syntax of the provided string.
1859 * @deprecated in favor of av_parse_time()
3217cb42 1860 */
f6c7375a 1861attribute_deprecated
0c1a9eda 1862int64_t parse_date(const char *datestr, int duration);
f6c7375a 1863#endif
de6d9b64 1864
76c56376
MN
1865/**
1866 * Get the current time in microseconds.
1867 */
0c1a9eda 1868int64_t av_gettime(void);
94988531 1869
ab0287fc 1870#if FF_API_FIND_INFO_TAG
3217cb42 1871/**
ab0287fc 1872 * @deprecated use av_find_info_tag in libavutil instead.
3217cb42 1873 */
ab0287fc
AK
1874attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1875#endif
de6d9b64 1876
3217cb42 1877/**
49bd8e4b 1878 * Return in 'buf' the path with '%d' replaced by a number.
4f57fa8c 1879 *
3217cb42
PI
1880 * Also handles the '%0nd' format where 'n' is the total number
1881 * of digits and '%%'.
1882 *
1883 * @param buf destination buffer
1884 * @param buf_size destination buffer size
1885 * @param path numbered sequence string
8ea0e802 1886 * @param number frame number
4f57fa8c 1887 * @return 0 if OK, -1 on format error
3217cb42 1888 */
5c07cf53
MB
1889int av_get_frame_filename(char *buf, int buf_size,
1890 const char *path, int number);
3217cb42
PI
1891
1892/**
49bd8e4b 1893 * Check whether filename actually is a numbered sequence generator.
3217cb42
PI
1894 *
1895 * @param filename possible numbered sequence string
4f57fa8c 1896 * @return 1 if a valid numbered sequence string, 0 otherwise
3217cb42 1897 */
5c07cf53 1898int av_filename_number_test(const char *filename);
96baaa6a 1899
c5388c07 1900/**
49bd8e4b 1901 * Generate an SDP for an RTP session.
c5388c07
LA
1902 *
1903 * @param ac array of AVFormatContexts describing the RTP streams. If the
1904 * array is composed by only one context, such context can contain
1905 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1906 * all the contexts in the array (an AVCodecContext per RTP stream)
4f57fa8c 1907 * must contain only one AVStream.
8767b80f 1908 * @param n_files number of AVCodecContexts contained in ac
c234d40b
AK
1909 * @param buf buffer where the SDP will be stored (must be allocated by
1910 * the caller)
8767b80f 1911 * @param size the size of the buffer
4f57fa8c 1912 * @return 0 if OK, AVERROR_xxx on error
c5388c07 1913 */
c234d40b 1914int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
c3675dfe
AK
1915
1916#if FF_API_SDP_CREATE
1917attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1918#endif
c5388c07 1919
1a70d127 1920/**
49bd8e4b 1921 * Return a positive value if the given filename has one of the given
1a70d127
SS
1922 * extensions, 0 otherwise.
1923 *
1924 * @param extensions a comma-separated list of filename extensions
1925 */
1926int av_match_ext(const char *filename, const char *extensions);
1927
48f9e457
AK
1928/**
1929 * Test if the given container can store a codec.
1930 *
1931 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1932 *
1933 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1934 * A negative number if this information is not available.
1935 */
1936int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1937
abf2c2d7
AK
1938/**
1939 * @}
1940 */
1941
98790382 1942#endif /* AVFORMAT_AVFORMAT_H */