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 23
26 #define LIBAVFORMAT_VERSION_MICRO 1
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 #include <stdio.h> /* FILE */
45 #include "libavcodec/avcodec.h"
51 * Public Metadata API.
52 * The metadata API allows libavformat to export metadata tags to a client
53 * application using a sequence of key/value pairs.
54 * Important concepts to keep in mind:
55 * 1. Keys are unique; there can never be 2 tags with the same key. This is
56 * also meant semantically, i.e., a demuxer should not knowingly produce
57 * several keys that are literally different but semantically identical.
58 * E.g., key=Author5, key=Author6. In this example, all authors must be
59 * placed in the same tag.
60 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
61 * want to store, e.g., the email address of the child of producer Alice
62 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
63 * 3. A tag whose value is localized for a particular language is appended
64 * with a dash character ('-') and the ISO 639 3-letter language code.
65 * For example: Author-ger=Michael, Author-eng=Mike
66 * The original/default language is in the unqualified "Author" tag.
67 * A demuxer should set a default if it sets any translated tag.
70 #define AV_METADATA_IGNORE_CASE 1
71 #define AV_METADATA_IGNORE_SUFFIX 2
81 * gets a metadata element with matching key.
82 * @param prev set to the previous matching element to find the next.
83 * @param flags allows case as well as suffix insensitive comparissions.
84 * @return found tag or NULL, changing key or value leads to undefined behavior.
87 av_metadata_get(struct AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
90 * sets the given tag in m, overwriting an existing tag.
91 * @param tag tag to add to m, key and value will be av_strduped.
92 * @return >= 0 if success otherwise error code that is <0.
94 int av_metadata_set(struct AVMetadata **m, AVMetadataTag tag);
97 /* packet functions */
99 typedef struct AVPacket {
101 * Presentation timestamp in time_base units.
102 * This is the time at which the decompressed packet will be presented
104 * Can be AV_NOPTS_VALUE if it is not stored in the file.
105 * pts MUST be larger or equal to dts as presentation cannot happen before
106 * decompression, unless one wants to view hex dumps. Some formats misuse
107 * the terms dts and pts/cts to mean something different, these timestamps
108 * must be converted to true pts/dts before they are stored in AVPacket.
112 * Decompression timestamp in time_base units.
113 * This is the time at which the packet is decompressed.
114 * Can be AV_NOPTS_VALUE if it is not stored in the file.
122 * Duration of this packet in time_base units, 0 if unknown.
123 * Equals next_pts - this_pts in presentation order.
126 void (*destruct)(struct AVPacket *);
128 int64_t pos; ///< byte position in stream, -1 if unknown
131 * Time difference in stream time base units from the pts of this
132 * packet to the point at which the output from the decoder has converged
133 * independent from the availability of previous frames. That is, the
134 * frames are virtually identical no matter if decoding started from
135 * the very first frame or from this keyframe.
136 * Is AV_NOPTS_VALUE if unknown.
137 * This field is not the display duration of the current packet.
139 * The purpose of this field is to allow seeking in streams that have no
140 * keyframes in the conventional sense. It corresponds to the
141 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
142 * essential for some types of subtitle streams to ensure that all
143 * subtitles are correctly displayed after seeking.
145 int64_t convergence_duration;
147 #define PKT_FLAG_KEY 0x0001
149 void av_destruct_packet_nofree(AVPacket *pkt);
152 * Default packet destructor.
154 void av_destruct_packet(AVPacket *pkt);
157 * Initialize optional fields of a packet with default values.
161 void av_init_packet(AVPacket *pkt);
164 * Allocate the payload of a packet and initialize its fields with
168 * @param size wanted payload size
169 * @return 0 if OK, AVERROR_xxx otherwise
171 int av_new_packet(AVPacket *pkt, int size);
174 * Allocate and read the payload of a packet and initialize its fields with
178 * @param size desired payload size
179 * @return >0 (read size) if OK, AVERROR_xxx otherwise
181 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
184 * @warning This is a hack - the packet memory allocation stuff is broken. The
185 * packet is allocated if it was not really allocated.
187 int av_dup_packet(AVPacket *pkt);
192 * @param pkt packet to free
194 static inline void av_free_packet(AVPacket *pkt)
196 if (pkt && pkt->destruct) {
201 /*************************************************/
202 /* fractional numbers for exact pts handling */
205 * The exact value of the fractional number is: 'val + num / den'.
206 * num is assumed to be 0 <= num < den.
207 * @deprecated Use AVRational instead.
209 typedef struct AVFrac {
210 int64_t val, num, den;
211 } AVFrac attribute_deprecated;
213 /*************************************************/
214 /* input/output formats */
218 struct AVFormatContext;
220 /** This structure contains the data a format has to probe a file. */
221 typedef struct AVProbeData {
222 const char *filename;
227 #define AVPROBE_SCORE_MAX 100 ///< Maximum score, half of that is used for file-extension-based detection.
228 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
230 typedef struct AVFormatParameters {
231 AVRational time_base;
236 enum PixelFormat pix_fmt;
237 int channel; /**< Used to select DV channel. */
238 const char *standard; /**< TV standard, NTSC, PAL, SECAM */
239 unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
240 unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
241 stream packet (only meaningful if
242 mpeg2ts_raw is TRUE). */
243 unsigned int initial_pause:1; /**< Do not begin to play the stream
244 immediately (RTSP only). */
245 unsigned int prealloced_context:1;
246 #if LIBAVFORMAT_VERSION_INT < (53<<16)
247 enum CodecID video_codec_id;
248 enum CodecID audio_codec_id;
250 } AVFormatParameters;
252 //! Demuxer will use url_fopen, no opened file should be provided by the caller.
253 #define AVFMT_NOFILE 0x0001
254 #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
255 #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
256 #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
258 #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
259 #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
260 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
261 #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
263 typedef struct AVOutputFormat {
266 * Descriptive name for the format, meant to be more human-readable
267 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
270 const char *long_name;
271 const char *mime_type;
272 const char *extensions; /**< comma-separated filename extensions */
273 /** Size of private data so that it can be allocated in the wrapper. */
276 enum CodecID audio_codec; /**< default audio codec */
277 enum CodecID video_codec; /**< default video codec */
278 int (*write_header)(struct AVFormatContext *);
279 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
280 int (*write_trailer)(struct AVFormatContext *);
281 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
283 /** Currently only used to set pixel format if not YUV420P. */
284 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
285 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
286 AVPacket *in, int flush);
289 * List of supported codec_id-codec_tag pairs, ordered by "better
290 * choice first". The arrays are all CODEC_ID_NONE terminated.
292 const struct AVCodecTag * const *codec_tag;
294 enum CodecID subtitle_codec; /**< default subtitle codec */
297 struct AVOutputFormat *next;
300 typedef struct AVInputFormat {
303 * Descriptive name for the format, meant to be more human-readable
304 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
307 const char *long_name;
308 /** Size of private data so that it can be allocated in the wrapper. */
311 * Tell if a given file has a chance of being parsed by this format.
312 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
313 * big so you do not have to check for that unless you need more.
315 int (*read_probe)(AVProbeData *);
316 /** Read the format header and initialize the AVFormatContext
317 structure. Return 0 if OK. 'ap' if non-NULL contains
318 additional parameters. Only used in raw format right
319 now. 'av_new_stream' should be called to create new streams. */
320 int (*read_header)(struct AVFormatContext *,
321 AVFormatParameters *ap);
322 /** Read one packet and put it in 'pkt'. pts and flags are also
323 set. 'av_new_stream' can be called only if the flag
324 AVFMTCTX_NOHEADER is used. */
325 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
326 /** Close the stream. The AVFormatContext and AVStreams are not
327 freed by this function */
328 int (*read_close)(struct AVFormatContext *);
330 * Seek to a given timestamp relative to the frames in
331 * stream component stream_index.
332 * @param stream_index must not be -1
333 * @param flags selects which direction should be preferred if no exact
335 * @return >= 0 on success (but not necessarily the new offset)
337 int (*read_seek)(struct AVFormatContext *,
338 int stream_index, int64_t timestamp, int flags);
340 * Gets the next timestamp in stream[stream_index].time_base units.
341 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
343 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
344 int64_t *pos, int64_t pos_limit);
345 /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
347 /** If extensions are defined, then no probe is done. You should
348 usually not use extension format guessing because it is not
350 const char *extensions;
351 /** General purpose read-only value that the format can use. */
354 /** Start/resume playing - only meaningful if using a network-based format
356 int (*read_play)(struct AVFormatContext *);
358 /** Pause playing - only meaningful if using a network-based format
360 int (*read_pause)(struct AVFormatContext *);
362 const struct AVCodecTag * const *codec_tag;
365 struct AVInputFormat *next;
368 enum AVStreamParseType {
370 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
371 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
372 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
375 typedef struct AVIndexEntry {
378 #define AVINDEX_KEYFRAME 0x0001
380 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).
381 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
384 #define AV_DISPOSITION_DEFAULT 0x0001
385 #define AV_DISPOSITION_DUB 0x0002
386 #define AV_DISPOSITION_ORIGINAL 0x0004
387 #define AV_DISPOSITION_COMMENT 0x0008
388 #define AV_DISPOSITION_LYRICS 0x0010
389 #define AV_DISPOSITION_KARAOKE 0x0020
393 * New fields can be added to the end with minor version bumps.
394 * Removal, reordering and changes to existing fields require a major
396 * sizeof(AVStream) must not be used outside libav*.
398 typedef struct AVStream {
399 int index; /**< stream index in AVFormatContext */
400 int id; /**< format-specific stream ID */
401 AVCodecContext *codec; /**< codec context */
403 * Real base frame rate of the stream.
404 * This is the lowest frame rate with which all timestamps can be
405 * represented accurately (it is the least common multiple of all
406 * frame rates in the stream). Note, this value is just a guess!
407 * For example if the time base is 1/90000 and all frames have either
408 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
410 AVRational r_frame_rate;
413 /* internal data used in av_find_stream_info() */
415 /** encoding: pts generation when outputting stream */
419 * This is the fundamental unit of time (in seconds) in terms
420 * of which frame timestamps are represented. For fixed-fps content,
421 * time base should be 1/frame rate and timestamp increments should be 1.
423 AVRational time_base;
424 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
425 /* ffmpeg.c private use */
426 int stream_copy; /**< If set, just copy stream. */
427 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
428 //FIXME move stuff to a flags field?
429 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
430 * MN: dunno if that is the right place for it */
433 * Decoding: pts of the first frame of the stream, in stream time base.
434 * Only set this if you are absolutely 100% sure that the value you set
435 * it to really is the pts of the first frame.
436 * This may be undefined (AV_NOPTS_VALUE).
437 * @note The ASF header does NOT contain a correct start_time the ASF
438 * demuxer must NOT set this.
442 * Decoding: duration of the stream, in stream time base.
443 * If a source file does not specify a duration, but does specify
444 * a bitrate, this value will be estimated from bitrate and file size.
448 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
450 /* av_read_frame() support */
451 enum AVStreamParseType need_parsing;
452 struct AVCodecParserContext *parser;
455 int last_IP_duration;
457 /* av_seek_frame() support */
458 AVIndexEntry *index_entries; /**< Only used if the format does not
459 support seeking natively. */
460 int nb_index_entries;
461 unsigned int index_entries_allocated_size;
463 int64_t nb_frames; ///< number of frames in this stream if known or 0
465 #if LIBAVFORMAT_VERSION_INT < (53<<16)
469 char *filename; /**< source filename of the stream */
471 int disposition; /**< AV_DISPOSITION_* bit field */
473 AVProbeData probe_data;
474 #define MAX_REORDER_DELAY 16
475 int64_t pts_buffer[MAX_REORDER_DELAY+1];
478 * sample aspect ratio (0 if unknown)
479 * - encoding: Set by user.
480 * - decoding: Set by libavformat.
482 AVRational sample_aspect_ratio;
484 struct AVMetadata *metadata;
487 #define AV_PROGRAM_RUNNING 1
490 * New fields can be added to the end with minor version bumps.
491 * Removal, reordering and changes to existing fields require a major
493 * sizeof(AVProgram) must not be used outside libav*.
495 typedef struct AVProgram {
497 char *provider_name; ///< network name for DVB streams
498 char *name; ///< service name for DVB streams
500 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
501 unsigned int *stream_index;
502 unsigned int nb_stream_indexes;
503 struct AVMetadata *metadata;
506 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
507 (streams are added dynamically) */
509 typedef struct AVChapter {
510 int id; ///< unique ID to identify the chapter
511 AVRational time_base; ///< time base in which the start/end timestamps are specified
512 int64_t start, end; ///< chapter start/end time in time_base units
513 char *title; ///< chapter title
514 struct AVMetadata *metadata;
517 #define MAX_STREAMS 20
520 * Format I/O context.
521 * New fields can be added to the end with minor version bumps.
522 * Removal, reordering and changes to existing fields require a major
524 * sizeof(AVFormatContext) must not be used outside libav*.
526 typedef struct AVFormatContext {
527 const AVClass *av_class; /**< Set by av_alloc_format_context. */
528 /* Can only be iformat or oformat, not both at the same time. */
529 struct AVInputFormat *iformat;
530 struct AVOutputFormat *oformat;
533 unsigned int nb_streams;
534 AVStream *streams[MAX_STREAMS];
535 char filename[1024]; /**< input or output filename */
543 int year; /**< ID3 year, 0 if none */
544 int track; /**< track number, 0 if none */
545 char genre[32]; /**< ID3 genre */
547 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
548 /* private data for pts handling (do not modify directly). */
549 /** This buffer is only needed when packets were already buffered but
550 not decoded, for example to get the codec parameters in MPEG
552 struct AVPacketList *packet_buffer;
554 /** Decoding: position of the first frame of the component, in
555 AV_TIME_BASE fractional seconds. NEVER set this value directly:
556 It is deduced from the AVStream values. */
558 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
559 seconds. NEVER set this value directly: it is deduced from the
562 /** decoding: total file size, 0 if unknown */
564 /** Decoding: total stream bitrate in bit/s, 0 if not
565 available. Never set it directly if the file_size and the
566 duration are known as ffmpeg can compute it automatically. */
569 /* av_read_frame() support */
571 const uint8_t *cur_ptr;
575 /* av_seek_frame() support */
576 int64_t data_offset; /** offset of the first packet */
584 #define AVFMT_NOOUTPUTLOOP -1
585 #define AVFMT_INFINITEOUTPUTLOOP 0
586 /** number of times to loop output in formats that support it */
590 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate pts if missing even if it requires parsing future frames.
591 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
592 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
595 /** Decoding: size of data to probe; encoding: unused. */
596 unsigned int probesize;
599 * Maximum time (in AV_TIME_BASE units) during which the input should
600 * be analyzed in av_find_stream_info().
602 int max_analyze_duration;
607 unsigned int nb_programs;
608 AVProgram **programs;
611 * Forced video codec_id.
612 * Demuxing: Set by user.
614 enum CodecID video_codec_id;
616 * Forced audio codec_id.
617 * Demuxing: Set by user.
619 enum CodecID audio_codec_id;
621 * Forced subtitle codec_id.
622 * Demuxing: Set by user.
624 enum CodecID subtitle_codec_id;
627 * Maximum amount of memory in bytes to use per stream for the index.
628 * If the needed index exceeds this size, entries will be discarded as
629 * needed to maintain a smaller size. This can lead to slower or less
630 * accurate seeking (depends on demuxer).
631 * Demuxers for which a full in-memory index is mandatory will ignore
634 * demuxing: set by user
636 unsigned int max_index_size;
639 * Maximum amount of memory in bytes to use for buffering frames
640 * obtained from realtime capture devices.
642 unsigned int max_picture_buffer;
644 unsigned int nb_chapters;
645 AVChapter **chapters;
648 * Flags to enable debugging.
651 #define FF_FDEBUG_TS 0x0001
654 * Raw packets from the demuxer, prior to parsing and decoding.
655 * This buffer is used for buffering packets until the codec can
656 * be identified, as parsing cannot be done without knowing the
659 struct AVPacketList *raw_packet_buffer;
660 struct AVPacketList *raw_packet_buffer_end;
662 struct AVPacketList *packet_buffer_end;
664 struct AVMetadata *metadata;
667 typedef struct AVPacketList {
669 struct AVPacketList *next;
672 #if LIBAVFORMAT_VERSION_INT < (53<<16)
673 extern AVInputFormat *first_iformat;
674 extern AVOutputFormat *first_oformat;
677 AVInputFormat *av_iformat_next(AVInputFormat *f);
678 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
680 enum CodecID av_guess_image2_codec(const char *filename);
682 /* XXX: use automatic init with either ELF sections or C file parser */
686 void av_register_input_format(AVInputFormat *format);
687 void av_register_output_format(AVOutputFormat *format);
688 AVOutputFormat *guess_stream_format(const char *short_name,
689 const char *filename,
690 const char *mime_type);
691 AVOutputFormat *guess_format(const char *short_name,
692 const char *filename,
693 const char *mime_type);
696 * Guesses the codec ID based upon muxer and filename.
698 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
699 const char *filename, const char *mime_type,
700 enum CodecType type);
703 * Send a nice hexadecimal dump of a buffer to the specified file stream.
705 * @param f The file stream pointer where the dump should be sent to.
707 * @param size buffer size
709 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
711 void av_hex_dump(FILE *f, uint8_t *buf, int size);
714 * Send a nice hexadecimal dump of a buffer to the log.
716 * @param avcl A pointer to an arbitrary struct of which the first field is a
717 * pointer to an AVClass struct.
718 * @param level The importance level of the message, lower values signifying
721 * @param size buffer size
723 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
725 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
728 * Send a nice dump of a packet to the specified file stream.
730 * @param f The file stream pointer where the dump should be sent to.
731 * @param pkt packet to dump
732 * @param dump_payload True if the payload must be displayed, too.
734 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
737 * Send a nice dump of a packet to the log.
739 * @param avcl A pointer to an arbitrary struct of which the first field is a
740 * pointer to an AVClass struct.
741 * @param level The importance level of the message, lower values signifying
743 * @param pkt packet to dump
744 * @param dump_payload True if the payload must be displayed, too.
746 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
748 void av_register_all(void);
750 /** codec tag <-> codec id */
751 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
752 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
754 /* media file input */
757 * Finds AVInputFormat based on the short name of the input format.
759 AVInputFormat *av_find_input_format(const char *short_name);
764 * @param is_opened Whether the file is already opened; determines whether
765 * demuxers with or without AVFMT_NOFILE are probed.
767 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
770 * Allocates all the structures needed to read an input stream.
771 * This does not open the needed codecs for decoding the stream[s].
773 int av_open_input_stream(AVFormatContext **ic_ptr,
774 ByteIOContext *pb, const char *filename,
775 AVInputFormat *fmt, AVFormatParameters *ap);
778 * Open a media file as input. The codecs are not opened. Only the file
779 * header (if present) is read.
781 * @param ic_ptr The opened media file handle is put here.
782 * @param filename filename to open
783 * @param fmt If non-NULL, force the file format to use.
784 * @param buf_size optional buffer size (zero if default is OK)
785 * @param ap Additional parameters needed when opening the file
787 * @return 0 if OK, AVERROR_xxx otherwise
789 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
792 AVFormatParameters *ap);
794 * Allocate an AVFormatContext.
795 * Can be freed with av_free() but do not forget to free everything you
796 * explicitly allocated as well!
798 AVFormatContext *av_alloc_format_context(void);
801 * Read packets of a media file to get stream information. This
802 * is useful for file formats with no headers such as MPEG. This
803 * function also computes the real frame rate in case of MPEG-2 repeat
805 * The logical file position is not changed by this function;
806 * examined packets may be buffered for later processing.
808 * @param ic media file handle
809 * @return >=0 if OK, AVERROR_xxx on error
810 * @todo Let the user decide somehow what information is needed so that
811 * we do not waste time getting stuff the user does not need.
813 int av_find_stream_info(AVFormatContext *ic);
816 * Read a transport packet from a media file.
818 * This function is obsolete and should never be used.
819 * Use av_read_frame() instead.
821 * @param s media file handle
822 * @param pkt is filled
823 * @return 0 if OK, AVERROR_xxx on error
825 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
828 * Return the next frame of a stream.
830 * The returned packet is valid
831 * until the next av_read_frame() or until av_close_input_file() and
832 * must be freed with av_free_packet. For video, the packet contains
833 * exactly one frame. For audio, it contains an integer number of
834 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
835 * data). If the audio frames have a variable size (e.g. MPEG audio),
836 * then it contains one frame.
838 * pkt->pts, pkt->dts and pkt->duration are always set to correct
839 * values in AVStream.timebase units (and guessed if the format cannot
840 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
841 * has B-frames, so it is better to rely on pkt->dts if you do not
842 * decompress the payload.
844 * @return 0 if OK, < 0 on error or end of file
846 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
849 * Seek to the key frame at timestamp.
850 * 'timestamp' in 'stream_index'.
851 * @param stream_index If stream_index is (-1), a default
852 * stream is selected, and timestamp is automatically converted
853 * from AV_TIME_BASE units to the stream specific time_base.
854 * @param timestamp Timestamp in AVStream.time_base units
855 * or, if no stream is specified, in AV_TIME_BASE units.
856 * @param flags flags which select direction and seeking mode
857 * @return >= 0 on success
859 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
863 * Start playing a network based stream (e.g. RTSP stream) at the
866 int av_read_play(AVFormatContext *s);
869 * Pause a network based stream (e.g. RTSP stream).
871 * Use av_read_play() to resume it.
873 int av_read_pause(AVFormatContext *s);
876 * Free a AVFormatContext allocated by av_open_input_stream.
877 * @param s context to free
879 void av_close_input_stream(AVFormatContext *s);
882 * Close a media file (but not its codecs).
884 * @param s media file handle
886 void av_close_input_file(AVFormatContext *s);
889 * Add a new stream to a media file.
891 * Can only be called in the read_header() function. If the flag
892 * AVFMTCTX_NOHEADER is in the format context, then new streams
893 * can be added in read_packet too.
895 * @param s media file handle
896 * @param id file-format-dependent stream ID
898 AVStream *av_new_stream(AVFormatContext *s, int id);
899 AVProgram *av_new_program(AVFormatContext *s, int id);
903 * This function is NOT part of the public API
904 * and should ONLY be used by demuxers.
906 * @param s media file handle
907 * @param id unique ID for this chapter
908 * @param start chapter start time in time_base units
909 * @param end chapter end time in time_base units
910 * @param title chapter title
912 * @return AVChapter or NULL on error
914 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
915 int64_t start, int64_t end, const char *title);
918 * Set the pts for a given stream.
921 * @param pts_wrap_bits number of bits effectively used by the pts
922 * (used for wrap control, 33 is the value for MPEG)
923 * @param pts_num numerator to convert to seconds (MPEG: 1)
924 * @param pts_den denominator to convert to seconds (MPEG: 90000)
926 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
927 int pts_num, int pts_den);
929 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
930 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
931 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
933 int av_find_default_stream_index(AVFormatContext *s);
936 * Gets the index for a specific timestamp.
937 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
938 * to the timestamp which is <= the requested one, if backward
939 * is 0, then it will be >=
940 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
941 * @return < 0 if no such timestamp could be found
943 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
946 * Ensures the index uses less memory than the maximum specified in
947 * AVFormatContext.max_index_size, by discarding entries if it grows
949 * This function is not part of the public API and should only be called
952 void ff_reduce_index(AVFormatContext *s, int stream_index);
955 * Add an index entry into a sorted list. Update the entry if the list
956 * already contains it.
958 * @param timestamp timestamp in the time base of the given stream
960 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
961 int size, int distance, int flags);
964 * Does a binary search using av_index_search_timestamp() and
965 * AVCodec.read_timestamp().
966 * This is not supposed to be called directly by a user application,
968 * @param target_ts target timestamp in the time base of the given stream
969 * @param stream_index stream number
971 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
972 int64_t target_ts, int flags);
975 * Updates cur_dts of all streams based on the given timestamp and AVStream.
977 * Stream ref_st unchanged, others set cur_dts in their native time base.
978 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
979 * @param timestamp new dts expressed in time_base of param ref_st
980 * @param ref_st reference stream giving time_base of param timestamp
982 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
985 * Does a binary search using read_timestamp().
986 * This is not supposed to be called directly by a user application,
988 * @param target_ts target timestamp in the time base of the given stream
989 * @param stream_index stream number
991 int64_t av_gen_search(AVFormatContext *s, int stream_index,
992 int64_t target_ts, int64_t pos_min,
993 int64_t pos_max, int64_t pos_limit,
994 int64_t ts_min, int64_t ts_max,
995 int flags, int64_t *ts_ret,
996 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
998 /** media file output */
999 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1002 * Allocate the stream private data and write the stream header to an
1003 * output media file.
1005 * @param s media file handle
1006 * @return 0 if OK, AVERROR_xxx on error
1008 int av_write_header(AVFormatContext *s);
1011 * Write a packet to an output media file.
1013 * The packet shall contain one audio or video frame.
1014 * The packet must be correctly interleaved according to the container
1015 * specification, if not then av_interleaved_write_frame must be used.
1017 * @param s media file handle
1018 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1020 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1022 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1025 * Writes a packet to an output media file ensuring correct interleaving.
1027 * The packet must contain one audio or video frame.
1028 * If the packets are already correctly interleaved the application should
1029 * call av_write_frame() instead as it is slightly faster. It is also important
1030 * to keep in mind that completely non-interleaved input will need huge amounts
1031 * of memory to interleave with this, so it is preferable to interleave at the
1034 * @param s media file handle
1035 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1037 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1039 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1042 * Interleave a packet per dts in an output media file.
1044 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1045 * function, so they cannot be used after it, note calling av_free_packet()
1046 * on them is still safe.
1048 * @param s media file handle
1049 * @param out the interleaved packet will be output here
1050 * @param in the input packet
1051 * @param flush 1 if no further packets are available as input and all
1052 * remaining packets should be output
1053 * @return 1 if a packet was output, 0 if no packet could be output,
1054 * < 0 if an error occurred
1056 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1057 AVPacket *pkt, int flush);
1060 * @brief Write the stream trailer to an output media file and
1061 * free the file private data.
1063 * May only be called after a successful call to av_write_header.
1065 * @param s media file handle
1066 * @return 0 if OK, AVERROR_xxx on error
1068 int av_write_trailer(AVFormatContext *s);
1070 void dump_format(AVFormatContext *ic,
1075 #if LIBAVFORMAT_VERSION_MAJOR < 53
1077 * Parses width and height out of string str.
1078 * @deprecated Use av_parse_video_frame_size instead.
1080 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1084 * Converts frame rate from string to a fraction.
1085 * @deprecated Use av_parse_video_frame_rate instead.
1087 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1092 * Parses \p datestr and returns a corresponding number of microseconds.
1093 * @param datestr String representing a date or a duration.
1094 * - If a date the syntax is:
1096 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1098 * Time is local time unless Z is appended, in which case it is
1099 * interpreted as UTC.
1100 * If the year-month-day part is not specified it takes the current
1102 * Returns the number of microseconds since 1st of January, 1970 up to
1103 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1104 * successfully parsed.
1105 * - If a duration the syntax is:
1107 * [-]HH[:MM[:SS[.m...]]]
1110 * Returns the number of microseconds contained in a time interval
1111 * with the specified duration or INT64_MIN if \p datestr cannot be
1112 * successfully parsed.
1113 * @param duration Flag which tells how to interpret \p datestr, if
1114 * not zero \p datestr is interpreted as a duration, otherwise as a
1117 int64_t parse_date(const char *datestr, int duration);
1119 /** Gets the current time in microseconds. */
1120 int64_t av_gettime(void);
1122 /* ffm-specific for ffserver */
1123 #define FFM_PACKET_SIZE 4096
1124 int64_t ffm_read_write_index(int fd);
1125 void ffm_write_write_index(int fd, int64_t pos);
1126 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1129 * Attempts to find a specific tag in a URL.
1131 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1132 * Return 1 if found.
1134 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1137 * Returns in 'buf' the path with '%d' replaced by number.
1139 * Also handles the '%0nd' format where 'n' is the total number
1140 * of digits and '%%'.
1142 * @param buf destination buffer
1143 * @param buf_size destination buffer size
1144 * @param path numbered sequence string
1145 * @param number frame number
1146 * @return 0 if OK, -1 on format error
1148 int av_get_frame_filename(char *buf, int buf_size,
1149 const char *path, int number);
1152 * Check whether filename actually is a numbered sequence generator.
1154 * @param filename possible numbered sequence string
1155 * @return 1 if a valid numbered sequence string, 0 otherwise
1157 int av_filename_number_test(const char *filename);
1160 * Generate an SDP for an RTP session.
1162 * @param ac array of AVFormatContexts describing the RTP streams. If the
1163 * array is composed by only one context, such context can contain
1164 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1165 * all the contexts in the array (an AVCodecContext per RTP stream)
1166 * must contain only one AVStream.
1167 * @param n_files number of AVCodecContexts contained in ac
1168 * @param buff buffer where the SDP will be stored (must be allocated by
1170 * @param size the size of the buffer
1171 * @return 0 if OK, AVERROR_xxx on error
1173 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1175 #ifdef HAVE_AV_CONFIG_H
1177 void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1180 #define dynarray_add(tab, nb_ptr, elem)\
1182 __typeof__(tab) _tab = (tab);\
1183 __typeof__(elem) _elem = (elem);\
1184 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1185 ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1188 #define dynarray_add(tab, nb_ptr, elem)\
1190 ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1194 time_t mktimegm(struct tm *tm);
1195 struct tm *brktimegm(time_t secs, struct tm *tm);
1196 const char *small_strptime(const char *p, const char *fmt,
1200 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1202 void url_split(char *proto, int proto_size,
1203 char *authorization, int authorization_size,
1204 char *hostname, int hostname_size,
1206 char *path, int path_size,
1209 int match_ext(const char *filename, const char *extensions);
1211 #endif /* HAVE_AV_CONFIG_H */
1213 #endif /* AVFORMAT_AVFORMAT_H */