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 26
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 comparissions.
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 tag tag to add to m, key and value will be av_strduped.
93 * @return >= 0 if success otherwise error code that is <0.
95 int av_metadata_set(AVMetadata
**m
, AVMetadataTag tag
);
98 * Free all the memory allocated for an AVMetadata struct.
100 void av_metadata_free(AVMetadata
**m
);
103 /* packet functions */
105 typedef struct AVPacket
{
107 * Presentation timestamp in time_base units.
108 * This is the time at which the decompressed packet will be presented
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, these timestamps
114 * must be converted to true pts/dts before they are stored in AVPacket.
118 * Decompression timestamp in time_base units.
119 * This is the time at which the 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.
213 * @deprecated Use AVRational instead.
215 typedef struct AVFrac
{
216 int64_t val
, num
, den
;
219 /*************************************************/
220 /* input/output formats */
224 struct AVFormatContext
;
226 /** This structure contains the data a format has to probe a file. */
227 typedef struct AVProbeData
{
228 const char *filename
;
233 #define AVPROBE_SCORE_MAX 100 ///< Maximum score, half of that is used for file-extension-based detection.
234 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
236 typedef struct AVFormatParameters
{
237 AVRational time_base
;
242 enum PixelFormat pix_fmt
;
243 int channel
; /**< Used to select DV channel. */
244 const char *standard
; /**< TV standard, NTSC, PAL, SECAM */
245 unsigned int mpeg2ts_raw
:1; /**< Force raw MPEG-2 transport stream output, if possible. */
246 unsigned int mpeg2ts_compute_pcr
:1; /**< Compute exact PCR for each transport
247 stream packet (only meaningful if
248 mpeg2ts_raw is TRUE). */
249 unsigned int initial_pause
:1; /**< Do not begin to play the stream
250 immediately (RTSP only). */
251 unsigned int prealloced_context
:1;
252 #if LIBAVFORMAT_VERSION_INT < (53<<16)
253 enum CodecID video_codec_id
;
254 enum CodecID audio_codec_id
;
256 } AVFormatParameters
;
258 //! Demuxer will use url_fopen, no opened file should be provided by the caller.
259 #define AVFMT_NOFILE 0x0001
260 #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
261 #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
262 #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
264 #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
265 #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
266 #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
267 #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
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 CODEC_ID_NONE terminated.
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 by 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 * Seek to a given timestamp relative to the frames in
337 * stream component stream_index.
338 * @param stream_index must not be -1
339 * @param flags selects which direction should be preferred if no exact
341 * @return >= 0 on success (but not necessarily the new offset)
343 int (*read_seek
)(struct AVFormatContext
*,
344 int stream_index
, int64_t timestamp
, int flags
);
346 * Gets the next timestamp in stream[stream_index].time_base units.
347 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
349 int64_t (*read_timestamp
)(struct AVFormatContext
*s
, int stream_index
,
350 int64_t *pos
, int64_t pos_limit
);
351 /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
353 /** If extensions are defined, then no probe is done. You should
354 usually not use extension format guessing because it is not
356 const char *extensions
;
357 /** General purpose read-only value that the format can use. */
360 /** Start/resume playing - only meaningful if using a network-based format
362 int (*read_play
)(struct AVFormatContext
*);
364 /** Pause playing - only meaningful if using a network-based format
366 int (*read_pause
)(struct AVFormatContext
*);
368 const struct AVCodecTag
* const *codec_tag
;
371 struct AVInputFormat
*next
;
374 enum AVStreamParseType
{
376 AVSTREAM_PARSE_FULL
, /**< full parsing and repack */
377 AVSTREAM_PARSE_HEADERS
, /**< Only parse headers, do not repack. */
378 AVSTREAM_PARSE_TIMESTAMPS
, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
381 typedef struct AVIndexEntry
{
384 #define AVINDEX_KEYFRAME 0x0001
386 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).
387 int min_distance
; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
390 #define AV_DISPOSITION_DEFAULT 0x0001
391 #define AV_DISPOSITION_DUB 0x0002
392 #define AV_DISPOSITION_ORIGINAL 0x0004
393 #define AV_DISPOSITION_COMMENT 0x0008
394 #define AV_DISPOSITION_LYRICS 0x0010
395 #define AV_DISPOSITION_KARAOKE 0x0020
399 * New fields can be added to the end with minor version bumps.
400 * Removal, reordering and changes to existing fields require a major
402 * sizeof(AVStream) must not be used outside libav*.
404 typedef struct AVStream
{
405 int index
; /**< stream index in AVFormatContext */
406 int id
; /**< format-specific stream ID */
407 AVCodecContext
*codec
; /**< codec context */
409 * Real base frame rate of the stream.
410 * This is the lowest frame rate with which all timestamps can be
411 * represented accurately (it is the least common multiple of all
412 * frame rates in the stream). Note, this value is just a guess!
413 * For example if the time base is 1/90000 and all frames have either
414 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
416 AVRational r_frame_rate
;
419 /* internal data used in av_find_stream_info() */
421 /** encoding: pts generation when outputting stream */
425 * This is the fundamental unit of time (in seconds) in terms
426 * of which frame timestamps are represented. For fixed-fps content,
427 * time base should be 1/frame rate and timestamp increments should be 1.
429 AVRational time_base
;
430 int pts_wrap_bits
; /**< number of bits in pts (used for wrapping control) */
431 /* ffmpeg.c private use */
432 int stream_copy
; /**< If set, just copy stream. */
433 enum AVDiscard discard
; ///< Selects which packets can be discarded at will and do not need to be demuxed.
434 //FIXME move stuff to a flags field?
435 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
436 * MN: dunno if that is the right place for it */
439 * Decoding: pts of the first frame of the stream, in stream time base.
440 * Only set this if you are absolutely 100% sure that the value you set
441 * it to really is the pts of the first frame.
442 * This may be undefined (AV_NOPTS_VALUE).
443 * @note The ASF header does NOT contain a correct start_time the ASF
444 * demuxer must NOT set this.
448 * Decoding: duration of the stream, in stream time base.
449 * If a source file does not specify a duration, but does specify
450 * a bitrate, this value will be estimated from bitrate and file size.
454 char language
[4]; /** ISO 639 3-letter language code (empty string if undefined) */
456 /* av_read_frame() support */
457 enum AVStreamParseType need_parsing
;
458 struct AVCodecParserContext
*parser
;
461 int last_IP_duration
;
463 /* av_seek_frame() support */
464 AVIndexEntry
*index_entries
; /**< Only used if the format does not
465 support seeking natively. */
466 int nb_index_entries
;
467 unsigned int index_entries_allocated_size
;
469 int64_t nb_frames
; ///< number of frames in this stream if known or 0
471 #if LIBAVFORMAT_VERSION_INT < (53<<16)
475 char *filename
; /**< source filename of the stream */
477 int disposition
; /**< AV_DISPOSITION_* bit field */
479 AVProbeData probe_data
;
480 #define MAX_REORDER_DELAY 16
481 int64_t pts_buffer
[MAX_REORDER_DELAY
+1];
484 * sample aspect ratio (0 if unknown)
485 * - encoding: Set by user.
486 * - decoding: Set by libavformat.
488 AVRational sample_aspect_ratio
;
490 AVMetadata
*metadata
;
492 /* av_read_frame() support */
493 const uint8_t *cur_ptr
;
498 #define AV_PROGRAM_RUNNING 1
501 * New fields can be added to the end with minor version bumps.
502 * Removal, reordering and changes to existing fields require a major
504 * sizeof(AVProgram) must not be used outside libav*.
506 typedef struct AVProgram
{
508 char *provider_name
; ///< network name for DVB streams
509 char *name
; ///< service name for DVB streams
511 enum AVDiscard discard
; ///< selects which program to discard and which to feed to the caller
512 unsigned int *stream_index
;
513 unsigned int nb_stream_indexes
;
514 AVMetadata
*metadata
;
517 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
518 (streams are added dynamically) */
520 typedef struct AVChapter
{
521 int id
; ///< unique ID to identify the chapter
522 AVRational time_base
; ///< time base in which the start/end timestamps are specified
523 int64_t start
, end
; ///< chapter start/end time in time_base units
524 char *title
; ///< chapter title
525 AVMetadata
*metadata
;
528 #define MAX_STREAMS 20
531 * Format I/O context.
532 * New fields can be added to the end with minor version bumps.
533 * Removal, reordering and changes to existing fields require a major
535 * sizeof(AVFormatContext) must not be used outside libav*.
537 typedef struct AVFormatContext
{
538 const AVClass
*av_class
; /**< Set by av_alloc_format_context. */
539 /* Can only be iformat or oformat, not both at the same time. */
540 struct AVInputFormat
*iformat
;
541 struct AVOutputFormat
*oformat
;
544 unsigned int nb_streams
;
545 AVStream
*streams
[MAX_STREAMS
];
546 char filename
[1024]; /**< input or output filename */
554 int year
; /**< ID3 year, 0 if none */
555 int track
; /**< track number, 0 if none */
556 char genre
[32]; /**< ID3 genre */
558 int ctx_flags
; /**< Format-specific flags, see AVFMTCTX_xx */
559 /* private data for pts handling (do not modify directly). */
560 /** This buffer is only needed when packets were already buffered but
561 not decoded, for example to get the codec parameters in MPEG
563 struct AVPacketList
*packet_buffer
;
565 /** Decoding: position of the first frame of the component, in
566 AV_TIME_BASE fractional seconds. NEVER set this value directly:
567 It is deduced from the AVStream values. */
569 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
570 seconds. NEVER set this value directly: it is deduced from the
573 /** decoding: total file size, 0 if unknown */
575 /** Decoding: total stream bitrate in bit/s, 0 if not
576 available. Never set it directly if the file_size and the
577 duration are known as ffmpeg can compute it automatically. */
580 /* av_read_frame() support */
582 #if LIBAVFORMAT_VERSION_INT < (53<<16)
583 const uint8_t *cur_ptr_deprecated
;
584 int cur_len_deprecated
;
585 AVPacket cur_pkt_deprecated
;
588 /* av_seek_frame() support */
589 int64_t data_offset
; /** offset of the first packet */
597 #define AVFMT_NOOUTPUTLOOP -1
598 #define AVFMT_INFINITEOUTPUTLOOP 0
599 /** number of times to loop output in formats that support it */
603 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate pts if missing even if it requires parsing future frames.
604 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
605 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
606 #define AVFMT_FLAG_IGNEXTERNS 0x0008 ///< Do not try to load external files.
607 #define AVFMT_FLAG_FORCEEXTERNS 0x0010 ///< Load external files even when they could be incompatible.
610 /** Decoding: size of data to probe; encoding: unused. */
611 unsigned int probesize
;
614 * Maximum time (in AV_TIME_BASE units) during which the input should
615 * be analyzed in av_find_stream_info().
617 int max_analyze_duration
;
622 unsigned int nb_programs
;
623 AVProgram
**programs
;
626 * Forced video codec_id.
627 * Demuxing: Set by user.
629 enum CodecID video_codec_id
;
631 * Forced audio codec_id.
632 * Demuxing: Set by user.
634 enum CodecID audio_codec_id
;
636 * Forced subtitle codec_id.
637 * Demuxing: Set by user.
639 enum CodecID subtitle_codec_id
;
642 * Maximum amount of memory in bytes to use per stream for the index.
643 * If the needed index exceeds this size, entries will be discarded as
644 * needed to maintain a smaller size. This can lead to slower or less
645 * accurate seeking (depends on demuxer).
646 * Demuxers for which a full in-memory index is mandatory will ignore
649 * demuxing: set by user
651 unsigned int max_index_size
;
654 * Maximum amount of memory in bytes to use for buffering frames
655 * obtained from realtime capture devices.
657 unsigned int max_picture_buffer
;
659 unsigned int nb_chapters
;
660 AVChapter
**chapters
;
663 * Flags to enable debugging.
666 #define FF_FDEBUG_TS 0x0001
669 * Raw packets from the demuxer, prior to parsing and decoding.
670 * This buffer is used for buffering packets until the codec can
671 * be identified, as parsing cannot be done without knowing the
674 struct AVPacketList
*raw_packet_buffer
;
675 struct AVPacketList
*raw_packet_buffer_end
;
677 struct AVPacketList
*packet_buffer_end
;
679 AVMetadata
*metadata
;
681 /** Handles of external streams */
682 struct AVFormatContext
**external_ctx
;
683 unsigned int nb_external_ctx
;
686 typedef struct AVPacketList
{
688 struct AVPacketList
*next
;
691 #if LIBAVFORMAT_VERSION_INT < (53<<16)
692 extern AVInputFormat
*first_iformat
;
693 extern AVOutputFormat
*first_oformat
;
696 AVInputFormat
*av_iformat_next(AVInputFormat
*f
);
697 AVOutputFormat
*av_oformat_next(AVOutputFormat
*f
);
699 enum CodecID
av_guess_image2_codec(const char *filename
);
701 /* XXX: use automatic init with either ELF sections or C file parser */
705 void av_register_input_format(AVInputFormat
*format
);
706 void av_register_output_format(AVOutputFormat
*format
);
707 AVOutputFormat
*guess_stream_format(const char *short_name
,
708 const char *filename
,
709 const char *mime_type
);
710 AVOutputFormat
*guess_format(const char *short_name
,
711 const char *filename
,
712 const char *mime_type
);
715 * Guesses the codec ID based upon muxer and filename.
717 enum CodecID
av_guess_codec(AVOutputFormat
*fmt
, const char *short_name
,
718 const char *filename
, const char *mime_type
,
719 enum CodecType type
);
722 * Send a nice hexadecimal dump of a buffer to the specified file stream.
724 * @param f The file stream pointer where the dump should be sent to.
726 * @param size buffer size
728 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
730 void av_hex_dump(FILE *f
, uint8_t *buf
, int size
);
733 * Send a nice hexadecimal dump of a buffer to the log.
735 * @param avcl A pointer to an arbitrary struct of which the first field is a
736 * pointer to an AVClass struct.
737 * @param level The importance level of the message, lower values signifying
740 * @param size buffer size
742 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
744 void av_hex_dump_log(void *avcl
, int level
, uint8_t *buf
, int size
);
747 * Send a nice dump of a packet to the specified file stream.
749 * @param f The file stream pointer where the dump should be sent to.
750 * @param pkt packet to dump
751 * @param dump_payload True if the payload must be displayed, too.
753 void av_pkt_dump(FILE *f
, AVPacket
*pkt
, int dump_payload
);
756 * Send a nice dump of a packet to the log.
758 * @param avcl A pointer to an arbitrary struct of which the first field is a
759 * pointer to an AVClass struct.
760 * @param level The importance level of the message, lower values signifying
762 * @param pkt packet to dump
763 * @param dump_payload True if the payload must be displayed, too.
765 void av_pkt_dump_log(void *avcl
, int level
, AVPacket
*pkt
, int dump_payload
);
768 * Initialize libavformat and register all the muxers, demuxers and
769 * protocols. If you do not call this function, then you can select
770 * exactly which formats you want to support.
772 * @see av_register_input_format()
773 * @see av_register_output_format()
774 * @see register_protocol()
776 void av_register_all(void);
778 /** codec tag <-> codec id */
779 enum CodecID
av_codec_get_id(const struct AVCodecTag
* const *tags
, unsigned int tag
);
780 unsigned int av_codec_get_tag(const struct AVCodecTag
* const *tags
, enum CodecID id
);
782 /* media file input */
785 * Finds AVInputFormat based on the short name of the input format.
787 AVInputFormat
*av_find_input_format(const char *short_name
);
792 * @param is_opened Whether the file is already opened; determines whether
793 * demuxers with or without AVFMT_NOFILE are probed.
795 AVInputFormat
*av_probe_input_format(AVProbeData
*pd
, int is_opened
);
798 * Allocates all the structures needed to read an input stream.
799 * This does not open the needed codecs for decoding the stream[s].
801 int av_open_input_stream(AVFormatContext
**ic_ptr
,
802 ByteIOContext
*pb
, const char *filename
,
803 AVInputFormat
*fmt
, AVFormatParameters
*ap
);
806 * Open a media file as input. The codecs are not opened. Only the file
807 * header (if present) is read.
809 * @param ic_ptr The opened media file handle is put here.
810 * @param filename filename to open
811 * @param fmt If non-NULL, force the file format to use.
812 * @param buf_size optional buffer size (zero if default is OK)
813 * @param ap Additional parameters needed when opening the file
815 * @return 0 if OK, AVERROR_xxx otherwise
817 int av_open_input_file(AVFormatContext
**ic_ptr
, const char *filename
,
820 AVFormatParameters
*ap
);
822 * Allocate an AVFormatContext.
823 * Can be freed with av_free() but do not forget to free everything you
824 * explicitly allocated as well!
826 AVFormatContext
*av_alloc_format_context(void);
829 * Read packets of a media file to get stream information. This
830 * is useful for file formats with no headers such as MPEG. This
831 * function also computes the real frame rate in case of MPEG-2 repeat
833 * The logical file position is not changed by this function;
834 * examined packets may be buffered for later processing.
836 * @param ic media file handle
837 * @return >=0 if OK, AVERROR_xxx on error
838 * @todo Let the user decide somehow what information is needed so that
839 * we do not waste time getting stuff the user does not need.
841 int av_find_stream_info(AVFormatContext
*ic
);
844 * Read a transport packet from a media file.
846 * This function is obsolete and should never be used.
847 * Use av_read_frame() instead.
849 * @param s media file handle
850 * @param pkt is filled
851 * @return 0 if OK, AVERROR_xxx on error
853 int av_read_packet(AVFormatContext
*s
, AVPacket
*pkt
);
856 * Return the next frame of a stream.
858 * The returned packet is valid
859 * until the next av_read_frame() or until av_close_input_file() and
860 * must be freed with av_free_packet. For video, the packet contains
861 * exactly one frame. For audio, it contains an integer number of
862 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
863 * data). If the audio frames have a variable size (e.g. MPEG audio),
864 * then it contains one frame.
866 * pkt->pts, pkt->dts and pkt->duration are always set to correct
867 * values in AVStream.timebase units (and guessed if the format cannot
868 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
869 * has B-frames, so it is better to rely on pkt->dts if you do not
870 * decompress the payload.
872 * @return 0 if OK, < 0 on error or end of file
874 int av_read_frame(AVFormatContext
*s
, AVPacket
*pkt
);
877 * Seek to the key frame at timestamp.
878 * 'timestamp' in 'stream_index'.
879 * @param stream_index If stream_index is (-1), a default
880 * stream is selected, and timestamp is automatically converted
881 * from AV_TIME_BASE units to the stream specific time_base.
882 * @param timestamp Timestamp in AVStream.time_base units
883 * or, if no stream is specified, in AV_TIME_BASE units.
884 * @param flags flags which select direction and seeking mode
885 * @return >= 0 on success
887 int av_seek_frame(AVFormatContext
*s
, int stream_index
, int64_t timestamp
,
891 * Start playing a network based stream (e.g. RTSP stream) at the
894 int av_read_play(AVFormatContext
*s
);
897 * Pause a network based stream (e.g. RTSP stream).
899 * Use av_read_play() to resume it.
901 int av_read_pause(AVFormatContext
*s
);
904 * Free a AVFormatContext allocated by av_open_input_stream.
905 * @param s context to free
907 void av_close_input_stream(AVFormatContext
*s
);
910 * Close a media file (but not its codecs).
912 * @param s media file handle
914 void av_close_input_file(AVFormatContext
*s
);
917 * Add a new stream to a media file.
919 * Can only be called in the read_header() function. If the flag
920 * AVFMTCTX_NOHEADER is in the format context, then new streams
921 * can be added in read_packet too.
923 * @param s media file handle
924 * @param id file-format-dependent stream ID
926 AVStream
*av_new_stream(AVFormatContext
*s
, int id
);
927 AVProgram
*av_new_program(AVFormatContext
*s
, int id
);
931 * This function is NOT part of the public API
932 * and should ONLY be used by demuxers.
934 * @param s media file handle
935 * @param id unique ID for this chapter
936 * @param start chapter start time in time_base units
937 * @param end chapter end time in time_base units
938 * @param title chapter title
940 * @return AVChapter or NULL on error
942 AVChapter
*ff_new_chapter(AVFormatContext
*s
, int id
, AVRational time_base
,
943 int64_t start
, int64_t end
, const char *title
);
946 * Set the pts for a given stream.
949 * @param pts_wrap_bits number of bits effectively used by the pts
950 * (used for wrap control, 33 is the value for MPEG)
951 * @param pts_num numerator to convert to seconds (MPEG: 1)
952 * @param pts_den denominator to convert to seconds (MPEG: 90000)
954 void av_set_pts_info(AVStream
*s
, int pts_wrap_bits
,
955 int pts_num
, int pts_den
);
957 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
958 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
959 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
961 int av_find_default_stream_index(AVFormatContext
*s
);
964 * Gets the index for a specific timestamp.
965 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
966 * to the timestamp which is <= the requested one, if backward
967 * is 0, then it will be >=
968 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
969 * @return < 0 if no such timestamp could be found
971 int av_index_search_timestamp(AVStream
*st
, int64_t timestamp
, int flags
);
974 * Ensures the index uses less memory than the maximum specified in
975 * AVFormatContext.max_index_size, by discarding entries if it grows
977 * This function is not part of the public API and should only be called
980 void ff_reduce_index(AVFormatContext
*s
, int stream_index
);
983 * Add an index entry into a sorted list. Update the entry if the list
984 * already contains it.
986 * @param timestamp timestamp in the time base of the given stream
988 int av_add_index_entry(AVStream
*st
, int64_t pos
, int64_t timestamp
,
989 int size
, int distance
, int flags
);
992 * Does a binary search using av_index_search_timestamp() and
993 * AVCodec.read_timestamp().
994 * This is not supposed to be called directly by a user application,
996 * @param target_ts target timestamp in the time base of the given stream
997 * @param stream_index stream number
999 int av_seek_frame_binary(AVFormatContext
*s
, int stream_index
,
1000 int64_t target_ts
, int flags
);
1003 * Updates cur_dts of all streams based on the given timestamp and AVStream.
1005 * Stream ref_st unchanged, others set cur_dts in their native time base.
1006 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1007 * @param timestamp new dts expressed in time_base of param ref_st
1008 * @param ref_st reference stream giving time_base of param timestamp
1010 void av_update_cur_dts(AVFormatContext
*s
, AVStream
*ref_st
, int64_t timestamp
);
1013 * Does a binary search using read_timestamp().
1014 * This is not supposed to be called directly by a user application,
1016 * @param target_ts target timestamp in the time base of the given stream
1017 * @param stream_index stream number
1019 int64_t av_gen_search(AVFormatContext
*s
, int stream_index
,
1020 int64_t target_ts
, int64_t pos_min
,
1021 int64_t pos_max
, int64_t pos_limit
,
1022 int64_t ts_min
, int64_t ts_max
,
1023 int flags
, int64_t *ts_ret
,
1024 int64_t (*read_timestamp
)(struct AVFormatContext
*, int , int64_t *, int64_t ));
1026 /** media file output */
1027 int av_set_parameters(AVFormatContext
*s
, AVFormatParameters
*ap
);
1030 * Allocate the stream private data and write the stream header to an
1031 * output media file.
1033 * @param s media file handle
1034 * @return 0 if OK, AVERROR_xxx on error
1036 int av_write_header(AVFormatContext
*s
);
1039 * Write a packet to an output media file.
1041 * The packet shall contain one audio or video frame.
1042 * The packet must be correctly interleaved according to the container
1043 * specification, if not then av_interleaved_write_frame must be used.
1045 * @param s media file handle
1046 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1048 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1050 int av_write_frame(AVFormatContext
*s
, AVPacket
*pkt
);
1053 * Writes a packet to an output media file ensuring correct interleaving.
1055 * The packet must contain one audio or video frame.
1056 * If the packets are already correctly interleaved the application should
1057 * call av_write_frame() instead as it is slightly faster. It is also important
1058 * to keep in mind that completely non-interleaved input will need huge amounts
1059 * of memory to interleave with this, so it is preferable to interleave at the
1062 * @param s media file handle
1063 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1065 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1067 int av_interleaved_write_frame(AVFormatContext
*s
, AVPacket
*pkt
);
1070 * Interleave a packet per dts in an output media file.
1072 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1073 * function, so they cannot be used after it, note calling av_free_packet()
1074 * on them is still safe.
1076 * @param s media file handle
1077 * @param out the interleaved packet will be output here
1078 * @param in the input packet
1079 * @param flush 1 if no further packets are available as input and all
1080 * remaining packets should be output
1081 * @return 1 if a packet was output, 0 if no packet could be output,
1082 * < 0 if an error occurred
1084 int av_interleave_packet_per_dts(AVFormatContext
*s
, AVPacket
*out
,
1085 AVPacket
*pkt
, int flush
);
1088 * @brief Write the stream trailer to an output media file and
1089 * free the file private data.
1091 * May only be called after a successful call to av_write_header.
1093 * @param s media file handle
1094 * @return 0 if OK, AVERROR_xxx on error
1096 int av_write_trailer(AVFormatContext
*s
);
1098 void dump_format(AVFormatContext
*ic
,
1103 #if LIBAVFORMAT_VERSION_MAJOR < 53
1105 * Parses width and height out of string str.
1106 * @deprecated Use av_parse_video_frame_size instead.
1108 attribute_deprecated
int parse_image_size(int *width_ptr
, int *height_ptr
,
1112 * Converts frame rate from string to a fraction.
1113 * @deprecated Use av_parse_video_frame_rate instead.
1115 attribute_deprecated
int parse_frame_rate(int *frame_rate
, int *frame_rate_base
,
1120 * Parses \p datestr and returns a corresponding number of microseconds.
1121 * @param datestr String representing a date or a duration.
1122 * - If a date the syntax is:
1124 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1126 * Time is local time unless Z is appended, in which case it is
1127 * interpreted as UTC.
1128 * If the year-month-day part is not specified it takes the current
1130 * Returns the number of microseconds since 1st of January, 1970 up to
1131 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1132 * successfully parsed.
1133 * - If a duration the syntax is:
1135 * [-]HH[:MM[:SS[.m...]]]
1138 * Returns the number of microseconds contained in a time interval
1139 * with the specified duration or INT64_MIN if \p datestr cannot be
1140 * successfully parsed.
1141 * @param duration Flag which tells how to interpret \p datestr, if
1142 * not zero \p datestr is interpreted as a duration, otherwise as a
1145 int64_t parse_date(const char *datestr
, int duration
);
1147 /** Gets the current time in microseconds. */
1148 int64_t av_gettime(void);
1150 /* ffm-specific for ffserver */
1151 #define FFM_PACKET_SIZE 4096
1152 int64_t ffm_read_write_index(int fd
);
1153 void ffm_write_write_index(int fd
, int64_t pos
);
1154 void ffm_set_write_index(AVFormatContext
*s
, int64_t pos
, int64_t file_size
);
1157 * Attempts to find a specific tag in a URL.
1159 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1160 * Return 1 if found.
1162 int find_info_tag(char *arg
, int arg_size
, const char *tag1
, const char *info
);
1165 * Returns in 'buf' the path with '%d' replaced by number.
1167 * Also handles the '%0nd' format where 'n' is the total number
1168 * of digits and '%%'.
1170 * @param buf destination buffer
1171 * @param buf_size destination buffer size
1172 * @param path numbered sequence string
1173 * @param number frame number
1174 * @return 0 if OK, -1 on format error
1176 int av_get_frame_filename(char *buf
, int buf_size
,
1177 const char *path
, int number
);
1180 * Check whether filename actually is a numbered sequence generator.
1182 * @param filename possible numbered sequence string
1183 * @return 1 if a valid numbered sequence string, 0 otherwise
1185 int av_filename_number_test(const char *filename
);
1188 * Generate an SDP for an RTP session.
1190 * @param ac array of AVFormatContexts describing the RTP streams. If the
1191 * array is composed by only one context, such context can contain
1192 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1193 * all the contexts in the array (an AVCodecContext per RTP stream)
1194 * must contain only one AVStream.
1195 * @param n_files number of AVCodecContexts contained in ac
1196 * @param buff buffer where the SDP will be stored (must be allocated by
1198 * @param size the size of the buffer
1199 * @return 0 if OK, AVERROR_xxx on error
1201 int avf_sdp_create(AVFormatContext
*ac
[], int n_files
, char *buff
, int size
);
1204 * Try to open an external stream. This function is not part of the
1205 * public API and should only be used by demuxers.
1207 AVFormatContext
*ff_open_external_stream(AVFormatContext
*s
, const char *filename
);
1209 #ifdef HAVE_AV_CONFIG_H
1211 void ff_dynarray_add(unsigned long **tab_ptr
, int *nb_ptr
, unsigned long elem
);
1214 #define dynarray_add(tab, nb_ptr, elem)\
1216 __typeof__(tab) _tab = (tab);\
1217 __typeof__(elem) _elem = (elem);\
1218 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1219 ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1222 #define dynarray_add(tab, nb_ptr, elem)\
1224 ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1228 time_t mktimegm(struct tm
*tm
);
1229 struct tm
*brktimegm(time_t secs
, struct tm
*tm
);
1230 const char *small_strptime(const char *p
, const char *fmt
,
1234 int resolve_host(struct in_addr
*sin_addr
, const char *hostname
);
1236 void url_split(char *proto
, int proto_size
,
1237 char *authorization
, int authorization_size
,
1238 char *hostname
, int hostname_size
,
1240 char *path
, int path_size
,
1243 int match_ext(const char *filename
, const char *extensions
);
1245 #endif /* HAVE_AV_CONFIG_H */
1247 #endif /* AVFORMAT_AVFORMAT_H */