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