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