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