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