Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 17ca374c

History | View | Annotate | Download (55.7 KB)

1 04d7f601 Diego Biurrun
/*
2
 * copyright (c) 2001 Fabrice Bellard
3
 *
4 2912e87a Mans Rullgard
 * This file is part of Libav.
5 b78e7197 Diego Biurrun
 *
6 2912e87a Mans Rullgard
 * Libav is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 2912e87a Mans Rullgard
 * Libav is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * 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
17 2912e87a Mans Rullgard
 * License along with Libav; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21 98790382 Stefano Sabatini
#ifndef AVFORMAT_AVFORMAT_H
22
#define AVFORMAT_AVFORMAT_H
23 de6d9b64 Fabrice Bellard
24 072e3efd Aurelien Jacobs
25 c97429e2 Stefano Sabatini
/**
26 f2e77e4b Art Clarke
 * I return the LIBAVFORMAT_VERSION_INT constant.  You got
27
 * a fucking problem with that, douchebag?
28 c97429e2 Stefano Sabatini
 */
29
unsigned avformat_version(void);
30
31 c1736936 Diego Biurrun
/**
32 49bd8e4b Måns Rullgård
 * Return the libavformat build-time configuration.
33 c1736936 Diego Biurrun
 */
34 41600690 Stefano Sabatini
const char *avformat_configuration(void);
35 c1736936 Diego Biurrun
36
/**
37 49bd8e4b Måns Rullgård
 * Return the libavformat license.
38 c1736936 Diego Biurrun
 */
39 41600690 Stefano Sabatini
const char *avformat_license(void);
40 c1736936 Diego Biurrun
41 f71869a4 Fabrice Bellard
#include <time.h>
42 67070e4f Zdenek Kabelac
#include <stdio.h>  /* FILE */
43 76a448ed Måns Rullgård
#include "libavcodec/avcodec.h"
44 de6d9b64 Fabrice Bellard
45
#include "avio.h"
46 50196a98 Anton Khirnov
#include "libavformat/version.h"
47 de6d9b64 Fabrice Bellard
48 f610a9f2 Aurelien Jacobs
struct AVFormatContext;
49
50 a6d18a0e Michael Niedermayer
51
/*
52 ea29242c Mike Melanson
 * Public Metadata API.
53
 * The metadata API allows libavformat to export metadata tags to a client
54 2912e87a Mans Rullgard
 * application using a sequence of key/value pairs. Like all strings in Libav,
55 61648423 Anton Khirnov
 * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
56
 * exported by demuxers isn't checked to be valid UTF-8 in most cases.
57 ea29242c Mike Melanson
 * Important concepts to keep in mind:
58
 * 1. Keys are unique; there can never be 2 tags with the same key. This is
59
 *    also meant semantically, i.e., a demuxer should not knowingly produce
60
 *    several keys that are literally different but semantically identical.
61
 *    E.g., key=Author5, key=Author6. In this example, all authors must be
62
 *    placed in the same tag.
63
 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
64
 *    want to store, e.g., the email address of the child of producer Alice
65
 *    and actor Bob, that could have key=alice_and_bobs_childs_email_address.
66 ca76a119 Anton Khirnov
 * 3. Several modifiers can be applied to the tag name. This is done by
67
 *    appending a dash character ('-') and the modifier name in the order
68
 *    they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
69
 *    a) language -- a tag whose value is localized for a particular language
70
 *       is appended with the ISO 639-2/B 3-letter language code.
71
 *       For example: Author-ger=Michael, Author-eng=Mike
72
 *       The original/default language is in the unqualified "Author" tag.
73
 *       A demuxer should set a default if it sets any translated tag.
74
 *    b) sorting  -- a modified version of a tag that should be used for
75
 *       sorting will have '-sort' appended. E.g. artist="The Beatles",
76
 *       artist-sort="Beatles, The".
77
 *
78 03700d39 Anton Khirnov
 * 4. Demuxers attempt to export metadata in a generic format, however tags
79
 *    with no generic equivalents are left as they are stored in the container.
80
 *    Follows a list of generic tag names:
81 ca76a119 Anton Khirnov
 *
82
 * album        -- name of the set this work belongs to
83
 * album_artist -- main creator of the set/album, if different from artist.
84
 *                 e.g. "Various Artists" for compilation albums.
85
 * artist       -- main creator of the work
86
 * comment      -- any additional description of the file.
87
 * composer     -- who composed the work, if different from artist.
88
 * copyright    -- name of copyright holder.
89 29c5c590 Anton Khirnov
 * creation_time-- date when the file was created, preferably in ISO 8601.
90 ca76a119 Anton Khirnov
 * date         -- date when the work was created, preferably in ISO 8601.
91
 * disc         -- number of a subset, e.g. disc in a multi-disc collection.
92
 * encoder      -- name/settings of the software/hardware that produced the file.
93
 * encoded_by   -- person/group who created the file.
94
 * filename     -- original name of the file.
95
 * genre        -- <self-evident>.
96
 * language     -- main language in which the work is performed, preferably
97 c9256246 Anssi Hannula
 *                 in ISO 639-2 format. Multiple languages can be specified by
98
 *                 separating them with commas.
99 ca76a119 Anton Khirnov
 * performer    -- artist who performed the work, if different from artist.
100
 *                 E.g for "Also sprach Zarathustra", artist would be "Richard
101
 *                 Strauss" and performer "London Philharmonic Orchestra".
102
 * publisher    -- name of the label/publisher.
103 69688e71 Georgi Chorbadzhiyski
 * service_name     -- name of the service in broadcasting (channel name).
104
 * service_provider -- name of the service provider in broadcasting.
105 ca76a119 Anton Khirnov
 * title        -- name of the work.
106
 * track        -- number of this work in the set, can be in form current/total.
107 a6d18a0e Michael Niedermayer
 */
108
109 48a81c0f Aurelien Jacobs
#define AV_METADATA_MATCH_CASE      1
110 a6d18a0e Michael Niedermayer
#define AV_METADATA_IGNORE_SUFFIX   2
111 a181981e Michael Niedermayer
#define AV_METADATA_DONT_STRDUP_KEY 4
112
#define AV_METADATA_DONT_STRDUP_VAL 8
113 56a8242f Ronald S. Bultje
#define AV_METADATA_DONT_OVERWRITE 16   ///< Don't overwrite existing tags.
114 a6d18a0e Michael Niedermayer
115
typedef struct {
116
    char *key;
117
    char *value;
118 bc1d2afb Aurelien Jacobs
}AVMetadataTag;
119 a6d18a0e Michael Niedermayer
120 e232c252 Aurelien Jacobs
typedef struct AVMetadata AVMetadata;
121 03700d39 Anton Khirnov
#if FF_API_OLD_METADATA
122 f610a9f2 Aurelien Jacobs
typedef struct AVMetadataConv AVMetadataConv;
123 03700d39 Anton Khirnov
#endif
124 a6d18a0e Michael Niedermayer
125
/**
126 49bd8e4b Måns Rullgård
 * Get a metadata element with matching key.
127 26cc5310 Stefano Sabatini
 *
128 22e77e44 Diego Biurrun
 * @param prev Set to the previous matching element to find the next.
129 66b6c745 Stefano Sabatini
 *             If set to NULL the first matching element is returned.
130 22e77e44 Diego Biurrun
 * @param flags Allows case as well as suffix-insensitive comparisons.
131
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
132 a6d18a0e Michael Niedermayer
 */
133 bc1d2afb Aurelien Jacobs
AVMetadataTag *
134 e232c252 Aurelien Jacobs
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
135 a6d18a0e Michael Niedermayer
136 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
137 a6d18a0e Michael Niedermayer
/**
138 32e6f246 Stefano Sabatini
 * Set the given tag in *pm, overwriting an existing tag.
139 26cc5310 Stefano Sabatini
 *
140 983ec304 Stefano Sabatini
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
141
 * a metadata struct is allocated and put in *pm.
142 32e6f246 Stefano Sabatini
 * @param key tag key to add to *pm (will be av_strduped)
143
 * @param value tag value to add to *pm (will be av_strduped)
144 22e77e44 Diego Biurrun
 * @return >= 0 on success otherwise an error code <0
145 2ef6c124 Stefano Sabatini
 * @deprecated Use av_metadata_set2() instead.
146 a6d18a0e Michael Niedermayer
 */
147 2ef6c124 Stefano Sabatini
attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
148 a181981e Michael Niedermayer
#endif
149
150
/**
151 32e6f246 Stefano Sabatini
 * Set the given tag in *pm, overwriting an existing tag.
152 26cc5310 Stefano Sabatini
 *
153 983ec304 Stefano Sabatini
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
154
 * a metadata struct is allocated and put in *pm.
155 32e6f246 Stefano Sabatini
 * @param key tag key to add to *pm (will be av_strduped depending on flags)
156
 * @param value tag value to add to *pm (will be av_strduped depending on flags).
157 160c896c Anton Khirnov
 *        Passing a NULL value will cause an existing tag to be deleted.
158 a181981e Michael Niedermayer
 * @return >= 0 on success otherwise an error code <0
159
 */
160
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
161 a6d18a0e Michael Niedermayer
162 03700d39 Anton Khirnov
#if FF_API_OLD_METADATA
163 094d9df7 Aurelien Jacobs
/**
164 03700d39 Anton Khirnov
 * This function is provided for compatibility reason and currently does nothing.
165 f610a9f2 Aurelien Jacobs
 */
166 03700d39 Anton Khirnov
attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
167
                                                                        const AVMetadataConv *s_conv);
168
#endif
169 f610a9f2 Aurelien Jacobs
170
/**
171 7f88a5bf Ronald S. Bultje
 * Copy metadata from one AVMetadata struct into another.
172
 * @param dst pointer to a pointer to a AVMetadata struct. If *dst is NULL,
173
 *            this function will allocate a struct for you and put it in *dst
174
 * @param src pointer to source AVMetadata struct
175
 * @param flags flags to use when setting metadata in *dst
176
 * @note metadata is read using the AV_METADATA_IGNORE_SUFFIX flag
177
 */
178
void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags);
179
180
/**
181 49bd8e4b Måns Rullgård
 * Free all the memory allocated for an AVMetadata struct.
182 094d9df7 Aurelien Jacobs
 */
183
void av_metadata_free(AVMetadata **m);
184
185 a6d18a0e Michael Niedermayer
186 de6d9b64 Fabrice Bellard
/* packet functions */
187
188 3217cb42 Panagiotis Issaris
189
/**
190 49bd8e4b Måns Rullgård
 * Allocate and read the payload of a packet and initialize its
191 d1b9adf2 Stefano Sabatini
 * fields with default values.
192 3217cb42 Panagiotis Issaris
 *
193
 * @param pkt packet
194 4f57fa8c Diego Biurrun
 * @param size desired payload size
195
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
196 3217cb42 Panagiotis Issaris
 */
197 ae628ec1 Anton Khirnov
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
198 3217cb42 Panagiotis Issaris
199 de6d9b64 Fabrice Bellard
200 6bfc2683 Reimar Döffinger
/**
201 fa8cc126 Reimar Döffinger
 * Read data and append it to the current content of the AVPacket.
202
 * If pkt->size is 0 this is identical to av_get_packet.
203 6bfc2683 Reimar Döffinger
 * Note that this uses av_grow_packet and thus involves a realloc
204
 * which is inefficient. Thus this function should only be used
205
 * when there is no reasonable way to know (an upper bound of)
206
 * the final size.
207
 *
208
 * @param pkt packet
209
 * @param size amount of data to read
210
 * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
211
 *         will not be lost even if an error occurs.
212
 */
213 ae628ec1 Anton Khirnov
int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
214 6bfc2683 Reimar Döffinger
215 de6d9b64 Fabrice Bellard
/*************************************************/
216 916c80e9 Fabrice Bellard
/* fractional numbers for exact pts handling */
217
218 671adb17 Mark Cox
/**
219 4f57fa8c Diego Biurrun
 * The exact value of the fractional number is: 'val + num / den'.
220
 * num is assumed to be 0 <= num < den.
221 4c08b2bd Stefano Sabatini
 */
222 916c80e9 Fabrice Bellard
typedef struct AVFrac {
223 115329f1 Diego Biurrun
    int64_t val, num, den;
224 52e57500 Diego Biurrun
} AVFrac;
225 916c80e9 Fabrice Bellard
226
/*************************************************/
227 b9a281db Fabrice Bellard
/* input/output formats */
228 de6d9b64 Fabrice Bellard
229 7caf0cc6 Michael Niedermayer
struct AVCodecTag;
230
231 76c56376 Michael Niedermayer
/**
232
 * This structure contains the data a format has to probe a file.
233
 */
234 b9a281db Fabrice Bellard
typedef struct AVProbeData {
235 5c91a675 Zdenek Kabelac
    const char *filename;
236 e5f58f81 shinya.tesutosan@hotmail.com
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
237
    int buf_size;       /**< Size of buf except extra allocated bytes */
238 b9a281db Fabrice Bellard
} AVProbeData;
239
240 22e77e44 Diego Biurrun
#define AVPROBE_SCORE_MAX 100               ///< maximum score, half of that is used for file-extension-based detection
241 87e87886 Michael Niedermayer
#define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
242 de6d9b64 Fabrice Bellard
243
typedef struct AVFormatParameters {
244 c0df9d75 Michael Niedermayer
    AVRational time_base;
245 de6d9b64 Fabrice Bellard
    int sample_rate;
246
    int channels;
247
    int width;
248
    int height;
249 4606ac8d Zdenek Kabelac
    enum PixelFormat pix_fmt;
250 4f57fa8c Diego Biurrun
    int channel; /**< Used to select DV channel. */
251
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
252
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
253
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
254 72e043dd Erik Hovland
                                            stream packet (only meaningful if
255 4f57fa8c Diego Biurrun
                                            mpeg2ts_raw is TRUE). */
256
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
257
                                            immediately (RTSP only). */
258 72e043dd Erik Hovland
    unsigned int prealloced_context:1;
259 0139fdea Aurelien Jacobs
#if FF_API_PARAMETERS_CODEC_ID
260 a15c7fd6 Anton Khirnov
    attribute_deprecated enum CodecID video_codec_id;
261
    attribute_deprecated enum CodecID audio_codec_id;
262 71957315 Michael Niedermayer
#endif
263 de6d9b64 Fabrice Bellard
} AVFormatParameters;
264
265 22a3212e Anton Khirnov
//! Demuxer will use avio_open, no opened file should be provided by the caller.
266 40d9c544 Reimar Döffinger
#define AVFMT_NOFILE        0x0001
267 4f57fa8c Diego Biurrun
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
268
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
269
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
270
                                      raw picture data. */
271
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
272
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
273
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
274 58ec7e00 Michael Niedermayer
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
275 25918212 Michael Niedermayer
#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
276 ab5a0175 Michael Niedermayer
#define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
277 bb62d5c1 Anton Khirnov
#define AVFMT_NOSTREAMS     0x1000 /**< Format does not require any streams */
278 b9a281db Fabrice Bellard
279
typedef struct AVOutputFormat {
280 de6d9b64 Fabrice Bellard
    const char *name;
281 bde15e74 Stefano Sabatini
    /**
282
     * Descriptive name for the format, meant to be more human-readable
283 819174fa Stefano Sabatini
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
284 bde15e74 Stefano Sabatini
     * to define it.
285
     */
286 de6d9b64 Fabrice Bellard
    const char *long_name;
287
    const char *mime_type;
288 4f57fa8c Diego Biurrun
    const char *extensions; /**< comma-separated filename extensions */
289 76c56376 Michael Niedermayer
    /**
290
     * size of private data so that it can be allocated in the wrapper
291
     */
292 b9a281db Fabrice Bellard
    int priv_data_size;
293 de6d9b64 Fabrice Bellard
    /* output support */
294 43d414ba Panagiotis Issaris
    enum CodecID audio_codec; /**< default audio codec */
295
    enum CodecID video_codec; /**< default video codec */
296 de6d9b64 Fabrice Bellard
    int (*write_header)(struct AVFormatContext *);
297 e928649b Michael Niedermayer
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
298 de6d9b64 Fabrice Bellard
    int (*write_trailer)(struct AVFormatContext *);
299 76c56376 Michael Niedermayer
    /**
300 89e568fe Anssi Hannula
     * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
301
     * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
302
     * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
303 76c56376 Michael Niedermayer
     */
304 b9a281db Fabrice Bellard
    int flags;
305 76c56376 Michael Niedermayer
    /**
306
     * Currently only used to set pixel format if not YUV420P.
307
     */
308 290c5fa6 Fabrice Bellard
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
309 78cb7273 Diego Biurrun
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
310
                             AVPacket *in, int flush);
311 7caf0cc6 Michael Niedermayer
312
    /**
313 78cb7273 Diego Biurrun
     * List of supported codec_id-codec_tag pairs, ordered by "better
314 22e77e44 Diego Biurrun
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
315 7caf0cc6 Michael Niedermayer
     */
316 c1854592 Reimar Döffinger
    const struct AVCodecTag * const *codec_tag;
317 7caf0cc6 Michael Niedermayer
318 11bf3847 Aurelien Jacobs
    enum CodecID subtitle_codec; /**< default subtitle codec */
319
320 03700d39 Anton Khirnov
#if FF_API_OLD_METADATA
321 719e721a Aurelien Jacobs
    const AVMetadataConv *metadata_conv;
322 03700d39 Anton Khirnov
#endif
323 f610a9f2 Aurelien Jacobs
324 cf99e4aa Anssi Hannula
    const AVClass *priv_class; ///< AVClass for the private context
325
326 b9a281db Fabrice Bellard
    /* private fields */
327
    struct AVOutputFormat *next;
328
} AVOutputFormat;
329 de6d9b64 Fabrice Bellard
330 b9a281db Fabrice Bellard
typedef struct AVInputFormat {
331 76c56376 Michael Niedermayer
    /**
332
     * A comma separated list of short names for the format. New names
333 ac3ccbc0 Alex Converse
     * may be appended with a minor bump.
334
     */
335 b9a281db Fabrice Bellard
    const char *name;
336 76c56376 Michael Niedermayer
337 bde15e74 Stefano Sabatini
    /**
338
     * Descriptive name for the format, meant to be more human-readable
339 819174fa Stefano Sabatini
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
340 bde15e74 Stefano Sabatini
     * to define it.
341
     */
342 b9a281db Fabrice Bellard
    const char *long_name;
343 76c56376 Michael Niedermayer
344
    /**
345
     * Size of private data so that it can be allocated in the wrapper.
346
     */
347 b9a281db Fabrice Bellard
    int priv_data_size;
348 76c56376 Michael Niedermayer
349 65d7d68b Michael Niedermayer
    /**
350 22e77e44 Diego Biurrun
     * Tell if a given file has a chance of being parsed as this format.
351 5d81d641 Diego Biurrun
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
352
     * big so you do not have to check for that unless you need more.
353 65d7d68b Michael Niedermayer
     */
354 b9a281db Fabrice Bellard
    int (*read_probe)(AVProbeData *);
355 76c56376 Michael Niedermayer
356
    /**
357
     * Read the format header and initialize the AVFormatContext
358
     * structure. Return 0 if OK. 'ap' if non-NULL contains
359
     * additional parameters. Only used in raw format right
360
     * now. 'av_new_stream' should be called to create new streams.
361
     */
362 de6d9b64 Fabrice Bellard
    int (*read_header)(struct AVFormatContext *,
363
                       AVFormatParameters *ap);
364 76c56376 Michael Niedermayer
365
    /**
366
     * Read one packet and put it in 'pkt'. pts and flags are also
367
     * set. 'av_new_stream' can be called only if the flag
368 2899a28c Aurelien Jacobs
     * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
369
     * background thread).
370 76c56376 Michael Niedermayer
     * @return 0 on success, < 0 on error.
371
     *         When returning an error, pkt must not have been allocated
372
     *         or must be freed before returning
373
     */
374 de6d9b64 Fabrice Bellard
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
375 76c56376 Michael Niedermayer
376
    /**
377
     * Close the stream. The AVFormatContext and AVStreams are not
378
     * freed by this function
379
     */
380 de6d9b64 Fabrice Bellard
    int (*read_close)(struct AVFormatContext *);
381 1de2db8f Michael Niedermayer
382 634e0304 Aurelien Jacobs
#if FF_API_READ_SEEK
383 115329f1 Diego Biurrun
    /**
384 4f57fa8c Diego Biurrun
     * Seek to a given timestamp relative to the frames in
385
     * stream component stream_index.
386 22e77e44 Diego Biurrun
     * @param stream_index Must not be -1.
387
     * @param flags Selects which direction should be preferred if no exact
388
     *              match is available.
389 05ce0f11 Maksym Veremeyenko
     * @return >= 0 on success (but not necessarily the new offset)
390 3ba1438d Michael Niedermayer
     */
391 a15c7fd6 Anton Khirnov
    attribute_deprecated int (*read_seek)(struct AVFormatContext *,
392
                                          int stream_index, int64_t timestamp, int flags);
393 1de2db8f Michael Niedermayer
#endif
394 8d14a25c Michael Niedermayer
    /**
395 4f57fa8c Diego Biurrun
     * Gets the next timestamp in stream[stream_index].time_base units.
396 d9526386 Diego Biurrun
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
397 8d14a25c Michael Niedermayer
     */
398
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
399
                              int64_t *pos, int64_t pos_limit);
400 76c56376 Michael Niedermayer
401
    /**
402
     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
403
     */
404 de6d9b64 Fabrice Bellard
    int flags;
405 76c56376 Michael Niedermayer
406
    /**
407
     * If extensions are defined, then no probe is done. You should
408
     * usually not use extension format guessing because it is not
409
     * reliable enough
410
     */
411 b9a281db Fabrice Bellard
    const char *extensions;
412 76c56376 Michael Niedermayer
413
    /**
414
     * General purpose read-only value that the format can use.
415
     */
416 b9a281db Fabrice Bellard
    int value;
417 fb2758c8 Fabrice Bellard
418 76c56376 Michael Niedermayer
    /**
419
     * Start/resume playing - only meaningful if using a network-based format
420
     * (RTSP).
421
     */
422 fb2758c8 Fabrice Bellard
    int (*read_play)(struct AVFormatContext *);
423
424 76c56376 Michael Niedermayer
    /**
425
     * Pause playing - only meaningful if using a network-based format
426
     * (RTSP).
427
     */
428 fb2758c8 Fabrice Bellard
    int (*read_pause)(struct AVFormatContext *);
429
430 c1854592 Reimar Döffinger
    const struct AVCodecTag * const *codec_tag;
431 7caf0cc6 Michael Niedermayer
432 1de2db8f Michael Niedermayer
    /**
433 49bd8e4b Måns Rullgård
     * Seek to timestamp ts.
434 1de2db8f Michael Niedermayer
     * Seeking will be done so that the point from which all active streams
435
     * can be presented successfully will be closest to ts and within min/max_ts.
436
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
437
     */
438 882fb0a3 Michael Niedermayer
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
439 1de2db8f Michael Niedermayer
440 03700d39 Anton Khirnov
#if FF_API_OLD_METADATA
441 719e721a Aurelien Jacobs
    const AVMetadataConv *metadata_conv;
442 03700d39 Anton Khirnov
#endif
443 f610a9f2 Aurelien Jacobs
444 b9a281db Fabrice Bellard
    /* private fields */
445
    struct AVInputFormat *next;
446
} AVInputFormat;
447 de6d9b64 Fabrice Bellard
448 57004ff1 Aurelien Jacobs
enum AVStreamParseType {
449
    AVSTREAM_PARSE_NONE,
450
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
451 4f57fa8c Diego Biurrun
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
452 78cb7273 Diego Biurrun
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
453 74a6df59 Alex Converse
    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
454 57004ff1 Aurelien Jacobs
};
455
456 fb2758c8 Fabrice Bellard
typedef struct AVIndexEntry {
457
    int64_t pos;
458
    int64_t timestamp;
459
#define AVINDEX_KEYFRAME 0x0001
460 30a43f2d Michael Niedermayer
    int flags:2;
461 4f57fa8c Diego Biurrun
    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).
462
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
463 fb2758c8 Fabrice Bellard
} AVIndexEntry;
464
465 90c2295b Evgeniy Stepanov
#define AV_DISPOSITION_DEFAULT   0x0001
466
#define AV_DISPOSITION_DUB       0x0002
467
#define AV_DISPOSITION_ORIGINAL  0x0004
468
#define AV_DISPOSITION_COMMENT   0x0008
469
#define AV_DISPOSITION_LYRICS    0x0010
470
#define AV_DISPOSITION_KARAOKE   0x0020
471 76c56376 Michael Niedermayer
472
/**
473
 * Track should be used during playback by default.
474
 * Useful for subtitle track that should be displayed
475
 * even when user did not explicitly ask for subtitles.
476
 */
477 7a617a86 Aurelien Jacobs
#define AV_DISPOSITION_FORCED    0x0040
478 12c14cd4 Peter Ross
#define AV_DISPOSITION_HEARING_IMPAIRED  0x0080  /**< stream for hearing impaired audiences */
479
#define AV_DISPOSITION_VISUAL_IMPAIRED   0x0100  /**< stream for visual impaired audiences */
480 24a83bd1 Anssi Hannula
#define AV_DISPOSITION_CLEAN_EFFECTS     0x0200  /**< stream without voice */
481 90c2295b Evgeniy Stepanov
482 ba66ae94 Michael Niedermayer
/**
483
 * Stream structure.
484
 * New fields can be added to the end with minor version bumps.
485 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
486 ba66ae94 Michael Niedermayer
 * version bump.
487 8bfb108b Diego Biurrun
 * sizeof(AVStream) must not be used outside libav*.
488 ba66ae94 Michael Niedermayer
 */
489 de6d9b64 Fabrice Bellard
typedef struct AVStream {
490 43d414ba Panagiotis Issaris
    int index;    /**< stream index in AVFormatContext */
491 4f57fa8c Diego Biurrun
    int id;       /**< format-specific stream ID */
492 43d414ba Panagiotis Issaris
    AVCodecContext *codec; /**< codec context */
493 b4b87d48 Michael Niedermayer
    /**
494 22e77e44 Diego Biurrun
     * Real base framerate of the stream.
495
     * This is the lowest framerate with which all timestamps can be
496 864ff8c1 Ramiro Polla
     * represented accurately (it is the least common multiple of all
497 22e77e44 Diego Biurrun
     * framerates in the stream). Note, this value is just a guess!
498
     * For example, if the time base is 1/90000 and all frames have either
499 4f57fa8c Diego Biurrun
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
500 b4b87d48 Michael Niedermayer
     */
501
    AVRational r_frame_rate;
502 de6d9b64 Fabrice Bellard
    void *priv_data;
503 82583548 Michael Niedermayer
504 b9a281db Fabrice Bellard
    /* internal data used in av_find_stream_info() */
505 82583548 Michael Niedermayer
    int64_t first_dts;
506 76c56376 Michael Niedermayer
507
    /**
508
     * encoding: pts generation when outputting stream
509
     */
510 a9fd2b19 Måns Rullgård
    struct AVFrac pts;
511 5b28c8c3 Michael Niedermayer
512
    /**
513 8bfb108b Diego Biurrun
     * This is the fundamental unit of time (in seconds) in terms
514
     * of which frame timestamps are represented. For fixed-fps content,
515 22e77e44 Diego Biurrun
     * time base should be 1/framerate and timestamp increments should be 1.
516 5d820db2 Reimar Döffinger
     * decoding: set by libavformat
517
     * encoding: set by libavformat in av_write_header
518 5b28c8c3 Michael Niedermayer
     */
519 9ee91c2f Michael Niedermayer
    AVRational time_base;
520 43d414ba Panagiotis Issaris
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
521 a48b7a6b Fabrice Bellard
    /* ffmpeg.c private use */
522 4f57fa8c Diego Biurrun
    int stream_copy; /**< If set, just copy stream. */
523
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
524 76c56376 Michael Niedermayer
525 b4aea108 Michael Niedermayer
    //FIXME move stuff to a flags field?
526 76c56376 Michael Niedermayer
    /**
527
     * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
528
     * MN: dunno if that is the right place for it
529
     */
530 115329f1 Diego Biurrun
    float quality;
531 76c56376 Michael Niedermayer
532 6d96a9b9 Michael Niedermayer
    /**
533 8bfb108b Diego Biurrun
     * Decoding: pts of the first frame of the stream, in stream time base.
534
     * Only set this if you are absolutely 100% sure that the value you set
535
     * it to really is the pts of the first frame.
536 4854c253 Neil Brown
     * This may be undefined (AV_NOPTS_VALUE).
537 6d96a9b9 Michael Niedermayer
     */
538 115329f1 Diego Biurrun
    int64_t start_time;
539 76c56376 Michael Niedermayer
540 e26381b6 Neil Brown
    /**
541 8bfb108b Diego Biurrun
     * Decoding: duration of the stream, in stream time base.
542 e26381b6 Neil Brown
     * If a source file does not specify a duration, but does specify
543 4f57fa8c Diego Biurrun
     * a bitrate, this value will be estimated from bitrate and file size.
544 e26381b6 Neil Brown
     */
545 ee404803 Fabrice Bellard
    int64_t duration;
546 fb2758c8 Fabrice Bellard
547 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
548 a15c7fd6 Anton Khirnov
    attribute_deprecated char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */
549 827f7e28 Aurelien Jacobs
#endif
550 09730260 Fabrice Bellard
551 fb2758c8 Fabrice Bellard
    /* av_read_frame() support */
552 57004ff1 Aurelien Jacobs
    enum AVStreamParseType need_parsing;
553 fb2758c8 Fabrice Bellard
    struct AVCodecParserContext *parser;
554 6ec87caa Fabrice Bellard
555 fb2758c8 Fabrice Bellard
    int64_t cur_dts;
556 635fbcb1 Michael Niedermayer
    int last_IP_duration;
557
    int64_t last_IP_pts;
558 fb2758c8 Fabrice Bellard
    /* av_seek_frame() support */
559 4f57fa8c Diego Biurrun
    AVIndexEntry *index_entries; /**< Only used if the format does not
560
                                    support seeking natively. */
561 fb2758c8 Fabrice Bellard
    int nb_index_entries;
562 191e8ca7 Måns Rullgård
    unsigned int index_entries_allocated_size;
563 115329f1 Diego Biurrun
564 b4b87d48 Michael Niedermayer
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
565 504ee036 Michael Niedermayer
566 d1742ff7 Aurelien Jacobs
#if FF_API_LAVF_UNUSED
567 a15c7fd6 Anton Khirnov
    attribute_deprecated int64_t unused[4+1];
568 dd872bf4 Aurelien Jacobs
#endif
569 f8d7c9d3 Evgeniy Stepanov
570 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
571 a15c7fd6 Anton Khirnov
    attribute_deprecated char *filename; /**< source filename of the stream */
572 827f7e28 Aurelien Jacobs
#endif
573 90c2295b Evgeniy Stepanov
574 4f57fa8c Diego Biurrun
    int disposition; /**< AV_DISPOSITION_* bit field */
575 0bef08e5 Michael Niedermayer
576
    AVProbeData probe_data;
577 0d84a8f6 Baptiste Coudurier
#define MAX_REORDER_DELAY 16
578
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
579 c30a4489 Aurelien Jacobs
580
    /**
581
     * sample aspect ratio (0 if unknown)
582
     * - encoding: Set by user.
583
     * - decoding: Set by libavformat.
584
     */
585
    AVRational sample_aspect_ratio;
586 f526adaf Aurelien Jacobs
587 e232c252 Aurelien Jacobs
    AVMetadata *metadata;
588 3a41c2f7 Michael Niedermayer
589 31769dad Víctor Paesa
    /* Intended mostly for av_read_frame() support. Not supposed to be used by */
590
    /* external applications; try to use something else if at all possible.    */
591 3a41c2f7 Michael Niedermayer
    const uint8_t *cur_ptr;
592
    int cur_len;
593
    AVPacket cur_pkt;
594 27ca0a79 Ivan Schreter
595
    // Timestamp generation support:
596
    /**
597
     * Timestamp corresponding to the last dts sync point.
598
     *
599
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
600
     * a DTS is received from the underlying container. Otherwise set to
601
     * AV_NOPTS_VALUE by default.
602
     */
603
    int64_t reference_dts;
604 86cb7e33 Baptiste Coudurier
605
    /**
606
     * Number of packets to buffer for codec probing
607
     * NOT PART OF PUBLIC API
608
     */
609 48616887 Carl Eugen Hoyos
#define MAX_PROBE_PACKETS 2500
610 86cb7e33 Baptiste Coudurier
    int probe_packets;
611 ddce56ef Michael Niedermayer
612
    /**
613 e07b882b Michael Niedermayer
     * last packet in packet_buffer for this stream when muxing.
614 ddce56ef Michael Niedermayer
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
615
     */
616 e07b882b Michael Niedermayer
    struct AVPacketList *last_in_packet_buffer;
617 02b398ef Michael Niedermayer
618
    /**
619
     * Average framerate
620
     */
621
    AVRational avg_frame_rate;
622 6c6e6ef5 Michael Niedermayer
623
    /**
624
     * Number of frames that have been demuxed during av_find_stream_info()
625
     */
626
    int codec_info_nb_frames;
627 fd0368e7 Aurelien Jacobs
628
    /**
629
     * Stream informations used internally by av_find_stream_info()
630
     */
631
#define MAX_STD_TIMEBASES (60*12+5)
632
    struct {
633
        int64_t last_dts;
634
        int64_t duration_gcd;
635
        int duration_count;
636
        double duration_error[MAX_STD_TIMEBASES];
637
        int64_t codec_info_duration;
638
    } *info;
639 de6d9b64 Fabrice Bellard
} AVStream;
640
641 15afa396 Nico Sabbi
#define AV_PROGRAM_RUNNING 1
642
643 ba66ae94 Michael Niedermayer
/**
644
 * New fields can be added to the end with minor version bumps.
645 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
646 ba66ae94 Michael Niedermayer
 * version bump.
647 8bfb108b Diego Biurrun
 * sizeof(AVProgram) must not be used outside libav*.
648 ba66ae94 Michael Niedermayer
 */
649 15afa396 Nico Sabbi
typedef struct AVProgram {
650
    int            id;
651 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
652 a15c7fd6 Anton Khirnov
    attribute_deprecated char           *provider_name; ///< network name for DVB streams
653
    attribute_deprecated char           *name;          ///< service name for DVB streams
654 827f7e28 Aurelien Jacobs
#endif
655 15afa396 Nico Sabbi
    int            flags;
656
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
657 526efa10 Nico Sabbi
    unsigned int   *stream_index;
658
    unsigned int   nb_stream_indexes;
659 e232c252 Aurelien Jacobs
    AVMetadata *metadata;
660 15afa396 Nico Sabbi
} AVProgram;
661
662 43d414ba Panagiotis Issaris
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
663 da24c5e3 Fabrice Bellard
                                         (streams are added dynamically) */
664
665 79d7836a Anton Khirnov
typedef struct AVChapter {
666 4f57fa8c Diego Biurrun
    int id;                 ///< unique ID to identify the chapter
667
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
668 8931e7b4 Michael Niedermayer
    int64_t start, end;     ///< chapter start/end time in time_base units
669 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
670 a15c7fd6 Anton Khirnov
    attribute_deprecated char *title;            ///< chapter title
671 827f7e28 Aurelien Jacobs
#endif
672 e232c252 Aurelien Jacobs
    AVMetadata *metadata;
673 79d7836a Anton Khirnov
} AVChapter;
674
675 54036be1 Aurelien Jacobs
#if FF_API_MAX_STREAMS
676 de6d9b64 Fabrice Bellard
#define MAX_STREAMS 20
677 ad5cc780 Jai Menon
#endif
678 de6d9b64 Fabrice Bellard
679 252f17e2 Michael Niedermayer
/**
680 4f57fa8c Diego Biurrun
 * Format I/O context.
681 252f17e2 Michael Niedermayer
 * New fields can be added to the end with minor version bumps.
682 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
683 252f17e2 Michael Niedermayer
 * version bump.
684 8bfb108b Diego Biurrun
 * sizeof(AVFormatContext) must not be used outside libav*.
685 252f17e2 Michael Niedermayer
 */
686 de6d9b64 Fabrice Bellard
typedef struct AVFormatContext {
687 1447aac4 avcoder
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
688 4f57fa8c Diego Biurrun
    /* Can only be iformat or oformat, not both at the same time. */
689 b9a281db Fabrice Bellard
    struct AVInputFormat *iformat;
690
    struct AVOutputFormat *oformat;
691 de6d9b64 Fabrice Bellard
    void *priv_data;
692 ae628ec1 Anton Khirnov
    AVIOContext *pb;
693 db69c2e5 Diego Biurrun
    unsigned int nb_streams;
694 61138c43 Aurelien Jacobs
#if FF_API_MAX_STREAMS
695 de6d9b64 Fabrice Bellard
    AVStream *streams[MAX_STREAMS];
696 38aab35f Aurelien Jacobs
#else
697
    AVStream **streams;
698
#endif
699 43d414ba Panagiotis Issaris
    char filename[1024]; /**< input or output filename */
700 de6d9b64 Fabrice Bellard
    /* stream info */
701 4568325a Roman Shaposhnik
    int64_t timestamp;
702 54036be1 Aurelien Jacobs
#if FF_API_OLD_METADATA
703 a15c7fd6 Anton Khirnov
    attribute_deprecated char title[512];
704
    attribute_deprecated char author[512];
705
    attribute_deprecated char copyright[512];
706
    attribute_deprecated char comment[512];
707
    attribute_deprecated char album[512];
708
    attribute_deprecated int year;  /**< ID3 year, 0 if none */
709
    attribute_deprecated int track; /**< track number, 0 if none */
710
    attribute_deprecated char genre[32]; /**< ID3 genre */
711 827f7e28 Aurelien Jacobs
#endif
712 6a58e151 Fabrice Bellard
713 4f57fa8c Diego Biurrun
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
714
    /* private data for pts handling (do not modify directly). */
715 76c56376 Michael Niedermayer
    /**
716
     * This buffer is only needed when packets were already buffered but
717
     * not decoded, for example to get the codec parameters in MPEG
718
     * streams.
719
     */
720 ee404803 Fabrice Bellard
    struct AVPacketList *packet_buffer;
721
722 76c56376 Michael Niedermayer
    /**
723
     * Decoding: position of the first frame of the component, in
724
     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
725
     * It is deduced from the AVStream values.
726
     */
727 115329f1 Diego Biurrun
    int64_t start_time;
728 76c56376 Michael Niedermayer
729
    /**
730
     * Decoding: duration of the stream, in AV_TIME_BASE fractional
731
     * seconds. Only set this value if you know none of the individual stream
732
     * durations and also dont set any of them. This is deduced from the
733
     * AVStream values if not set.
734
     */
735 ee404803 Fabrice Bellard
    int64_t duration;
736 76c56376 Michael Niedermayer
737
    /**
738
     * decoding: total file size, 0 if unknown
739
     */
740 ee404803 Fabrice Bellard
    int64_t file_size;
741 76c56376 Michael Niedermayer
742
    /**
743
     * Decoding: total stream bitrate in bit/s, 0 if not
744
     * available. Never set it directly if the file_size and the
745
     * duration are known as FFmpeg can compute it automatically.
746
     */
747 ee404803 Fabrice Bellard
    int bit_rate;
748 fb2758c8 Fabrice Bellard
749
    /* av_read_frame() support */
750
    AVStream *cur_st;
751 d1742ff7 Aurelien Jacobs
#if FF_API_LAVF_UNUSED
752 3a41c2f7 Michael Niedermayer
    const uint8_t *cur_ptr_deprecated;
753
    int cur_len_deprecated;
754
    AVPacket cur_pkt_deprecated;
755
#endif
756 fb2758c8 Fabrice Bellard
757
    /* av_seek_frame() support */
758 ec906fcd Michael Niedermayer
    int64_t data_offset; /**< offset of the first packet */
759 b0294c80 Anton Khirnov
#if FF_API_INDEX_BUILT
760
    attribute_deprecated int index_built;
761
#endif
762 115329f1 Diego Biurrun
763 2db3c638 Michael Niedermayer
    int mux_rate;
764 92400be2 Ronald S. Bultje
    unsigned int packet_size;
765 17c88cb0 Michael Niedermayer
    int preload;
766
    int max_delay;
767 8108551a Todd Kirby
768 115329f1 Diego Biurrun
#define AVFMT_NOOUTPUTLOOP -1
769
#define AVFMT_INFINITEOUTPUTLOOP 0
770 76c56376 Michael Niedermayer
    /**
771
     * number of times to loop output in formats that support it
772
     */
773 8108551a Todd Kirby
    int loop_output;
774 115329f1 Diego Biurrun
775 30bc6613 Michael Niedermayer
    int flags;
776 22e77e44 Diego Biurrun
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
777 4f57fa8c Diego Biurrun
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
778
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
779 c55806e3 Michael Niedermayer
#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
780 fe8344a2 Michael Niedermayer
#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
781
#define AVFMT_FLAG_NOPARSE      0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
782 796ac233 Martin Storsjö
#define AVFMT_FLAG_RTP_HINT     0x0040 ///< Add RTP hinting to the output file
783 5894e1bb Víctor Paesa
784
    int loop_input;
785 76c56376 Michael Niedermayer
786
    /**
787
     * decoding: size of data to probe; encoding: unused.
788
     */
789 9e6c9470 Nico Sabbi
    unsigned int probesize;
790 a44b3c4d Michael Niedermayer
791
    /**
792 4f57fa8c Diego Biurrun
     * Maximum time (in AV_TIME_BASE units) during which the input should
793
     * be analyzed in av_find_stream_info().
794 a44b3c4d Michael Niedermayer
     */
795
    int max_analyze_duration;
796 c964c2c7 Reimar Döffinger
797
    const uint8_t *key;
798
    int keylen;
799 15afa396 Nico Sabbi
800
    unsigned int nb_programs;
801
    AVProgram **programs;
802 62600469 Michael Niedermayer
803
    /**
804
     * Forced video codec_id.
805 4f57fa8c Diego Biurrun
     * Demuxing: Set by user.
806 62600469 Michael Niedermayer
     */
807
    enum CodecID video_codec_id;
808 76c56376 Michael Niedermayer
809 62600469 Michael Niedermayer
    /**
810
     * Forced audio codec_id.
811 4f57fa8c Diego Biurrun
     * Demuxing: Set by user.
812 62600469 Michael Niedermayer
     */
813
    enum CodecID audio_codec_id;
814 76c56376 Michael Niedermayer
815 62600469 Michael Niedermayer
    /**
816
     * Forced subtitle codec_id.
817 4f57fa8c Diego Biurrun
     * Demuxing: Set by user.
818 62600469 Michael Niedermayer
     */
819
    enum CodecID subtitle_codec_id;
820 3dea63bd Paul Kelly
821
    /**
822 22e77e44 Diego Biurrun
     * Maximum amount of memory in bytes to use for the index of each stream.
823
     * If the index exceeds this size, entries will be discarded as
824 3dea63bd Paul Kelly
     * needed to maintain a smaller size. This can lead to slower or less
825
     * accurate seeking (depends on demuxer).
826 4f57fa8c Diego Biurrun
     * Demuxers for which a full in-memory index is mandatory will ignore
827 3dea63bd Paul Kelly
     * this.
828
     * muxing  : unused
829
     * demuxing: set by user
830
     */
831
    unsigned int max_index_size;
832 ab8ab30c Ramiro Polla
833
    /**
834 ffa71b2b Ramiro Polla
     * Maximum amount of memory in bytes to use for buffering frames
835 4f57fa8c Diego Biurrun
     * obtained from realtime capture devices.
836 ab8ab30c Ramiro Polla
     */
837
    unsigned int max_picture_buffer;
838 79d7836a Anton Khirnov
839 fbabf1e9 Michael Niedermayer
    unsigned int nb_chapters;
840 79d7836a Anton Khirnov
    AVChapter **chapters;
841 45b2b05f Michael Niedermayer
842
    /**
843 4f57fa8c Diego Biurrun
     * Flags to enable debugging.
844 45b2b05f Michael Niedermayer
     */
845
    int debug;
846
#define FF_FDEBUG_TS        0x0001
847 0bef08e5 Michael Niedermayer
848
    /**
849 4f57fa8c Diego Biurrun
     * Raw packets from the demuxer, prior to parsing and decoding.
850 0bef08e5 Michael Niedermayer
     * This buffer is used for buffering packets until the codec can
851
     * be identified, as parsing cannot be done without knowing the
852
     * codec.
853
     */
854
    struct AVPacketList *raw_packet_buffer;
855 5c5b1731 Måns Rullgård
    struct AVPacketList *raw_packet_buffer_end;
856
857
    struct AVPacketList *packet_buffer_end;
858 47146dfb Michael Niedermayer
859 e232c252 Aurelien Jacobs
    AVMetadata *metadata;
860 af122d6a Baptiste Coudurier
861
    /**
862
     * Remaining size available for raw_packet_buffer, in bytes.
863
     * NOT PART OF PUBLIC API
864
     */
865 48616887 Carl Eugen Hoyos
#define RAW_PACKET_BUFFER_SIZE 2500000
866 af122d6a Baptiste Coudurier
    int raw_packet_buffer_remaining_size;
867 b8819c85 Martin Storsjö
868
    /**
869
     * Start time of the stream in real world time, in microseconds
870
     * since the unix epoch (00:00 1st January 1970). That is, pts=0
871
     * in the stream was captured at this real world time.
872
     * - encoding: Set by user.
873
     * - decoding: Unused.
874
     */
875
    int64_t start_time_realtime;
876 de6d9b64 Fabrice Bellard
} AVFormatContext;
877
878
typedef struct AVPacketList {
879
    AVPacket pkt;
880
    struct AVPacketList *next;
881
} AVPacketList;
882
883 114c9a59 Aurelien Jacobs
#if FF_API_FIRST_FORMAT
884 a15c7fd6 Anton Khirnov
attribute_deprecated extern AVInputFormat *first_iformat;
885
attribute_deprecated extern AVOutputFormat *first_oformat;
886 84be6e72 Michael Niedermayer
#endif
887
888 aeedac95 Stefano Sabatini
/**
889
 * If f is NULL, returns the first registered input format,
890 22e77e44 Diego Biurrun
 * if f is non-NULL, returns the next registered input format after f
891 aeedac95 Stefano Sabatini
 * or NULL if f is the last one.
892
 */
893 84be6e72 Michael Niedermayer
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
894 aeedac95 Stefano Sabatini
895
/**
896
 * If f is NULL, returns the first registered output format,
897 22e77e44 Diego Biurrun
 * if f is non-NULL, returns the next registered output format after f
898 aeedac95 Stefano Sabatini
 * or NULL if f is the last one.
899
 */
900 84be6e72 Michael Niedermayer
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
901 de6d9b64 Fabrice Bellard
902 a9bf9d8e Anton Khirnov
#if FF_API_GUESS_IMG2_CODEC
903
attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
904
#endif
905 290c5fa6 Fabrice Bellard
906 22e77e44 Diego Biurrun
/* XXX: Use automatic init with either ELF sections or C file parser */
907
/* modules. */
908 de6d9b64 Fabrice Bellard
909 b9a281db Fabrice Bellard
/* utils.c */
910
void av_register_input_format(AVInputFormat *format);
911
void av_register_output_format(AVOutputFormat *format);
912 198ac67f Aurelien Jacobs
#if FF_API_GUESS_FORMAT
913 1642ee43 Stefano Sabatini
attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
914 78cb7273 Diego Biurrun
                                    const char *filename,
915
                                    const char *mime_type);
916 a1f547b9 Stefano Sabatini
917
/**
918
 * @deprecated Use av_guess_format() instead.
919
 */
920
attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
921
                                                  const char *filename,
922
                                                  const char *mime_type);
923 1642ee43 Stefano Sabatini
#endif
924 f48b0fa2 Stefano Sabatini
925
/**
926 49bd8e4b Måns Rullgård
 * Return the output format in the list of registered output formats
927
 * which best matches the provided parameters, or return NULL if
928 f48b0fa2 Stefano Sabatini
 * there is no match.
929
 *
930
 * @param short_name if non-NULL checks if short_name matches with the
931
 * names of the registered formats
932
 * @param filename if non-NULL checks if filename terminates with the
933
 * extensions of the registered formats
934
 * @param mime_type if non-NULL checks if mime_type matches with the
935
 * MIME type of the registered formats
936
 */
937 a1f547b9 Stefano Sabatini
AVOutputFormat *av_guess_format(const char *short_name,
938 94b1f338 Stefano Sabatini
                                const char *filename,
939
                                const char *mime_type);
940 3217cb42 Panagiotis Issaris
941
/**
942 49bd8e4b Måns Rullgård
 * Guess the codec ID based upon muxer and filename.
943 3217cb42 Panagiotis Issaris
 */
944 115329f1 Diego Biurrun
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
945 78cb7273 Diego Biurrun
                            const char *filename, const char *mime_type,
946 72415b2a Stefano Sabatini
                            enum AVMediaType type);
947 de6d9b64 Fabrice Bellard
948 3217cb42 Panagiotis Issaris
/**
949 49bd8e4b Måns Rullgård
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
950 750f0e1f Panagiotis Issaris
 *
951
 * @param f The file stream pointer where the dump should be sent to.
952 3217cb42 Panagiotis Issaris
 * @param buf buffer
953
 * @param size buffer size
954 750f0e1f Panagiotis Issaris
 *
955 863c4716 Martin Storsjö
 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
956 3217cb42 Panagiotis Issaris
 */
957 fb2758c8 Fabrice Bellard
void av_hex_dump(FILE *f, uint8_t *buf, int size);
958 3217cb42 Panagiotis Issaris
959
/**
960 49bd8e4b Måns Rullgård
 * Send a nice hexadecimal dump of a buffer to the log.
961 750f0e1f Panagiotis Issaris
 *
962
 * @param avcl A pointer to an arbitrary struct of which the first field is a
963
 * pointer to an AVClass struct.
964
 * @param level The importance level of the message, lower values signifying
965
 * higher importance.
966
 * @param buf buffer
967
 * @param size buffer size
968
 *
969 863c4716 Martin Storsjö
 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
970 750f0e1f Panagiotis Issaris
 */
971
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
972
973
/**
974 49bd8e4b Måns Rullgård
 * Send a nice dump of a packet to the specified file stream.
975 750f0e1f Panagiotis Issaris
 *
976
 * @param f The file stream pointer where the dump should be sent to.
977 3217cb42 Panagiotis Issaris
 * @param pkt packet to dump
978 4f57fa8c Diego Biurrun
 * @param dump_payload True if the payload must be displayed, too.
979 863c4716 Martin Storsjö
 * @param st AVStream that the packet belongs to
980 3217cb42 Panagiotis Issaris
 */
981 863c4716 Martin Storsjö
void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
982
983 de6d9b64 Fabrice Bellard
984 750f0e1f Panagiotis Issaris
/**
985 49bd8e4b Måns Rullgård
 * Send a nice dump of a packet to the log.
986 750f0e1f Panagiotis Issaris
 *
987
 * @param avcl A pointer to an arbitrary struct of which the first field is a
988
 * pointer to an AVClass struct.
989
 * @param level The importance level of the message, lower values signifying
990
 * higher importance.
991
 * @param pkt packet to dump
992 4f57fa8c Diego Biurrun
 * @param dump_payload True if the payload must be displayed, too.
993 863c4716 Martin Storsjö
 * @param st AVStream that the packet belongs to
994 750f0e1f Panagiotis Issaris
 */
995 863c4716 Martin Storsjö
void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
996
                      AVStream *st);
997
998 c5704b2b Anton Khirnov
#if FF_API_PKT_DUMP
999
attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1000 863c4716 Martin Storsjö
attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1001
                                          int dump_payload);
1002 17ca374c Anton Khirnov
#endif
1003 750f0e1f Panagiotis Issaris
1004 4815e246 Stefano Sabatini
/**
1005 49bd8e4b Måns Rullgård
 * Initialize libavformat and register all the muxers, demuxers and
1006 4815e246 Stefano Sabatini
 * protocols. If you do not call this function, then you can select
1007
 * exactly which formats you want to support.
1008
 *
1009
 * @see av_register_input_format()
1010
 * @see av_register_output_format()
1011 5d377501 Stefano Sabatini
 * @see av_register_protocol()
1012 4815e246 Stefano Sabatini
 */
1013 94988531 Fabrice Bellard
void av_register_all(void);
1014 de6d9b64 Fabrice Bellard
1015 7693b93e Stefano Sabatini
/**
1016 49bd8e4b Måns Rullgård
 * Get the CodecID for the given codec tag tag.
1017 7693b93e Stefano Sabatini
 * If no codec id is found returns CODEC_ID_NONE.
1018
 *
1019
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1020
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1021
 */
1022 15545a09 Stefano Sabatini
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1023 7693b93e Stefano Sabatini
1024
/**
1025 49bd8e4b Måns Rullgård
 * Get the codec tag for the given codec id id.
1026 7693b93e Stefano Sabatini
 * If no codec tag is found returns 0.
1027
 *
1028
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1029
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1030
 */
1031 15545a09 Stefano Sabatini
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1032 7caf0cc6 Michael Niedermayer
1033 b9a281db Fabrice Bellard
/* media file input */
1034 3217cb42 Panagiotis Issaris
1035
/**
1036 49bd8e4b Måns Rullgård
 * Find AVInputFormat based on the short name of the input format.
1037 3217cb42 Panagiotis Issaris
 */
1038 b9a281db Fabrice Bellard
AVInputFormat *av_find_input_format(const char *short_name);
1039 3217cb42 Panagiotis Issaris
1040
/**
1041 49bd8e4b Måns Rullgård
 * Guess the file format.
1042 3217cb42 Panagiotis Issaris
 *
1043 4f57fa8c Diego Biurrun
 * @param is_opened Whether the file is already opened; determines whether
1044
 *                  demuxers with or without AVFMT_NOFILE are probed.
1045 3217cb42 Panagiotis Issaris
 */
1046 94988531 Fabrice Bellard
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1047 3217cb42 Panagiotis Issaris
1048
/**
1049 49bd8e4b Måns Rullgård
 * Guess the file format.
1050 8e2ee182 Reimar Döffinger
 *
1051
 * @param is_opened Whether the file is already opened; determines whether
1052
 *                  demuxers with or without AVFMT_NOFILE are probed.
1053 c99d506b Reimar Döffinger
 * @param score_max A probe score larger that this is required to accept a
1054
 *                  detection, the variable is set to the actual detection
1055
 *                  score afterwards.
1056
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1057 8e2ee182 Reimar Döffinger
 *                  to retry with a larger probe buffer.
1058
 */
1059
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1060
1061
/**
1062 3940caad Anssi Hannula
 * Probe a bytestream to determine the input format. Each time a probe returns
1063
 * with a score that is too low, the probe buffer size is increased and another
1064
 * attempt is made. When the maximum probe size is reached, the input format
1065
 * with the highest score is returned.
1066
 *
1067
 * @param pb the bytestream to probe
1068
 * @param fmt the input format is put here
1069
 * @param filename the filename of the stream
1070
 * @param logctx the log context
1071
 * @param offset the offset within the bytestream to probe from
1072
 * @param max_probe_size the maximum probe buffer size (zero for default)
1073
 * @return 0 in case of success, a negative value corresponding to an
1074
 * AVERROR code otherwise
1075
 */
1076 ae628ec1 Anton Khirnov
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
1077 3940caad Anssi Hannula
                          const char *filename, void *logctx,
1078
                          unsigned int offset, unsigned int max_probe_size);
1079
1080
/**
1081 49bd8e4b Måns Rullgård
 * Allocate all the structures needed to read an input stream.
1082 3217cb42 Panagiotis Issaris
 *        This does not open the needed codecs for decoding the stream[s].
1083
 */
1084 115329f1 Diego Biurrun
int av_open_input_stream(AVFormatContext **ic_ptr,
1085 ae628ec1 Anton Khirnov
                         AVIOContext *pb, const char *filename,
1086 da24c5e3 Fabrice Bellard
                         AVInputFormat *fmt, AVFormatParameters *ap);
1087 3217cb42 Panagiotis Issaris
1088
/**
1089 49bd8e4b Måns Rullgård
 * Open a media file as input. The codecs are not opened. Only the file
1090 3217cb42 Panagiotis Issaris
 * header (if present) is read.
1091
 *
1092 4f57fa8c Diego Biurrun
 * @param ic_ptr The opened media file handle is put here.
1093
 * @param filename filename to open
1094
 * @param fmt If non-NULL, force the file format to use.
1095 3217cb42 Panagiotis Issaris
 * @param buf_size optional buffer size (zero if default is OK)
1096 78cb7273 Diego Biurrun
 * @param ap Additional parameters needed when opening the file
1097
 *           (NULL if default).
1098 4f57fa8c Diego Biurrun
 * @return 0 if OK, AVERROR_xxx otherwise
1099 3217cb42 Panagiotis Issaris
 */
1100 115329f1 Diego Biurrun
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1101 b9a281db Fabrice Bellard
                       AVInputFormat *fmt,
1102
                       int buf_size,
1103
                       AVFormatParameters *ap);
1104 88a28965 Stefano Sabatini
1105 ca51d86c Aurelien Jacobs
#if FF_API_ALLOC_FORMAT_CONTEXT
1106 88a28965 Stefano Sabatini
/**
1107
 * @deprecated Use avformat_alloc_context() instead.
1108
 */
1109
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
1110
#endif
1111
1112 88808c60 Michael Niedermayer
/**
1113 49bd8e4b Måns Rullgård
 * Allocate an AVFormatContext.
1114 f124b087 Martin Storsjö
 * avformat_free_context() can be used to free the context and everything
1115
 * allocated by the framework within it.
1116 88808c60 Michael Niedermayer
 */
1117 88a28965 Stefano Sabatini
AVFormatContext *avformat_alloc_context(void);
1118 b9a281db Fabrice Bellard
1119 3217cb42 Panagiotis Issaris
/**
1120 49bd8e4b Måns Rullgård
 * Read packets of a media file to get stream information. This
1121 3217cb42 Panagiotis Issaris
 * is useful for file formats with no headers such as MPEG. This
1122 22e77e44 Diego Biurrun
 * function also computes the real framerate in case of MPEG-2 repeat
1123 3217cb42 Panagiotis Issaris
 * frame mode.
1124
 * The logical file position is not changed by this function;
1125
 * examined packets may be buffered for later processing.
1126
 *
1127
 * @param ic media file handle
1128 4f57fa8c Diego Biurrun
 * @return >=0 if OK, AVERROR_xxx on error
1129
 * @todo Let the user decide somehow what information is needed so that
1130
 *       we do not waste time getting stuff the user does not need.
1131 3217cb42 Panagiotis Issaris
 */
1132 b9a281db Fabrice Bellard
int av_find_stream_info(AVFormatContext *ic);
1133 3217cb42 Panagiotis Issaris
1134
/**
1135 9128ae08 Nicolas George
 * Find the "best" stream in the file.
1136
 * The best stream is determined according to various heuristics as the most
1137
 * likely to be what the user expects.
1138
 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1139
 * default decoder for the stream's codec; streams for which no decoder can
1140
 * be found are ignored.
1141
 *
1142
 * @param ic                media file handle
1143
 * @param type              stream type: video, audio, subtitles, etc.
1144
 * @param wanted_stream_nb  user-requested stream number,
1145
 *                          or -1 for automatic selection
1146
 * @param related_stream    try to find a stream related (eg. in the same
1147
 *                          program) to this one, or -1 if none
1148
 * @param decoder_ret       if non-NULL, returns the decoder for the
1149
 *                          selected stream
1150
 * @param flags             flags; none are currently defined
1151
 * @return  the non-negative stream number in case of success,
1152
 *          AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1153
 *          could be found,
1154
 *          AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1155
 * @note  If av_find_best_stream returns successfully and decoder_ret is not
1156
 *        NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1157
 */
1158
int av_find_best_stream(AVFormatContext *ic,
1159
                        enum AVMediaType type,
1160
                        int wanted_stream_nb,
1161
                        int related_stream,
1162
                        AVCodec **decoder_ret,
1163
                        int flags);
1164
1165
/**
1166 49bd8e4b Måns Rullgård
 * Read a transport packet from a media file.
1167 3217cb42 Panagiotis Issaris
 *
1168 864ff8c1 Ramiro Polla
 * This function is obsolete and should never be used.
1169 3217cb42 Panagiotis Issaris
 * Use av_read_frame() instead.
1170
 *
1171
 * @param s media file handle
1172
 * @param pkt is filled
1173 4f57fa8c Diego Biurrun
 * @return 0 if OK, AVERROR_xxx on error
1174 3217cb42 Panagiotis Issaris
 */
1175 de6d9b64 Fabrice Bellard
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1176 3217cb42 Panagiotis Issaris
1177
/**
1178 49bd8e4b Måns Rullgård
 * Return the next frame of a stream.
1179 4faf628f Michael Niedermayer
 * This function returns what is stored in the file, and does not validate
1180
 * that what is there are valid frames for the decoder. It will split what is
1181
 * stored in the file into frames and return one for each call. It will not
1182
 * omit invalid data between valid frames so as to give the decoder the maximum
1183
 * information possible for decoding.
1184 3217cb42 Panagiotis Issaris
 *
1185
 * The returned packet is valid
1186
 * until the next av_read_frame() or until av_close_input_file() and
1187
 * must be freed with av_free_packet. For video, the packet contains
1188
 * exactly one frame. For audio, it contains an integer number of
1189
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1190
 * data). If the audio frames have a variable size (e.g. MPEG audio),
1191
 * then it contains one frame.
1192
 *
1193
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1194 22e77e44 Diego Biurrun
 * values in AVStream.time_base units (and guessed if the format cannot
1195 4f57fa8c Diego Biurrun
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1196
 * has B-frames, so it is better to rely on pkt->dts if you do not
1197 3217cb42 Panagiotis Issaris
 * decompress the payload.
1198
 *
1199 4f57fa8c Diego Biurrun
 * @return 0 if OK, < 0 on error or end of file
1200 3217cb42 Panagiotis Issaris
 */
1201 fb2758c8 Fabrice Bellard
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1202 3217cb42 Panagiotis Issaris
1203
/**
1204 49bd8e4b Måns Rullgård
 * Seek to the keyframe at timestamp.
1205 3217cb42 Panagiotis Issaris
 * 'timestamp' in 'stream_index'.
1206
 * @param stream_index If stream_index is (-1), a default
1207
 * stream is selected, and timestamp is automatically converted
1208
 * from AV_TIME_BASE units to the stream specific time_base.
1209 4f57fa8c Diego Biurrun
 * @param timestamp Timestamp in AVStream.time_base units
1210
 *        or, if no stream is specified, in AV_TIME_BASE units.
1211 3217cb42 Panagiotis Issaris
 * @param flags flags which select direction and seeking mode
1212
 * @return >= 0 on success
1213
 */
1214 78cb7273 Diego Biurrun
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1215
                  int flags);
1216 3217cb42 Panagiotis Issaris
1217
/**
1218 49bd8e4b Måns Rullgård
 * Seek to timestamp ts.
1219 d04768fa Michael Niedermayer
 * Seeking will be done so that the point from which all active streams
1220
 * can be presented successfully will be closest to ts and within min/max_ts.
1221
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1222
 *
1223 22e77e44 Diego Biurrun
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1224 d04768fa Michael Niedermayer
 * are the file position (this may not be supported by all demuxers).
1225 22e77e44 Diego Biurrun
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1226 d04768fa Michael Niedermayer
 * in the stream with stream_index (this may not be supported by all demuxers).
1227 22e77e44 Diego Biurrun
 * Otherwise all timestamps are in units of the stream selected by stream_index
1228
 * or if stream_index is -1, in AV_TIME_BASE units.
1229
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1230 d04768fa Michael Niedermayer
 * keyframes (this may not be supported by all demuxers).
1231
 *
1232 22e77e44 Diego Biurrun
 * @param stream_index index of the stream which is used as time base reference
1233 d04768fa Michael Niedermayer
 * @param min_ts smallest acceptable timestamp
1234
 * @param ts target timestamp
1235
 * @param max_ts largest acceptable timestamp
1236
 * @param flags flags
1237 32e543f8 Benoit Fouet
 * @return >=0 on success, error code otherwise
1238 998b6f7c Michael Niedermayer
 *
1239 8a4d7a30 Diego Biurrun
 * @note This is part of the new seek API which is still under construction.
1240 22e77e44 Diego Biurrun
 *       Thus do not use this yet. It may change at any time, do not expect
1241
 *       ABI compatibility yet!
1242 d04768fa Michael Niedermayer
 */
1243
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1244
1245
/**
1246 49bd8e4b Måns Rullgård
 * Start playing a network-based stream (e.g. RTSP stream) at the
1247 4f57fa8c Diego Biurrun
 * current position.
1248 3217cb42 Panagiotis Issaris
 */
1249 fb2758c8 Fabrice Bellard
int av_read_play(AVFormatContext *s);
1250 3217cb42 Panagiotis Issaris
1251
/**
1252 49bd8e4b Måns Rullgård
 * Pause a network-based stream (e.g. RTSP stream).
1253 3217cb42 Panagiotis Issaris
 *
1254
 * Use av_read_play() to resume it.
1255
 */
1256 fb2758c8 Fabrice Bellard
int av_read_pause(AVFormatContext *s);
1257 3217cb42 Panagiotis Issaris
1258
/**
1259 49bd8e4b Måns Rullgård
 * Free a AVFormatContext allocated by av_open_input_stream.
1260 2506fd54 Reimar Döffinger
 * @param s context to free
1261
 */
1262
void av_close_input_stream(AVFormatContext *s);
1263
1264
/**
1265 49bd8e4b Måns Rullgård
 * Close a media file (but not its codecs).
1266 3217cb42 Panagiotis Issaris
 *
1267
 * @param s media file handle
1268
 */
1269 de6d9b64 Fabrice Bellard
void av_close_input_file(AVFormatContext *s);
1270 3217cb42 Panagiotis Issaris
1271
/**
1272 f124b087 Martin Storsjö
 * Free an AVFormatContext and all its streams.
1273
 * @param s context to free
1274
 */
1275
void avformat_free_context(AVFormatContext *s);
1276
1277
/**
1278 49bd8e4b Måns Rullgård
 * Add a new stream to a media file.
1279 3217cb42 Panagiotis Issaris
 *
1280
 * Can only be called in the read_header() function. If the flag
1281
 * AVFMTCTX_NOHEADER is in the format context, then new streams
1282
 * can be added in read_packet too.
1283
 *
1284
 * @param s media file handle
1285 4f57fa8c Diego Biurrun
 * @param id file-format-dependent stream ID
1286 3217cb42 Panagiotis Issaris
 */
1287 b9a281db Fabrice Bellard
AVStream *av_new_stream(AVFormatContext *s, int id);
1288 15afa396 Nico Sabbi
AVProgram *av_new_program(AVFormatContext *s, int id);
1289 3217cb42 Panagiotis Issaris
1290
/**
1291 b3190529 Reimar Döffinger
 * Set the pts for a given stream. If the new values would be invalid
1292
 * (<= 0), it leaves the AVStream unchanged.
1293 3217cb42 Panagiotis Issaris
 *
1294
 * @param s stream
1295
 * @param pts_wrap_bits number of bits effectively used by the pts
1296
 *        (used for wrap control, 33 is the value for MPEG)
1297
 * @param pts_num numerator to convert to seconds (MPEG: 1)
1298
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1299
 */
1300 9ee91c2f Michael Niedermayer
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1301 dec14949 Michael Niedermayer
                     unsigned int pts_num, unsigned int pts_den);
1302 de6d9b64 Fabrice Bellard
1303 3ba1438d Michael Niedermayer
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1304
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1305 4f57fa8c Diego Biurrun
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1306 2bf74f49 Aurelien Jacobs
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1307 3ba1438d Michael Niedermayer
1308 b754978a Michael Niedermayer
int av_find_default_stream_index(AVFormatContext *s);
1309 3217cb42 Panagiotis Issaris
1310
/**
1311 49bd8e4b Måns Rullgård
 * Get the index for a specific timestamp.
1312 4f57fa8c Diego Biurrun
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1313
 *                 to the timestamp which is <= the requested one, if backward
1314
 *                 is 0, then it will be >=
1315 3217cb42 Panagiotis Issaris
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1316
 * @return < 0 if no such timestamp could be found
1317
 */
1318 dc56fc38 Michael Niedermayer
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1319 3217cb42 Panagiotis Issaris
1320
/**
1321 49bd8e4b Måns Rullgård
 * Add an index entry into a sorted list. Update the entry if the list
1322 4f57fa8c Diego Biurrun
 * already contains it.
1323 3217cb42 Panagiotis Issaris
 *
1324 4f57fa8c Diego Biurrun
 * @param timestamp timestamp in the time base of the given stream
1325 3217cb42 Panagiotis Issaris
 */
1326 78cb7273 Diego Biurrun
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1327
                       int size, int distance, int flags);
1328 3217cb42 Panagiotis Issaris
1329
/**
1330 49bd8e4b Måns Rullgård
 * Perform a binary search using av_index_search_timestamp() and
1331 3673f4ab Aurelien Jacobs
 * AVInputFormat.read_timestamp().
1332 78cb7273 Diego Biurrun
 * This is not supposed to be called directly by a user application,
1333
 * but by demuxers.
1334 3217cb42 Panagiotis Issaris
 * @param target_ts target timestamp in the time base of the given stream
1335
 * @param stream_index stream number
1336
 */
1337 78cb7273 Diego Biurrun
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1338
                         int64_t target_ts, int flags);
1339 3217cb42 Panagiotis Issaris
1340
/**
1341 49bd8e4b Måns Rullgård
 * Update cur_dts of all streams based on the given timestamp and AVStream.
1342 3217cb42 Panagiotis Issaris
 *
1343 4f57fa8c Diego Biurrun
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1344
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1345 3217cb42 Panagiotis Issaris
 * @param timestamp new dts expressed in time_base of param ref_st
1346
 * @param ref_st reference stream giving time_base of param timestamp
1347
 */
1348 22ffac70 Reimar Döffinger
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1349 3217cb42 Panagiotis Issaris
1350
/**
1351 49bd8e4b Måns Rullgård
 * Perform a binary search using read_timestamp().
1352 78cb7273 Diego Biurrun
 * This is not supposed to be called directly by a user application,
1353
 * but by demuxers.
1354 3217cb42 Panagiotis Issaris
 * @param target_ts target timestamp in the time base of the given stream
1355
 * @param stream_index stream number
1356
 */
1357 78cb7273 Diego Biurrun
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1358
                      int64_t target_ts, int64_t pos_min,
1359
                      int64_t pos_max, int64_t pos_limit,
1360
                      int64_t ts_min, int64_t ts_max,
1361
                      int flags, int64_t *ts_ret,
1362
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1363 b754978a Michael Niedermayer
1364 76c56376 Michael Niedermayer
/**
1365
 * media file output
1366
 */
1367 290c5fa6 Fabrice Bellard
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1368 3217cb42 Panagiotis Issaris
1369
/**
1370 f3bfe388 Måns Rullgård
 * Split a URL string into components.
1371
 *
1372
 * The pointers to buffers for storing individual components may be null,
1373
 * in order to ignore that component. Buffers for components not found are
1374
 * set to empty strings. If the port is not found, it is set to a negative
1375
 * value.
1376
 *
1377
 * @param proto the buffer for the protocol
1378
 * @param proto_size the size of the proto buffer
1379
 * @param authorization the buffer for the authorization
1380
 * @param authorization_size the size of the authorization buffer
1381
 * @param hostname the buffer for the host name
1382
 * @param hostname_size the size of the hostname buffer
1383
 * @param port_ptr a pointer to store the port number in
1384
 * @param path the buffer for the path
1385
 * @param path_size the size of the path buffer
1386
 * @param url the URL to split
1387
 */
1388
void av_url_split(char *proto,         int proto_size,
1389
                  char *authorization, int authorization_size,
1390
                  char *hostname,      int hostname_size,
1391
                  int *port_ptr,
1392
                  char *path,          int path_size,
1393
                  const char *url);
1394
1395
/**
1396 49bd8e4b Måns Rullgård
 * Allocate the stream private data and write the stream header to an
1397 755bfeab Diego Biurrun
 * output media file.
1398 5d820db2 Reimar Döffinger
 * @note: this sets stream time-bases, if possible to stream->codec->time_base
1399
 * but for some formats it might also be some other time base
1400 3217cb42 Panagiotis Issaris
 *
1401
 * @param s media file handle
1402 4f57fa8c Diego Biurrun
 * @return 0 if OK, AVERROR_xxx on error
1403 3217cb42 Panagiotis Issaris
 */
1404 b9a281db Fabrice Bellard
int av_write_header(AVFormatContext *s);
1405 3217cb42 Panagiotis Issaris
1406
/**
1407 49bd8e4b Måns Rullgård
 * Write a packet to an output media file.
1408 3217cb42 Panagiotis Issaris
 *
1409
 * The packet shall contain one audio or video frame.
1410 78cb7273 Diego Biurrun
 * The packet must be correctly interleaved according to the container
1411
 * specification, if not then av_interleaved_write_frame must be used.
1412 3217cb42 Panagiotis Issaris
 *
1413
 * @param s media file handle
1414 78cb7273 Diego Biurrun
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1415
              dts/pts, ...
1416 4f57fa8c Diego Biurrun
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1417 3217cb42 Panagiotis Issaris
 */
1418 e928649b Michael Niedermayer
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1419 3217cb42 Panagiotis Issaris
1420
/**
1421 49bd8e4b Måns Rullgård
 * Write a packet to an output media file ensuring correct interleaving.
1422 3217cb42 Panagiotis Issaris
 *
1423
 * The packet must contain one audio or video frame.
1424 22e77e44 Diego Biurrun
 * If the packets are already correctly interleaved, the application should
1425 90b5b51e Diego Biurrun
 * call av_write_frame() instead as it is slightly faster. It is also important
1426
 * to keep in mind that completely non-interleaved input will need huge amounts
1427
 * of memory to interleave with this, so it is preferable to interleave at the
1428
 * demuxer level.
1429 3217cb42 Panagiotis Issaris
 *
1430
 * @param s media file handle
1431 78cb7273 Diego Biurrun
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1432
              dts/pts, ...
1433 4f57fa8c Diego Biurrun
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1434 3217cb42 Panagiotis Issaris
 */
1435 3c895fc0 Michael Niedermayer
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1436 3217cb42 Panagiotis Issaris
1437
/**
1438 49bd8e4b Måns Rullgård
 * Interleave a packet per dts in an output media file.
1439 3217cb42 Panagiotis Issaris
 *
1440 78cb7273 Diego Biurrun
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1441 22e77e44 Diego Biurrun
 * function, so they cannot be used after it. Note that calling av_free_packet()
1442 78cb7273 Diego Biurrun
 * on them is still safe.
1443 3217cb42 Panagiotis Issaris
 *
1444
 * @param s media file handle
1445
 * @param out the interleaved packet will be output here
1446 9a58234f Diego Biurrun
 * @param pkt the input packet
1447 3217cb42 Panagiotis Issaris
 * @param flush 1 if no further packets are available as input and all
1448
 *              remaining packets should be output
1449
 * @return 1 if a packet was output, 0 if no packet could be output,
1450 d9526386 Diego Biurrun
 *         < 0 if an error occurred
1451 3217cb42 Panagiotis Issaris
 */
1452 78cb7273 Diego Biurrun
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1453
                                 AVPacket *pkt, int flush);
1454 e928649b Michael Niedermayer
1455 3217cb42 Panagiotis Issaris
/**
1456 49bd8e4b Måns Rullgård
 * Write the stream trailer to an output media file and free the
1457 2b75bde6 Stefano Sabatini
 * file private data.
1458 3217cb42 Panagiotis Issaris
 *
1459 dc76fe13 Reimar Döffinger
 * May only be called after a successful call to av_write_header.
1460
 *
1461 3217cb42 Panagiotis Issaris
 * @param s media file handle
1462 4f57fa8c Diego Biurrun
 * @return 0 if OK, AVERROR_xxx on error
1463 3217cb42 Panagiotis Issaris
 */
1464 b9a281db Fabrice Bellard
int av_write_trailer(AVFormatContext *s);
1465 de6d9b64 Fabrice Bellard
1466 610219a5 Anton Khirnov
#if FF_API_DUMP_FORMAT
1467
attribute_deprecated void dump_format(AVFormatContext *ic,
1468
                                      int index,
1469
                                      const char *url,
1470
                                      int is_output);
1471
#endif
1472
1473
void av_dump_format(AVFormatContext *ic,
1474
                    int index,
1475
                    const char *url,
1476
                    int is_output);
1477 3217cb42 Panagiotis Issaris
1478 d87a521c Aurelien Jacobs
#if FF_API_PARSE_FRAME_PARAM
1479 3217cb42 Panagiotis Issaris
/**
1480 49bd8e4b Måns Rullgård
 * Parse width and height out of string str.
1481 26ef3220 Stefano Sabatini
 * @deprecated Use av_parse_video_frame_size instead.
1482 3217cb42 Panagiotis Issaris
 */
1483 78cb7273 Diego Biurrun
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1484
                                          const char *str);
1485 3217cb42 Panagiotis Issaris
1486
/**
1487 49bd8e4b Måns Rullgård
 * Convert framerate from a string to a fraction.
1488 26ef3220 Stefano Sabatini
 * @deprecated Use av_parse_video_frame_rate instead.
1489 3217cb42 Panagiotis Issaris
 */
1490 78cb7273 Diego Biurrun
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1491
                                          const char *arg);
1492 1ca9133f Stefano Sabatini
#endif
1493 3217cb42 Panagiotis Issaris
1494 f6c7375a Stefano Sabatini
#if FF_API_PARSE_DATE
1495 3217cb42 Panagiotis Issaris
/**
1496 49bd8e4b Måns Rullgård
 * Parse datestr and return a corresponding number of microseconds.
1497 f6c7375a Stefano Sabatini
 *
1498 f9436161 Stefano Sabatini
 * @param datestr String representing a date or a duration.
1499 f6c7375a Stefano Sabatini
 * See av_parse_time() for the syntax of the provided string.
1500
 * @deprecated in favor of av_parse_time()
1501 3217cb42 Panagiotis Issaris
 */
1502 f6c7375a Stefano Sabatini
attribute_deprecated
1503 0c1a9eda Zdenek Kabelac
int64_t parse_date(const char *datestr, int duration);
1504 f6c7375a Stefano Sabatini
#endif
1505 de6d9b64 Fabrice Bellard
1506 76c56376 Michael Niedermayer
/**
1507
 * Get the current time in microseconds.
1508
 */
1509 0c1a9eda Zdenek Kabelac
int64_t av_gettime(void);
1510 94988531 Fabrice Bellard
1511 ab0287fc Anton Khirnov
#if FF_API_FIND_INFO_TAG
1512 3217cb42 Panagiotis Issaris
/**
1513 ab0287fc Anton Khirnov
 * @deprecated use av_find_info_tag in libavutil instead.
1514 3217cb42 Panagiotis Issaris
 */
1515 ab0287fc Anton Khirnov
attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1516
#endif
1517 de6d9b64 Fabrice Bellard
1518 3217cb42 Panagiotis Issaris
/**
1519 49bd8e4b Måns Rullgård
 * Return in 'buf' the path with '%d' replaced by a number.
1520 4f57fa8c Diego Biurrun
 *
1521 3217cb42 Panagiotis Issaris
 * Also handles the '%0nd' format where 'n' is the total number
1522
 * of digits and '%%'.
1523
 *
1524
 * @param buf destination buffer
1525
 * @param buf_size destination buffer size
1526
 * @param path numbered sequence string
1527 8ea0e802 Panagiotis Issaris
 * @param number frame number
1528 4f57fa8c Diego Biurrun
 * @return 0 if OK, -1 on format error
1529 3217cb42 Panagiotis Issaris
 */
1530 5c07cf53 Michel Bardiaux
int av_get_frame_filename(char *buf, int buf_size,
1531
                          const char *path, int number);
1532 3217cb42 Panagiotis Issaris
1533
/**
1534 49bd8e4b Måns Rullgård
 * Check whether filename actually is a numbered sequence generator.
1535 3217cb42 Panagiotis Issaris
 *
1536
 * @param filename possible numbered sequence string
1537 4f57fa8c Diego Biurrun
 * @return 1 if a valid numbered sequence string, 0 otherwise
1538 3217cb42 Panagiotis Issaris
 */
1539 5c07cf53 Michel Bardiaux
int av_filename_number_test(const char *filename);
1540 96baaa6a Fabrice Bellard
1541 c5388c07 Luca Abeni
/**
1542 49bd8e4b Måns Rullgård
 * Generate an SDP for an RTP session.
1543 c5388c07 Luca Abeni
 *
1544
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1545
 *           array is composed by only one context, such context can contain
1546
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1547
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1548 4f57fa8c Diego Biurrun
 *           must contain only one AVStream.
1549 8767b80f Luca Abeni
 * @param n_files number of AVCodecContexts contained in ac
1550 c234d40b Anton Khirnov
 * @param buf buffer where the SDP will be stored (must be allocated by
1551
 *            the caller)
1552 8767b80f Luca Abeni
 * @param size the size of the buffer
1553 4f57fa8c Diego Biurrun
 * @return 0 if OK, AVERROR_xxx on error
1554 c5388c07 Luca Abeni
 */
1555 c234d40b Anton Khirnov
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1556 c3675dfe Anton Khirnov
1557
#if FF_API_SDP_CREATE
1558
attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1559
#endif
1560 c5388c07 Luca Abeni
1561 1a70d127 Stefano Sabatini
/**
1562 49bd8e4b Måns Rullgård
 * Return a positive value if the given filename has one of the given
1563 1a70d127 Stefano Sabatini
 * extensions, 0 otherwise.
1564
 *
1565
 * @param extensions a comma-separated list of filename extensions
1566
 */
1567
int av_match_ext(const char *filename, const char *extensions);
1568
1569 98790382 Stefano Sabatini
#endif /* AVFORMAT_AVFORMAT_H */