lavf doxy: expand/reword metadata API doxy.
[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
FB
325
326typedef struct AVOutputFormat {
de6d9b64 327 const char *name;
bde15e74
SS
328 /**
329 * Descriptive name for the format, meant to be more human-readable
819174fa 330 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
331 * to define it.
332 */
de6d9b64
FB
333 const char *long_name;
334 const char *mime_type;
4f57fa8c 335 const char *extensions; /**< comma-separated filename extensions */
76c56376
MN
336 /**
337 * size of private data so that it can be allocated in the wrapper
338 */
b9a281db 339 int priv_data_size;
de6d9b64 340 /* output support */
43d414ba
PI
341 enum CodecID audio_codec; /**< default audio codec */
342 enum CodecID video_codec; /**< default video codec */
de6d9b64 343 int (*write_header)(struct AVFormatContext *);
e928649b 344 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
de6d9b64 345 int (*write_trailer)(struct AVFormatContext *);
76c56376 346 /**
89e568fe
AH
347 * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
348 * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
349 * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
76c56376 350 */
b9a281db 351 int flags;
76c56376
MN
352 /**
353 * Currently only used to set pixel format if not YUV420P.
354 */
290c5fa6 355 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
78cb7273
DB
356 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
357 AVPacket *in, int flush);
7caf0cc6
MN
358
359 /**
78cb7273 360 * List of supported codec_id-codec_tag pairs, ordered by "better
22e77e44 361 * choice first". The arrays are all terminated by CODEC_ID_NONE.
7caf0cc6 362 */
c1854592 363 const struct AVCodecTag * const *codec_tag;
7caf0cc6 364
11bf3847
AJ
365 enum CodecID subtitle_codec; /**< default subtitle codec */
366
451d566f 367#if FF_API_OLD_METADATA2
719e721a 368 const AVMetadataConv *metadata_conv;
03700d39 369#endif
f610a9f2 370
cf99e4aa
AH
371 const AVClass *priv_class; ///< AVClass for the private context
372
48f9e457
AK
373 /**
374 * Test if the given codec can be stored in this container.
375 *
376 * @return 1 if the codec is supported, 0 if it is not.
377 * A negative number if unknown.
378 */
379 int (*query_codec)(enum CodecID id, int std_compliance);
380
b9a281db
FB
381 /* private fields */
382 struct AVOutputFormat *next;
383} AVOutputFormat;
de6d9b64 384
b9a281db 385typedef struct AVInputFormat {
76c56376
MN
386 /**
387 * A comma separated list of short names for the format. New names
ac3ccbc0
AC
388 * may be appended with a minor bump.
389 */
b9a281db 390 const char *name;
76c56376 391
bde15e74
SS
392 /**
393 * Descriptive name for the format, meant to be more human-readable
819174fa 394 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
395 * to define it.
396 */
b9a281db 397 const char *long_name;
76c56376
MN
398
399 /**
400 * Size of private data so that it can be allocated in the wrapper.
401 */
b9a281db 402 int priv_data_size;
76c56376 403
65d7d68b 404 /**
22e77e44 405 * Tell if a given file has a chance of being parsed as this format.
5d81d641
DB
406 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
407 * big so you do not have to check for that unless you need more.
65d7d68b 408 */
b9a281db 409 int (*read_probe)(AVProbeData *);
76c56376
MN
410
411 /**
412 * Read the format header and initialize the AVFormatContext
413 * structure. Return 0 if OK. 'ap' if non-NULL contains
414 * additional parameters. Only used in raw format right
415 * now. 'av_new_stream' should be called to create new streams.
416 */
de6d9b64
FB
417 int (*read_header)(struct AVFormatContext *,
418 AVFormatParameters *ap);
76c56376
MN
419
420 /**
421 * Read one packet and put it in 'pkt'. pts and flags are also
422 * set. 'av_new_stream' can be called only if the flag
2899a28c
AJ
423 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
424 * background thread).
76c56376
MN
425 * @return 0 on success, < 0 on error.
426 * When returning an error, pkt must not have been allocated
427 * or must be freed before returning
428 */
de6d9b64 429 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
76c56376
MN
430
431 /**
432 * Close the stream. The AVFormatContext and AVStreams are not
433 * freed by this function
434 */
de6d9b64 435 int (*read_close)(struct AVFormatContext *);
1de2db8f 436
634e0304 437#if FF_API_READ_SEEK
115329f1 438 /**
4f57fa8c
DB
439 * Seek to a given timestamp relative to the frames in
440 * stream component stream_index.
22e77e44
DB
441 * @param stream_index Must not be -1.
442 * @param flags Selects which direction should be preferred if no exact
443 * match is available.
05ce0f11 444 * @return >= 0 on success (but not necessarily the new offset)
3ba1438d 445 */
a15c7fd6
AK
446 attribute_deprecated int (*read_seek)(struct AVFormatContext *,
447 int stream_index, int64_t timestamp, int flags);
1de2db8f 448#endif
8d14a25c 449 /**
4f57fa8c 450 * Gets the next timestamp in stream[stream_index].time_base units.
d9526386 451 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
8d14a25c
MN
452 */
453 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
454 int64_t *pos, int64_t pos_limit);
76c56376
MN
455
456 /**
050e20ae
JR
457 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
458 * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
b631fba9 459 * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
76c56376 460 */
de6d9b64 461 int flags;
76c56376
MN
462
463 /**
464 * If extensions are defined, then no probe is done. You should
465 * usually not use extension format guessing because it is not
466 * reliable enough
467 */
b9a281db 468 const char *extensions;
76c56376
MN
469
470 /**
471 * General purpose read-only value that the format can use.
472 */
b9a281db 473 int value;
fb2758c8 474
76c56376
MN
475 /**
476 * Start/resume playing - only meaningful if using a network-based format
477 * (RTSP).
478 */
fb2758c8
FB
479 int (*read_play)(struct AVFormatContext *);
480
76c56376
MN
481 /**
482 * Pause playing - only meaningful if using a network-based format
483 * (RTSP).
484 */
fb2758c8
FB
485 int (*read_pause)(struct AVFormatContext *);
486
c1854592 487 const struct AVCodecTag * const *codec_tag;
7caf0cc6 488
1de2db8f 489 /**
49bd8e4b 490 * Seek to timestamp ts.
1de2db8f
MN
491 * Seeking will be done so that the point from which all active streams
492 * can be presented successfully will be closest to ts and within min/max_ts.
493 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
494 */
882fb0a3 495 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1de2db8f 496
451d566f 497#if FF_API_OLD_METADATA2
719e721a 498 const AVMetadataConv *metadata_conv;
03700d39 499#endif
f610a9f2 500
5dc82144
AK
501 const AVClass *priv_class; ///< AVClass for the private context
502
b9a281db
FB
503 /* private fields */
504 struct AVInputFormat *next;
505} AVInputFormat;
de6d9b64 506
57004ff1
AJ
507enum AVStreamParseType {
508 AVSTREAM_PARSE_NONE,
509 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
4f57fa8c 510 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
78cb7273 511 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
74a6df59 512 AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
57004ff1
AJ
513};
514
fb2758c8
FB
515typedef struct AVIndexEntry {
516 int64_t pos;
517 int64_t timestamp;
518#define AVINDEX_KEYFRAME 0x0001
30a43f2d 519 int flags:2;
4f57fa8c
DB
520 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).
521 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
fb2758c8
FB
522} AVIndexEntry;
523
90c2295b
ES
524#define AV_DISPOSITION_DEFAULT 0x0001
525#define AV_DISPOSITION_DUB 0x0002
526#define AV_DISPOSITION_ORIGINAL 0x0004
527#define AV_DISPOSITION_COMMENT 0x0008
528#define AV_DISPOSITION_LYRICS 0x0010
529#define AV_DISPOSITION_KARAOKE 0x0020
76c56376
MN
530
531/**
532 * Track should be used during playback by default.
533 * Useful for subtitle track that should be displayed
534 * even when user did not explicitly ask for subtitles.
535 */
7a617a86 536#define AV_DISPOSITION_FORCED 0x0040
12c14cd4
PR
537#define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
538#define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
24a83bd1 539#define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
90c2295b 540
ba66ae94
MN
541/**
542 * Stream structure.
543 * New fields can be added to the end with minor version bumps.
8bfb108b 544 * Removal, reordering and changes to existing fields require a major
ba66ae94 545 * version bump.
8bfb108b 546 * sizeof(AVStream) must not be used outside libav*.
ba66ae94 547 */
de6d9b64 548typedef struct AVStream {
43d414ba 549 int index; /**< stream index in AVFormatContext */
4f57fa8c 550 int id; /**< format-specific stream ID */
43d414ba 551 AVCodecContext *codec; /**< codec context */
b4b87d48 552 /**
22e77e44
DB
553 * Real base framerate of the stream.
554 * This is the lowest framerate with which all timestamps can be
864ff8c1 555 * represented accurately (it is the least common multiple of all
22e77e44
DB
556 * framerates in the stream). Note, this value is just a guess!
557 * For example, if the time base is 1/90000 and all frames have either
4f57fa8c 558 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
b4b87d48
MN
559 */
560 AVRational r_frame_rate;
de6d9b64 561 void *priv_data;
82583548 562
9a174562 563#if FF_API_REORDER_PRIVATE
b9a281db 564 /* internal data used in av_find_stream_info() */
82583548 565 int64_t first_dts;
9a174562 566#endif
76c56376
MN
567
568 /**
569 * encoding: pts generation when outputting stream
570 */
a9fd2b19 571 struct AVFrac pts;
5b28c8c3
MN
572
573 /**
8bfb108b
DB
574 * This is the fundamental unit of time (in seconds) in terms
575 * of which frame timestamps are represented. For fixed-fps content,
22e77e44 576 * time base should be 1/framerate and timestamp increments should be 1.
5d820db2
RD
577 * decoding: set by libavformat
578 * encoding: set by libavformat in av_write_header
5b28c8c3 579 */
9ee91c2f 580 AVRational time_base;
9a174562 581#if FF_API_REORDER_PRIVATE
43d414ba 582 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
9a174562 583#endif
3d813e4c 584#if FF_API_STREAM_COPY
a48b7a6b 585 /* ffmpeg.c private use */
3d813e4c
AK
586 attribute_deprecated int stream_copy; /**< If set, just copy stream. */
587#endif
4f57fa8c 588 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
76c56376 589
5e8d2e33 590#if FF_API_AVSTREAM_QUALITY
b4aea108 591 //FIXME move stuff to a flags field?
76c56376
MN
592 /**
593 * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
594 * MN: dunno if that is the right place for it
595 */
5e8d2e33
AK
596 attribute_deprecated float quality;
597#endif
76c56376 598
6d96a9b9 599 /**
8bfb108b
DB
600 * Decoding: pts of the first frame of the stream, in stream time base.
601 * Only set this if you are absolutely 100% sure that the value you set
602 * it to really is the pts of the first frame.
4854c253 603 * This may be undefined (AV_NOPTS_VALUE).
6d96a9b9 604 */
115329f1 605 int64_t start_time;
76c56376 606
e26381b6 607 /**
8bfb108b 608 * Decoding: duration of the stream, in stream time base.
e26381b6 609 * If a source file does not specify a duration, but does specify
4f57fa8c 610 * a bitrate, this value will be estimated from bitrate and file size.
e26381b6 611 */
ee404803 612 int64_t duration;
fb2758c8 613
9a174562 614#if FF_API_REORDER_PRIVATE
fb2758c8 615 /* av_read_frame() support */
57004ff1 616 enum AVStreamParseType need_parsing;
fb2758c8 617 struct AVCodecParserContext *parser;
6ec87caa 618
fb2758c8 619 int64_t cur_dts;
635fbcb1
MN
620 int last_IP_duration;
621 int64_t last_IP_pts;
fb2758c8 622 /* av_seek_frame() support */
4f57fa8c
DB
623 AVIndexEntry *index_entries; /**< Only used if the format does not
624 support seeking natively. */
fb2758c8 625 int nb_index_entries;
191e8ca7 626 unsigned int index_entries_allocated_size;
9a174562 627#endif
115329f1 628
b4b87d48 629 int64_t nb_frames; ///< number of frames in this stream if known or 0
504ee036 630
4f57fa8c 631 int disposition; /**< AV_DISPOSITION_* bit field */
0bef08e5 632
9a174562 633#if FF_API_REORDER_PRIVATE
0bef08e5 634 AVProbeData probe_data;
0d84a8f6
BC
635#define MAX_REORDER_DELAY 16
636 int64_t pts_buffer[MAX_REORDER_DELAY+1];
9a174562 637#endif
c30a4489
AJ
638
639 /**
640 * sample aspect ratio (0 if unknown)
641 * - encoding: Set by user.
642 * - decoding: Set by libavformat.
643 */
644 AVRational sample_aspect_ratio;
f526adaf 645
d2d67e42 646 AVDictionary *metadata;
3a41c2f7 647
9a174562 648#if FF_API_REORDER_PRIVATE
31769dad
VP
649 /* Intended mostly for av_read_frame() support. Not supposed to be used by */
650 /* external applications; try to use something else if at all possible. */
3a41c2f7
MN
651 const uint8_t *cur_ptr;
652 int cur_len;
653 AVPacket cur_pkt;
27ca0a79
IS
654
655 // Timestamp generation support:
656 /**
657 * Timestamp corresponding to the last dts sync point.
658 *
659 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
660 * a DTS is received from the underlying container. Otherwise set to
661 * AV_NOPTS_VALUE by default.
662 */
663 int64_t reference_dts;
86cb7e33
BC
664
665 /**
666 * Number of packets to buffer for codec probing
667 * NOT PART OF PUBLIC API
668 */
48616887 669#define MAX_PROBE_PACKETS 2500
86cb7e33 670 int probe_packets;
ddce56ef
MN
671
672 /**
e07b882b 673 * last packet in packet_buffer for this stream when muxing.
ddce56ef
MN
674 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
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 /**
698 * Stream informations used internally by av_find_stream_info()
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
866 * durations and also dont set any of them. This is deduced from the
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
aeedac95
SS
1098/**
1099 * If f is NULL, returns the first registered input format,
22e77e44 1100 * if f is non-NULL, returns the next registered input format after f
aeedac95
SS
1101 * or NULL if f is the last one.
1102 */
84be6e72 1103AVInputFormat *av_iformat_next(AVInputFormat *f);
aeedac95
SS
1104
1105/**
1106 * If f is NULL, returns the first registered output format,
22e77e44 1107 * if f is non-NULL, returns the next registered output format after f
aeedac95
SS
1108 * or NULL if f is the last one.
1109 */
84be6e72 1110AVOutputFormat *av_oformat_next(AVOutputFormat *f);
de6d9b64 1111
a9bf9d8e
AK
1112#if FF_API_GUESS_IMG2_CODEC
1113attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1114#endif
290c5fa6 1115
22e77e44
DB
1116/* XXX: Use automatic init with either ELF sections or C file parser */
1117/* modules. */
de6d9b64 1118
b9a281db 1119/* utils.c */
b9a281db
FB
1120void av_register_input_format(AVInputFormat *format);
1121void av_register_output_format(AVOutputFormat *format);
f48b0fa2
SS
1122
1123/**
49bd8e4b
MR
1124 * Return the output format in the list of registered output formats
1125 * which best matches the provided parameters, or return NULL if
f48b0fa2
SS
1126 * there is no match.
1127 *
1128 * @param short_name if non-NULL checks if short_name matches with the
1129 * names of the registered formats
1130 * @param filename if non-NULL checks if filename terminates with the
1131 * extensions of the registered formats
1132 * @param mime_type if non-NULL checks if mime_type matches with the
1133 * MIME type of the registered formats
1134 */
a1f547b9 1135AVOutputFormat *av_guess_format(const char *short_name,
94b1f338
SS
1136 const char *filename,
1137 const char *mime_type);
3217cb42
PI
1138
1139/**
49bd8e4b 1140 * Guess the codec ID based upon muxer and filename.
3217cb42 1141 */
115329f1 1142enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
78cb7273 1143 const char *filename, const char *mime_type,
72415b2a 1144 enum AVMediaType type);
de6d9b64 1145
3217cb42 1146/**
49bd8e4b 1147 * Send a nice hexadecimal dump of a buffer to the specified file stream.
750f0e1f
PI
1148 *
1149 * @param f The file stream pointer where the dump should be sent to.
3217cb42
PI
1150 * @param buf buffer
1151 * @param size buffer size
750f0e1f 1152 *
863c4716 1153 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
3217cb42 1154 */
fb2758c8 1155void av_hex_dump(FILE *f, uint8_t *buf, int size);
3217cb42
PI
1156
1157/**
49bd8e4b 1158 * Send a nice hexadecimal dump of a buffer to the log.
750f0e1f
PI
1159 *
1160 * @param avcl A pointer to an arbitrary struct of which the first field is a
1161 * pointer to an AVClass struct.
1162 * @param level The importance level of the message, lower values signifying
1163 * higher importance.
1164 * @param buf buffer
1165 * @param size buffer size
1166 *
863c4716 1167 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
750f0e1f
PI
1168 */
1169void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1170
1171/**
49bd8e4b 1172 * Send a nice dump of a packet to the specified file stream.
750f0e1f
PI
1173 *
1174 * @param f The file stream pointer where the dump should be sent to.
3217cb42 1175 * @param pkt packet to dump
4f57fa8c 1176 * @param dump_payload True if the payload must be displayed, too.
863c4716 1177 * @param st AVStream that the packet belongs to
3217cb42 1178 */
863c4716
MS
1179void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1180
de6d9b64 1181
750f0e1f 1182/**
49bd8e4b 1183 * Send a nice dump of a packet to the log.
750f0e1f
PI
1184 *
1185 * @param avcl A pointer to an arbitrary struct of which the first field is a
1186 * pointer to an AVClass struct.
1187 * @param level The importance level of the message, lower values signifying
1188 * higher importance.
1189 * @param pkt packet to dump
4f57fa8c 1190 * @param dump_payload True if the payload must be displayed, too.
863c4716 1191 * @param st AVStream that the packet belongs to
750f0e1f 1192 */
863c4716
MS
1193void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1194 AVStream *st);
1195
c5704b2b
AK
1196#if FF_API_PKT_DUMP
1197attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
863c4716
MS
1198attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1199 int dump_payload);
17ca374c 1200#endif
750f0e1f 1201
4815e246 1202/**
49bd8e4b 1203 * Initialize libavformat and register all the muxers, demuxers and
4815e246
SS
1204 * protocols. If you do not call this function, then you can select
1205 * exactly which formats you want to support.
1206 *
1207 * @see av_register_input_format()
1208 * @see av_register_output_format()
5d377501 1209 * @see av_register_protocol()
4815e246 1210 */
94988531 1211void av_register_all(void);
de6d9b64 1212
7693b93e 1213/**
49bd8e4b 1214 * Get the CodecID for the given codec tag tag.
7693b93e
SS
1215 * If no codec id is found returns CODEC_ID_NONE.
1216 *
1217 * @param tags list of supported codec_id-codec_tag pairs, as stored
1218 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1219 */
15545a09 1220enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
7693b93e
SS
1221
1222/**
49bd8e4b 1223 * Get the codec tag for the given codec id id.
7693b93e
SS
1224 * If no codec tag is found returns 0.
1225 *
1226 * @param tags list of supported codec_id-codec_tag pairs, as stored
1227 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1228 */
15545a09 1229unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
7caf0cc6 1230
b9a281db 1231/* media file input */
3217cb42
PI
1232
1233/**
49bd8e4b 1234 * Find AVInputFormat based on the short name of the input format.
3217cb42 1235 */
b9a281db 1236AVInputFormat *av_find_input_format(const char *short_name);
3217cb42
PI
1237
1238/**
49bd8e4b 1239 * Guess the file format.
3217cb42 1240 *
4f57fa8c
DB
1241 * @param is_opened Whether the file is already opened; determines whether
1242 * demuxers with or without AVFMT_NOFILE are probed.
3217cb42 1243 */
94988531 1244AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
3217cb42
PI
1245
1246/**
49bd8e4b 1247 * Guess the file format.
8e2ee182
RD
1248 *
1249 * @param is_opened Whether the file is already opened; determines whether
1250 * demuxers with or without AVFMT_NOFILE are probed.
c99d506b
RD
1251 * @param score_max A probe score larger that this is required to accept a
1252 * detection, the variable is set to the actual detection
1253 * score afterwards.
1254 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
8e2ee182
RD
1255 * to retry with a larger probe buffer.
1256 */
1257AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1258
1259/**
3940caad
AH
1260 * Probe a bytestream to determine the input format. Each time a probe returns
1261 * with a score that is too low, the probe buffer size is increased and another
1262 * attempt is made. When the maximum probe size is reached, the input format
1263 * with the highest score is returned.
1264 *
1265 * @param pb the bytestream to probe
1266 * @param fmt the input format is put here
1267 * @param filename the filename of the stream
1268 * @param logctx the log context
1269 * @param offset the offset within the bytestream to probe from
1270 * @param max_probe_size the maximum probe buffer size (zero for default)
1271 * @return 0 in case of success, a negative value corresponding to an
1272 * AVERROR code otherwise
1273 */
ae628ec1 1274int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
3940caad
AH
1275 const char *filename, void *logctx,
1276 unsigned int offset, unsigned int max_probe_size);
1277
603b8bc2 1278#if FF_API_FORMAT_PARAMETERS
3940caad 1279/**
49bd8e4b 1280 * Allocate all the structures needed to read an input stream.
3217cb42 1281 * This does not open the needed codecs for decoding the stream[s].
603b8bc2 1282 * @deprecated use avformat_open_input instead.
3217cb42 1283 */
603b8bc2 1284attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
ae628ec1 1285 AVIOContext *pb, const char *filename,
da24c5e3 1286 AVInputFormat *fmt, AVFormatParameters *ap);
3217cb42
PI
1287
1288/**
49bd8e4b 1289 * Open a media file as input. The codecs are not opened. Only the file
3217cb42
PI
1290 * header (if present) is read.
1291 *
4f57fa8c
DB
1292 * @param ic_ptr The opened media file handle is put here.
1293 * @param filename filename to open
1294 * @param fmt If non-NULL, force the file format to use.
3217cb42 1295 * @param buf_size optional buffer size (zero if default is OK)
78cb7273
DB
1296 * @param ap Additional parameters needed when opening the file
1297 * (NULL if default).
4f57fa8c 1298 * @return 0 if OK, AVERROR_xxx otherwise
603b8bc2
AK
1299 *
1300 * @deprecated use avformat_open_input instead.
3217cb42 1301 */
603b8bc2 1302attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
b9a281db
FB
1303 AVInputFormat *fmt,
1304 int buf_size,
1305 AVFormatParameters *ap);
603b8bc2 1306#endif
88a28965 1307
88808c60 1308/**
05e84c95
AK
1309 * Open an input stream and read the header. The codecs are not opened.
1310 * The stream must be closed with av_close_input_file().
1311 *
1312 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1313 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1314 * function and written into ps.
1315 * Note that a user-supplied AVFormatContext will be freed on failure.
1316 * @param filename Name of the stream to open.
1317 * @param fmt If non-NULL, this parameter forces a specific input format.
1318 * Otherwise the format is autodetected.
1319 * @param options A dictionary filled with AVFormatContext and demuxer-private options.
1320 * On return this parameter will be destroyed and replaced with a dict containing
1321 * options that were not found. May be NULL.
1322 *
1323 * @return 0 on success, a negative AVERROR on failure.
1324 *
1325 * @note If you want to use custom IO, preallocate the format context and set its pb field.
1326 */
1327int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1328
1329/**
49bd8e4b 1330 * Allocate an AVFormatContext.
f124b087
MS
1331 * avformat_free_context() can be used to free the context and everything
1332 * allocated by the framework within it.
88808c60 1333 */
88a28965 1334AVFormatContext *avformat_alloc_context(void);
b9a281db 1335
a67c061e 1336#if FF_API_FORMAT_PARAMETERS
3217cb42 1337/**
49bd8e4b 1338 * Read packets of a media file to get stream information. This
3217cb42 1339 * is useful for file formats with no headers such as MPEG. This
22e77e44 1340 * function also computes the real framerate in case of MPEG-2 repeat
3217cb42
PI
1341 * frame mode.
1342 * The logical file position is not changed by this function;
1343 * examined packets may be buffered for later processing.
1344 *
1345 * @param ic media file handle
4f57fa8c
DB
1346 * @return >=0 if OK, AVERROR_xxx on error
1347 * @todo Let the user decide somehow what information is needed so that
1348 * we do not waste time getting stuff the user does not need.
a67c061e
AK
1349 *
1350 * @deprecated use avformat_find_stream_info.
3217cb42 1351 */
3c7fa664 1352attribute_deprecated
b9a281db 1353int av_find_stream_info(AVFormatContext *ic);
a67c061e
AK
1354#endif
1355
1356/**
1357 * Read packets of a media file to get stream information. This
1358 * is useful for file formats with no headers such as MPEG. This
1359 * function also computes the real framerate in case of MPEG-2 repeat
1360 * frame mode.
1361 * The logical file position is not changed by this function;
1362 * examined packets may be buffered for later processing.
1363 *
1364 * @param ic media file handle
1365 * @param options If non-NULL, an ic.nb_streams long array of pointers to
1366 * dictionaries, where i-th member contains options for
1367 * codec corresponding to i-th stream.
1368 * On return each dictionary will be filled with options that were not found.
1369 * @return >=0 if OK, AVERROR_xxx on error
1370 *
1371 * @note this function isn't guaranteed to open all the codecs, so
1372 * options being non-empty at return is a perfectly normal behavior.
1373 *
1374 * @todo Let the user decide somehow what information is needed so that
1375 * we do not waste time getting stuff the user does not need.
1376 */
1377int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
3217cb42
PI
1378
1379/**
9128ae08
NG
1380 * Find the "best" stream in the file.
1381 * The best stream is determined according to various heuristics as the most
1382 * likely to be what the user expects.
1383 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1384 * default decoder for the stream's codec; streams for which no decoder can
1385 * be found are ignored.
1386 *
1387 * @param ic media file handle
1388 * @param type stream type: video, audio, subtitles, etc.
1389 * @param wanted_stream_nb user-requested stream number,
1390 * or -1 for automatic selection
1391 * @param related_stream try to find a stream related (eg. in the same
1392 * program) to this one, or -1 if none
1393 * @param decoder_ret if non-NULL, returns the decoder for the
1394 * selected stream
1395 * @param flags flags; none are currently defined
1396 * @return the non-negative stream number in case of success,
1397 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1398 * could be found,
1399 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1400 * @note If av_find_best_stream returns successfully and decoder_ret is not
1401 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1402 */
1403int av_find_best_stream(AVFormatContext *ic,
1404 enum AVMediaType type,
1405 int wanted_stream_nb,
1406 int related_stream,
1407 AVCodec **decoder_ret,
1408 int flags);
1409
1410/**
49bd8e4b 1411 * Read a transport packet from a media file.
3217cb42 1412 *
864ff8c1 1413 * This function is obsolete and should never be used.
3217cb42
PI
1414 * Use av_read_frame() instead.
1415 *
1416 * @param s media file handle
1417 * @param pkt is filled
4f57fa8c 1418 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1419 */
de6d9b64 1420int av_read_packet(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1421
1422/**
49bd8e4b 1423 * Return the next frame of a stream.
4faf628f
MN
1424 * This function returns what is stored in the file, and does not validate
1425 * that what is there are valid frames for the decoder. It will split what is
1426 * stored in the file into frames and return one for each call. It will not
1427 * omit invalid data between valid frames so as to give the decoder the maximum
1428 * information possible for decoding.
3217cb42
PI
1429 *
1430 * The returned packet is valid
1431 * until the next av_read_frame() or until av_close_input_file() and
1432 * must be freed with av_free_packet. For video, the packet contains
1433 * exactly one frame. For audio, it contains an integer number of
1434 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1435 * data). If the audio frames have a variable size (e.g. MPEG audio),
1436 * then it contains one frame.
1437 *
1438 * pkt->pts, pkt->dts and pkt->duration are always set to correct
22e77e44 1439 * values in AVStream.time_base units (and guessed if the format cannot
4f57fa8c
DB
1440 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1441 * has B-frames, so it is better to rely on pkt->dts if you do not
3217cb42
PI
1442 * decompress the payload.
1443 *
4f57fa8c 1444 * @return 0 if OK, < 0 on error or end of file
3217cb42 1445 */
fb2758c8 1446int av_read_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1447
1448/**
49bd8e4b 1449 * Seek to the keyframe at timestamp.
3217cb42
PI
1450 * 'timestamp' in 'stream_index'.
1451 * @param stream_index If stream_index is (-1), a default
1452 * stream is selected, and timestamp is automatically converted
1453 * from AV_TIME_BASE units to the stream specific time_base.
4f57fa8c
DB
1454 * @param timestamp Timestamp in AVStream.time_base units
1455 * or, if no stream is specified, in AV_TIME_BASE units.
3217cb42
PI
1456 * @param flags flags which select direction and seeking mode
1457 * @return >= 0 on success
1458 */
78cb7273
DB
1459int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1460 int flags);
3217cb42
PI
1461
1462/**
49bd8e4b 1463 * Seek to timestamp ts.
d04768fa
MN
1464 * Seeking will be done so that the point from which all active streams
1465 * can be presented successfully will be closest to ts and within min/max_ts.
1466 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1467 *
22e77e44 1468 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
d04768fa 1469 * are the file position (this may not be supported by all demuxers).
22e77e44 1470 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
d04768fa 1471 * in the stream with stream_index (this may not be supported by all demuxers).
22e77e44
DB
1472 * Otherwise all timestamps are in units of the stream selected by stream_index
1473 * or if stream_index is -1, in AV_TIME_BASE units.
1474 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
d04768fa
MN
1475 * keyframes (this may not be supported by all demuxers).
1476 *
22e77e44 1477 * @param stream_index index of the stream which is used as time base reference
d04768fa
MN
1478 * @param min_ts smallest acceptable timestamp
1479 * @param ts target timestamp
1480 * @param max_ts largest acceptable timestamp
1481 * @param flags flags
32e543f8 1482 * @return >=0 on success, error code otherwise
998b6f7c 1483 *
8a4d7a30 1484 * @note This is part of the new seek API which is still under construction.
22e77e44
DB
1485 * Thus do not use this yet. It may change at any time, do not expect
1486 * ABI compatibility yet!
d04768fa
MN
1487 */
1488int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1489
1490/**
49bd8e4b 1491 * Start playing a network-based stream (e.g. RTSP stream) at the
4f57fa8c 1492 * current position.
3217cb42 1493 */
fb2758c8 1494int av_read_play(AVFormatContext *s);
3217cb42
PI
1495
1496/**
49bd8e4b 1497 * Pause a network-based stream (e.g. RTSP stream).
3217cb42
PI
1498 *
1499 * Use av_read_play() to resume it.
1500 */
fb2758c8 1501int av_read_pause(AVFormatContext *s);
3217cb42
PI
1502
1503/**
49bd8e4b 1504 * Free a AVFormatContext allocated by av_open_input_stream.
2506fd54
RD
1505 * @param s context to free
1506 */
1507void av_close_input_stream(AVFormatContext *s);
1508
1509/**
49bd8e4b 1510 * Close a media file (but not its codecs).
3217cb42
PI
1511 *
1512 * @param s media file handle
1513 */
de6d9b64 1514void av_close_input_file(AVFormatContext *s);
3217cb42
PI
1515
1516/**
f124b087
MS
1517 * Free an AVFormatContext and all its streams.
1518 * @param s context to free
1519 */
1520void avformat_free_context(AVFormatContext *s);
1521
569129a6 1522#if FF_API_NEW_STREAM
f124b087 1523/**
49bd8e4b 1524 * Add a new stream to a media file.
3217cb42
PI
1525 *
1526 * Can only be called in the read_header() function. If the flag
1527 * AVFMTCTX_NOHEADER is in the format context, then new streams
1528 * can be added in read_packet too.
1529 *
1530 * @param s media file handle
4f57fa8c 1531 * @param id file-format-dependent stream ID
3217cb42 1532 */
569129a6 1533attribute_deprecated
b9a281db 1534AVStream *av_new_stream(AVFormatContext *s, int id);
569129a6
AK
1535#endif
1536
1537/**
1538 * Add a new stream to a media file.
1539 *
1540 * When demuxing, it is called by the demuxer in read_header(). If the
1541 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1542 * be called in read_packet().
1543 *
1544 * When muxing, should be called by the user before avformat_write_header().
1545 *
1546 * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1547 * will be initialized to use this codec. This is needed for e.g. codec-specific
1548 * defaults to be set, so codec should be provided if it is known.
1549 *
1550 * @return newly created stream or NULL on error.
1551 */
1552AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1553
15afa396 1554AVProgram *av_new_program(AVFormatContext *s, int id);
3217cb42 1555
c3f9ebf7 1556#if FF_API_SET_PTS_INFO
3217cb42 1557/**
c3f9ebf7 1558 * @deprecated this function is not supposed to be called outside of lavf
3217cb42 1559 */
c3f9ebf7 1560attribute_deprecated
9ee91c2f 1561void av_set_pts_info(AVStream *s, int pts_wrap_bits,
dec14949 1562 unsigned int pts_num, unsigned int pts_den);
c3f9ebf7 1563#endif
de6d9b64 1564
3ba1438d
MN
1565#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1566#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
4f57fa8c 1567#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
2bf74f49 1568#define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
3ba1438d 1569
b754978a 1570int av_find_default_stream_index(AVFormatContext *s);
3217cb42
PI
1571
1572/**
49bd8e4b 1573 * Get the index for a specific timestamp.
4f57fa8c
DB
1574 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1575 * to the timestamp which is <= the requested one, if backward
1576 * is 0, then it will be >=
3217cb42
PI
1577 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1578 * @return < 0 if no such timestamp could be found
1579 */
dc56fc38 1580int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
3217cb42
PI
1581
1582/**
49bd8e4b 1583 * Add an index entry into a sorted list. Update the entry if the list
4f57fa8c 1584 * already contains it.
3217cb42 1585 *
4f57fa8c 1586 * @param timestamp timestamp in the time base of the given stream
3217cb42 1587 */
78cb7273
DB
1588int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1589 int size, int distance, int flags);
3217cb42 1590
a2faa951
AK
1591#if FF_API_SEEK_PUBLIC
1592attribute_deprecated
78cb7273
DB
1593int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1594 int64_t target_ts, int flags);
a2faa951 1595attribute_deprecated
22ffac70 1596void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
a2faa951 1597attribute_deprecated
78cb7273
DB
1598int64_t av_gen_search(AVFormatContext *s, int stream_index,
1599 int64_t target_ts, int64_t pos_min,
1600 int64_t pos_max, int64_t pos_limit,
1601 int64_t ts_min, int64_t ts_max,
1602 int flags, int64_t *ts_ret,
1603 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
a2faa951 1604#endif
b754978a 1605
76c56376
MN
1606/**
1607 * media file output
1608 */
25de5958
AK
1609#if FF_API_FORMAT_PARAMETERS
1610/**
1611 * @deprecated pass the options to avformat_write_header directly.
1612 */
1613attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1614#endif
3217cb42
PI
1615
1616/**
f3bfe388
MR
1617 * Split a URL string into components.
1618 *
1619 * The pointers to buffers for storing individual components may be null,
1620 * in order to ignore that component. Buffers for components not found are
1621 * set to empty strings. If the port is not found, it is set to a negative
1622 * value.
1623 *
1624 * @param proto the buffer for the protocol
1625 * @param proto_size the size of the proto buffer
1626 * @param authorization the buffer for the authorization
1627 * @param authorization_size the size of the authorization buffer
1628 * @param hostname the buffer for the host name
1629 * @param hostname_size the size of the hostname buffer
1630 * @param port_ptr a pointer to store the port number in
1631 * @param path the buffer for the path
1632 * @param path_size the size of the path buffer
1633 * @param url the URL to split
1634 */
1635void av_url_split(char *proto, int proto_size,
1636 char *authorization, int authorization_size,
1637 char *hostname, int hostname_size,
1638 int *port_ptr,
1639 char *path, int path_size,
1640 const char *url);
1641
1642/**
25de5958
AK
1643 * Allocate the stream private data and write the stream header to
1644 * an output media file.
1645 *
1646 * @param s Media file handle, must be allocated with avformat_alloc_context().
1647 * Its oformat field must be set to the desired output format;
1648 * Its pb field must be set to an already openened AVIOContext.
1649 * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
1650 * On return this parameter will be destroyed and replaced with a dict containing
1651 * options that were not found. May be NULL.
1652 *
1653 * @return 0 on success, negative AVERROR on failure.
1654 *
1655 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1656 */
1657int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1658
1659#if FF_API_FORMAT_PARAMETERS
1660/**
49bd8e4b 1661 * Allocate the stream private data and write the stream header to an
755bfeab 1662 * output media file.
5d820db2
RD
1663 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1664 * but for some formats it might also be some other time base
3217cb42
PI
1665 *
1666 * @param s media file handle
4f57fa8c 1667 * @return 0 if OK, AVERROR_xxx on error
25de5958
AK
1668 *
1669 * @deprecated use avformat_write_header.
3217cb42 1670 */
25de5958
AK
1671attribute_deprecated int av_write_header(AVFormatContext *s);
1672#endif
3217cb42
PI
1673
1674/**
49bd8e4b 1675 * Write a packet to an output media file.
3217cb42
PI
1676 *
1677 * The packet shall contain one audio or video frame.
78cb7273
DB
1678 * The packet must be correctly interleaved according to the container
1679 * specification, if not then av_interleaved_write_frame must be used.
3217cb42
PI
1680 *
1681 * @param s media file handle
78cb7273
DB
1682 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1683 dts/pts, ...
4f57fa8c 1684 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1685 */
e928649b 1686int av_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1687
1688/**
49bd8e4b 1689 * Write a packet to an output media file ensuring correct interleaving.
3217cb42
PI
1690 *
1691 * The packet must contain one audio or video frame.
22e77e44 1692 * If the packets are already correctly interleaved, the application should
90b5b51e
DB
1693 * call av_write_frame() instead as it is slightly faster. It is also important
1694 * to keep in mind that completely non-interleaved input will need huge amounts
1695 * of memory to interleave with this, so it is preferable to interleave at the
1696 * demuxer level.
3217cb42
PI
1697 *
1698 * @param s media file handle
78cb7273
DB
1699 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1700 dts/pts, ...
4f57fa8c 1701 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1702 */
3c895fc0 1703int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1704
1705/**
49bd8e4b 1706 * Interleave a packet per dts in an output media file.
3217cb42 1707 *
78cb7273 1708 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
22e77e44 1709 * function, so they cannot be used after it. Note that calling av_free_packet()
78cb7273 1710 * on them is still safe.
3217cb42
PI
1711 *
1712 * @param s media file handle
1713 * @param out the interleaved packet will be output here
9a58234f 1714 * @param pkt the input packet
3217cb42
PI
1715 * @param flush 1 if no further packets are available as input and all
1716 * remaining packets should be output
1717 * @return 1 if a packet was output, 0 if no packet could be output,
d9526386 1718 * < 0 if an error occurred
3217cb42 1719 */
78cb7273
DB
1720int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1721 AVPacket *pkt, int flush);
e928649b 1722
3217cb42 1723/**
49bd8e4b 1724 * Write the stream trailer to an output media file and free the
2b75bde6 1725 * file private data.
3217cb42 1726 *
dc76fe13
RD
1727 * May only be called after a successful call to av_write_header.
1728 *
3217cb42 1729 * @param s media file handle
4f57fa8c 1730 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1731 */
b9a281db 1732int av_write_trailer(AVFormatContext *s);
de6d9b64 1733
610219a5
AK
1734#if FF_API_DUMP_FORMAT
1735attribute_deprecated void dump_format(AVFormatContext *ic,
1736 int index,
1737 const char *url,
1738 int is_output);
1739#endif
1740
1741void av_dump_format(AVFormatContext *ic,
1742 int index,
1743 const char *url,
1744 int is_output);
3217cb42 1745
f6c7375a 1746#if FF_API_PARSE_DATE
3217cb42 1747/**
49bd8e4b 1748 * Parse datestr and return a corresponding number of microseconds.
f6c7375a 1749 *
f9436161 1750 * @param datestr String representing a date or a duration.
f6c7375a
SS
1751 * See av_parse_time() for the syntax of the provided string.
1752 * @deprecated in favor of av_parse_time()
3217cb42 1753 */
f6c7375a 1754attribute_deprecated
0c1a9eda 1755int64_t parse_date(const char *datestr, int duration);
f6c7375a 1756#endif
de6d9b64 1757
76c56376
MN
1758/**
1759 * Get the current time in microseconds.
1760 */
0c1a9eda 1761int64_t av_gettime(void);
94988531 1762
ab0287fc 1763#if FF_API_FIND_INFO_TAG
3217cb42 1764/**
ab0287fc 1765 * @deprecated use av_find_info_tag in libavutil instead.
3217cb42 1766 */
ab0287fc
AK
1767attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1768#endif
de6d9b64 1769
3217cb42 1770/**
49bd8e4b 1771 * Return in 'buf' the path with '%d' replaced by a number.
4f57fa8c 1772 *
3217cb42
PI
1773 * Also handles the '%0nd' format where 'n' is the total number
1774 * of digits and '%%'.
1775 *
1776 * @param buf destination buffer
1777 * @param buf_size destination buffer size
1778 * @param path numbered sequence string
8ea0e802 1779 * @param number frame number
4f57fa8c 1780 * @return 0 if OK, -1 on format error
3217cb42 1781 */
5c07cf53
MB
1782int av_get_frame_filename(char *buf, int buf_size,
1783 const char *path, int number);
3217cb42
PI
1784
1785/**
49bd8e4b 1786 * Check whether filename actually is a numbered sequence generator.
3217cb42
PI
1787 *
1788 * @param filename possible numbered sequence string
4f57fa8c 1789 * @return 1 if a valid numbered sequence string, 0 otherwise
3217cb42 1790 */
5c07cf53 1791int av_filename_number_test(const char *filename);
96baaa6a 1792
c5388c07 1793/**
49bd8e4b 1794 * Generate an SDP for an RTP session.
c5388c07
LA
1795 *
1796 * @param ac array of AVFormatContexts describing the RTP streams. If the
1797 * array is composed by only one context, such context can contain
1798 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1799 * all the contexts in the array (an AVCodecContext per RTP stream)
4f57fa8c 1800 * must contain only one AVStream.
8767b80f 1801 * @param n_files number of AVCodecContexts contained in ac
c234d40b
AK
1802 * @param buf buffer where the SDP will be stored (must be allocated by
1803 * the caller)
8767b80f 1804 * @param size the size of the buffer
4f57fa8c 1805 * @return 0 if OK, AVERROR_xxx on error
c5388c07 1806 */
c234d40b 1807int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
c3675dfe
AK
1808
1809#if FF_API_SDP_CREATE
1810attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1811#endif
c5388c07 1812
1a70d127 1813/**
49bd8e4b 1814 * Return a positive value if the given filename has one of the given
1a70d127
SS
1815 * extensions, 0 otherwise.
1816 *
1817 * @param extensions a comma-separated list of filename extensions
1818 */
1819int av_match_ext(const char *filename, const char *extensions);
1820
48f9e457
AK
1821/**
1822 * Test if the given container can store a codec.
1823 *
1824 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1825 *
1826 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1827 * A negative number if this information is not available.
1828 */
1829int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1830
fb4ca26b
AK
1831/**
1832 * Get the AVClass for AVFormatContext. It can be used in combination with
1833 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1834 *
1835 * @see av_opt_find().
1836 */
1837const AVClass *avformat_get_class(void);
1838
b6d08f40
MS
1839/**
1840 * Do global initialization of network components. This is optional,
1841 * but recommended, since it avoids the overhead of implicitly
1842 * doing the setup for each session.
1843 *
87892ef8
MS
1844 * Calling this function will become mandatory if using network
1845 * protocols at some major version bump.
b6d08f40
MS
1846 */
1847int avformat_network_init(void);
1848
1849/**
1850 * Undo the initialization done by avformat_network_init.
1851 */
1852int avformat_network_deinit(void);
1853
98790382 1854#endif /* AVFORMAT_AVFORMAT_H */