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