]> git.sesse.net Git - ffmpeg/blob - libavformat/avformat.h
avconv: use avcodec_decode_audio4() instead of avcodec_decode_audio3()
[ffmpeg] / libavformat / avformat.h
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
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
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef AVFORMAT_AVFORMAT_H
22 #define AVFORMAT_AVFORMAT_H
23
24 /**
25  * @defgroup libavf I/O and Muxing/Demuxing Library
26  * @{
27  *
28  * @defgroup lavf_decoding Demuxing
29  * @{
30  * @}
31  *
32  * @defgroup lavf_encoding Muxing
33  * @{
34  * @}
35  *
36  * @defgroup lavf_proto I/O Read/Write
37  * @{
38  * @}
39  *
40  * @defgroup lavf_codec Demuxers
41  * @{
42  * @defgroup lavf_codec_native Native Demuxers
43  * @{
44  * @}
45  * @defgroup lavf_codec_wrappers External library wrappers
46  * @{
47  * @}
48  * @}
49  * @defgroup lavf_protos I/O Protocols
50  * @{
51  * @}
52  * @defgroup lavf_internal Internal
53  * @{
54  * @}
55  * @}
56  *
57  */
58
59 /**
60  * Return the LIBAVFORMAT_VERSION_INT constant.
61  */
62 unsigned avformat_version(void);
63
64 /**
65  * Return the libavformat build-time configuration.
66  */
67 const char *avformat_configuration(void);
68
69 /**
70  * Return the libavformat license.
71  */
72 const char *avformat_license(void);
73
74 #include <time.h>
75 #include <stdio.h>  /* FILE */
76 #include "libavcodec/avcodec.h"
77 #include "libavutil/dict.h"
78 #include "libavutil/log.h"
79
80 #include "avio.h"
81 #include "libavformat/version.h"
82
83 struct AVFormatContext;
84
85
86 /**
87  * @defgroup metadata_api Public Metadata API
88  * @{
89  * The metadata API allows libavformat to export metadata tags to a client
90  * application using a sequence of key/value pairs. Like all strings in Libav,
91  * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
92  * exported by demuxers isn't checked to be valid UTF-8 in most cases.
93  * Important concepts to keep in mind:
94  * -  Keys are unique; there can never be 2 tags with the same key. This is
95  *    also meant semantically, i.e., a demuxer should not knowingly produce
96  *    several keys that are literally different but semantically identical.
97  *    E.g., key=Author5, key=Author6. In this example, all authors must be
98  *    placed in the same tag.
99  * -  Metadata is flat, not hierarchical; there are no subtags. If you
100  *    want to store, e.g., the email address of the child of producer Alice
101  *    and actor Bob, that could have key=alice_and_bobs_childs_email_address.
102  * -  Several modifiers can be applied to the tag name. This is done by
103  *    appending a dash character ('-') and the modifier name in the order
104  *    they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
105  *    -  language -- a tag whose value is localized for a particular language
106  *       is appended with the ISO 639-2/B 3-letter language code.
107  *       For example: Author-ger=Michael, Author-eng=Mike
108  *       The original/default language is in the unqualified "Author" tag.
109  *       A demuxer should set a default if it sets any translated tag.
110  *    -  sorting  -- a modified version of a tag that should be used for
111  *       sorting will have '-sort' appended. E.g. artist="The Beatles",
112  *       artist-sort="Beatles, The".
113  *
114  * -  Demuxers attempt to export metadata in a generic format, however tags
115  *    with no generic equivalents are left as they are stored in the container.
116  *    Follows a list of generic tag names:
117  *
118  @verbatim
119  album        -- name of the set this work belongs to
120  album_artist -- main creator of the set/album, if different from artist.
121                  e.g. "Various Artists" for compilation albums.
122  artist       -- main creator of the work
123  comment      -- any additional description of the file.
124  composer     -- who composed the work, if different from artist.
125  copyright    -- name of copyright holder.
126  creation_time-- date when the file was created, preferably in ISO 8601.
127  date         -- date when the work was created, preferably in ISO 8601.
128  disc         -- number of a subset, e.g. disc in a multi-disc collection.
129  encoder      -- name/settings of the software/hardware that produced the file.
130  encoded_by   -- person/group who created the file.
131  filename     -- original name of the file.
132  genre        -- <self-evident>.
133  language     -- main language in which the work is performed, preferably
134                  in ISO 639-2 format. Multiple languages can be specified by
135                  separating them with commas.
136  performer    -- artist who performed the work, if different from artist.
137                  E.g for "Also sprach Zarathustra", artist would be "Richard
138                  Strauss" and performer "London Philharmonic Orchestra".
139  publisher    -- name of the label/publisher.
140  service_name     -- name of the service in broadcasting (channel name).
141  service_provider -- name of the service provider in broadcasting.
142  title        -- name of the work.
143  track        -- number of this work in the set, can be in form current/total.
144  variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
145  @endverbatim
146  *
147  * Look in the examples section for an application example how to use the Metadata API.
148  *
149  * @}
150  */
151
152 #if FF_API_OLD_METADATA2
153 /**
154  * @defgroup old_metadata Old metadata API
155  * The following functions are deprecated, use
156  * their equivalents from libavutil/dict.h instead.
157  * @{
158  */
159
160 #define AV_METADATA_MATCH_CASE      AV_DICT_MATCH_CASE
161 #define AV_METADATA_IGNORE_SUFFIX   AV_DICT_IGNORE_SUFFIX
162 #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
163 #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
164 #define AV_METADATA_DONT_OVERWRITE  AV_DICT_DONT_OVERWRITE
165
166 typedef attribute_deprecated AVDictionary AVMetadata;
167 typedef attribute_deprecated AVDictionaryEntry  AVMetadataTag;
168
169 typedef struct AVMetadataConv AVMetadataConv;
170
171 /**
172  * Get a metadata element with matching key.
173  *
174  * @param prev Set to the previous matching element to find the next.
175  *             If set to NULL the first matching element is returned.
176  * @param flags Allows case as well as suffix-insensitive comparisons.
177  * @return Found tag or NULL, changing key or value leads to undefined behavior.
178  */
179 attribute_deprecated AVDictionaryEntry *
180 av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
181
182 /**
183  * Set the given tag in *pm, overwriting an existing tag.
184  *
185  * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
186  * a metadata struct is allocated and put in *pm.
187  * @param key tag key to add to *pm (will be av_strduped depending on flags)
188  * @param value tag value to add to *pm (will be av_strduped depending on flags).
189  *        Passing a NULL value will cause an existing tag to be deleted.
190  * @return >= 0 on success otherwise an error code <0
191  */
192 attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
193
194 /**
195  * This function is provided for compatibility reason and currently does nothing.
196  */
197 attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
198                                                                         const AVMetadataConv *s_conv);
199
200 /**
201  * Copy metadata from one AVDictionary struct into another.
202  * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
203  *            this function will allocate a struct for you and put it in *dst
204  * @param src pointer to source AVDictionary struct
205  * @param flags flags to use when setting metadata in *dst
206  * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
207  */
208 attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
209
210 /**
211  * Free all the memory allocated for an AVDictionary struct.
212  */
213 attribute_deprecated void av_metadata_free(AVDictionary **m);
214 /**
215  * @}
216  */
217 #endif
218
219
220 /* packet functions */
221
222
223 /**
224  * Allocate and read the payload of a packet and initialize its
225  * fields with default values.
226  *
227  * @param pkt packet
228  * @param size desired payload size
229  * @return >0 (read size) if OK, AVERROR_xxx otherwise
230  */
231 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
232
233
234 /**
235  * Read data and append it to the current content of the AVPacket.
236  * If pkt->size is 0 this is identical to av_get_packet.
237  * Note that this uses av_grow_packet and thus involves a realloc
238  * which is inefficient. Thus this function should only be used
239  * when there is no reasonable way to know (an upper bound of)
240  * the final size.
241  *
242  * @param pkt packet
243  * @param size amount of data to read
244  * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
245  *         will not be lost even if an error occurs.
246  */
247 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
248
249 /*************************************************/
250 /* fractional numbers for exact pts handling */
251
252 /**
253  * The exact value of the fractional number is: 'val + num / den'.
254  * num is assumed to be 0 <= num < den.
255  */
256 typedef struct AVFrac {
257     int64_t val, num, den;
258 } AVFrac;
259
260 /*************************************************/
261 /* input/output formats */
262
263 struct AVCodecTag;
264
265 /**
266  * This structure contains the data a format has to probe a file.
267  */
268 typedef struct AVProbeData {
269     const char *filename;
270     unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
271     int buf_size;       /**< Size of buf except extra allocated bytes */
272 } AVProbeData;
273
274 #define AVPROBE_SCORE_MAX 100               ///< maximum score, half of that is used for file-extension-based detection
275 #define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
276
277 typedef struct AVFormatParameters {
278 #if FF_API_FORMAT_PARAMETERS
279     attribute_deprecated AVRational time_base;
280     attribute_deprecated int sample_rate;
281     attribute_deprecated int channels;
282     attribute_deprecated int width;
283     attribute_deprecated int height;
284     attribute_deprecated enum PixelFormat pix_fmt;
285     attribute_deprecated int channel; /**< Used to select DV channel. */
286     attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
287     attribute_deprecated unsigned int mpeg2ts_raw:1;  /**< deprecated, use mpegtsraw demuxer */
288     /**< deprecated, use mpegtsraw demuxer-specific options instead */
289     attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
290     attribute_deprecated unsigned int initial_pause:1;       /**< Do not begin to play the stream
291                                                                   immediately (RTSP only). */
292     attribute_deprecated unsigned int prealloced_context:1;
293 #endif
294 } AVFormatParameters;
295
296 //! Demuxer will use avio_open, no opened file should be provided by the caller.
297 #define AVFMT_NOFILE        0x0001
298 #define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
299 #define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
300 #define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
301                                       raw picture data. */
302 #define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
303 #define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
304 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
305 #define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
306 #define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
307 #define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
308 #define AVFMT_NOSTREAMS     0x1000 /**< Format does not require any streams */
309 #define AVFMT_NOBINSEARCH   0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
310 #define AVFMT_NOGENSEARCH   0x4000 /**< Format does not allow to fallback to generic search */
311 #define AVFMT_NO_BYTE_SEEK  0x8000 /**< Format does not allow seeking by bytes */
312
313 typedef struct AVOutputFormat {
314     const char *name;
315     /**
316      * Descriptive name for the format, meant to be more human-readable
317      * than name. You should use the NULL_IF_CONFIG_SMALL() macro
318      * to define it.
319      */
320     const char *long_name;
321     const char *mime_type;
322     const char *extensions; /**< comma-separated filename extensions */
323     /**
324      * size of private data so that it can be allocated in the wrapper
325      */
326     int priv_data_size;
327     /* output support */
328     enum CodecID audio_codec; /**< default audio codec */
329     enum CodecID video_codec; /**< default video codec */
330     int (*write_header)(struct AVFormatContext *);
331     int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
332     int (*write_trailer)(struct AVFormatContext *);
333     /**
334      * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
335      * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
336      * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
337      */
338     int flags;
339     /**
340      * Currently only used to set pixel format if not YUV420P.
341      */
342     int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
343     int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
344                              AVPacket *in, int flush);
345
346     /**
347      * List of supported codec_id-codec_tag pairs, ordered by "better
348      * choice first". The arrays are all terminated by CODEC_ID_NONE.
349      */
350     const struct AVCodecTag * const *codec_tag;
351
352     enum CodecID subtitle_codec; /**< default subtitle codec */
353
354 #if FF_API_OLD_METADATA2
355     const AVMetadataConv *metadata_conv;
356 #endif
357
358     const AVClass *priv_class; ///< AVClass for the private context
359
360     /**
361      * Test if the given codec can be stored in this container.
362      *
363      * @return 1 if the codec is supported, 0 if it is not.
364      *         A negative number if unknown.
365      */
366     int (*query_codec)(enum CodecID id, int std_compliance);
367
368     /* private fields */
369     struct AVOutputFormat *next;
370 } AVOutputFormat;
371
372 typedef struct AVInputFormat {
373     /**
374      * A comma separated list of short names for the format. New names
375      * may be appended with a minor bump.
376      */
377     const char *name;
378
379     /**
380      * Descriptive name for the format, meant to be more human-readable
381      * than name. You should use the NULL_IF_CONFIG_SMALL() macro
382      * to define it.
383      */
384     const char *long_name;
385
386     /**
387      * Size of private data so that it can be allocated in the wrapper.
388      */
389     int priv_data_size;
390
391     /**
392      * Tell if a given file has a chance of being parsed as this format.
393      * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
394      * big so you do not have to check for that unless you need more.
395      */
396     int (*read_probe)(AVProbeData *);
397
398     /**
399      * Read the format header and initialize the AVFormatContext
400      * structure. Return 0 if OK. 'ap' if non-NULL contains
401      * additional parameters. Only used in raw format right
402      * now. 'av_new_stream' should be called to create new streams.
403      */
404     int (*read_header)(struct AVFormatContext *,
405                        AVFormatParameters *ap);
406
407     /**
408      * Read one packet and put it in 'pkt'. pts and flags are also
409      * set. 'av_new_stream' can be called only if the flag
410      * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
411      * background thread).
412      * @return 0 on success, < 0 on error.
413      *         When returning an error, pkt must not have been allocated
414      *         or must be freed before returning
415      */
416     int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
417
418     /**
419      * Close the stream. The AVFormatContext and AVStreams are not
420      * freed by this function
421      */
422     int (*read_close)(struct AVFormatContext *);
423
424 #if FF_API_READ_SEEK
425     /**
426      * Seek to a given timestamp relative to the frames in
427      * stream component stream_index.
428      * @param stream_index Must not be -1.
429      * @param flags Selects which direction should be preferred if no exact
430      *              match is available.
431      * @return >= 0 on success (but not necessarily the new offset)
432      */
433     attribute_deprecated int (*read_seek)(struct AVFormatContext *,
434                                           int stream_index, int64_t timestamp, int flags);
435 #endif
436     /**
437      * Gets the next timestamp in stream[stream_index].time_base units.
438      * @return the timestamp or AV_NOPTS_VALUE if an error occurred
439      */
440     int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
441                               int64_t *pos, int64_t pos_limit);
442
443     /**
444      * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
445      * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
446      * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
447      */
448     int flags;
449
450     /**
451      * If extensions are defined, then no probe is done. You should
452      * usually not use extension format guessing because it is not
453      * reliable enough
454      */
455     const char *extensions;
456
457     /**
458      * General purpose read-only value that the format can use.
459      */
460     int value;
461
462     /**
463      * Start/resume playing - only meaningful if using a network-based format
464      * (RTSP).
465      */
466     int (*read_play)(struct AVFormatContext *);
467
468     /**
469      * Pause playing - only meaningful if using a network-based format
470      * (RTSP).
471      */
472     int (*read_pause)(struct AVFormatContext *);
473
474     const struct AVCodecTag * const *codec_tag;
475
476     /**
477      * Seek to timestamp ts.
478      * Seeking will be done so that the point from which all active streams
479      * can be presented successfully will be closest to ts and within min/max_ts.
480      * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
481      */
482     int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
483
484 #if FF_API_OLD_METADATA2
485     const AVMetadataConv *metadata_conv;
486 #endif
487
488     const AVClass *priv_class; ///< AVClass for the private context
489
490     /* private fields */
491     struct AVInputFormat *next;
492 } AVInputFormat;
493
494 enum AVStreamParseType {
495     AVSTREAM_PARSE_NONE,
496     AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
497     AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
498     AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
499     AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
500 };
501
502 typedef struct AVIndexEntry {
503     int64_t pos;
504     int64_t timestamp;
505 #define AVINDEX_KEYFRAME 0x0001
506     int flags:2;
507     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).
508     int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
509 } AVIndexEntry;
510
511 #define AV_DISPOSITION_DEFAULT   0x0001
512 #define AV_DISPOSITION_DUB       0x0002
513 #define AV_DISPOSITION_ORIGINAL  0x0004
514 #define AV_DISPOSITION_COMMENT   0x0008
515 #define AV_DISPOSITION_LYRICS    0x0010
516 #define AV_DISPOSITION_KARAOKE   0x0020
517
518 /**
519  * Track should be used during playback by default.
520  * Useful for subtitle track that should be displayed
521  * even when user did not explicitly ask for subtitles.
522  */
523 #define AV_DISPOSITION_FORCED    0x0040
524 #define AV_DISPOSITION_HEARING_IMPAIRED  0x0080  /**< stream for hearing impaired audiences */
525 #define AV_DISPOSITION_VISUAL_IMPAIRED   0x0100  /**< stream for visual impaired audiences */
526 #define AV_DISPOSITION_CLEAN_EFFECTS     0x0200  /**< stream without voice */
527
528 /**
529  * Stream structure.
530  * New fields can be added to the end with minor version bumps.
531  * Removal, reordering and changes to existing fields require a major
532  * version bump.
533  * sizeof(AVStream) must not be used outside libav*.
534  */
535 typedef struct AVStream {
536     int index;    /**< stream index in AVFormatContext */
537     int id;       /**< format-specific stream ID */
538     AVCodecContext *codec; /**< codec context */
539     /**
540      * Real base framerate of the stream.
541      * This is the lowest framerate with which all timestamps can be
542      * represented accurately (it is the least common multiple of all
543      * framerates in the stream). Note, this value is just a guess!
544      * For example, if the time base is 1/90000 and all frames have either
545      * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
546      */
547     AVRational r_frame_rate;
548     void *priv_data;
549
550 #if FF_API_REORDER_PRIVATE
551     /* internal data used in av_find_stream_info() */
552     int64_t first_dts;
553 #endif
554
555     /**
556      * encoding: pts generation when outputting stream
557      */
558     struct AVFrac pts;
559
560     /**
561      * This is the fundamental unit of time (in seconds) in terms
562      * of which frame timestamps are represented. For fixed-fps content,
563      * time base should be 1/framerate and timestamp increments should be 1.
564      * decoding: set by libavformat
565      * encoding: set by libavformat in av_write_header
566      */
567     AVRational time_base;
568 #if FF_API_REORDER_PRIVATE
569     int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
570 #endif
571 #if FF_API_STREAM_COPY
572     /* ffmpeg.c private use */
573     attribute_deprecated int stream_copy; /**< If set, just copy stream. */
574 #endif
575     enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
576
577 #if FF_API_AVSTREAM_QUALITY
578     //FIXME move stuff to a flags field?
579     /**
580      * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
581      * MN: dunno if that is the right place for it
582      */
583     attribute_deprecated float quality;
584 #endif
585
586     /**
587      * Decoding: pts of the first frame of the stream, in stream time base.
588      * Only set this if you are absolutely 100% sure that the value you set
589      * it to really is the pts of the first frame.
590      * This may be undefined (AV_NOPTS_VALUE).
591      */
592     int64_t start_time;
593
594     /**
595      * Decoding: duration of the stream, in stream time base.
596      * If a source file does not specify a duration, but does specify
597      * a bitrate, this value will be estimated from bitrate and file size.
598      */
599     int64_t duration;
600
601 #if FF_API_REORDER_PRIVATE
602     /* av_read_frame() support */
603     enum AVStreamParseType need_parsing;
604     struct AVCodecParserContext *parser;
605
606     int64_t cur_dts;
607     int last_IP_duration;
608     int64_t last_IP_pts;
609     /* av_seek_frame() support */
610     AVIndexEntry *index_entries; /**< Only used if the format does not
611                                     support seeking natively. */
612     int nb_index_entries;
613     unsigned int index_entries_allocated_size;
614 #endif
615
616     int64_t nb_frames;                 ///< number of frames in this stream if known or 0
617
618     int disposition; /**< AV_DISPOSITION_* bit field */
619
620 #if FF_API_REORDER_PRIVATE
621     AVProbeData probe_data;
622 #define MAX_REORDER_DELAY 16
623     int64_t pts_buffer[MAX_REORDER_DELAY+1];
624 #endif
625
626     /**
627      * sample aspect ratio (0 if unknown)
628      * - encoding: Set by user.
629      * - decoding: Set by libavformat.
630      */
631     AVRational sample_aspect_ratio;
632
633     AVDictionary *metadata;
634
635 #if FF_API_REORDER_PRIVATE
636     /* Intended mostly for av_read_frame() support. Not supposed to be used by */
637     /* external applications; try to use something else if at all possible.    */
638     const uint8_t *cur_ptr;
639     int cur_len;
640     AVPacket cur_pkt;
641
642     // Timestamp generation support:
643     /**
644      * Timestamp corresponding to the last dts sync point.
645      *
646      * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
647      * a DTS is received from the underlying container. Otherwise set to
648      * AV_NOPTS_VALUE by default.
649      */
650     int64_t reference_dts;
651
652     /**
653      * Number of packets to buffer for codec probing
654      * NOT PART OF PUBLIC API
655      */
656 #define MAX_PROBE_PACKETS 2500
657     int probe_packets;
658
659     /**
660      * last packet in packet_buffer for this stream when muxing.
661      * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
662      */
663     struct AVPacketList *last_in_packet_buffer;
664 #endif
665
666     /**
667      * Average framerate
668      */
669     AVRational avg_frame_rate;
670
671     /*****************************************************************
672      * All fields below this line are not part of the public API. They
673      * may not be used outside of libavformat and can be changed and
674      * removed at will.
675      * New public fields should be added right above.
676      *****************************************************************
677      */
678
679     /**
680      * Number of frames that have been demuxed during av_find_stream_info()
681      */
682     int codec_info_nb_frames;
683
684     /**
685      * Stream informations used internally by av_find_stream_info()
686      */
687 #define MAX_STD_TIMEBASES (60*12+5)
688     struct {
689         int64_t last_dts;
690         int64_t duration_gcd;
691         int duration_count;
692         double duration_error[MAX_STD_TIMEBASES];
693         int64_t codec_info_duration;
694         int nb_decoded_frames;
695     } *info;
696 #if !FF_API_REORDER_PRIVATE
697     const uint8_t *cur_ptr;
698     int cur_len;
699     AVPacket cur_pkt;
700
701     // Timestamp generation support:
702     /**
703      * Timestamp corresponding to the last dts sync point.
704      *
705      * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
706      * a DTS is received from the underlying container. Otherwise set to
707      * AV_NOPTS_VALUE by default.
708      */
709     int64_t reference_dts;
710     int64_t first_dts;
711     int64_t cur_dts;
712     int last_IP_duration;
713     int64_t last_IP_pts;
714
715     /**
716      * Number of packets to buffer for codec probing
717      */
718 #define MAX_PROBE_PACKETS 2500
719     int probe_packets;
720
721     /**
722      * last packet in packet_buffer for this stream when muxing.
723      */
724     struct AVPacketList *last_in_packet_buffer;
725     AVProbeData probe_data;
726 #define MAX_REORDER_DELAY 16
727     int64_t pts_buffer[MAX_REORDER_DELAY+1];
728     /* av_read_frame() support */
729     enum AVStreamParseType need_parsing;
730     struct AVCodecParserContext *parser;
731
732     AVIndexEntry *index_entries; /**< Only used if the format does not
733                                     support seeking natively. */
734     int nb_index_entries;
735     unsigned int index_entries_allocated_size;
736
737     int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
738 #endif
739 } AVStream;
740
741 #define AV_PROGRAM_RUNNING 1
742
743 /**
744  * New fields can be added to the end with minor version bumps.
745  * Removal, reordering and changes to existing fields require a major
746  * version bump.
747  * sizeof(AVProgram) must not be used outside libav*.
748  */
749 typedef struct AVProgram {
750     int            id;
751     int            flags;
752     enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
753     unsigned int   *stream_index;
754     unsigned int   nb_stream_indexes;
755     AVDictionary *metadata;
756 } AVProgram;
757
758 #define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
759                                          (streams are added dynamically) */
760
761 typedef struct AVChapter {
762     int id;                 ///< unique ID to identify the chapter
763     AVRational time_base;   ///< time base in which the start/end timestamps are specified
764     int64_t start, end;     ///< chapter start/end time in time_base units
765     AVDictionary *metadata;
766 } AVChapter;
767
768 /**
769  * Format I/O context.
770  * New fields can be added to the end with minor version bumps.
771  * Removal, reordering and changes to existing fields require a major
772  * version bump.
773  * sizeof(AVFormatContext) must not be used outside libav*, use
774  * avformat_alloc_context() to create an AVFormatContext.
775  */
776 typedef struct AVFormatContext {
777     /**
778      * A class for logging and AVOptions. Set by avformat_alloc_context().
779      * Exports (de)muxer private options if they exist.
780      */
781     const AVClass *av_class;
782
783     /**
784      * Can only be iformat or oformat, not both at the same time.
785      *
786      * decoding: set by avformat_open_input().
787      * encoding: set by the user.
788      */
789     struct AVInputFormat *iformat;
790     struct AVOutputFormat *oformat;
791
792     /**
793      * Format private data. This is an AVOptions-enabled struct
794      * if and only if iformat/oformat.priv_class is not NULL.
795      */
796     void *priv_data;
797
798     /*
799      * I/O context.
800      *
801      * decoding: either set by the user before avformat_open_input() (then
802      * the user must close it manually) or set by avformat_open_input().
803      * encoding: set by the user.
804      *
805      * Do NOT set this field if AVFMT_NOFILE flag is set in
806      * iformat/oformat.flags. In such a case, the (de)muxer will handle
807      * I/O in some other way and this field will be NULL.
808      */
809     AVIOContext *pb;
810
811     /**
812      * A list of all streams in the file. New streams are created with
813      * avformat_new_stream().
814      *
815      * decoding: streams are created by libavformat in avformat_open_input().
816      * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
817      * appear in av_read_frame().
818      * encoding: streams are created by the user before avformat_write_header().
819      */
820     unsigned int nb_streams;
821     AVStream **streams;
822
823     char filename[1024]; /**< input or output filename */
824     /* stream info */
825 #if FF_API_TIMESTAMP
826     /**
827      * @deprecated use 'creation_time' metadata tag instead
828      */
829     attribute_deprecated int64_t timestamp;
830 #endif
831
832     int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
833 #if FF_API_REORDER_PRIVATE
834     /* private data for pts handling (do not modify directly). */
835     /**
836      * This buffer is only needed when packets were already buffered but
837      * not decoded, for example to get the codec parameters in MPEG
838      * streams.
839      */
840     struct AVPacketList *packet_buffer;
841 #endif
842
843     /**
844      * Decoding: position of the first frame of the component, in
845      * AV_TIME_BASE fractional seconds. NEVER set this value directly:
846      * It is deduced from the AVStream values.
847      */
848     int64_t start_time;
849
850     /**
851      * Decoding: duration of the stream, in AV_TIME_BASE fractional
852      * seconds. Only set this value if you know none of the individual stream
853      * durations and also dont set any of them. This is deduced from the
854      * AVStream values if not set.
855      */
856     int64_t duration;
857
858 #if FF_API_FILESIZE
859     /**
860      * decoding: total file size, 0 if unknown
861      */
862     attribute_deprecated int64_t file_size;
863 #endif
864
865     /**
866      * Decoding: total stream bitrate in bit/s, 0 if not
867      * available. Never set it directly if the file_size and the
868      * duration are known as Libav can compute it automatically.
869      */
870     int bit_rate;
871
872 #if FF_API_REORDER_PRIVATE
873     /* av_read_frame() support */
874     AVStream *cur_st;
875
876     /* av_seek_frame() support */
877     int64_t data_offset; /**< offset of the first packet */
878 #endif
879
880 #if FF_API_MUXRATE
881     /**
882      * use mpeg muxer private options instead
883      */
884     attribute_deprecated int mux_rate;
885 #endif
886     unsigned int packet_size;
887 #if FF_API_PRELOAD
888     attribute_deprecated int preload;
889 #endif
890     int max_delay;
891
892 #if FF_API_LOOP_OUTPUT
893 #define AVFMT_NOOUTPUTLOOP -1
894 #define AVFMT_INFINITEOUTPUTLOOP 0
895     /**
896      * number of times to loop output in formats that support it
897      *
898      * @deprecated use the 'loop' private option in the gif muxer.
899      */
900     attribute_deprecated int loop_output;
901 #endif
902
903     int flags;
904 #define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
905 #define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
906 #define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
907 #define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
908 #define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
909 #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
910 #if FF_API_FLAG_RTP_HINT
911 #define AVFMT_FLAG_RTP_HINT     0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
912 #endif
913 #define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
914 #define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
915
916 #if FF_API_LOOP_INPUT
917     /**
918      * @deprecated, use the 'loop' img2 demuxer private option.
919      */
920     attribute_deprecated int loop_input;
921 #endif
922
923     /**
924      * decoding: size of data to probe; encoding: unused.
925      */
926     unsigned int probesize;
927
928     /**
929      * decoding: maximum time (in AV_TIME_BASE units) during which the input should
930      * be analyzed in avformat_find_stream_info().
931      */
932     int max_analyze_duration;
933
934     const uint8_t *key;
935     int keylen;
936
937     unsigned int nb_programs;
938     AVProgram **programs;
939
940     /**
941      * Forced video codec_id.
942      * Demuxing: Set by user.
943      */
944     enum CodecID video_codec_id;
945
946     /**
947      * Forced audio codec_id.
948      * Demuxing: Set by user.
949      */
950     enum CodecID audio_codec_id;
951
952     /**
953      * Forced subtitle codec_id.
954      * Demuxing: Set by user.
955      */
956     enum CodecID subtitle_codec_id;
957
958     /**
959      * Maximum amount of memory in bytes to use for the index of each stream.
960      * If the index exceeds this size, entries will be discarded as
961      * needed to maintain a smaller size. This can lead to slower or less
962      * accurate seeking (depends on demuxer).
963      * Demuxers for which a full in-memory index is mandatory will ignore
964      * this.
965      * muxing  : unused
966      * demuxing: set by user
967      */
968     unsigned int max_index_size;
969
970     /**
971      * Maximum amount of memory in bytes to use for buffering frames
972      * obtained from realtime capture devices.
973      */
974     unsigned int max_picture_buffer;
975
976     unsigned int nb_chapters;
977     AVChapter **chapters;
978
979     /**
980      * Flags to enable debugging.
981      */
982     int debug;
983 #define FF_FDEBUG_TS        0x0001
984
985 #if FF_API_REORDER_PRIVATE
986     /**
987      * Raw packets from the demuxer, prior to parsing and decoding.
988      * This buffer is used for buffering packets until the codec can
989      * be identified, as parsing cannot be done without knowing the
990      * codec.
991      */
992     struct AVPacketList *raw_packet_buffer;
993     struct AVPacketList *raw_packet_buffer_end;
994
995     struct AVPacketList *packet_buffer_end;
996 #endif
997
998     AVDictionary *metadata;
999
1000 #if FF_API_REORDER_PRIVATE
1001     /**
1002      * Remaining size available for raw_packet_buffer, in bytes.
1003      * NOT PART OF PUBLIC API
1004      */
1005 #define RAW_PACKET_BUFFER_SIZE 2500000
1006     int raw_packet_buffer_remaining_size;
1007 #endif
1008
1009     /**
1010      * Start time of the stream in real world time, in microseconds
1011      * since the unix epoch (00:00 1st January 1970). That is, pts=0
1012      * in the stream was captured at this real world time.
1013      * - encoding: Set by user.
1014      * - decoding: Unused.
1015      */
1016     int64_t start_time_realtime;
1017
1018     /**
1019      * decoding: number of frames used to probe fps
1020      */
1021     int fps_probe_size;
1022
1023     /**
1024      * Error recognition; higher values will detect more errors but may
1025      * misdetect some more or less valid parts as errors.
1026      * - encoding: unused
1027      * - decoding: Set by user.
1028      */
1029     int error_recognition;
1030
1031     /**
1032      * Custom interrupt callbacks for the I/O layer.
1033      *
1034      * decoding: set by the user before avformat_open_input().
1035      * encoding: set by the user before avformat_write_header()
1036      * (mainly useful for AVFMT_NOFILE formats). The callback
1037      * should also be passed to avio_open2() if it's used to
1038      * open the file.
1039      */
1040     AVIOInterruptCB interrupt_callback;
1041
1042     /*****************************************************************
1043      * All fields below this line are not part of the public API. They
1044      * may not be used outside of libavformat and can be changed and
1045      * removed at will.
1046      * New public fields should be added right above.
1047      *****************************************************************
1048      */
1049 #if !FF_API_REORDER_PRIVATE
1050     /**
1051      * Raw packets from the demuxer, prior to parsing and decoding.
1052      * This buffer is used for buffering packets until the codec can
1053      * be identified, as parsing cannot be done without knowing the
1054      * codec.
1055      */
1056     struct AVPacketList *raw_packet_buffer;
1057     struct AVPacketList *raw_packet_buffer_end;
1058     /**
1059      * Remaining size available for raw_packet_buffer, in bytes.
1060      */
1061 #define RAW_PACKET_BUFFER_SIZE 2500000
1062     int raw_packet_buffer_remaining_size;
1063
1064     /**
1065      * This buffer is only needed when packets were already buffered but
1066      * not decoded, for example to get the codec parameters in MPEG
1067      * streams.
1068      */
1069     struct AVPacketList *packet_buffer;
1070     struct AVPacketList *packet_buffer_end;
1071
1072     /* av_read_frame() support */
1073     AVStream *cur_st;
1074
1075     /* av_seek_frame() support */
1076     int64_t data_offset; /**< offset of the first packet */
1077 #endif
1078 } AVFormatContext;
1079
1080 typedef struct AVPacketList {
1081     AVPacket pkt;
1082     struct AVPacketList *next;
1083 } AVPacketList;
1084
1085 /**
1086  * If f is NULL, returns the first registered input format,
1087  * if f is non-NULL, returns the next registered input format after f
1088  * or NULL if f is the last one.
1089  */
1090 AVInputFormat  *av_iformat_next(AVInputFormat  *f);
1091
1092 /**
1093  * If f is NULL, returns the first registered output format,
1094  * if f is non-NULL, returns the next registered output format after f
1095  * or NULL if f is the last one.
1096  */
1097 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
1098
1099 #if FF_API_GUESS_IMG2_CODEC
1100 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1101 #endif
1102
1103 /* XXX: Use automatic init with either ELF sections or C file parser */
1104 /* modules. */
1105
1106 /* utils.c */
1107 void av_register_input_format(AVInputFormat *format);
1108 void av_register_output_format(AVOutputFormat *format);
1109
1110 /**
1111  * Return the output format in the list of registered output formats
1112  * which best matches the provided parameters, or return NULL if
1113  * there is no match.
1114  *
1115  * @param short_name if non-NULL checks if short_name matches with the
1116  * names of the registered formats
1117  * @param filename if non-NULL checks if filename terminates with the
1118  * extensions of the registered formats
1119  * @param mime_type if non-NULL checks if mime_type matches with the
1120  * MIME type of the registered formats
1121  */
1122 AVOutputFormat *av_guess_format(const char *short_name,
1123                                 const char *filename,
1124                                 const char *mime_type);
1125
1126 /**
1127  * Guess the codec ID based upon muxer and filename.
1128  */
1129 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1130                             const char *filename, const char *mime_type,
1131                             enum AVMediaType type);
1132
1133 /**
1134  * Send a nice hexadecimal dump of a buffer to the specified file stream.
1135  *
1136  * @param f The file stream pointer where the dump should be sent to.
1137  * @param buf buffer
1138  * @param size buffer size
1139  *
1140  * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
1141  */
1142 void av_hex_dump(FILE *f, uint8_t *buf, int size);
1143
1144 /**
1145  * Send a nice hexadecimal dump of a buffer to the log.
1146  *
1147  * @param avcl A pointer to an arbitrary struct of which the first field is a
1148  * pointer to an AVClass struct.
1149  * @param level The importance level of the message, lower values signifying
1150  * higher importance.
1151  * @param buf buffer
1152  * @param size buffer size
1153  *
1154  * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
1155  */
1156 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1157
1158 /**
1159  * Send a nice dump of a packet to the specified file stream.
1160  *
1161  * @param f The file stream pointer where the dump should be sent to.
1162  * @param pkt packet to dump
1163  * @param dump_payload True if the payload must be displayed, too.
1164  * @param st AVStream that the packet belongs to
1165  */
1166 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1167
1168
1169 /**
1170  * Send a nice dump of a packet to the log.
1171  *
1172  * @param avcl A pointer to an arbitrary struct of which the first field is a
1173  * pointer to an AVClass struct.
1174  * @param level The importance level of the message, lower values signifying
1175  * higher importance.
1176  * @param pkt packet to dump
1177  * @param dump_payload True if the payload must be displayed, too.
1178  * @param st AVStream that the packet belongs to
1179  */
1180 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1181                       AVStream *st);
1182
1183 #if FF_API_PKT_DUMP
1184 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1185 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1186                                           int dump_payload);
1187 #endif
1188
1189 /**
1190  * Initialize libavformat and register all the muxers, demuxers and
1191  * protocols. If you do not call this function, then you can select
1192  * exactly which formats you want to support.
1193  *
1194  * @see av_register_input_format()
1195  * @see av_register_output_format()
1196  * @see av_register_protocol()
1197  */
1198 void av_register_all(void);
1199
1200 /**
1201  * Get the CodecID for the given codec tag tag.
1202  * If no codec id is found returns CODEC_ID_NONE.
1203  *
1204  * @param tags list of supported codec_id-codec_tag pairs, as stored
1205  * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1206  */
1207 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1208
1209 /**
1210  * Get the codec tag for the given codec id id.
1211  * If no codec tag is found returns 0.
1212  *
1213  * @param tags list of supported codec_id-codec_tag pairs, as stored
1214  * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1215  */
1216 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1217
1218 /* media file input */
1219
1220 /**
1221  * Find AVInputFormat based on the short name of the input format.
1222  */
1223 AVInputFormat *av_find_input_format(const char *short_name);
1224
1225 /**
1226  * Guess the file format.
1227  *
1228  * @param is_opened Whether the file is already opened; determines whether
1229  *                  demuxers with or without AVFMT_NOFILE are probed.
1230  */
1231 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1232
1233 /**
1234  * Guess the file format.
1235  *
1236  * @param is_opened Whether the file is already opened; determines whether
1237  *                  demuxers with or without AVFMT_NOFILE are probed.
1238  * @param score_max A probe score larger that this is required to accept a
1239  *                  detection, the variable is set to the actual detection
1240  *                  score afterwards.
1241  *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1242  *                  to retry with a larger probe buffer.
1243  */
1244 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1245
1246 /**
1247  * Probe a bytestream to determine the input format. Each time a probe returns
1248  * with a score that is too low, the probe buffer size is increased and another
1249  * attempt is made. When the maximum probe size is reached, the input format
1250  * with the highest score is returned.
1251  *
1252  * @param pb the bytestream to probe
1253  * @param fmt the input format is put here
1254  * @param filename the filename of the stream
1255  * @param logctx the log context
1256  * @param offset the offset within the bytestream to probe from
1257  * @param max_probe_size the maximum probe buffer size (zero for default)
1258  * @return 0 in case of success, a negative value corresponding to an
1259  * AVERROR code otherwise
1260  */
1261 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
1262                           const char *filename, void *logctx,
1263                           unsigned int offset, unsigned int max_probe_size);
1264
1265 #if FF_API_FORMAT_PARAMETERS
1266 /**
1267  * Allocate all the structures needed to read an input stream.
1268  *        This does not open the needed codecs for decoding the stream[s].
1269  * @deprecated use avformat_open_input instead.
1270  */
1271 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
1272                          AVIOContext *pb, const char *filename,
1273                          AVInputFormat *fmt, AVFormatParameters *ap);
1274
1275 /**
1276  * Open a media file as input. The codecs are not opened. Only the file
1277  * header (if present) is read.
1278  *
1279  * @param ic_ptr The opened media file handle is put here.
1280  * @param filename filename to open
1281  * @param fmt If non-NULL, force the file format to use.
1282  * @param buf_size optional buffer size (zero if default is OK)
1283  * @param ap Additional parameters needed when opening the file
1284  *           (NULL if default).
1285  * @return 0 if OK, AVERROR_xxx otherwise
1286  *
1287  * @deprecated use avformat_open_input instead.
1288  */
1289 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1290                        AVInputFormat *fmt,
1291                        int buf_size,
1292                        AVFormatParameters *ap);
1293 #endif
1294
1295 /**
1296  * Open an input stream and read the header. The codecs are not opened.
1297  * The stream must be closed with av_close_input_file().
1298  *
1299  * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
1300  *           May be a pointer to NULL, in which case an AVFormatContext is allocated by this
1301  *           function and written into ps.
1302  *           Note that a user-supplied AVFormatContext will be freed on failure.
1303  * @param filename Name of the stream to open.
1304  * @param fmt If non-NULL, this parameter forces a specific input format.
1305  *            Otherwise the format is autodetected.
1306  * @param options  A dictionary filled with AVFormatContext and demuxer-private options.
1307  *                 On return this parameter will be destroyed and replaced with a dict containing
1308  *                 options that were not found. May be NULL.
1309  *
1310  * @return 0 on success, a negative AVERROR on failure.
1311  *
1312  * @note If you want to use custom IO, preallocate the format context and set its pb field.
1313  */
1314 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1315
1316 /**
1317  * Allocate an AVFormatContext.
1318  * avformat_free_context() can be used to free the context and everything
1319  * allocated by the framework within it.
1320  */
1321 AVFormatContext *avformat_alloc_context(void);
1322
1323 #if FF_API_FORMAT_PARAMETERS
1324 /**
1325  * Read packets of a media file to get stream information. This
1326  * is useful for file formats with no headers such as MPEG. This
1327  * function also computes the real framerate in case of MPEG-2 repeat
1328  * frame mode.
1329  * The logical file position is not changed by this function;
1330  * examined packets may be buffered for later processing.
1331  *
1332  * @param ic media file handle
1333  * @return >=0 if OK, AVERROR_xxx on error
1334  * @todo Let the user decide somehow what information is needed so that
1335  *       we do not waste time getting stuff the user does not need.
1336  *
1337  * @deprecated use avformat_find_stream_info.
1338  */
1339 attribute_deprecated
1340 int av_find_stream_info(AVFormatContext *ic);
1341 #endif
1342
1343 /**
1344  * Read packets of a media file to get stream information. This
1345  * is useful for file formats with no headers such as MPEG. This
1346  * function also computes the real framerate in case of MPEG-2 repeat
1347  * frame mode.
1348  * The logical file position is not changed by this function;
1349  * examined packets may be buffered for later processing.
1350  *
1351  * @param ic media file handle
1352  * @param options  If non-NULL, an ic.nb_streams long array of pointers to
1353  *                 dictionaries, where i-th member contains options for
1354  *                 codec corresponding to i-th stream.
1355  *                 On return each dictionary will be filled with options that were not found.
1356  * @return >=0 if OK, AVERROR_xxx on error
1357  *
1358  * @note this function isn't guaranteed to open all the codecs, so
1359  *       options being non-empty at return is a perfectly normal behavior.
1360  *
1361  * @todo Let the user decide somehow what information is needed so that
1362  *       we do not waste time getting stuff the user does not need.
1363  */
1364 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
1365
1366 /**
1367  * Find the "best" stream in the file.
1368  * The best stream is determined according to various heuristics as the most
1369  * likely to be what the user expects.
1370  * If the decoder parameter is non-NULL, av_find_best_stream will find the
1371  * default decoder for the stream's codec; streams for which no decoder can
1372  * be found are ignored.
1373  *
1374  * @param ic                media file handle
1375  * @param type              stream type: video, audio, subtitles, etc.
1376  * @param wanted_stream_nb  user-requested stream number,
1377  *                          or -1 for automatic selection
1378  * @param related_stream    try to find a stream related (eg. in the same
1379  *                          program) to this one, or -1 if none
1380  * @param decoder_ret       if non-NULL, returns the decoder for the
1381  *                          selected stream
1382  * @param flags             flags; none are currently defined
1383  * @return  the non-negative stream number in case of success,
1384  *          AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1385  *          could be found,
1386  *          AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1387  * @note  If av_find_best_stream returns successfully and decoder_ret is not
1388  *        NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1389  */
1390 int av_find_best_stream(AVFormatContext *ic,
1391                         enum AVMediaType type,
1392                         int wanted_stream_nb,
1393                         int related_stream,
1394                         AVCodec **decoder_ret,
1395                         int flags);
1396
1397 /**
1398  * Read a transport packet from a media file.
1399  *
1400  * This function is obsolete and should never be used.
1401  * Use av_read_frame() instead.
1402  *
1403  * @param s media file handle
1404  * @param pkt is filled
1405  * @return 0 if OK, AVERROR_xxx on error
1406  */
1407 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1408
1409 /**
1410  * Return the next frame of a stream.
1411  * This function returns what is stored in the file, and does not validate
1412  * that what is there are valid frames for the decoder. It will split what is
1413  * stored in the file into frames and return one for each call. It will not
1414  * omit invalid data between valid frames so as to give the decoder the maximum
1415  * information possible for decoding.
1416  *
1417  * The returned packet is valid
1418  * until the next av_read_frame() or until av_close_input_file() and
1419  * must be freed with av_free_packet. For video, the packet contains
1420  * exactly one frame. For audio, it contains an integer number of
1421  * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1422  * data). If the audio frames have a variable size (e.g. MPEG audio),
1423  * then it contains one frame.
1424  *
1425  * pkt->pts, pkt->dts and pkt->duration are always set to correct
1426  * values in AVStream.time_base units (and guessed if the format cannot
1427  * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1428  * has B-frames, so it is better to rely on pkt->dts if you do not
1429  * decompress the payload.
1430  *
1431  * @return 0 if OK, < 0 on error or end of file
1432  */
1433 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1434
1435 /**
1436  * Seek to the keyframe at timestamp.
1437  * 'timestamp' in 'stream_index'.
1438  * @param stream_index If stream_index is (-1), a default
1439  * stream is selected, and timestamp is automatically converted
1440  * from AV_TIME_BASE units to the stream specific time_base.
1441  * @param timestamp Timestamp in AVStream.time_base units
1442  *        or, if no stream is specified, in AV_TIME_BASE units.
1443  * @param flags flags which select direction and seeking mode
1444  * @return >= 0 on success
1445  */
1446 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1447                   int flags);
1448
1449 /**
1450  * Seek to timestamp ts.
1451  * Seeking will be done so that the point from which all active streams
1452  * can be presented successfully will be closest to ts and within min/max_ts.
1453  * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1454  *
1455  * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1456  * are the file position (this may not be supported by all demuxers).
1457  * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1458  * in the stream with stream_index (this may not be supported by all demuxers).
1459  * Otherwise all timestamps are in units of the stream selected by stream_index
1460  * or if stream_index is -1, in AV_TIME_BASE units.
1461  * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1462  * keyframes (this may not be supported by all demuxers).
1463  *
1464  * @param stream_index index of the stream which is used as time base reference
1465  * @param min_ts smallest acceptable timestamp
1466  * @param ts target timestamp
1467  * @param max_ts largest acceptable timestamp
1468  * @param flags flags
1469  * @return >=0 on success, error code otherwise
1470  *
1471  * @note This is part of the new seek API which is still under construction.
1472  *       Thus do not use this yet. It may change at any time, do not expect
1473  *       ABI compatibility yet!
1474  */
1475 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1476
1477 /**
1478  * Start playing a network-based stream (e.g. RTSP stream) at the
1479  * current position.
1480  */
1481 int av_read_play(AVFormatContext *s);
1482
1483 /**
1484  * Pause a network-based stream (e.g. RTSP stream).
1485  *
1486  * Use av_read_play() to resume it.
1487  */
1488 int av_read_pause(AVFormatContext *s);
1489
1490 /**
1491  * Free a AVFormatContext allocated by av_open_input_stream.
1492  * @param s context to free
1493  */
1494 void av_close_input_stream(AVFormatContext *s);
1495
1496 /**
1497  * Close a media file (but not its codecs).
1498  *
1499  * @param s media file handle
1500  */
1501 void av_close_input_file(AVFormatContext *s);
1502
1503 /**
1504  * Free an AVFormatContext and all its streams.
1505  * @param s context to free
1506  */
1507 void avformat_free_context(AVFormatContext *s);
1508
1509 #if FF_API_NEW_STREAM
1510 /**
1511  * Add a new stream to a media file.
1512  *
1513  * Can only be called in the read_header() function. If the flag
1514  * AVFMTCTX_NOHEADER is in the format context, then new streams
1515  * can be added in read_packet too.
1516  *
1517  * @param s media file handle
1518  * @param id file-format-dependent stream ID
1519  */
1520 attribute_deprecated
1521 AVStream *av_new_stream(AVFormatContext *s, int id);
1522 #endif
1523
1524 /**
1525  * Add a new stream to a media file.
1526  *
1527  * When demuxing, it is called by the demuxer in read_header(). If the
1528  * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
1529  * be called in read_packet().
1530  *
1531  * When muxing, should be called by the user before avformat_write_header().
1532  *
1533  * @param c If non-NULL, the AVCodecContext corresponding to the new stream
1534  * will be initialized to use this codec. This is needed for e.g. codec-specific
1535  * defaults to be set, so codec should be provided if it is known.
1536  *
1537  * @return newly created stream or NULL on error.
1538  */
1539 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
1540
1541 AVProgram *av_new_program(AVFormatContext *s, int id);
1542
1543 #if FF_API_SET_PTS_INFO
1544 /**
1545  * @deprecated this function is not supposed to be called outside of lavf
1546  */
1547 attribute_deprecated
1548 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1549                      unsigned int pts_num, unsigned int pts_den);
1550 #endif
1551
1552 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1553 #define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1554 #define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1555 #define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1556
1557 int av_find_default_stream_index(AVFormatContext *s);
1558
1559 /**
1560  * Get the index for a specific timestamp.
1561  * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1562  *                 to the timestamp which is <= the requested one, if backward
1563  *                 is 0, then it will be >=
1564  *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1565  * @return < 0 if no such timestamp could be found
1566  */
1567 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1568
1569 /**
1570  * Add an index entry into a sorted list. Update the entry if the list
1571  * already contains it.
1572  *
1573  * @param timestamp timestamp in the time base of the given stream
1574  */
1575 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1576                        int size, int distance, int flags);
1577
1578 #if FF_API_SEEK_PUBLIC
1579 attribute_deprecated
1580 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1581                          int64_t target_ts, int flags);
1582 attribute_deprecated
1583 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1584 attribute_deprecated
1585 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1586                       int64_t target_ts, int64_t pos_min,
1587                       int64_t pos_max, int64_t pos_limit,
1588                       int64_t ts_min, int64_t ts_max,
1589                       int flags, int64_t *ts_ret,
1590                       int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1591 #endif
1592
1593 /**
1594  * media file output
1595  */
1596 #if FF_API_FORMAT_PARAMETERS
1597 /**
1598  * @deprecated pass the options to avformat_write_header directly.
1599  */
1600 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1601 #endif
1602
1603 /**
1604  * Split a URL string into components.
1605  *
1606  * The pointers to buffers for storing individual components may be null,
1607  * in order to ignore that component. Buffers for components not found are
1608  * set to empty strings. If the port is not found, it is set to a negative
1609  * value.
1610  *
1611  * @param proto the buffer for the protocol
1612  * @param proto_size the size of the proto buffer
1613  * @param authorization the buffer for the authorization
1614  * @param authorization_size the size of the authorization buffer
1615  * @param hostname the buffer for the host name
1616  * @param hostname_size the size of the hostname buffer
1617  * @param port_ptr a pointer to store the port number in
1618  * @param path the buffer for the path
1619  * @param path_size the size of the path buffer
1620  * @param url the URL to split
1621  */
1622 void av_url_split(char *proto,         int proto_size,
1623                   char *authorization, int authorization_size,
1624                   char *hostname,      int hostname_size,
1625                   int *port_ptr,
1626                   char *path,          int path_size,
1627                   const char *url);
1628
1629 /**
1630  * Allocate the stream private data and write the stream header to
1631  * an output media file.
1632  *
1633  * @param s Media file handle, must be allocated with avformat_alloc_context().
1634  *          Its oformat field must be set to the desired output format;
1635  *          Its pb field must be set to an already openened AVIOContext.
1636  * @param options  An AVDictionary filled with AVFormatContext and muxer-private options.
1637  *                 On return this parameter will be destroyed and replaced with a dict containing
1638  *                 options that were not found. May be NULL.
1639  *
1640  * @return 0 on success, negative AVERROR on failure.
1641  *
1642  * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
1643  */
1644 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
1645
1646 #if FF_API_FORMAT_PARAMETERS
1647 /**
1648  * Allocate the stream private data and write the stream header to an
1649  * output media file.
1650  * @note: this sets stream time-bases, if possible to stream->codec->time_base
1651  * but for some formats it might also be some other time base
1652  *
1653  * @param s media file handle
1654  * @return 0 if OK, AVERROR_xxx on error
1655  *
1656  * @deprecated use avformat_write_header.
1657  */
1658 attribute_deprecated int av_write_header(AVFormatContext *s);
1659 #endif
1660
1661 /**
1662  * Write a packet to an output media file.
1663  *
1664  * The packet shall contain one audio or video frame.
1665  * The packet must be correctly interleaved according to the container
1666  * specification, if not then av_interleaved_write_frame must be used.
1667  *
1668  * @param s media file handle
1669  * @param pkt The packet, which contains the stream_index, buf/buf_size,
1670               dts/pts, ...
1671  * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1672  */
1673 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1674
1675 /**
1676  * Write a packet to an output media file ensuring correct interleaving.
1677  *
1678  * The packet must contain one audio or video frame.
1679  * If the packets are already correctly interleaved, the application should
1680  * call av_write_frame() instead as it is slightly faster. It is also important
1681  * to keep in mind that completely non-interleaved input will need huge amounts
1682  * of memory to interleave with this, so it is preferable to interleave at the
1683  * demuxer level.
1684  *
1685  * @param s media file handle
1686  * @param pkt The packet, which contains the stream_index, buf/buf_size,
1687               dts/pts, ...
1688  * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1689  */
1690 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1691
1692 /**
1693  * Interleave a packet per dts in an output media file.
1694  *
1695  * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1696  * function, so they cannot be used after it. Note that calling av_free_packet()
1697  * on them is still safe.
1698  *
1699  * @param s media file handle
1700  * @param out the interleaved packet will be output here
1701  * @param pkt the input packet
1702  * @param flush 1 if no further packets are available as input and all
1703  *              remaining packets should be output
1704  * @return 1 if a packet was output, 0 if no packet could be output,
1705  *         < 0 if an error occurred
1706  */
1707 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1708                                  AVPacket *pkt, int flush);
1709
1710 /**
1711  * Write the stream trailer to an output media file and free the
1712  * file private data.
1713  *
1714  * May only be called after a successful call to av_write_header.
1715  *
1716  * @param s media file handle
1717  * @return 0 if OK, AVERROR_xxx on error
1718  */
1719 int av_write_trailer(AVFormatContext *s);
1720
1721 #if FF_API_DUMP_FORMAT
1722 attribute_deprecated void dump_format(AVFormatContext *ic,
1723                                       int index,
1724                                       const char *url,
1725                                       int is_output);
1726 #endif
1727
1728 void av_dump_format(AVFormatContext *ic,
1729                     int index,
1730                     const char *url,
1731                     int is_output);
1732
1733 #if FF_API_PARSE_DATE
1734 /**
1735  * Parse datestr and return a corresponding number of microseconds.
1736  *
1737  * @param datestr String representing a date or a duration.
1738  * See av_parse_time() for the syntax of the provided string.
1739  * @deprecated in favor of av_parse_time()
1740  */
1741 attribute_deprecated
1742 int64_t parse_date(const char *datestr, int duration);
1743 #endif
1744
1745 /**
1746  * Get the current time in microseconds.
1747  */
1748 int64_t av_gettime(void);
1749
1750 #if FF_API_FIND_INFO_TAG
1751 /**
1752  * @deprecated use av_find_info_tag in libavutil instead.
1753  */
1754 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1755 #endif
1756
1757 /**
1758  * Return in 'buf' the path with '%d' replaced by a number.
1759  *
1760  * Also handles the '%0nd' format where 'n' is the total number
1761  * of digits and '%%'.
1762  *
1763  * @param buf destination buffer
1764  * @param buf_size destination buffer size
1765  * @param path numbered sequence string
1766  * @param number frame number
1767  * @return 0 if OK, -1 on format error
1768  */
1769 int av_get_frame_filename(char *buf, int buf_size,
1770                           const char *path, int number);
1771
1772 /**
1773  * Check whether filename actually is a numbered sequence generator.
1774  *
1775  * @param filename possible numbered sequence string
1776  * @return 1 if a valid numbered sequence string, 0 otherwise
1777  */
1778 int av_filename_number_test(const char *filename);
1779
1780 /**
1781  * Generate an SDP for an RTP session.
1782  *
1783  * @param ac array of AVFormatContexts describing the RTP streams. If the
1784  *           array is composed by only one context, such context can contain
1785  *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1786  *           all the contexts in the array (an AVCodecContext per RTP stream)
1787  *           must contain only one AVStream.
1788  * @param n_files number of AVCodecContexts contained in ac
1789  * @param buf buffer where the SDP will be stored (must be allocated by
1790  *            the caller)
1791  * @param size the size of the buffer
1792  * @return 0 if OK, AVERROR_xxx on error
1793  */
1794 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1795
1796 #if FF_API_SDP_CREATE
1797 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1798 #endif
1799
1800 /**
1801  * Return a positive value if the given filename has one of the given
1802  * extensions, 0 otherwise.
1803  *
1804  * @param extensions a comma-separated list of filename extensions
1805  */
1806 int av_match_ext(const char *filename, const char *extensions);
1807
1808 /**
1809  * Test if the given container can store a codec.
1810  *
1811  * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
1812  *
1813  * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
1814  *         A negative number if this information is not available.
1815  */
1816 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1817
1818 /**
1819  * Get the AVClass for AVFormatContext. It can be used in combination with
1820  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
1821  *
1822  * @see av_opt_find().
1823  */
1824 const AVClass *avformat_get_class(void);
1825
1826 /**
1827  * Do global initialization of network components. This is optional,
1828  * but recommended, since it avoids the overhead of implicitly
1829  * doing the setup for each session.
1830  *
1831  * Calling this function will become mandatory if using network
1832  * protocols at some major version bump.
1833  */
1834 int avformat_network_init(void);
1835
1836 /**
1837  * Undo the initialization done by avformat_network_init.
1838  */
1839 int avformat_network_deinit(void);
1840
1841 #endif /* AVFORMAT_AVFORMAT_H */