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