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