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