Move the internal function declarations in avformat.h to internal.h.
[libav.git] / libavformat / avformat.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2001 Fabrice Bellard
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg 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 *
b78e7197 11 * FFmpeg 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
b78e7197 17 * License along with FFmpeg; 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
800c289a 24#define LIBAVFORMAT_VERSION_MAJOR 52
3dd6180f 25#define LIBAVFORMAT_VERSION_MINOR 61
0f943ce6 26#define LIBAVFORMAT_VERSION_MICRO 0
e97ac1e6 27
800c289a
MR
28#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
29 LIBAVFORMAT_VERSION_MINOR, \
30 LIBAVFORMAT_VERSION_MICRO)
31#define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
32 LIBAVFORMAT_VERSION_MINOR, \
33 LIBAVFORMAT_VERSION_MICRO)
5aa083ee 34#define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
8026c3b5 35
5aa083ee 36#define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
4b1f4f23 37
c97429e2 38/**
f2e77e4b
AC
39 * I return the LIBAVFORMAT_VERSION_INT constant. You got
40 * a fucking problem with that, douchebag?
c97429e2
SS
41 */
42unsigned avformat_version(void);
43
c1736936
DB
44/**
45 * Returns the libavformat build-time configuration.
46 */
41600690 47const char *avformat_configuration(void);
c1736936
DB
48
49/**
50 * Returns the libavformat license.
51 */
41600690 52const char *avformat_license(void);
c1736936 53
f71869a4 54#include <time.h>
67070e4f 55#include <stdio.h> /* FILE */
76a448ed 56#include "libavcodec/avcodec.h"
de6d9b64 57
de6d9b64
FB
58#include "avio.h"
59
f610a9f2
AJ
60struct AVFormatContext;
61
a6d18a0e
MN
62
63/*
ea29242c
MM
64 * Public Metadata API.
65 * The metadata API allows libavformat to export metadata tags to a client
61648423
AK
66 * application using a sequence of key/value pairs. Like all strings in FFmpeg,
67 * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
68 * exported by demuxers isn't checked to be valid UTF-8 in most cases.
ea29242c
MM
69 * Important concepts to keep in mind:
70 * 1. Keys are unique; there can never be 2 tags with the same key. This is
71 * also meant semantically, i.e., a demuxer should not knowingly produce
72 * several keys that are literally different but semantically identical.
73 * E.g., key=Author5, key=Author6. In this example, all authors must be
74 * placed in the same tag.
75 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
76 * want to store, e.g., the email address of the child of producer Alice
77 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
ca76a119
AK
78 * 3. Several modifiers can be applied to the tag name. This is done by
79 * appending a dash character ('-') and the modifier name in the order
80 * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
81 * a) language -- a tag whose value is localized for a particular language
82 * is appended with the ISO 639-2/B 3-letter language code.
83 * For example: Author-ger=Michael, Author-eng=Mike
84 * The original/default language is in the unqualified "Author" tag.
85 * A demuxer should set a default if it sets any translated tag.
86 * b) sorting -- a modified version of a tag that should be used for
87 * sorting will have '-sort' appended. E.g. artist="The Beatles",
88 * artist-sort="Beatles, The".
89 *
90 * 4. Tag names are normally exported exactly as stored in the container to
91 * allow lossless remuxing to the same format. For container-independent
92 * handling of metadata, av_metadata_conv() can convert it to ffmpeg generic
93 * format. Follows a list of generic tag names:
94 *
95 * album -- name of the set this work belongs to
96 * album_artist -- main creator of the set/album, if different from artist.
97 * e.g. "Various Artists" for compilation albums.
98 * artist -- main creator of the work
99 * comment -- any additional description of the file.
100 * composer -- who composed the work, if different from artist.
101 * copyright -- name of copyright holder.
102 * date -- date when the work was created, preferably in ISO 8601.
103 * disc -- number of a subset, e.g. disc in a multi-disc collection.
104 * encoder -- name/settings of the software/hardware that produced the file.
105 * encoded_by -- person/group who created the file.
106 * filename -- original name of the file.
107 * genre -- <self-evident>.
108 * language -- main language in which the work is performed, preferably
109 * in ISO 639-2 format.
110 * performer -- artist who performed the work, if different from artist.
111 * E.g for "Also sprach Zarathustra", artist would be "Richard
112 * Strauss" and performer "London Philharmonic Orchestra".
113 * publisher -- name of the label/publisher.
114 * title -- name of the work.
115 * track -- number of this work in the set, can be in form current/total.
a6d18a0e
MN
116 */
117
48a81c0f 118#define AV_METADATA_MATCH_CASE 1
a6d18a0e 119#define AV_METADATA_IGNORE_SUFFIX 2
a181981e
MN
120#define AV_METADATA_DONT_STRDUP_KEY 4
121#define AV_METADATA_DONT_STRDUP_VAL 8
56a8242f 122#define AV_METADATA_DONT_OVERWRITE 16 ///< Don't overwrite existing tags.
a6d18a0e
MN
123
124typedef struct {
125 char *key;
126 char *value;
bc1d2afb 127}AVMetadataTag;
a6d18a0e 128
e232c252 129typedef struct AVMetadata AVMetadata;
f610a9f2 130typedef struct AVMetadataConv AVMetadataConv;
a6d18a0e
MN
131
132/**
22e77e44
DB
133 * Gets a metadata element with matching key.
134 * @param prev Set to the previous matching element to find the next.
66b6c745 135 * If set to NULL the first matching element is returned.
22e77e44
DB
136 * @param flags Allows case as well as suffix-insensitive comparisons.
137 * @return Found tag or NULL, changing key or value leads to undefined behavior.
a6d18a0e 138 */
bc1d2afb 139AVMetadataTag *
e232c252 140av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
a6d18a0e 141
a181981e 142#if LIBAVFORMAT_VERSION_MAJOR == 52
a6d18a0e 143/**
22e77e44
DB
144 * Sets the given tag in m, overwriting an existing tag.
145 * @param key tag key to add to m (will be av_strduped)
146 * @param value tag value to add to m (will be av_strduped)
147 * @return >= 0 on success otherwise an error code <0
a6d18a0e 148 */
5ea7ce88 149int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
a181981e
MN
150#endif
151
152/**
153 * Sets the given tag in m, overwriting an existing tag.
154 * @param key tag key to add to m (will be av_strduped depending on flags)
155 * @param value tag value to add to m (will be av_strduped depending on flags)
156 * @return >= 0 on success otherwise an error code <0
157 */
158int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
a6d18a0e 159
094d9df7 160/**
d1b9adf2 161 * Converts all the metadata sets from ctx according to the source and
ca76a119
AK
162 * destination conversion tables. If one of the tables is NULL, then
163 * tags are converted to/from ffmpeg generic tag names.
f610a9f2
AJ
164 * @param d_conv destination tags format conversion table
165 * @param s_conv source tags format conversion table
166 */
167void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
168 const AVMetadataConv *s_conv);
169
170/**
22e77e44 171 * Frees all the memory allocated for an AVMetadata struct.
094d9df7
AJ
172 */
173void av_metadata_free(AVMetadata **m);
174
a6d18a0e 175
de6d9b64
FB
176/* packet functions */
177
3217cb42
PI
178
179/**
d1b9adf2
SS
180 * Allocates and reads the payload of a packet and initializes its
181 * fields with default values.
3217cb42
PI
182 *
183 * @param pkt packet
4f57fa8c
DB
184 * @param size desired payload size
185 * @return >0 (read size) if OK, AVERROR_xxx otherwise
3217cb42 186 */
2692067a 187int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
3217cb42 188
de6d9b64
FB
189
190/*************************************************/
916c80e9
FB
191/* fractional numbers for exact pts handling */
192
671adb17 193/**
4f57fa8c
DB
194 * The exact value of the fractional number is: 'val + num / den'.
195 * num is assumed to be 0 <= num < den.
4c08b2bd 196 */
916c80e9 197typedef struct AVFrac {
115329f1 198 int64_t val, num, den;
52e57500 199} AVFrac;
916c80e9 200
916c80e9 201/*************************************************/
b9a281db 202/* input/output formats */
de6d9b64 203
7caf0cc6
MN
204struct AVCodecTag;
205
4f57fa8c 206/** This structure contains the data a format has to probe a file. */
b9a281db 207typedef struct AVProbeData {
5c91a675 208 const char *filename;
e5f58f81 209 unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
210 int buf_size; /**< Size of buf except extra allocated bytes */
b9a281db
FB
211} AVProbeData;
212
22e77e44 213#define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
87e87886 214#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
de6d9b64
FB
215
216typedef struct AVFormatParameters {
c0df9d75 217 AVRational time_base;
de6d9b64
FB
218 int sample_rate;
219 int channels;
220 int width;
221 int height;
4606ac8d 222 enum PixelFormat pix_fmt;
4f57fa8c
DB
223 int channel; /**< Used to select DV channel. */
224 const char *standard; /**< TV standard, NTSC, PAL, SECAM */
225 unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
226 unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
72e043dd 227 stream packet (only meaningful if
4f57fa8c
DB
228 mpeg2ts_raw is TRUE). */
229 unsigned int initial_pause:1; /**< Do not begin to play the stream
230 immediately (RTSP only). */
72e043dd 231 unsigned int prealloced_context:1;
71957315 232#if LIBAVFORMAT_VERSION_INT < (53<<16)
5b6d5596
MN
233 enum CodecID video_codec_id;
234 enum CodecID audio_codec_id;
71957315 235#endif
de6d9b64
FB
236} AVFormatParameters;
237
4f57fa8c 238//! Demuxer will use url_fopen, no opened file should be provided by the caller.
40d9c544 239#define AVFMT_NOFILE 0x0001
4f57fa8c
DB
240#define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
241#define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
242#define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
243 raw picture data. */
244#define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
245#define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
246#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
247#define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
25918212 248#define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
ab5a0175 249#define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
b9a281db
FB
250
251typedef struct AVOutputFormat {
de6d9b64 252 const char *name;
bde15e74
SS
253 /**
254 * Descriptive name for the format, meant to be more human-readable
819174fa 255 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
256 * to define it.
257 */
de6d9b64
FB
258 const char *long_name;
259 const char *mime_type;
4f57fa8c 260 const char *extensions; /**< comma-separated filename extensions */
22e77e44 261 /** size of private data so that it can be allocated in the wrapper */
b9a281db 262 int priv_data_size;
de6d9b64 263 /* output support */
43d414ba
PI
264 enum CodecID audio_codec; /**< default audio codec */
265 enum CodecID video_codec; /**< default video codec */
de6d9b64 266 int (*write_header)(struct AVFormatContext *);
e928649b 267 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
de6d9b64 268 int (*write_trailer)(struct AVFormatContext *);
43d414ba 269 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
b9a281db 270 int flags;
4f57fa8c 271 /** Currently only used to set pixel format if not YUV420P. */
290c5fa6 272 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
78cb7273
DB
273 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
274 AVPacket *in, int flush);
7caf0cc6
MN
275
276 /**
78cb7273 277 * List of supported codec_id-codec_tag pairs, ordered by "better
22e77e44 278 * choice first". The arrays are all terminated by CODEC_ID_NONE.
7caf0cc6 279 */
c1854592 280 const struct AVCodecTag * const *codec_tag;
7caf0cc6 281
11bf3847
AJ
282 enum CodecID subtitle_codec; /**< default subtitle codec */
283
719e721a 284 const AVMetadataConv *metadata_conv;
f610a9f2 285
b9a281db
FB
286 /* private fields */
287 struct AVOutputFormat *next;
288} AVOutputFormat;
de6d9b64 289
b9a281db
FB
290typedef struct AVInputFormat {
291 const char *name;
bde15e74
SS
292 /**
293 * Descriptive name for the format, meant to be more human-readable
819174fa 294 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
295 * to define it.
296 */
b9a281db 297 const char *long_name;
4f57fa8c 298 /** Size of private data so that it can be allocated in the wrapper. */
b9a281db 299 int priv_data_size;
65d7d68b 300 /**
22e77e44 301 * Tell if a given file has a chance of being parsed as this format.
5d81d641
DB
302 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
303 * big so you do not have to check for that unless you need more.
65d7d68b 304 */
b9a281db 305 int (*read_probe)(AVProbeData *);
4f57fa8c
DB
306 /** Read the format header and initialize the AVFormatContext
307 structure. Return 0 if OK. 'ap' if non-NULL contains
308 additional parameters. Only used in raw format right
b9a281db 309 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
310 int (*read_header)(struct AVFormatContext *,
311 AVFormatParameters *ap);
4f57fa8c 312 /** Read one packet and put it in 'pkt'. pts and flags are also
b9a281db 313 set. 'av_new_stream' can be called only if the flag
6883ebe4
RD
314 AVFMTCTX_NOHEADER is used.
315 @return 0 on success, < 0 on error.
316 When returning an error, pkt must not have been allocated
317 or must be freed before returning */
de6d9b64 318 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
4f57fa8c 319 /** Close the stream. The AVFormatContext and AVStreams are not
de6d9b64
FB
320 freed by this function */
321 int (*read_close)(struct AVFormatContext *);
1de2db8f
MN
322
323#if LIBAVFORMAT_VERSION_MAJOR < 53
115329f1 324 /**
4f57fa8c
DB
325 * Seek to a given timestamp relative to the frames in
326 * stream component stream_index.
22e77e44
DB
327 * @param stream_index Must not be -1.
328 * @param flags Selects which direction should be preferred if no exact
329 * match is available.
05ce0f11 330 * @return >= 0 on success (but not necessarily the new offset)
3ba1438d 331 */
115329f1 332 int (*read_seek)(struct AVFormatContext *,
3ba1438d 333 int stream_index, int64_t timestamp, int flags);
1de2db8f 334#endif
8d14a25c 335 /**
4f57fa8c 336 * Gets the next timestamp in stream[stream_index].time_base units.
d9526386 337 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
8d14a25c
MN
338 */
339 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
340 int64_t *pos, int64_t pos_limit);
4f57fa8c 341 /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
de6d9b64 342 int flags;
4f57fa8c 343 /** If extensions are defined, then no probe is done. You should
b9a281db
FB
344 usually not use extension format guessing because it is not
345 reliable enough */
346 const char *extensions;
4f57fa8c 347 /** General purpose read-only value that the format can use. */
b9a281db 348 int value;
fb2758c8 349
d1b9adf2 350 /** Starts/resumes playing - only meaningful if using a network-based format
4f57fa8c 351 (RTSP). */
fb2758c8
FB
352 int (*read_play)(struct AVFormatContext *);
353
d1b9adf2 354 /** Pauses playing - only meaningful if using a network-based format
4f57fa8c 355 (RTSP). */
fb2758c8
FB
356 int (*read_pause)(struct AVFormatContext *);
357
c1854592 358 const struct AVCodecTag * const *codec_tag;
7caf0cc6 359
1de2db8f 360 /**
d1b9adf2 361 * Seeks to timestamp ts.
1de2db8f
MN
362 * Seeking will be done so that the point from which all active streams
363 * can be presented successfully will be closest to ts and within min/max_ts.
364 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
365 */
882fb0a3 366 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1de2db8f 367
719e721a 368 const AVMetadataConv *metadata_conv;
f610a9f2 369
b9a281db
FB
370 /* private fields */
371 struct AVInputFormat *next;
372} AVInputFormat;
de6d9b64 373
57004ff1
AJ
374enum AVStreamParseType {
375 AVSTREAM_PARSE_NONE,
376 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
4f57fa8c 377 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
78cb7273 378 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
57004ff1
AJ
379};
380
fb2758c8
FB
381typedef struct AVIndexEntry {
382 int64_t pos;
383 int64_t timestamp;
384#define AVINDEX_KEYFRAME 0x0001
30a43f2d 385 int flags:2;
4f57fa8c
DB
386 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).
387 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
fb2758c8
FB
388} AVIndexEntry;
389
90c2295b
ES
390#define AV_DISPOSITION_DEFAULT 0x0001
391#define AV_DISPOSITION_DUB 0x0002
392#define AV_DISPOSITION_ORIGINAL 0x0004
393#define AV_DISPOSITION_COMMENT 0x0008
394#define AV_DISPOSITION_LYRICS 0x0010
395#define AV_DISPOSITION_KARAOKE 0x0020
396
ba66ae94
MN
397/**
398 * Stream structure.
399 * New fields can be added to the end with minor version bumps.
8bfb108b 400 * Removal, reordering and changes to existing fields require a major
ba66ae94 401 * version bump.
8bfb108b 402 * sizeof(AVStream) must not be used outside libav*.
ba66ae94 403 */
de6d9b64 404typedef struct AVStream {
43d414ba 405 int index; /**< stream index in AVFormatContext */
4f57fa8c 406 int id; /**< format-specific stream ID */
43d414ba 407 AVCodecContext *codec; /**< codec context */
b4b87d48 408 /**
22e77e44
DB
409 * Real base framerate of the stream.
410 * This is the lowest framerate with which all timestamps can be
864ff8c1 411 * represented accurately (it is the least common multiple of all
22e77e44
DB
412 * framerates in the stream). Note, this value is just a guess!
413 * For example, if the time base is 1/90000 and all frames have either
4f57fa8c 414 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
b4b87d48
MN
415 */
416 AVRational r_frame_rate;
de6d9b64 417 void *priv_data;
82583548 418
b9a281db 419 /* internal data used in av_find_stream_info() */
82583548 420 int64_t first_dts;
4f57fa8c 421 /** encoding: pts generation when outputting stream */
a9fd2b19 422 struct AVFrac pts;
5b28c8c3
MN
423
424 /**
8bfb108b
DB
425 * This is the fundamental unit of time (in seconds) in terms
426 * of which frame timestamps are represented. For fixed-fps content,
22e77e44 427 * time base should be 1/framerate and timestamp increments should be 1.
5b28c8c3 428 */
9ee91c2f 429 AVRational time_base;
43d414ba 430 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
a48b7a6b 431 /* ffmpeg.c private use */
4f57fa8c
DB
432 int stream_copy; /**< If set, just copy stream. */
433 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
b4aea108 434 //FIXME move stuff to a flags field?
4f57fa8c 435 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
755bfeab 436 * MN: dunno if that is the right place for it */
115329f1 437 float quality;
6d96a9b9 438 /**
8bfb108b
DB
439 * Decoding: pts of the first frame of the stream, in stream time base.
440 * Only set this if you are absolutely 100% sure that the value you set
441 * it to really is the pts of the first frame.
4854c253 442 * This may be undefined (AV_NOPTS_VALUE).
8bfb108b
DB
443 * @note The ASF header does NOT contain a correct start_time the ASF
444 * demuxer must NOT set this.
6d96a9b9 445 */
115329f1 446 int64_t start_time;
e26381b6 447 /**
8bfb108b 448 * Decoding: duration of the stream, in stream time base.
e26381b6 449 * If a source file does not specify a duration, but does specify
4f57fa8c 450 * a bitrate, this value will be estimated from bitrate and file size.
e26381b6 451 */
ee404803 452 int64_t duration;
fb2758c8 453
827f7e28 454#if LIBAVFORMAT_VERSION_INT < (53<<16)
7e030c47 455 char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
827f7e28 456#endif
09730260 457
fb2758c8 458 /* av_read_frame() support */
57004ff1 459 enum AVStreamParseType need_parsing;
fb2758c8 460 struct AVCodecParserContext *parser;
6ec87caa 461
fb2758c8 462 int64_t cur_dts;
635fbcb1
MN
463 int last_IP_duration;
464 int64_t last_IP_pts;
fb2758c8 465 /* av_seek_frame() support */
4f57fa8c
DB
466 AVIndexEntry *index_entries; /**< Only used if the format does not
467 support seeking natively. */
fb2758c8 468 int nb_index_entries;
191e8ca7 469 unsigned int index_entries_allocated_size;
115329f1 470
b4b87d48 471 int64_t nb_frames; ///< number of frames in this stream if known or 0
504ee036 472
0d84a8f6
BC
473#if LIBAVFORMAT_VERSION_INT < (53<<16)
474 int64_t unused[4+1];
f8d7c9d3
ES
475
476 char *filename; /**< source filename of the stream */
827f7e28 477#endif
90c2295b 478
4f57fa8c 479 int disposition; /**< AV_DISPOSITION_* bit field */
0bef08e5
MN
480
481 AVProbeData probe_data;
0d84a8f6
BC
482#define MAX_REORDER_DELAY 16
483 int64_t pts_buffer[MAX_REORDER_DELAY+1];
c30a4489
AJ
484
485 /**
486 * sample aspect ratio (0 if unknown)
487 * - encoding: Set by user.
488 * - decoding: Set by libavformat.
489 */
490 AVRational sample_aspect_ratio;
f526adaf 491
e232c252 492 AVMetadata *metadata;
3a41c2f7
MN
493
494 /* av_read_frame() support */
495 const uint8_t *cur_ptr;
496 int cur_len;
497 AVPacket cur_pkt;
27ca0a79
IS
498
499 // Timestamp generation support:
500 /**
501 * Timestamp corresponding to the last dts sync point.
502 *
503 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
504 * a DTS is received from the underlying container. Otherwise set to
505 * AV_NOPTS_VALUE by default.
506 */
507 int64_t reference_dts;
86cb7e33
BC
508
509 /**
510 * Number of packets to buffer for codec probing
511 * NOT PART OF PUBLIC API
512 */
48616887 513#define MAX_PROBE_PACKETS 2500
86cb7e33 514 int probe_packets;
ddce56ef
MN
515
516 /**
e07b882b 517 * last packet in packet_buffer for this stream when muxing.
ddce56ef
MN
518 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
519 */
e07b882b 520 struct AVPacketList *last_in_packet_buffer;
02b398ef
MN
521
522 /**
523 * Average framerate
524 */
525 AVRational avg_frame_rate;
6c6e6ef5
MN
526
527 /**
528 * Number of frames that have been demuxed during av_find_stream_info()
529 */
530 int codec_info_nb_frames;
de6d9b64
FB
531} AVStream;
532
15afa396
NS
533#define AV_PROGRAM_RUNNING 1
534
ba66ae94 535/**
ba66ae94 536 * New fields can be added to the end with minor version bumps.
8bfb108b 537 * Removal, reordering and changes to existing fields require a major
ba66ae94 538 * version bump.
8bfb108b 539 * sizeof(AVProgram) must not be used outside libav*.
ba66ae94 540 */
15afa396
NS
541typedef struct AVProgram {
542 int id;
827f7e28 543#if LIBAVFORMAT_VERSION_INT < (53<<16)
4f57fa8c
DB
544 char *provider_name; ///< network name for DVB streams
545 char *name; ///< service name for DVB streams
827f7e28 546#endif
15afa396
NS
547 int flags;
548 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
526efa10
NS
549 unsigned int *stream_index;
550 unsigned int nb_stream_indexes;
e232c252 551 AVMetadata *metadata;
15afa396
NS
552} AVProgram;
553
43d414ba 554#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
da24c5e3
FB
555 (streams are added dynamically) */
556
79d7836a 557typedef struct AVChapter {
4f57fa8c
DB
558 int id; ///< unique ID to identify the chapter
559 AVRational time_base; ///< time base in which the start/end timestamps are specified
8931e7b4 560 int64_t start, end; ///< chapter start/end time in time_base units
827f7e28 561#if LIBAVFORMAT_VERSION_INT < (53<<16)
c2fb6be4 562 char *title; ///< chapter title
827f7e28 563#endif
e232c252 564 AVMetadata *metadata;
79d7836a
AK
565} AVChapter;
566
ad5cc780 567#if LIBAVFORMAT_VERSION_MAJOR < 53
de6d9b64 568#define MAX_STREAMS 20
ad5cc780
JM
569#else
570#define MAX_STREAMS 100
571#endif
de6d9b64 572
252f17e2 573/**
4f57fa8c 574 * Format I/O context.
252f17e2 575 * New fields can be added to the end with minor version bumps.
8bfb108b 576 * Removal, reordering and changes to existing fields require a major
252f17e2 577 * version bump.
8bfb108b 578 * sizeof(AVFormatContext) must not be used outside libav*.
252f17e2 579 */
de6d9b64 580typedef struct AVFormatContext {
1447aac4 581 const AVClass *av_class; /**< Set by avformat_alloc_context. */
4f57fa8c 582 /* Can only be iformat or oformat, not both at the same time. */
b9a281db
FB
583 struct AVInputFormat *iformat;
584 struct AVOutputFormat *oformat;
de6d9b64 585 void *priv_data;
899681cd 586 ByteIOContext *pb;
db69c2e5 587 unsigned int nb_streams;
de6d9b64 588 AVStream *streams[MAX_STREAMS];
43d414ba 589 char filename[1024]; /**< input or output filename */
de6d9b64 590 /* stream info */
4568325a 591 int64_t timestamp;
827f7e28 592#if LIBAVFORMAT_VERSION_INT < (53<<16)
de6d9b64
FB
593 char title[512];
594 char author[512];
595 char copyright[512];
596 char comment[512];
6a58e151 597 char album[512];
43d414ba
PI
598 int year; /**< ID3 year, 0 if none */
599 int track; /**< track number, 0 if none */
600 char genre[32]; /**< ID3 genre */
827f7e28 601#endif
6a58e151 602
4f57fa8c
DB
603 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
604 /* private data for pts handling (do not modify directly). */
43d414ba 605 /** This buffer is only needed when packets were already buffered but
4f57fa8c
DB
606 not decoded, for example to get the codec parameters in MPEG
607 streams. */
ee404803
FB
608 struct AVPacketList *packet_buffer;
609
4f57fa8c 610 /** Decoding: position of the first frame of the component, in
ee404803 611 AV_TIME_BASE fractional seconds. NEVER set this value directly:
4f57fa8c 612 It is deduced from the AVStream values. */
115329f1 613 int64_t start_time;
4f57fa8c 614 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
37f57ab4
MN
615 seconds. Only set this value if you know none of the individual stream
616 durations and also dont set any of them. This is deduced from the
617 AVStream values if not set. */
ee404803 618 int64_t duration;
4f57fa8c 619 /** decoding: total file size, 0 if unknown */
ee404803 620 int64_t file_size;
4f57fa8c 621 /** Decoding: total stream bitrate in bit/s, 0 if not
ee404803 622 available. Never set it directly if the file_size and the
22e77e44 623 duration are known as FFmpeg can compute it automatically. */
ee404803 624 int bit_rate;
fb2758c8
FB
625
626 /* av_read_frame() support */
627 AVStream *cur_st;
3a41c2f7
MN
628#if LIBAVFORMAT_VERSION_INT < (53<<16)
629 const uint8_t *cur_ptr_deprecated;
630 int cur_len_deprecated;
631 AVPacket cur_pkt_deprecated;
632#endif
fb2758c8 633
fb2758c8 634 /* av_seek_frame() support */
43d414ba 635 int64_t data_offset; /** offset of the first packet */
fb2758c8 636 int index_built;
115329f1 637
2db3c638 638 int mux_rate;
92400be2 639 unsigned int packet_size;
17c88cb0
MN
640 int preload;
641 int max_delay;
8108551a 642
115329f1
DB
643#define AVFMT_NOOUTPUTLOOP -1
644#define AVFMT_INFINITEOUTPUTLOOP 0
43d414ba 645 /** number of times to loop output in formats that support it */
8108551a 646 int loop_output;
115329f1 647
30bc6613 648 int flags;
22e77e44 649#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
4f57fa8c
DB
650#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
651#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
c55806e3 652#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
fe8344a2
MN
653#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
654#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
5894e1bb
VP
655
656 int loop_input;
22e77e44 657 /** decoding: size of data to probe; encoding: unused. */
9e6c9470 658 unsigned int probesize;
a44b3c4d
MN
659
660 /**
4f57fa8c
DB
661 * Maximum time (in AV_TIME_BASE units) during which the input should
662 * be analyzed in av_find_stream_info().
a44b3c4d
MN
663 */
664 int max_analyze_duration;
c964c2c7
RD
665
666 const uint8_t *key;
667 int keylen;
15afa396
NS
668
669 unsigned int nb_programs;
670 AVProgram **programs;
62600469
MN
671
672 /**
673 * Forced video codec_id.
4f57fa8c 674 * Demuxing: Set by user.
62600469
MN
675 */
676 enum CodecID video_codec_id;
677 /**
678 * Forced audio codec_id.
4f57fa8c 679 * Demuxing: Set by user.
62600469
MN
680 */
681 enum CodecID audio_codec_id;
682 /**
683 * Forced subtitle codec_id.
4f57fa8c 684 * Demuxing: Set by user.
62600469
MN
685 */
686 enum CodecID subtitle_codec_id;
3dea63bd
PK
687
688 /**
22e77e44
DB
689 * Maximum amount of memory in bytes to use for the index of each stream.
690 * If the index exceeds this size, entries will be discarded as
3dea63bd
PK
691 * needed to maintain a smaller size. This can lead to slower or less
692 * accurate seeking (depends on demuxer).
4f57fa8c 693 * Demuxers for which a full in-memory index is mandatory will ignore
3dea63bd
PK
694 * this.
695 * muxing : unused
696 * demuxing: set by user
697 */
698 unsigned int max_index_size;
ab8ab30c
RP
699
700 /**
ffa71b2b 701 * Maximum amount of memory in bytes to use for buffering frames
4f57fa8c 702 * obtained from realtime capture devices.
ab8ab30c
RP
703 */
704 unsigned int max_picture_buffer;
79d7836a 705
fbabf1e9 706 unsigned int nb_chapters;
79d7836a 707 AVChapter **chapters;
45b2b05f
MN
708
709 /**
4f57fa8c 710 * Flags to enable debugging.
45b2b05f
MN
711 */
712 int debug;
713#define FF_FDEBUG_TS 0x0001
0bef08e5
MN
714
715 /**
4f57fa8c 716 * Raw packets from the demuxer, prior to parsing and decoding.
0bef08e5
MN
717 * This buffer is used for buffering packets until the codec can
718 * be identified, as parsing cannot be done without knowing the
719 * codec.
720 */
721 struct AVPacketList *raw_packet_buffer;
5c5b1731
MR
722 struct AVPacketList *raw_packet_buffer_end;
723
724 struct AVPacketList *packet_buffer_end;
47146dfb 725
e232c252 726 AVMetadata *metadata;
af122d6a
BC
727
728 /**
729 * Remaining size available for raw_packet_buffer, in bytes.
730 * NOT PART OF PUBLIC API
731 */
48616887 732#define RAW_PACKET_BUFFER_SIZE 2500000
af122d6a 733 int raw_packet_buffer_remaining_size;
b8819c85
MS
734
735 /**
736 * Start time of the stream in real world time, in microseconds
737 * since the unix epoch (00:00 1st January 1970). That is, pts=0
738 * in the stream was captured at this real world time.
739 * - encoding: Set by user.
740 * - decoding: Unused.
741 */
742 int64_t start_time_realtime;
de6d9b64
FB
743} AVFormatContext;
744
745typedef struct AVPacketList {
746 AVPacket pkt;
747 struct AVPacketList *next;
748} AVPacketList;
749
84be6e72 750#if LIBAVFORMAT_VERSION_INT < (53<<16)
b9a281db
FB
751extern AVInputFormat *first_iformat;
752extern AVOutputFormat *first_oformat;
84be6e72
MN
753#endif
754
aeedac95
SS
755/**
756 * If f is NULL, returns the first registered input format,
22e77e44 757 * if f is non-NULL, returns the next registered input format after f
aeedac95
SS
758 * or NULL if f is the last one.
759 */
84be6e72 760AVInputFormat *av_iformat_next(AVInputFormat *f);
aeedac95
SS
761
762/**
763 * If f is NULL, returns the first registered output format,
22e77e44 764 * if f is non-NULL, returns the next registered output format after f
aeedac95
SS
765 * or NULL if f is the last one.
766 */
84be6e72 767AVOutputFormat *av_oformat_next(AVOutputFormat *f);
de6d9b64 768
5b6d5596 769enum CodecID av_guess_image2_codec(const char *filename);
290c5fa6 770
22e77e44
DB
771/* XXX: Use automatic init with either ELF sections or C file parser */
772/* modules. */
de6d9b64 773
b9a281db 774/* utils.c */
b9a281db
FB
775void av_register_input_format(AVInputFormat *format);
776void av_register_output_format(AVOutputFormat *format);
1642ee43
SS
777#if LIBAVFORMAT_VERSION_MAJOR < 53
778attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
78cb7273
DB
779 const char *filename,
780 const char *mime_type);
a1f547b9
SS
781
782/**
783 * @deprecated Use av_guess_format() instead.
784 */
785attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
786 const char *filename,
787 const char *mime_type);
1642ee43 788#endif
f48b0fa2
SS
789
790/**
791 * Returns the output format in the list of registered output formats
792 * which best matches the provided parameters, or returns NULL if
793 * there is no match.
794 *
795 * @param short_name if non-NULL checks if short_name matches with the
796 * names of the registered formats
797 * @param filename if non-NULL checks if filename terminates with the
798 * extensions of the registered formats
799 * @param mime_type if non-NULL checks if mime_type matches with the
800 * MIME type of the registered formats
801 */
a1f547b9 802AVOutputFormat *av_guess_format(const char *short_name,
94b1f338
SS
803 const char *filename,
804 const char *mime_type);
3217cb42
PI
805
806/**
4f57fa8c 807 * Guesses the codec ID based upon muxer and filename.
3217cb42 808 */
115329f1 809enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
78cb7273 810 const char *filename, const char *mime_type,
72415b2a 811 enum AVMediaType type);
de6d9b64 812
3217cb42 813/**
d1b9adf2 814 * Sends a nice hexadecimal dump of a buffer to the specified file stream.
750f0e1f
PI
815 *
816 * @param f The file stream pointer where the dump should be sent to.
3217cb42
PI
817 * @param buf buffer
818 * @param size buffer size
750f0e1f
PI
819 *
820 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
3217cb42 821 */
fb2758c8 822void av_hex_dump(FILE *f, uint8_t *buf, int size);
3217cb42
PI
823
824/**
d1b9adf2 825 * Sends a nice hexadecimal dump of a buffer to the log.
750f0e1f
PI
826 *
827 * @param avcl A pointer to an arbitrary struct of which the first field is a
828 * pointer to an AVClass struct.
829 * @param level The importance level of the message, lower values signifying
830 * higher importance.
831 * @param buf buffer
832 * @param size buffer size
833 *
834 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
835 */
836void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
837
838/**
d1b9adf2 839 * Sends a nice dump of a packet to the specified file stream.
750f0e1f
PI
840 *
841 * @param f The file stream pointer where the dump should be sent to.
3217cb42 842 * @param pkt packet to dump
4f57fa8c 843 * @param dump_payload True if the payload must be displayed, too.
3217cb42 844 */
fb2758c8 845void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
de6d9b64 846
750f0e1f 847/**
d1b9adf2 848 * Sends a nice dump of a packet to the log.
750f0e1f
PI
849 *
850 * @param avcl A pointer to an arbitrary struct of which the first field is a
851 * pointer to an AVClass struct.
852 * @param level The importance level of the message, lower values signifying
853 * higher importance.
854 * @param pkt packet to dump
4f57fa8c 855 * @param dump_payload True if the payload must be displayed, too.
750f0e1f
PI
856 */
857void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
858
4815e246 859/**
d1b9adf2 860 * Initializes libavformat and registers all the muxers, demuxers and
4815e246
SS
861 * protocols. If you do not call this function, then you can select
862 * exactly which formats you want to support.
863 *
864 * @see av_register_input_format()
865 * @see av_register_output_format()
5d377501 866 * @see av_register_protocol()
4815e246 867 */
94988531 868void av_register_all(void);
de6d9b64 869
43d414ba 870/** codec tag <-> codec id */
15545a09
SS
871enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
872unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
7caf0cc6 873
b9a281db 874/* media file input */
3217cb42
PI
875
876/**
4f57fa8c 877 * Finds AVInputFormat based on the short name of the input format.
3217cb42 878 */
b9a281db 879AVInputFormat *av_find_input_format(const char *short_name);
3217cb42
PI
880
881/**
d1b9adf2 882 * Guesses the file format.
3217cb42 883 *
4f57fa8c
DB
884 * @param is_opened Whether the file is already opened; determines whether
885 * demuxers with or without AVFMT_NOFILE are probed.
3217cb42 886 */
94988531 887AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
3217cb42
PI
888
889/**
890 * Allocates all the structures needed to read an input stream.
891 * This does not open the needed codecs for decoding the stream[s].
892 */
115329f1
DB
893int av_open_input_stream(AVFormatContext **ic_ptr,
894 ByteIOContext *pb, const char *filename,
da24c5e3 895 AVInputFormat *fmt, AVFormatParameters *ap);
3217cb42
PI
896
897/**
d1b9adf2 898 * Opens a media file as input. The codecs are not opened. Only the file
3217cb42
PI
899 * header (if present) is read.
900 *
4f57fa8c
DB
901 * @param ic_ptr The opened media file handle is put here.
902 * @param filename filename to open
903 * @param fmt If non-NULL, force the file format to use.
3217cb42 904 * @param buf_size optional buffer size (zero if default is OK)
78cb7273
DB
905 * @param ap Additional parameters needed when opening the file
906 * (NULL if default).
4f57fa8c 907 * @return 0 if OK, AVERROR_xxx otherwise
3217cb42 908 */
115329f1 909int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
b9a281db
FB
910 AVInputFormat *fmt,
911 int buf_size,
912 AVFormatParameters *ap);
88a28965
SS
913
914#if LIBAVFORMAT_VERSION_MAJOR < 53
915/**
916 * @deprecated Use avformat_alloc_context() instead.
917 */
918attribute_deprecated AVFormatContext *av_alloc_format_context(void);
919#endif
920
88808c60 921/**
d1b9adf2 922 * Allocates an AVFormatContext.
5d81d641 923 * Can be freed with av_free() but do not forget to free everything you
88808c60
MN
924 * explicitly allocated as well!
925 */
88a28965 926AVFormatContext *avformat_alloc_context(void);
b9a281db 927
3217cb42 928/**
d1b9adf2 929 * Reads packets of a media file to get stream information. This
3217cb42 930 * is useful for file formats with no headers such as MPEG. This
22e77e44 931 * function also computes the real framerate in case of MPEG-2 repeat
3217cb42
PI
932 * frame mode.
933 * The logical file position is not changed by this function;
934 * examined packets may be buffered for later processing.
935 *
936 * @param ic media file handle
4f57fa8c
DB
937 * @return >=0 if OK, AVERROR_xxx on error
938 * @todo Let the user decide somehow what information is needed so that
939 * we do not waste time getting stuff the user does not need.
3217cb42 940 */
b9a281db 941int av_find_stream_info(AVFormatContext *ic);
3217cb42
PI
942
943/**
d1b9adf2 944 * Reads a transport packet from a media file.
3217cb42 945 *
864ff8c1 946 * This function is obsolete and should never be used.
3217cb42
PI
947 * Use av_read_frame() instead.
948 *
949 * @param s media file handle
950 * @param pkt is filled
4f57fa8c 951 * @return 0 if OK, AVERROR_xxx on error
3217cb42 952 */
de6d9b64 953int av_read_packet(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
954
955/**
d1b9adf2 956 * Returns the next frame of a stream.
3217cb42
PI
957 *
958 * The returned packet is valid
959 * until the next av_read_frame() or until av_close_input_file() and
960 * must be freed with av_free_packet. For video, the packet contains
961 * exactly one frame. For audio, it contains an integer number of
962 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
963 * data). If the audio frames have a variable size (e.g. MPEG audio),
964 * then it contains one frame.
965 *
966 * pkt->pts, pkt->dts and pkt->duration are always set to correct
22e77e44 967 * values in AVStream.time_base units (and guessed if the format cannot
4f57fa8c
DB
968 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
969 * has B-frames, so it is better to rely on pkt->dts if you do not
3217cb42
PI
970 * decompress the payload.
971 *
4f57fa8c 972 * @return 0 if OK, < 0 on error or end of file
3217cb42 973 */
fb2758c8 974int av_read_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
975
976/**
d1b9adf2 977 * Seeks to the keyframe at timestamp.
3217cb42
PI
978 * 'timestamp' in 'stream_index'.
979 * @param stream_index If stream_index is (-1), a default
980 * stream is selected, and timestamp is automatically converted
981 * from AV_TIME_BASE units to the stream specific time_base.
4f57fa8c
DB
982 * @param timestamp Timestamp in AVStream.time_base units
983 * or, if no stream is specified, in AV_TIME_BASE units.
3217cb42
PI
984 * @param flags flags which select direction and seeking mode
985 * @return >= 0 on success
986 */
78cb7273
DB
987int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
988 int flags);
3217cb42
PI
989
990/**
d1b9adf2 991 * Seeks to timestamp ts.
d04768fa
MN
992 * Seeking will be done so that the point from which all active streams
993 * can be presented successfully will be closest to ts and within min/max_ts.
994 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
995 *
22e77e44 996 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
d04768fa 997 * are the file position (this may not be supported by all demuxers).
22e77e44 998 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
d04768fa 999 * in the stream with stream_index (this may not be supported by all demuxers).
22e77e44
DB
1000 * Otherwise all timestamps are in units of the stream selected by stream_index
1001 * or if stream_index is -1, in AV_TIME_BASE units.
1002 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
d04768fa
MN
1003 * keyframes (this may not be supported by all demuxers).
1004 *
22e77e44 1005 * @param stream_index index of the stream which is used as time base reference
d04768fa
MN
1006 * @param min_ts smallest acceptable timestamp
1007 * @param ts target timestamp
1008 * @param max_ts largest acceptable timestamp
1009 * @param flags flags
32e543f8 1010 * @return >=0 on success, error code otherwise
998b6f7c 1011 *
22e77e44
DB
1012 * @NOTE This is part of the new seek API which is still under construction.
1013 * Thus do not use this yet. It may change at any time, do not expect
1014 * ABI compatibility yet!
d04768fa
MN
1015 */
1016int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1017
1018/**
d1b9adf2 1019 * Starts playing a network-based stream (e.g. RTSP stream) at the
4f57fa8c 1020 * current position.
3217cb42 1021 */
fb2758c8 1022int av_read_play(AVFormatContext *s);
3217cb42
PI
1023
1024/**
d1b9adf2 1025 * Pauses a network-based stream (e.g. RTSP stream).
3217cb42
PI
1026 *
1027 * Use av_read_play() to resume it.
1028 */
fb2758c8 1029int av_read_pause(AVFormatContext *s);
3217cb42
PI
1030
1031/**
d1b9adf2 1032 * Frees a AVFormatContext allocated by av_open_input_stream.
2506fd54
RD
1033 * @param s context to free
1034 */
1035void av_close_input_stream(AVFormatContext *s);
1036
1037/**
d1b9adf2 1038 * Closes a media file (but not its codecs).
3217cb42
PI
1039 *
1040 * @param s media file handle
1041 */
de6d9b64 1042void av_close_input_file(AVFormatContext *s);
3217cb42
PI
1043
1044/**
d1b9adf2 1045 * Adds a new stream to a media file.
3217cb42
PI
1046 *
1047 * Can only be called in the read_header() function. If the flag
1048 * AVFMTCTX_NOHEADER is in the format context, then new streams
1049 * can be added in read_packet too.
1050 *
1051 * @param s media file handle
4f57fa8c 1052 * @param id file-format-dependent stream ID
3217cb42 1053 */
b9a281db 1054AVStream *av_new_stream(AVFormatContext *s, int id);
15afa396 1055AVProgram *av_new_program(AVFormatContext *s, int id);
3217cb42
PI
1056
1057/**
d1b9adf2 1058 * Adds a new chapter.
79d7836a 1059 * This function is NOT part of the public API
4f57fa8c 1060 * and should ONLY be used by demuxers.
79d7836a
AK
1061 *
1062 * @param s media file handle
4f57fa8c 1063 * @param id unique ID for this chapter
abd2256d
MN
1064 * @param start chapter start time in time_base units
1065 * @param end chapter end time in time_base units
79d7836a 1066 * @param title chapter title
5c37f43a 1067 *
4f57fa8c 1068 * @return AVChapter or NULL on error
79d7836a 1069 */
78cb7273
DB
1070AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1071 int64_t start, int64_t end, const char *title);
79d7836a
AK
1072
1073/**
d1b9adf2 1074 * Sets the pts for a given stream.
3217cb42
PI
1075 *
1076 * @param s stream
1077 * @param pts_wrap_bits number of bits effectively used by the pts
1078 * (used for wrap control, 33 is the value for MPEG)
1079 * @param pts_num numerator to convert to seconds (MPEG: 1)
1080 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1081 */
9ee91c2f 1082void av_set_pts_info(AVStream *s, int pts_wrap_bits,
dec14949 1083 unsigned int pts_num, unsigned int pts_den);
de6d9b64 1084
3ba1438d
MN
1085#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1086#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
4f57fa8c 1087#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
2bf74f49 1088#define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
3ba1438d 1089
b754978a 1090int av_find_default_stream_index(AVFormatContext *s);
3217cb42
PI
1091
1092/**
1093 * Gets the index for a specific timestamp.
4f57fa8c
DB
1094 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1095 * to the timestamp which is <= the requested one, if backward
1096 * is 0, then it will be >=
3217cb42
PI
1097 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1098 * @return < 0 if no such timestamp could be found
1099 */
dc56fc38 1100int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
3217cb42
PI
1101
1102/**
3dea63bd 1103 * Ensures the index uses less memory than the maximum specified in
22e77e44 1104 * AVFormatContext.max_index_size by discarding entries if it grows
3dea63bd
PK
1105 * too large.
1106 * This function is not part of the public API and should only be called
1107 * by demuxers.
1108 */
1109void ff_reduce_index(AVFormatContext *s, int stream_index);
1110
1111/**
d1b9adf2 1112 * Adds an index entry into a sorted list. Updates the entry if the list
4f57fa8c 1113 * already contains it.
3217cb42 1114 *
4f57fa8c 1115 * @param timestamp timestamp in the time base of the given stream
3217cb42 1116 */
78cb7273
DB
1117int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1118 int size, int distance, int flags);
3217cb42
PI
1119
1120/**
78cb7273
DB
1121 * Does a binary search using av_index_search_timestamp() and
1122 * AVCodec.read_timestamp().
1123 * This is not supposed to be called directly by a user application,
1124 * but by demuxers.
3217cb42
PI
1125 * @param target_ts target timestamp in the time base of the given stream
1126 * @param stream_index stream number
1127 */
78cb7273
DB
1128int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1129 int64_t target_ts, int flags);
3217cb42
PI
1130
1131/**
4f57fa8c 1132 * Updates cur_dts of all streams based on the given timestamp and AVStream.
3217cb42 1133 *
4f57fa8c
DB
1134 * Stream ref_st unchanged, others set cur_dts in their native time base.
1135 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
3217cb42
PI
1136 * @param timestamp new dts expressed in time_base of param ref_st
1137 * @param ref_st reference stream giving time_base of param timestamp
1138 */
22ffac70 1139void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
3217cb42
PI
1140
1141/**
1142 * Does a binary search using read_timestamp().
78cb7273
DB
1143 * This is not supposed to be called directly by a user application,
1144 * but by demuxers.
3217cb42
PI
1145 * @param target_ts target timestamp in the time base of the given stream
1146 * @param stream_index stream number
1147 */
78cb7273
DB
1148int64_t av_gen_search(AVFormatContext *s, int stream_index,
1149 int64_t target_ts, int64_t pos_min,
1150 int64_t pos_max, int64_t pos_limit,
1151 int64_t ts_min, int64_t ts_max,
1152 int flags, int64_t *ts_ret,
1153 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
b754978a 1154
43d414ba 1155/** media file output */
290c5fa6 1156int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
3217cb42
PI
1157
1158/**
d1b9adf2 1159 * Allocates the stream private data and writes the stream header to an
755bfeab 1160 * output media file.
3217cb42
PI
1161 *
1162 * @param s media file handle
4f57fa8c 1163 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1164 */
b9a281db 1165int av_write_header(AVFormatContext *s);
3217cb42
PI
1166
1167/**
d1b9adf2 1168 * Writes a packet to an output media file.
3217cb42
PI
1169 *
1170 * The packet shall contain one audio or video frame.
78cb7273
DB
1171 * The packet must be correctly interleaved according to the container
1172 * specification, if not then av_interleaved_write_frame must be used.
3217cb42
PI
1173 *
1174 * @param s media file handle
78cb7273
DB
1175 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1176 dts/pts, ...
4f57fa8c 1177 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1178 */
e928649b 1179int av_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1180
1181/**
1182 * Writes a packet to an output media file ensuring correct interleaving.
1183 *
1184 * The packet must contain one audio or video frame.
22e77e44 1185 * If the packets are already correctly interleaved, the application should
90b5b51e
DB
1186 * call av_write_frame() instead as it is slightly faster. It is also important
1187 * to keep in mind that completely non-interleaved input will need huge amounts
1188 * of memory to interleave with this, so it is preferable to interleave at the
1189 * demuxer level.
3217cb42
PI
1190 *
1191 * @param s media file handle
78cb7273
DB
1192 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1193 dts/pts, ...
4f57fa8c 1194 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1195 */
3c895fc0 1196int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1197
1198/**
d1b9adf2 1199 * Interleaves a packet per dts in an output media file.
3217cb42 1200 *
78cb7273 1201 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
22e77e44 1202 * function, so they cannot be used after it. Note that calling av_free_packet()
78cb7273 1203 * on them is still safe.
3217cb42
PI
1204 *
1205 * @param s media file handle
1206 * @param out the interleaved packet will be output here
1207 * @param in the input packet
1208 * @param flush 1 if no further packets are available as input and all
1209 * remaining packets should be output
1210 * @return 1 if a packet was output, 0 if no packet could be output,
d9526386 1211 * < 0 if an error occurred
3217cb42 1212 */
78cb7273
DB
1213int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1214 AVPacket *pkt, int flush);
e928649b 1215
3217cb42 1216/**
2b75bde6
SS
1217 * Writes the stream trailer to an output media file and frees the
1218 * file private data.
3217cb42 1219 *
dc76fe13
RD
1220 * May only be called after a successful call to av_write_header.
1221 *
3217cb42 1222 * @param s media file handle
4f57fa8c 1223 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1224 */
b9a281db 1225int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
1226
1227void dump_format(AVFormatContext *ic,
115329f1 1228 int index,
de6d9b64
FB
1229 const char *url,
1230 int is_output);
3217cb42 1231
1ca9133f 1232#if LIBAVFORMAT_VERSION_MAJOR < 53
3217cb42 1233/**
4f57fa8c 1234 * Parses width and height out of string str.
26ef3220 1235 * @deprecated Use av_parse_video_frame_size instead.
3217cb42 1236 */
78cb7273
DB
1237attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1238 const char *str);
3217cb42
PI
1239
1240/**
22e77e44 1241 * Converts framerate from a string to a fraction.
26ef3220 1242 * @deprecated Use av_parse_video_frame_rate instead.
3217cb42 1243 */
78cb7273
DB
1244attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1245 const char *arg);
1ca9133f 1246#endif
3217cb42
PI
1247
1248/**
819174fa 1249 * Parses datestr and returns a corresponding number of microseconds.
f9436161
SS
1250 * @param datestr String representing a date or a duration.
1251 * - If a date the syntax is:
3217cb42 1252 * @code
3217cb42 1253 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
3217cb42 1254 * @endcode
4f57fa8c 1255 * Time is local time unless Z is appended, in which case it is
f9436161 1256 * interpreted as UTC.
4f57fa8c 1257 * If the year-month-day part is not specified it takes the current
f9436161
SS
1258 * year-month-day.
1259 * Returns the number of microseconds since 1st of January, 1970 up to
819174fa 1260 * the time of the parsed date or INT64_MIN if datestr cannot be
f9436161
SS
1261 * successfully parsed.
1262 * - If a duration the syntax is:
1263 * @code
1264 * [-]HH[:MM[:SS[.m...]]]
1265 * [-]S+[.m...]
1266 * @endcode
1267 * Returns the number of microseconds contained in a time interval
819174fa 1268 * with the specified duration or INT64_MIN if datestr cannot be
7338d368 1269 * successfully parsed.
819174fa
SS
1270 * @param duration Flag which tells how to interpret datestr, if
1271 * not zero datestr is interpreted as a duration, otherwise as a
f9436161 1272 * date.
3217cb42 1273 */
0c1a9eda 1274int64_t parse_date(const char *datestr, int duration);
de6d9b64 1275
fff5e687 1276/** Gets the current time in microseconds. */
0c1a9eda 1277int64_t av_gettime(void);
94988531 1278
4f57fa8c 1279/* ffm-specific for ffserver */
de6d9b64 1280#define FFM_PACKET_SIZE 4096
bc5c918e 1281int64_t ffm_read_write_index(int fd);
6fcce4f9 1282int ffm_write_write_index(int fd, int64_t pos);
bc5c918e 1283void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
de6d9b64 1284
3217cb42
PI
1285/**
1286 * Attempts to find a specific tag in a URL.
1287 *
1288 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1289 * Return 1 if found.
1290 */
de6d9b64
FB
1291int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1292
3217cb42 1293/**
22e77e44 1294 * Returns in 'buf' the path with '%d' replaced by a number.
4f57fa8c 1295 *
3217cb42
PI
1296 * Also handles the '%0nd' format where 'n' is the total number
1297 * of digits and '%%'.
1298 *
1299 * @param buf destination buffer
1300 * @param buf_size destination buffer size
1301 * @param path numbered sequence string
8ea0e802 1302 * @param number frame number
4f57fa8c 1303 * @return 0 if OK, -1 on format error
3217cb42 1304 */
5c07cf53
MB
1305int av_get_frame_filename(char *buf, int buf_size,
1306 const char *path, int number);
3217cb42
PI
1307
1308/**
d1b9adf2 1309 * Checks whether filename actually is a numbered sequence generator.
3217cb42
PI
1310 *
1311 * @param filename possible numbered sequence string
4f57fa8c 1312 * @return 1 if a valid numbered sequence string, 0 otherwise
3217cb42 1313 */
5c07cf53 1314int av_filename_number_test(const char *filename);
96baaa6a 1315
c5388c07 1316/**
d1b9adf2 1317 * Generates an SDP for an RTP session.
c5388c07
LA
1318 *
1319 * @param ac array of AVFormatContexts describing the RTP streams. If the
1320 * array is composed by only one context, such context can contain
1321 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1322 * all the contexts in the array (an AVCodecContext per RTP stream)
4f57fa8c 1323 * must contain only one AVStream.
8767b80f
LA
1324 * @param n_files number of AVCodecContexts contained in ac
1325 * @param buff buffer where the SDP will be stored (must be allocated by
4f57fa8c 1326 * the caller)
8767b80f 1327 * @param size the size of the buffer
4f57fa8c 1328 * @return 0 if OK, AVERROR_xxx on error
c5388c07 1329 */
8767b80f 1330int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
c5388c07 1331
1a70d127
SS
1332/**
1333 * Returns a positive value if the given filename has one of the given
1334 * extensions, 0 otherwise.
1335 *
1336 * @param extensions a comma-separated list of filename extensions
1337 */
1338int av_match_ext(const char *filename, const char *extensions);
1339
98790382 1340#endif /* AVFORMAT_AVFORMAT_H */