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 30
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 #include <stdio.h> /* FILE */
45 #include "libavcodec/avcodec.h"
51 * Public Metadata API.
52 * !!WARNING!! This is a work in progress. Don't use outside FFmpeg for now.
53 * The metadata API allows libavformat to export metadata tags to a client
54 * application using a sequence of key/value pairs.
55 * Important concepts to keep in mind:
56 * 1. Keys are unique; there can never be 2 tags with the same key. This is
57 * also meant semantically, i.e., a demuxer should not knowingly produce
58 * several keys that are literally different but semantically identical.
59 * E.g., key=Author5, key=Author6. In this example, all authors must be
60 * placed in the same tag.
61 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
62 * want to store, e.g., the email address of the child of producer Alice
63 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
64 * 3. A tag whose value is localized for a particular language is appended
65 * with a dash character ('-') and the ISO 639 3-letter language code.
66 * For example: Author-ger=Michael, Author-eng=Mike
67 * The original/default language is in the unqualified "Author" tag.
68 * A demuxer should set a default if it sets any translated tag.
71 #define AV_METADATA_MATCH_CASE 1
72 #define AV_METADATA_IGNORE_SUFFIX 2
79 typedef struct AVMetadata AVMetadata;
82 * Gets a metadata element with matching key.
83 * @param prev Set to the previous matching element to find the next.
84 * @param flags Allows case as well as suffix-insensitive comparisons.
85 * @return Found tag or NULL, changing key or value leads to undefined behavior.
88 av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
91 * Sets the given tag in m, overwriting an existing tag.
92 * @param key tag key to add to m (will be av_strduped)
93 * @param value tag value to add to m (will be av_strduped)
94 * @return >= 0 on success otherwise an error code <0
96 int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
99 * Frees all the memory allocated for an AVMetadata struct.
101 void av_metadata_free(AVMetadata **m);
104 /* packet functions */
106 typedef struct AVPacket {
108 * Presentation timestamp in time_base units; the time at which the
109 * decompressed packet will be presented to the user.
110 * Can be AV_NOPTS_VALUE if it is not stored in the file.
111 * pts MUST be larger or equal to dts as presentation cannot happen before
112 * decompression, unless one wants to view hex dumps. Some formats misuse
113 * the terms dts and pts/cts to mean something different. Such timestamps
114 * must be converted to true pts/dts before they are stored in AVPacket.
118 * Decompression timestamp in time_base units; the time at which the
119 * packet is decompressed.
120 * Can be AV_NOPTS_VALUE if it is not stored in the file.
128 * Duration of this packet in time_base units, 0 if unknown.
129 * Equals next_pts - this_pts in presentation order.
132 void (*destruct)(struct AVPacket *);
134 int64_t pos; ///< byte position in stream, -1 if unknown
137 * Time difference in stream time base units from the pts of this
138 * packet to the point at which the output from the decoder has converged
139 * independent from the availability of previous frames. That is, the
140 * frames are virtually identical no matter if decoding started from
141 * the very first frame or from this keyframe.
142 * Is AV_NOPTS_VALUE if unknown.
143 * This field is not the display duration of the current packet.
145 * The purpose of this field is to allow seeking in streams that have no
146 * keyframes in the conventional sense. It corresponds to the
147 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
148 * essential for some types of subtitle streams to ensure that all
149 * subtitles are correctly displayed after seeking.
151 int64_t convergence_duration;
153 #define PKT_FLAG_KEY 0x0001
155 void av_destruct_packet_nofree(AVPacket *pkt);
158 * Default packet destructor.
160 void av_destruct_packet(AVPacket *pkt);
163 * Initialize optional fields of a packet with default values.
167 void av_init_packet(AVPacket *pkt);
170 * Allocate the payload of a packet and initialize its fields with
174 * @param size wanted payload size
175 * @return 0 if OK, AVERROR_xxx otherwise
177 int av_new_packet(AVPacket *pkt, int size);
180 * Allocate and read the payload of a packet and initialize its fields with
184 * @param size desired payload size
185 * @return >0 (read size) if OK, AVERROR_xxx otherwise
187 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
190 * @warning This is a hack - the packet memory allocation stuff is broken. The
191 * packet is allocated if it was not really allocated.
193 int av_dup_packet(AVPacket *pkt);
198 * @param pkt packet to free
200 static inline void av_free_packet(AVPacket *pkt)
202 if (pkt && pkt->destruct) {
207 /*************************************************/
208 /* fractional numbers for exact pts handling */
211 * The exact value of the fractional number is: 'val + num / den'.
212 * num is assumed to be 0 <= num < den.
214 typedef struct AVFrac {
215 int64_t val, num, den;
218 /*************************************************/
219 /* input/output formats */
223 struct AVFormatContext;
225 /** This structure contains the data a format has to probe a file. */
226 typedef struct AVProbeData {
227 const char *filename;
232 #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
233 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
235 typedef struct AVFormatParameters {
236 AVRational time_base;
241 enum PixelFormat pix_fmt;
242 int channel; /**< Used to select DV channel. */
243 const char *standard; /**< TV standard, NTSC, PAL, SECAM */
244 unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
245 unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
246 stream packet (only meaningful if
247 mpeg2ts_raw is TRUE). */
248 unsigned int initial_pause:1; /**< Do not begin to play the stream
249 immediately (RTSP only). */
250 unsigned int prealloced_context:1;
251 #if LIBAVFORMAT_VERSION_INT < (53<<16)
252 enum CodecID video_codec_id;
253 enum CodecID audio_codec_id;
255 } AVFormatParameters;
257 //! Demuxer will use url_fopen, no opened file should be provided by the caller.
258 #define AVFMT_NOFILE 0x0001
259 #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
260 #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
261 #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
263 #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
264 #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
265 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
266 #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
267 #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
269 typedef struct AVOutputFormat {
272 * Descriptive name for the format, meant to be more human-readable
273 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
276 const char *long_name;
277 const char *mime_type;
278 const char *extensions; /**< comma-separated filename extensions */
279 /** size of private data so that it can be allocated in the wrapper */
282 enum CodecID audio_codec; /**< default audio codec */
283 enum CodecID video_codec; /**< default video codec */
284 int (*write_header)(struct AVFormatContext *);
285 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
286 int (*write_trailer)(struct AVFormatContext *);
287 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
289 /** Currently only used to set pixel format if not YUV420P. */
290 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
291 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
292 AVPacket *in, int flush);
295 * List of supported codec_id-codec_tag pairs, ordered by "better
296 * choice first". The arrays are all terminated by CODEC_ID_NONE.
298 const struct AVCodecTag * const *codec_tag;
300 enum CodecID subtitle_codec; /**< default subtitle codec */
303 struct AVOutputFormat *next;
306 typedef struct AVInputFormat {
309 * Descriptive name for the format, meant to be more human-readable
310 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
313 const char *long_name;
314 /** Size of private data so that it can be allocated in the wrapper. */
317 * Tell if a given file has a chance of being parsed as this format.
318 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
319 * big so you do not have to check for that unless you need more.
321 int (*read_probe)(AVProbeData *);
322 /** Read the format header and initialize the AVFormatContext
323 structure. Return 0 if OK. 'ap' if non-NULL contains
324 additional parameters. Only used in raw format right
325 now. 'av_new_stream' should be called to create new streams. */
326 int (*read_header)(struct AVFormatContext *,
327 AVFormatParameters *ap);
328 /** Read one packet and put it in 'pkt'. pts and flags are also
329 set. 'av_new_stream' can be called only if the flag
330 AVFMTCTX_NOHEADER is used. */
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 *);
336 #if LIBAVFORMAT_VERSION_MAJOR < 53
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)
345 int (*read_seek)(struct AVFormatContext *,
346 int stream_index, int64_t timestamp, int flags);
349 * Gets the next timestamp in stream[stream_index].time_base units.
350 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
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. */
356 /** If extensions are defined, then no probe is done. You should
357 usually not use extension format guessing because it is not
359 const char *extensions;
360 /** General purpose read-only value that the format can use. */
363 /** Start/resume playing - only meaningful if using a network-based format
365 int (*read_play)(struct AVFormatContext *);
367 /** Pause playing - only meaningful if using a network-based format
369 int (*read_pause)(struct AVFormatContext *);
371 const struct AVCodecTag * const *codec_tag;
374 * Seek 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.
379 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
382 struct AVInputFormat *next;
385 enum AVStreamParseType {
387 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
388 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
389 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
392 typedef struct AVIndexEntry {
395 #define AVINDEX_KEYFRAME 0x0001
397 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).
398 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
401 #define AV_DISPOSITION_DEFAULT 0x0001
402 #define AV_DISPOSITION_DUB 0x0002
403 #define AV_DISPOSITION_ORIGINAL 0x0004
404 #define AV_DISPOSITION_COMMENT 0x0008
405 #define AV_DISPOSITION_LYRICS 0x0010
406 #define AV_DISPOSITION_KARAOKE 0x0020
410 * New fields can be added to the end with minor version bumps.
411 * Removal, reordering and changes to existing fields require a major
413 * sizeof(AVStream) must not be used outside libav*.
415 typedef struct AVStream {
416 int index; /**< stream index in AVFormatContext */
417 int id; /**< format-specific stream ID */
418 AVCodecContext *codec; /**< codec context */
420 * Real base framerate of the stream.
421 * This is the lowest framerate with which all timestamps can be
422 * represented accurately (it is the least common multiple of all
423 * framerates in the stream). Note, this value is just a guess!
424 * For example, if the time base is 1/90000 and all frames have either
425 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
427 AVRational r_frame_rate;
430 /* internal data used in av_find_stream_info() */
432 /** encoding: pts generation when outputting stream */
436 * This is the fundamental unit of time (in seconds) in terms
437 * of which frame timestamps are represented. For fixed-fps content,
438 * time base should be 1/framerate and timestamp increments should be 1.
440 AVRational time_base;
441 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
442 /* ffmpeg.c private use */
443 int stream_copy; /**< If set, just copy stream. */
444 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
445 //FIXME move stuff to a flags field?
446 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
447 * MN: dunno if that is the right place for it */
450 * Decoding: pts of the first frame of the stream, in stream time base.
451 * Only set this if you are absolutely 100% sure that the value you set
452 * it to really is the pts of the first frame.
453 * This may be undefined (AV_NOPTS_VALUE).
454 * @note The ASF header does NOT contain a correct start_time the ASF
455 * demuxer must NOT set this.
459 * Decoding: duration of the stream, in stream time base.
460 * If a source file does not specify a duration, but does specify
461 * a bitrate, this value will be estimated from bitrate and file size.
465 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
467 /* av_read_frame() support */
468 enum AVStreamParseType need_parsing;
469 struct AVCodecParserContext *parser;
472 int last_IP_duration;
474 /* av_seek_frame() support */
475 AVIndexEntry *index_entries; /**< Only used if the format does not
476 support seeking natively. */
477 int nb_index_entries;
478 unsigned int index_entries_allocated_size;
480 int64_t nb_frames; ///< number of frames in this stream if known or 0
482 #if LIBAVFORMAT_VERSION_INT < (53<<16)
486 char *filename; /**< source filename of the stream */
488 int disposition; /**< AV_DISPOSITION_* bit field */
490 AVProbeData probe_data;
491 #define MAX_REORDER_DELAY 16
492 int64_t pts_buffer[MAX_REORDER_DELAY+1];
495 * sample aspect ratio (0 if unknown)
496 * - encoding: Set by user.
497 * - decoding: Set by libavformat.
499 AVRational sample_aspect_ratio;
501 AVMetadata *metadata;
503 /* av_read_frame() support */
504 const uint8_t *cur_ptr;
508 // Timestamp generation support:
510 * Timestamp corresponding to the last dts sync point.
512 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
513 * a DTS is received from the underlying container. Otherwise set to
514 * AV_NOPTS_VALUE by default.
516 int64_t reference_dts;
519 #define AV_PROGRAM_RUNNING 1
522 * New fields can be added to the end with minor version bumps.
523 * Removal, reordering and changes to existing fields require a major
525 * sizeof(AVProgram) must not be used outside libav*.
527 typedef struct AVProgram {
529 char *provider_name; ///< network name for DVB streams
530 char *name; ///< service name for DVB streams
532 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
533 unsigned int *stream_index;
534 unsigned int nb_stream_indexes;
535 AVMetadata *metadata;
538 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
539 (streams are added dynamically) */
541 typedef struct AVChapter {
542 int id; ///< unique ID to identify the chapter
543 AVRational time_base; ///< time base in which the start/end timestamps are specified
544 int64_t start, end; ///< chapter start/end time in time_base units
545 char *title; ///< chapter title
546 AVMetadata *metadata;
549 #define MAX_STREAMS 20
552 * Format I/O context.
553 * New fields can be added to the end with minor version bumps.
554 * Removal, reordering and changes to existing fields require a major
556 * sizeof(AVFormatContext) must not be used outside libav*.
558 typedef struct AVFormatContext {
559 const AVClass *av_class; /**< Set by avformat_alloc_context. */
560 /* Can only be iformat or oformat, not both at the same time. */
561 struct AVInputFormat *iformat;
562 struct AVOutputFormat *oformat;
565 unsigned int nb_streams;
566 AVStream *streams[MAX_STREAMS];
567 char filename[1024]; /**< input or output filename */
575 int year; /**< ID3 year, 0 if none */
576 int track; /**< track number, 0 if none */
577 char genre[32]; /**< ID3 genre */
579 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
580 /* private data for pts handling (do not modify directly). */
581 /** This buffer is only needed when packets were already buffered but
582 not decoded, for example to get the codec parameters in MPEG
584 struct AVPacketList *packet_buffer;
586 /** Decoding: position of the first frame of the component, in
587 AV_TIME_BASE fractional seconds. NEVER set this value directly:
588 It is deduced from the AVStream values. */
590 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
591 seconds. NEVER set this value directly: it is deduced from the
594 /** decoding: total file size, 0 if unknown */
596 /** Decoding: total stream bitrate in bit/s, 0 if not
597 available. Never set it directly if the file_size and the
598 duration are known as FFmpeg can compute it automatically. */
601 /* av_read_frame() support */
603 #if LIBAVFORMAT_VERSION_INT < (53<<16)
604 const uint8_t *cur_ptr_deprecated;
605 int cur_len_deprecated;
606 AVPacket cur_pkt_deprecated;
609 /* av_seek_frame() support */
610 int64_t data_offset; /** offset of the first packet */
618 #define AVFMT_NOOUTPUTLOOP -1
619 #define AVFMT_INFINITEOUTPUTLOOP 0
620 /** number of times to loop output in formats that support it */
624 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
625 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
626 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
629 /** decoding: size of data to probe; encoding: unused. */
630 unsigned int probesize;
633 * Maximum time (in AV_TIME_BASE units) during which the input should
634 * be analyzed in av_find_stream_info().
636 int max_analyze_duration;
641 unsigned int nb_programs;
642 AVProgram **programs;
645 * Forced video codec_id.
646 * Demuxing: Set by user.
648 enum CodecID video_codec_id;
650 * Forced audio codec_id.
651 * Demuxing: Set by user.
653 enum CodecID audio_codec_id;
655 * Forced subtitle codec_id.
656 * Demuxing: Set by user.
658 enum CodecID subtitle_codec_id;
661 * Maximum amount of memory in bytes to use for the index of each stream.
662 * If the index exceeds this size, entries will be discarded as
663 * needed to maintain a smaller size. This can lead to slower or less
664 * accurate seeking (depends on demuxer).
665 * Demuxers for which a full in-memory index is mandatory will ignore
668 * demuxing: set by user
670 unsigned int max_index_size;
673 * Maximum amount of memory in bytes to use for buffering frames
674 * obtained from realtime capture devices.
676 unsigned int max_picture_buffer;
678 unsigned int nb_chapters;
679 AVChapter **chapters;
682 * Flags to enable debugging.
685 #define FF_FDEBUG_TS 0x0001
688 * Raw packets from the demuxer, prior to parsing and decoding.
689 * This buffer is used for buffering packets until the codec can
690 * be identified, as parsing cannot be done without knowing the
693 struct AVPacketList *raw_packet_buffer;
694 struct AVPacketList *raw_packet_buffer_end;
696 struct AVPacketList *packet_buffer_end;
698 AVMetadata *metadata;
701 typedef struct AVPacketList {
703 struct AVPacketList *next;
706 #if LIBAVFORMAT_VERSION_INT < (53<<16)
707 extern AVInputFormat *first_iformat;
708 extern AVOutputFormat *first_oformat;
712 * If f is NULL, returns the first registered input format,
713 * if f is non-NULL, returns the next registered input format after f
714 * or NULL if f is the last one.
716 AVInputFormat *av_iformat_next(AVInputFormat *f);
719 * If f is NULL, returns the first registered output format,
720 * if f is non-NULL, returns the next registered output format after f
721 * or NULL if f is the last one.
723 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
725 enum CodecID av_guess_image2_codec(const char *filename);
727 /* XXX: Use automatic init with either ELF sections or C file parser */
731 void av_register_input_format(AVInputFormat *format);
732 void av_register_output_format(AVOutputFormat *format);
733 AVOutputFormat *guess_stream_format(const char *short_name,
734 const char *filename,
735 const char *mime_type);
736 AVOutputFormat *guess_format(const char *short_name,
737 const char *filename,
738 const char *mime_type);
741 * Guesses the codec ID based upon muxer and filename.
743 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
744 const char *filename, const char *mime_type,
745 enum CodecType type);
748 * Send a nice hexadecimal dump of a buffer to the specified file stream.
750 * @param f The file stream pointer where the dump should be sent to.
752 * @param size buffer size
754 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
756 void av_hex_dump(FILE *f, uint8_t *buf, int size);
759 * Send a nice hexadecimal dump of a buffer to the log.
761 * @param avcl A pointer to an arbitrary struct of which the first field is a
762 * pointer to an AVClass struct.
763 * @param level The importance level of the message, lower values signifying
766 * @param size buffer size
768 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
770 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
773 * Send a nice dump of a packet to the specified file stream.
775 * @param f The file stream pointer where the dump should be sent to.
776 * @param pkt packet to dump
777 * @param dump_payload True if the payload must be displayed, too.
779 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
782 * Send a nice dump of a packet to the log.
784 * @param avcl A pointer to an arbitrary struct of which the first field is a
785 * pointer to an AVClass struct.
786 * @param level The importance level of the message, lower values signifying
788 * @param pkt packet to dump
789 * @param dump_payload True if the payload must be displayed, too.
791 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
794 * Initialize libavformat and register all the muxers, demuxers and
795 * protocols. If you do not call this function, then you can select
796 * exactly which formats you want to support.
798 * @see av_register_input_format()
799 * @see av_register_output_format()
800 * @see av_register_protocol()
802 void av_register_all(void);
804 /** codec tag <-> codec id */
805 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
806 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
808 /* media file input */
811 * Finds AVInputFormat based on the short name of the input format.
813 AVInputFormat *av_find_input_format(const char *short_name);
818 * @param is_opened Whether the file is already opened; determines whether
819 * demuxers with or without AVFMT_NOFILE are probed.
821 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
824 * Allocates all the structures needed to read an input stream.
825 * This does not open the needed codecs for decoding the stream[s].
827 int av_open_input_stream(AVFormatContext **ic_ptr,
828 ByteIOContext *pb, const char *filename,
829 AVInputFormat *fmt, AVFormatParameters *ap);
832 * Open a media file as input. The codecs are not opened. Only the file
833 * header (if present) is read.
835 * @param ic_ptr The opened media file handle is put here.
836 * @param filename filename to open
837 * @param fmt If non-NULL, force the file format to use.
838 * @param buf_size optional buffer size (zero if default is OK)
839 * @param ap Additional parameters needed when opening the file
841 * @return 0 if OK, AVERROR_xxx otherwise
843 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
846 AVFormatParameters *ap);
848 #if LIBAVFORMAT_VERSION_MAJOR < 53
850 * @deprecated Use avformat_alloc_context() instead.
852 attribute_deprecated AVFormatContext *av_alloc_format_context(void);
856 * Allocate an AVFormatContext.
857 * Can be freed with av_free() but do not forget to free everything you
858 * explicitly allocated as well!
860 AVFormatContext *avformat_alloc_context(void);
863 * Read packets of a media file to get stream information. This
864 * is useful for file formats with no headers such as MPEG. This
865 * function also computes the real framerate in case of MPEG-2 repeat
867 * The logical file position is not changed by this function;
868 * examined packets may be buffered for later processing.
870 * @param ic media file handle
871 * @return >=0 if OK, AVERROR_xxx on error
872 * @todo Let the user decide somehow what information is needed so that
873 * we do not waste time getting stuff the user does not need.
875 int av_find_stream_info(AVFormatContext *ic);
878 * Read a transport packet from a media file.
880 * This function is obsolete and should never be used.
881 * Use av_read_frame() instead.
883 * @param s media file handle
884 * @param pkt is filled
885 * @return 0 if OK, AVERROR_xxx on error
887 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
890 * Return the next frame of a stream.
892 * The returned packet is valid
893 * until the next av_read_frame() or until av_close_input_file() and
894 * must be freed with av_free_packet. For video, the packet contains
895 * exactly one frame. For audio, it contains an integer number of
896 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
897 * data). If the audio frames have a variable size (e.g. MPEG audio),
898 * then it contains one frame.
900 * pkt->pts, pkt->dts and pkt->duration are always set to correct
901 * values in AVStream.time_base units (and guessed if the format cannot
902 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
903 * has B-frames, so it is better to rely on pkt->dts if you do not
904 * decompress the payload.
906 * @return 0 if OK, < 0 on error or end of file
908 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
911 * Seek to the keyframe at timestamp.
912 * 'timestamp' in 'stream_index'.
913 * @param stream_index If stream_index is (-1), a default
914 * stream is selected, and timestamp is automatically converted
915 * from AV_TIME_BASE units to the stream specific time_base.
916 * @param timestamp Timestamp in AVStream.time_base units
917 * or, if no stream is specified, in AV_TIME_BASE units.
918 * @param flags flags which select direction and seeking mode
919 * @return >= 0 on success
921 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
925 * Seek to timestamp ts.
926 * Seeking will be done so that the point from which all active streams
927 * can be presented successfully will be closest to ts and within min/max_ts.
928 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
930 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
931 * are the file position (this may not be supported by all demuxers).
932 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
933 * in the stream with stream_index (this may not be supported by all demuxers).
934 * Otherwise all timestamps are in units of the stream selected by stream_index
935 * or if stream_index is -1, in AV_TIME_BASE units.
936 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
937 * keyframes (this may not be supported by all demuxers).
939 * @param stream_index index of the stream which is used as time base reference
940 * @param min_ts smallest acceptable timestamp
941 * @param ts target timestamp
942 * @param max_ts largest acceptable timestamp
944 * @returns >=0 on success, error code otherwise
946 * @NOTE This is part of the new seek API which is still under construction.
947 * Thus do not use this yet. It may change at any time, do not expect
948 * ABI compatibility yet!
950 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
953 * Start playing a network-based stream (e.g. RTSP stream) at the
956 int av_read_play(AVFormatContext *s);
959 * Pause a network-based stream (e.g. RTSP stream).
961 * Use av_read_play() to resume it.
963 int av_read_pause(AVFormatContext *s);
966 * Free a AVFormatContext allocated by av_open_input_stream.
967 * @param s context to free
969 void av_close_input_stream(AVFormatContext *s);
972 * Close a media file (but not its codecs).
974 * @param s media file handle
976 void av_close_input_file(AVFormatContext *s);
979 * Add a new stream to a media file.
981 * Can only be called in the read_header() function. If the flag
982 * AVFMTCTX_NOHEADER is in the format context, then new streams
983 * can be added in read_packet too.
985 * @param s media file handle
986 * @param id file-format-dependent stream ID
988 AVStream *av_new_stream(AVFormatContext *s, int id);
989 AVProgram *av_new_program(AVFormatContext *s, int id);
993 * This function is NOT part of the public API
994 * and should ONLY be used by demuxers.
996 * @param s media file handle
997 * @param id unique ID for this chapter
998 * @param start chapter start time in time_base units
999 * @param end chapter end time in time_base units
1000 * @param title chapter title
1002 * @return AVChapter or NULL on error
1004 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1005 int64_t start, int64_t end, const char *title);
1008 * Set the pts for a given stream.
1011 * @param pts_wrap_bits number of bits effectively used by the pts
1012 * (used for wrap control, 33 is the value for MPEG)
1013 * @param pts_num numerator to convert to seconds (MPEG: 1)
1014 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1016 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1017 int pts_num, int pts_den);
1019 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1020 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
1021 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
1023 int av_find_default_stream_index(AVFormatContext *s);
1026 * Gets the index for a specific timestamp.
1027 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1028 * to the timestamp which is <= the requested one, if backward
1029 * is 0, then it will be >=
1030 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1031 * @return < 0 if no such timestamp could be found
1033 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1036 * Ensures the index uses less memory than the maximum specified in
1037 * AVFormatContext.max_index_size by discarding entries if it grows
1039 * This function is not part of the public API and should only be called
1042 void ff_reduce_index(AVFormatContext *s, int stream_index);
1045 * Add an index entry into a sorted list. Update the entry if the list
1046 * already contains it.
1048 * @param timestamp timestamp in the time base of the given stream
1050 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1051 int size, int distance, int flags);
1054 * Does a binary search using av_index_search_timestamp() and
1055 * AVCodec.read_timestamp().
1056 * This is not supposed to be called directly by a user application,
1058 * @param target_ts target timestamp in the time base of the given stream
1059 * @param stream_index stream number
1061 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1062 int64_t target_ts, int flags);
1065 * Updates cur_dts of all streams based on the given timestamp and AVStream.
1067 * Stream ref_st unchanged, others set cur_dts in their native time base.
1068 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1069 * @param timestamp new dts expressed in time_base of param ref_st
1070 * @param ref_st reference stream giving time_base of param timestamp
1072 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1075 * Does a binary search using read_timestamp().
1076 * This is not supposed to be called directly by a user application,
1078 * @param target_ts target timestamp in the time base of the given stream
1079 * @param stream_index stream number
1081 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1082 int64_t target_ts, int64_t pos_min,
1083 int64_t pos_max, int64_t pos_limit,
1084 int64_t ts_min, int64_t ts_max,
1085 int flags, int64_t *ts_ret,
1086 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1088 /** media file output */
1089 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1092 * Allocate the stream private data and write the stream header to an
1093 * output media file.
1095 * @param s media file handle
1096 * @return 0 if OK, AVERROR_xxx on error
1098 int av_write_header(AVFormatContext *s);
1101 * Write a packet to an output media file.
1103 * The packet shall contain one audio or video frame.
1104 * The packet must be correctly interleaved according to the container
1105 * specification, if not then av_interleaved_write_frame must be used.
1107 * @param s media file handle
1108 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1110 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1112 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1115 * Writes a packet to an output media file ensuring correct interleaving.
1117 * The packet must contain one audio or video frame.
1118 * If the packets are already correctly interleaved, the application should
1119 * call av_write_frame() instead as it is slightly faster. It is also important
1120 * to keep in mind that completely non-interleaved input will need huge amounts
1121 * of memory to interleave with this, so it is preferable to interleave at the
1124 * @param s media file handle
1125 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1127 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1129 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1132 * Interleave a packet per dts in an output media file.
1134 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1135 * function, so they cannot be used after it. Note that calling av_free_packet()
1136 * on them is still safe.
1138 * @param s media file handle
1139 * @param out the interleaved packet will be output here
1140 * @param in the input packet
1141 * @param flush 1 if no further packets are available as input and all
1142 * remaining packets should be output
1143 * @return 1 if a packet was output, 0 if no packet could be output,
1144 * < 0 if an error occurred
1146 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1147 AVPacket *pkt, int flush);
1150 * @brief Write the stream trailer to an output media file and
1151 * free the file private data.
1153 * May only be called after a successful call to av_write_header.
1155 * @param s media file handle
1156 * @return 0 if OK, AVERROR_xxx on error
1158 int av_write_trailer(AVFormatContext *s);
1160 void dump_format(AVFormatContext *ic,
1165 #if LIBAVFORMAT_VERSION_MAJOR < 53
1167 * Parses width and height out of string str.
1168 * @deprecated Use av_parse_video_frame_size instead.
1170 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1174 * Converts framerate from a string to a fraction.
1175 * @deprecated Use av_parse_video_frame_rate instead.
1177 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1182 * Parses \p datestr and returns a corresponding number of microseconds.
1183 * @param datestr String representing a date or a duration.
1184 * - If a date the syntax is:
1186 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1188 * Time is local time unless Z is appended, in which case it is
1189 * interpreted as UTC.
1190 * If the year-month-day part is not specified it takes the current
1192 * Returns the number of microseconds since 1st of January, 1970 up to
1193 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1194 * successfully parsed.
1195 * - If a duration the syntax is:
1197 * [-]HH[:MM[:SS[.m...]]]
1200 * Returns the number of microseconds contained in a time interval
1201 * with the specified duration or INT64_MIN if \p datestr cannot be
1202 * successfully parsed.
1203 * @param duration Flag which tells how to interpret \p datestr, if
1204 * not zero \p datestr is interpreted as a duration, otherwise as a
1207 int64_t parse_date(const char *datestr, int duration);
1209 /** Gets the current time in microseconds. */
1210 int64_t av_gettime(void);
1212 /* ffm-specific for ffserver */
1213 #define FFM_PACKET_SIZE 4096
1214 int64_t ffm_read_write_index(int fd);
1215 int ffm_write_write_index(int fd, int64_t pos);
1216 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1219 * Attempts to find a specific tag in a URL.
1221 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1222 * Return 1 if found.
1224 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1227 * Returns in 'buf' the path with '%d' replaced by a number.
1229 * Also handles the '%0nd' format where 'n' is the total number
1230 * of digits and '%%'.
1232 * @param buf destination buffer
1233 * @param buf_size destination buffer size
1234 * @param path numbered sequence string
1235 * @param number frame number
1236 * @return 0 if OK, -1 on format error
1238 int av_get_frame_filename(char *buf, int buf_size,
1239 const char *path, int number);
1242 * Check whether filename actually is a numbered sequence generator.
1244 * @param filename possible numbered sequence string
1245 * @return 1 if a valid numbered sequence string, 0 otherwise
1247 int av_filename_number_test(const char *filename);
1250 * Generate an SDP for an RTP session.
1252 * @param ac array of AVFormatContexts describing the RTP streams. If the
1253 * array is composed by only one context, such context can contain
1254 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1255 * all the contexts in the array (an AVCodecContext per RTP stream)
1256 * must contain only one AVStream.
1257 * @param n_files number of AVCodecContexts contained in ac
1258 * @param buff buffer where the SDP will be stored (must be allocated by
1260 * @param size the size of the buffer
1261 * @return 0 if OK, AVERROR_xxx on error
1263 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1265 #ifdef HAVE_AV_CONFIG_H
1267 void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
1270 #define dynarray_add(tab, nb_ptr, elem)\
1272 __typeof__(tab) _tab = (tab);\
1273 __typeof__(elem) _elem = (elem);\
1274 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1275 ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
1278 #define dynarray_add(tab, nb_ptr, elem)\
1280 ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
1284 time_t mktimegm(struct tm *tm);
1285 struct tm *brktimegm(time_t secs, struct tm *tm);
1286 const char *small_strptime(const char *p, const char *fmt,
1290 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1292 void url_split(char *proto, int proto_size,
1293 char *authorization, int authorization_size,
1294 char *hostname, int hostname_size,
1296 char *path, int path_size,
1299 int match_ext(const char *filename, const char *extensions);
1301 #endif /* HAVE_AV_CONFIG_H */
1303 #endif /* AVFORMAT_AVFORMAT_H */