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