2 * copyright (c) 2001 Fabrice Bellard
4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVFORMAT_AVFORMAT_H
22 #define AVFORMAT_AVFORMAT_H
24 #define LIBAVFORMAT_VERSION_MAJOR 52
25 #define LIBAVFORMAT_VERSION_MINOR 46
26 #define LIBAVFORMAT_VERSION_MICRO 0
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
36 #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
39 * Returns the LIBAVFORMAT_VERSION_INT constant.
41 unsigned avformat_version(void);
44 * Returns the libavformat build-time configuration.
46 const char *avformat_configuration(void);
49 * Returns the libavformat license.
51 const char *avformat_license(void);
54 #include <stdio.h> /* FILE */
55 #include "libavcodec/avcodec.h"
59 struct AVFormatContext;
63 * Public Metadata API.
64 * The metadata API allows libavformat to export metadata tags to a client
65 * application using a sequence of key/value pairs.
66 * Important concepts to keep in mind:
67 * 1. Keys are unique; there can never be 2 tags with the same key. This is
68 * also meant semantically, i.e., a demuxer should not knowingly produce
69 * several keys that are literally different but semantically identical.
70 * E.g., key=Author5, key=Author6. In this example, all authors must be
71 * placed in the same tag.
72 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
73 * want to store, e.g., the email address of the child of producer Alice
74 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
75 * 3. A tag whose value is localized for a particular language is appended
76 * with a dash character ('-') and the ISO 639-2/B 3-letter language code.
77 * For example: Author-ger=Michael, Author-eng=Mike
78 * The original/default language is in the unqualified "Author" tag.
79 * A demuxer should set a default if it sets any translated tag.
82 #define AV_METADATA_MATCH_CASE 1
83 #define AV_METADATA_IGNORE_SUFFIX 2
84 #define AV_METADATA_DONT_STRDUP_KEY 4
85 #define AV_METADATA_DONT_STRDUP_VAL 8
92 typedef struct AVMetadata AVMetadata;
93 typedef struct AVMetadataConv AVMetadataConv;
96 * Gets a metadata element with matching key.
97 * @param prev Set to the previous matching element to find the next.
98 * @param flags Allows case as well as suffix-insensitive comparisons.
99 * @return Found tag or NULL, changing key or value leads to undefined behavior.
102 av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
104 #if LIBAVFORMAT_VERSION_MAJOR == 52
106 * Sets the given tag in m, overwriting an existing tag.
107 * @param key tag key to add to m (will be av_strduped)
108 * @param value tag value to add to m (will be av_strduped)
109 * @return >= 0 on success otherwise an error code <0
111 int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
115 * Sets the given tag in m, overwriting an existing tag.
116 * @param key tag key to add to m (will be av_strduped depending on flags)
117 * @param value tag value to add to m (will be av_strduped depending on flags)
118 * @return >= 0 on success otherwise an error code <0
120 int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
123 * Converts all the metadata sets from ctx according to the source and
124 * destination conversion tables.
125 * @param d_conv destination tags format conversion table
126 * @param s_conv source tags format conversion table
128 void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
129 const AVMetadataConv *s_conv);
132 * Frees all the memory allocated for an AVMetadata struct.
134 void av_metadata_free(AVMetadata **m);
137 /* packet functions */
141 * Allocates and reads the payload of a packet and initializes its
142 * fields with default values.
145 * @param size desired payload size
146 * @return >0 (read size) if OK, AVERROR_xxx otherwise
148 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
151 /*************************************************/
152 /* fractional numbers for exact pts handling */
155 * The exact value of the fractional number is: 'val + num / den'.
156 * num is assumed to be 0 <= num < den.
158 typedef struct AVFrac {
159 int64_t val, num, den;
162 /*************************************************/
163 /* input/output formats */
167 /** This structure contains the data a format has to probe a file. */
168 typedef struct AVProbeData {
169 const char *filename;
170 unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
171 int buf_size; /**< Size of buf except extra allocated bytes */
174 #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
175 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
177 typedef struct AVFormatParameters {
178 AVRational time_base;
183 enum PixelFormat pix_fmt;
184 int channel; /**< Used to select DV channel. */
185 const char *standard; /**< TV standard, NTSC, PAL, SECAM */
186 unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
187 unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
188 stream packet (only meaningful if
189 mpeg2ts_raw is TRUE). */
190 unsigned int initial_pause:1; /**< Do not begin to play the stream
191 immediately (RTSP only). */
192 unsigned int prealloced_context:1;
193 #if LIBAVFORMAT_VERSION_INT < (53<<16)
194 enum CodecID video_codec_id;
195 enum CodecID audio_codec_id;
197 } AVFormatParameters;
199 //! Demuxer will use url_fopen, no opened file should be provided by the caller.
200 #define AVFMT_NOFILE 0x0001
201 #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
202 #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
203 #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
205 #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
206 #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
207 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
208 #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
209 #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
211 typedef struct AVOutputFormat {
214 * Descriptive name for the format, meant to be more human-readable
215 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
218 const char *long_name;
219 const char *mime_type;
220 const char *extensions; /**< comma-separated filename extensions */
221 /** size of private data so that it can be allocated in the wrapper */
224 enum CodecID audio_codec; /**< default audio codec */
225 enum CodecID video_codec; /**< default video codec */
226 int (*write_header)(struct AVFormatContext *);
227 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
228 int (*write_trailer)(struct AVFormatContext *);
229 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
231 /** Currently only used to set pixel format if not YUV420P. */
232 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
233 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
234 AVPacket *in, int flush);
237 * List of supported codec_id-codec_tag pairs, ordered by "better
238 * choice first". The arrays are all terminated by CODEC_ID_NONE.
240 const struct AVCodecTag * const *codec_tag;
242 enum CodecID subtitle_codec; /**< default subtitle codec */
244 const AVMetadataConv *metadata_conv;
247 struct AVOutputFormat *next;
250 typedef struct AVInputFormat {
253 * Descriptive name for the format, meant to be more human-readable
254 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
257 const char *long_name;
258 /** Size of private data so that it can be allocated in the wrapper. */
261 * Tell if a given file has a chance of being parsed as this format.
262 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
263 * big so you do not have to check for that unless you need more.
265 int (*read_probe)(AVProbeData *);
266 /** Read the format header and initialize the AVFormatContext
267 structure. Return 0 if OK. 'ap' if non-NULL contains
268 additional parameters. Only used in raw format right
269 now. 'av_new_stream' should be called to create new streams. */
270 int (*read_header)(struct AVFormatContext *,
271 AVFormatParameters *ap);
272 /** Read one packet and put it in 'pkt'. pts and flags are also
273 set. 'av_new_stream' can be called only if the flag
274 AVFMTCTX_NOHEADER is used.
275 @return 0 on success, < 0 on error.
276 When returning an error, pkt must not have been allocated
277 or must be freed before returning */
278 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
279 /** Close the stream. The AVFormatContext and AVStreams are not
280 freed by this function */
281 int (*read_close)(struct AVFormatContext *);
283 #if LIBAVFORMAT_VERSION_MAJOR < 53
285 * Seek to a given timestamp relative to the frames in
286 * stream component stream_index.
287 * @param stream_index Must not be -1.
288 * @param flags Selects which direction should be preferred if no exact
289 * match is available.
290 * @return >= 0 on success (but not necessarily the new offset)
292 int (*read_seek)(struct AVFormatContext *,
293 int stream_index, int64_t timestamp, int flags);
296 * Gets the next timestamp in stream[stream_index].time_base units.
297 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
299 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
300 int64_t *pos, int64_t pos_limit);
301 /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
303 /** If extensions are defined, then no probe is done. You should
304 usually not use extension format guessing because it is not
306 const char *extensions;
307 /** General purpose read-only value that the format can use. */
310 /** Starts/resumes playing - only meaningful if using a network-based format
312 int (*read_play)(struct AVFormatContext *);
314 /** Pauses playing - only meaningful if using a network-based format
316 int (*read_pause)(struct AVFormatContext *);
318 const struct AVCodecTag * const *codec_tag;
321 * Seeks to timestamp ts.
322 * Seeking will be done so that the point from which all active streams
323 * can be presented successfully will be closest to ts and within min/max_ts.
324 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
326 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
328 const AVMetadataConv *metadata_conv;
331 struct AVInputFormat *next;
334 enum AVStreamParseType {
336 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
337 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
338 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
341 typedef struct AVIndexEntry {
344 #define AVINDEX_KEYFRAME 0x0001
346 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).
347 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
350 #define AV_DISPOSITION_DEFAULT 0x0001
351 #define AV_DISPOSITION_DUB 0x0002
352 #define AV_DISPOSITION_ORIGINAL 0x0004
353 #define AV_DISPOSITION_COMMENT 0x0008
354 #define AV_DISPOSITION_LYRICS 0x0010
355 #define AV_DISPOSITION_KARAOKE 0x0020
359 * New fields can be added to the end with minor version bumps.
360 * Removal, reordering and changes to existing fields require a major
362 * sizeof(AVStream) must not be used outside libav*.
364 typedef struct AVStream {
365 int index; /**< stream index in AVFormatContext */
366 int id; /**< format-specific stream ID */
367 AVCodecContext *codec; /**< codec context */
369 * Real base framerate of the stream.
370 * This is the lowest framerate with which all timestamps can be
371 * represented accurately (it is the least common multiple of all
372 * framerates in the stream). Note, this value is just a guess!
373 * For example, if the time base is 1/90000 and all frames have either
374 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
376 AVRational r_frame_rate;
379 /* internal data used in av_find_stream_info() */
381 /** encoding: pts generation when outputting stream */
385 * This is the fundamental unit of time (in seconds) in terms
386 * of which frame timestamps are represented. For fixed-fps content,
387 * time base should be 1/framerate and timestamp increments should be 1.
389 AVRational time_base;
390 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
391 /* ffmpeg.c private use */
392 int stream_copy; /**< If set, just copy stream. */
393 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
394 //FIXME move stuff to a flags field?
395 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
396 * MN: dunno if that is the right place for it */
399 * Decoding: pts of the first frame of the stream, in stream time base.
400 * Only set this if you are absolutely 100% sure that the value you set
401 * it to really is the pts of the first frame.
402 * This may be undefined (AV_NOPTS_VALUE).
403 * @note The ASF header does NOT contain a correct start_time the ASF
404 * demuxer must NOT set this.
408 * Decoding: duration of the stream, in stream time base.
409 * If a source file does not specify a duration, but does specify
410 * a bitrate, this value will be estimated from bitrate and file size.
414 #if LIBAVFORMAT_VERSION_INT < (53<<16)
415 char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
418 /* av_read_frame() support */
419 enum AVStreamParseType need_parsing;
420 struct AVCodecParserContext *parser;
423 int last_IP_duration;
425 /* av_seek_frame() support */
426 AVIndexEntry *index_entries; /**< Only used if the format does not
427 support seeking natively. */
428 int nb_index_entries;
429 unsigned int index_entries_allocated_size;
431 int64_t nb_frames; ///< number of frames in this stream if known or 0
433 #if LIBAVFORMAT_VERSION_INT < (53<<16)
436 char *filename; /**< source filename of the stream */
439 int disposition; /**< AV_DISPOSITION_* bit field */
441 AVProbeData probe_data;
442 #define MAX_REORDER_DELAY 16
443 int64_t pts_buffer[MAX_REORDER_DELAY+1];
446 * sample aspect ratio (0 if unknown)
447 * - encoding: Set by user.
448 * - decoding: Set by libavformat.
450 AVRational sample_aspect_ratio;
452 AVMetadata *metadata;
454 /* av_read_frame() support */
455 const uint8_t *cur_ptr;
459 // Timestamp generation support:
461 * Timestamp corresponding to the last dts sync point.
463 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
464 * a DTS is received from the underlying container. Otherwise set to
465 * AV_NOPTS_VALUE by default.
467 int64_t reference_dts;
470 * Number of packets to buffer for codec probing
471 * NOT PART OF PUBLIC API
473 #define MAX_PROBE_PACKETS 2500
477 * last packet in packet_buffer for this stream when muxing.
478 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
480 struct AVPacketList *last_in_packet_buffer;
485 AVRational avg_frame_rate;
488 #define AV_PROGRAM_RUNNING 1
491 * New fields can be added to the end with minor version bumps.
492 * Removal, reordering and changes to existing fields require a major
494 * sizeof(AVProgram) must not be used outside libav*.
496 typedef struct AVProgram {
498 #if LIBAVFORMAT_VERSION_INT < (53<<16)
499 char *provider_name; ///< network name for DVB streams
500 char *name; ///< service name for DVB streams
503 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
504 unsigned int *stream_index;
505 unsigned int nb_stream_indexes;
506 AVMetadata *metadata;
509 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
510 (streams are added dynamically) */
512 typedef struct AVChapter {
513 int id; ///< unique ID to identify the chapter
514 AVRational time_base; ///< time base in which the start/end timestamps are specified
515 int64_t start, end; ///< chapter start/end time in time_base units
516 #if LIBAVFORMAT_VERSION_INT < (53<<16)
517 char *title; ///< chapter title
519 AVMetadata *metadata;
522 #define MAX_STREAMS 20
525 * Format I/O context.
526 * New fields can be added to the end with minor version bumps.
527 * Removal, reordering and changes to existing fields require a major
529 * sizeof(AVFormatContext) must not be used outside libav*.
531 typedef struct AVFormatContext {
532 const AVClass *av_class; /**< Set by avformat_alloc_context. */
533 /* Can only be iformat or oformat, not both at the same time. */
534 struct AVInputFormat *iformat;
535 struct AVOutputFormat *oformat;
538 unsigned int nb_streams;
539 AVStream *streams[MAX_STREAMS];
540 char filename[1024]; /**< input or output filename */
543 #if LIBAVFORMAT_VERSION_INT < (53<<16)
549 int year; /**< ID3 year, 0 if none */
550 int track; /**< track number, 0 if none */
551 char genre[32]; /**< ID3 genre */
554 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
555 /* private data for pts handling (do not modify directly). */
556 /** This buffer is only needed when packets were already buffered but
557 not decoded, for example to get the codec parameters in MPEG
559 struct AVPacketList *packet_buffer;
561 /** Decoding: position of the first frame of the component, in
562 AV_TIME_BASE fractional seconds. NEVER set this value directly:
563 It is deduced from the AVStream values. */
565 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
566 seconds. NEVER set this value directly: it is deduced from the
569 /** decoding: total file size, 0 if unknown */
571 /** Decoding: total stream bitrate in bit/s, 0 if not
572 available. Never set it directly if the file_size and the
573 duration are known as FFmpeg can compute it automatically. */
576 /* av_read_frame() support */
578 #if LIBAVFORMAT_VERSION_INT < (53<<16)
579 const uint8_t *cur_ptr_deprecated;
580 int cur_len_deprecated;
581 AVPacket cur_pkt_deprecated;
584 /* av_seek_frame() support */
585 int64_t data_offset; /** offset of the first packet */
589 unsigned int packet_size;
593 #define AVFMT_NOOUTPUTLOOP -1
594 #define AVFMT_INFINITEOUTPUTLOOP 0
595 /** number of times to loop output in formats that support it */
599 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
600 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
601 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
604 /** decoding: size of data to probe; encoding: unused. */
605 unsigned int probesize;
608 * Maximum time (in AV_TIME_BASE units) during which the input should
609 * be analyzed in av_find_stream_info().
611 int max_analyze_duration;
616 unsigned int nb_programs;
617 AVProgram **programs;
620 * Forced video codec_id.
621 * Demuxing: Set by user.
623 enum CodecID video_codec_id;
625 * Forced audio codec_id.
626 * Demuxing: Set by user.
628 enum CodecID audio_codec_id;
630 * Forced subtitle codec_id.
631 * Demuxing: Set by user.
633 enum CodecID subtitle_codec_id;
636 * Maximum amount of memory in bytes to use for the index of each stream.
637 * If the index exceeds this size, entries will be discarded as
638 * needed to maintain a smaller size. This can lead to slower or less
639 * accurate seeking (depends on demuxer).
640 * Demuxers for which a full in-memory index is mandatory will ignore
643 * demuxing: set by user
645 unsigned int max_index_size;
648 * Maximum amount of memory in bytes to use for buffering frames
649 * obtained from realtime capture devices.
651 unsigned int max_picture_buffer;
653 unsigned int nb_chapters;
654 AVChapter **chapters;
657 * Flags to enable debugging.
660 #define FF_FDEBUG_TS 0x0001
663 * Raw packets from the demuxer, prior to parsing and decoding.
664 * This buffer is used for buffering packets until the codec can
665 * be identified, as parsing cannot be done without knowing the
668 struct AVPacketList *raw_packet_buffer;
669 struct AVPacketList *raw_packet_buffer_end;
671 struct AVPacketList *packet_buffer_end;
673 AVMetadata *metadata;
676 * Remaining size available for raw_packet_buffer, in bytes.
677 * NOT PART OF PUBLIC API
679 #define RAW_PACKET_BUFFER_SIZE 2500000
680 int raw_packet_buffer_remaining_size;
683 typedef struct AVPacketList {
685 struct AVPacketList *next;
688 #if LIBAVFORMAT_VERSION_INT < (53<<16)
689 extern AVInputFormat *first_iformat;
690 extern AVOutputFormat *first_oformat;
694 * If f is NULL, returns the first registered input format,
695 * if f is non-NULL, returns the next registered input format after f
696 * or NULL if f is the last one.
698 AVInputFormat *av_iformat_next(AVInputFormat *f);
701 * If f is NULL, returns the first registered output format,
702 * if f is non-NULL, returns the next registered output format after f
703 * or NULL if f is the last one.
705 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
707 enum CodecID av_guess_image2_codec(const char *filename);
709 /* XXX: Use automatic init with either ELF sections or C file parser */
713 void av_register_input_format(AVInputFormat *format);
714 void av_register_output_format(AVOutputFormat *format);
715 #if LIBAVFORMAT_VERSION_MAJOR < 53
716 attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
717 const char *filename,
718 const char *mime_type);
721 * @deprecated Use av_guess_format() instead.
723 attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
724 const char *filename,
725 const char *mime_type);
729 * Returns the output format in the list of registered output formats
730 * which best matches the provided parameters, or returns NULL if
733 * @param short_name if non-NULL checks if short_name matches with the
734 * names of the registered formats
735 * @param filename if non-NULL checks if filename terminates with the
736 * extensions of the registered formats
737 * @param mime_type if non-NULL checks if mime_type matches with the
738 * MIME type of the registered formats
740 AVOutputFormat *av_guess_format(const char *short_name,
741 const char *filename,
742 const char *mime_type);
745 * Guesses the codec ID based upon muxer and filename.
747 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
748 const char *filename, const char *mime_type,
749 enum CodecType type);
752 * Sends a nice hexadecimal dump of a buffer to the specified file stream.
754 * @param f The file stream pointer where the dump should be sent to.
756 * @param size buffer size
758 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
760 void av_hex_dump(FILE *f, uint8_t *buf, int size);
763 * Sends a nice hexadecimal dump of a buffer to the log.
765 * @param avcl A pointer to an arbitrary struct of which the first field is a
766 * pointer to an AVClass struct.
767 * @param level The importance level of the message, lower values signifying
770 * @param size buffer size
772 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
774 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
777 * Sends a nice dump of a packet to the specified file stream.
779 * @param f The file stream pointer where the dump should be sent to.
780 * @param pkt packet to dump
781 * @param dump_payload True if the payload must be displayed, too.
783 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
786 * Sends a nice dump of a packet to the log.
788 * @param avcl A pointer to an arbitrary struct of which the first field is a
789 * pointer to an AVClass struct.
790 * @param level The importance level of the message, lower values signifying
792 * @param pkt packet to dump
793 * @param dump_payload True if the payload must be displayed, too.
795 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
798 * Initializes libavformat and registers all the muxers, demuxers and
799 * protocols. If you do not call this function, then you can select
800 * exactly which formats you want to support.
802 * @see av_register_input_format()
803 * @see av_register_output_format()
804 * @see av_register_protocol()
806 void av_register_all(void);
808 /** codec tag <-> codec id */
809 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
810 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
812 /* media file input */
815 * Finds AVInputFormat based on the short name of the input format.
817 AVInputFormat *av_find_input_format(const char *short_name);
820 * Guesses the file format.
822 * @param is_opened Whether the file is already opened; determines whether
823 * demuxers with or without AVFMT_NOFILE are probed.
825 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
828 * Allocates all the structures needed to read an input stream.
829 * This does not open the needed codecs for decoding the stream[s].
831 int av_open_input_stream(AVFormatContext **ic_ptr,
832 ByteIOContext *pb, const char *filename,
833 AVInputFormat *fmt, AVFormatParameters *ap);
836 * Opens a media file as input. The codecs are not opened. Only the file
837 * header (if present) is read.
839 * @param ic_ptr The opened media file handle is put here.
840 * @param filename filename to open
841 * @param fmt If non-NULL, force the file format to use.
842 * @param buf_size optional buffer size (zero if default is OK)
843 * @param ap Additional parameters needed when opening the file
845 * @return 0 if OK, AVERROR_xxx otherwise
847 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
850 AVFormatParameters *ap);
852 #if LIBAVFORMAT_VERSION_MAJOR < 53
854 * @deprecated Use avformat_alloc_context() instead.
856 attribute_deprecated AVFormatContext *av_alloc_format_context(void);
860 * Allocates an AVFormatContext.
861 * Can be freed with av_free() but do not forget to free everything you
862 * explicitly allocated as well!
864 AVFormatContext *avformat_alloc_context(void);
867 * Reads packets of a media file to get stream information. This
868 * is useful for file formats with no headers such as MPEG. This
869 * function also computes the real framerate in case of MPEG-2 repeat
871 * The logical file position is not changed by this function;
872 * examined packets may be buffered for later processing.
874 * @param ic media file handle
875 * @return >=0 if OK, AVERROR_xxx on error
876 * @todo Let the user decide somehow what information is needed so that
877 * we do not waste time getting stuff the user does not need.
879 int av_find_stream_info(AVFormatContext *ic);
882 * Reads a transport packet from a media file.
884 * This function is obsolete and should never be used.
885 * Use av_read_frame() instead.
887 * @param s media file handle
888 * @param pkt is filled
889 * @return 0 if OK, AVERROR_xxx on error
891 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
894 * Returns the next frame of a stream.
896 * The returned packet is valid
897 * until the next av_read_frame() or until av_close_input_file() and
898 * must be freed with av_free_packet. For video, the packet contains
899 * exactly one frame. For audio, it contains an integer number of
900 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
901 * data). If the audio frames have a variable size (e.g. MPEG audio),
902 * then it contains one frame.
904 * pkt->pts, pkt->dts and pkt->duration are always set to correct
905 * values in AVStream.time_base units (and guessed if the format cannot
906 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
907 * has B-frames, so it is better to rely on pkt->dts if you do not
908 * decompress the payload.
910 * @return 0 if OK, < 0 on error or end of file
912 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
915 * Seeks to the keyframe at timestamp.
916 * 'timestamp' in 'stream_index'.
917 * @param stream_index If stream_index is (-1), a default
918 * stream is selected, and timestamp is automatically converted
919 * from AV_TIME_BASE units to the stream specific time_base.
920 * @param timestamp Timestamp in AVStream.time_base units
921 * or, if no stream is specified, in AV_TIME_BASE units.
922 * @param flags flags which select direction and seeking mode
923 * @return >= 0 on success
925 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
929 * Seeks to timestamp ts.
930 * Seeking will be done so that the point from which all active streams
931 * can be presented successfully will be closest to ts and within min/max_ts.
932 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
934 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
935 * are the file position (this may not be supported by all demuxers).
936 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
937 * in the stream with stream_index (this may not be supported by all demuxers).
938 * Otherwise all timestamps are in units of the stream selected by stream_index
939 * or if stream_index is -1, in AV_TIME_BASE units.
940 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
941 * keyframes (this may not be supported by all demuxers).
943 * @param stream_index index of the stream which is used as time base reference
944 * @param min_ts smallest acceptable timestamp
945 * @param ts target timestamp
946 * @param max_ts largest acceptable timestamp
948 * @returns >=0 on success, error code otherwise
950 * @NOTE This is part of the new seek API which is still under construction.
951 * Thus do not use this yet. It may change at any time, do not expect
952 * ABI compatibility yet!
954 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
957 * Starts playing a network-based stream (e.g. RTSP stream) at the
960 int av_read_play(AVFormatContext *s);
963 * Pauses a network-based stream (e.g. RTSP stream).
965 * Use av_read_play() to resume it.
967 int av_read_pause(AVFormatContext *s);
970 * Frees a AVFormatContext allocated by av_open_input_stream.
971 * @param s context to free
973 void av_close_input_stream(AVFormatContext *s);
976 * Closes a media file (but not its codecs).
978 * @param s media file handle
980 void av_close_input_file(AVFormatContext *s);
983 * Adds a new stream to a media file.
985 * Can only be called in the read_header() function. If the flag
986 * AVFMTCTX_NOHEADER is in the format context, then new streams
987 * can be added in read_packet too.
989 * @param s media file handle
990 * @param id file-format-dependent stream ID
992 AVStream *av_new_stream(AVFormatContext *s, int id);
993 AVProgram *av_new_program(AVFormatContext *s, int id);
996 * Adds a new chapter.
997 * This function is NOT part of the public API
998 * and should ONLY be used by demuxers.
1000 * @param s media file handle
1001 * @param id unique ID for this chapter
1002 * @param start chapter start time in time_base units
1003 * @param end chapter end time in time_base units
1004 * @param title chapter title
1006 * @return AVChapter or NULL on error
1008 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1009 int64_t start, int64_t end, const char *title);
1012 * Sets the pts for a given stream.
1015 * @param pts_wrap_bits number of bits effectively used by the pts
1016 * (used for wrap control, 33 is the value for MPEG)
1017 * @param pts_num numerator to convert to seconds (MPEG: 1)
1018 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1020 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1021 unsigned int pts_num, unsigned int pts_den);
1023 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1024 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
1025 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
1026 #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
1028 int av_find_default_stream_index(AVFormatContext *s);
1031 * Gets the index for a specific timestamp.
1032 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1033 * to the timestamp which is <= the requested one, if backward
1034 * is 0, then it will be >=
1035 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1036 * @return < 0 if no such timestamp could be found
1038 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1041 * Ensures the index uses less memory than the maximum specified in
1042 * AVFormatContext.max_index_size by discarding entries if it grows
1044 * This function is not part of the public API and should only be called
1047 void ff_reduce_index(AVFormatContext *s, int stream_index);
1050 * Adds an index entry into a sorted list. Updates the entry if the list
1051 * already contains it.
1053 * @param timestamp timestamp in the time base of the given stream
1055 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1056 int size, int distance, int flags);
1059 * Does a binary search using av_index_search_timestamp() and
1060 * AVCodec.read_timestamp().
1061 * This is not supposed to be called directly by a user application,
1063 * @param target_ts target timestamp in the time base of the given stream
1064 * @param stream_index stream number
1066 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1067 int64_t target_ts, int flags);
1070 * Updates cur_dts of all streams based on the given timestamp and AVStream.
1072 * Stream ref_st unchanged, others set cur_dts in their native time base.
1073 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1074 * @param timestamp new dts expressed in time_base of param ref_st
1075 * @param ref_st reference stream giving time_base of param timestamp
1077 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1080 * Does a binary search using read_timestamp().
1081 * This is not supposed to be called directly by a user application,
1083 * @param target_ts target timestamp in the time base of the given stream
1084 * @param stream_index stream number
1086 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1087 int64_t target_ts, int64_t pos_min,
1088 int64_t pos_max, int64_t pos_limit,
1089 int64_t ts_min, int64_t ts_max,
1090 int flags, int64_t *ts_ret,
1091 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1093 /** media file output */
1094 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1097 * Allocates the stream private data and writes the stream header to an
1098 * output media file.
1100 * @param s media file handle
1101 * @return 0 if OK, AVERROR_xxx on error
1103 int av_write_header(AVFormatContext *s);
1106 * Writes a packet to an output media file.
1108 * The packet shall contain one audio or video frame.
1109 * The packet must be correctly interleaved according to the container
1110 * specification, if not then av_interleaved_write_frame must be used.
1112 * @param s media file handle
1113 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1115 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1117 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1120 * Writes a packet to an output media file ensuring correct interleaving.
1122 * The packet must contain one audio or video frame.
1123 * If the packets are already correctly interleaved, the application should
1124 * call av_write_frame() instead as it is slightly faster. It is also important
1125 * to keep in mind that completely non-interleaved input will need huge amounts
1126 * of memory to interleave with this, so it is preferable to interleave at the
1129 * @param s media file handle
1130 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1132 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1134 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1137 * Interleaves a packet per dts in an output media file.
1139 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1140 * function, so they cannot be used after it. Note that calling av_free_packet()
1141 * on them is still safe.
1143 * @param s media file handle
1144 * @param out the interleaved packet will be output here
1145 * @param in the input packet
1146 * @param flush 1 if no further packets are available as input and all
1147 * remaining packets should be output
1148 * @return 1 if a packet was output, 0 if no packet could be output,
1149 * < 0 if an error occurred
1151 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1152 AVPacket *pkt, int flush);
1155 * Writes the stream trailer to an output media file and frees the
1156 * file private data.
1158 * May only be called after a successful call to av_write_header.
1160 * @param s media file handle
1161 * @return 0 if OK, AVERROR_xxx on error
1163 int av_write_trailer(AVFormatContext *s);
1165 void dump_format(AVFormatContext *ic,
1170 #if LIBAVFORMAT_VERSION_MAJOR < 53
1172 * Parses width and height out of string str.
1173 * @deprecated Use av_parse_video_frame_size instead.
1175 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1179 * Converts framerate from a string to a fraction.
1180 * @deprecated Use av_parse_video_frame_rate instead.
1182 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1187 * Parses datestr and returns a corresponding number of microseconds.
1188 * @param datestr String representing a date or a duration.
1189 * - If a date the syntax is:
1191 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1193 * Time is local time unless Z is appended, in which case it is
1194 * interpreted as UTC.
1195 * If the year-month-day part is not specified it takes the current
1197 * Returns the number of microseconds since 1st of January, 1970 up to
1198 * the time of the parsed date or INT64_MIN if datestr cannot be
1199 * successfully parsed.
1200 * - If a duration the syntax is:
1202 * [-]HH[:MM[:SS[.m...]]]
1205 * Returns the number of microseconds contained in a time interval
1206 * with the specified duration or INT64_MIN if datestr cannot be
1207 * successfully parsed.
1208 * @param duration Flag which tells how to interpret datestr, if
1209 * not zero datestr is interpreted as a duration, otherwise as a
1212 int64_t parse_date(const char *datestr, int duration);
1214 /** Gets the current time in microseconds. */
1215 int64_t av_gettime(void);
1217 /* ffm-specific for ffserver */
1218 #define FFM_PACKET_SIZE 4096
1219 int64_t ffm_read_write_index(int fd);
1220 int ffm_write_write_index(int fd, int64_t pos);
1221 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1224 * Attempts to find a specific tag in a URL.
1226 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1227 * Return 1 if found.
1229 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1232 * Returns in 'buf' the path with '%d' replaced by a number.
1234 * Also handles the '%0nd' format where 'n' is the total number
1235 * of digits and '%%'.
1237 * @param buf destination buffer
1238 * @param buf_size destination buffer size
1239 * @param path numbered sequence string
1240 * @param number frame number
1241 * @return 0 if OK, -1 on format error
1243 int av_get_frame_filename(char *buf, int buf_size,
1244 const char *path, int number);
1247 * Checks whether filename actually is a numbered sequence generator.
1249 * @param filename possible numbered sequence string
1250 * @return 1 if a valid numbered sequence string, 0 otherwise
1252 int av_filename_number_test(const char *filename);
1255 * Generates an SDP for an RTP session.
1257 * @param ac array of AVFormatContexts describing the RTP streams. If the
1258 * array is composed by only one context, such context can contain
1259 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1260 * all the contexts in the array (an AVCodecContext per RTP stream)
1261 * must contain only one AVStream.
1262 * @param n_files number of AVCodecContexts contained in ac
1263 * @param buff buffer where the SDP will be stored (must be allocated by
1265 * @param size the size of the buffer
1266 * @return 0 if OK, AVERROR_xxx on error
1268 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1270 #ifdef HAVE_AV_CONFIG_H
1272 void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
1275 #define dynarray_add(tab, nb_ptr, elem)\
1277 __typeof__(tab) _tab = (tab);\
1278 __typeof__(elem) _elem = (elem);\
1279 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1280 ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
1283 #define dynarray_add(tab, nb_ptr, elem)\
1285 ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
1289 time_t mktimegm(struct tm *tm);
1290 struct tm *brktimegm(time_t secs, struct tm *tm);
1291 const char *small_strptime(const char *p, const char *fmt,
1295 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1297 void url_split(char *proto, int proto_size,
1298 char *authorization, int authorization_size,
1299 char *hostname, int hostname_size,
1301 char *path, int path_size,
1304 #if LIBAVFORMAT_VERSION_MAJOR < 53
1306 * @deprecated Use av_match_ext() instead.
1308 attribute_deprecated int match_ext(const char *filename, const char *extensions);
1312 * Returns a positive value if the given filename has one of the given
1313 * extensions, 0 otherwise.
1315 * @param extensions a comma-separated list of filename extensions
1317 int av_match_ext(const char *filename, const char *extensions);
1319 #endif /* HAVE_AV_CONFIG_H */
1321 #endif /* AVFORMAT_AVFORMAT_H */