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