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 21
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"
49 /* packet functions */
51 typedef struct AVPacket {
53 * Presentation time stamp in time_base units.
54 * This is the time at which the decompressed packet will be presented
56 * Can be AV_NOPTS_VALUE if it is not stored in the file.
57 * pts MUST be larger or equal to dts as presentation can not happen before
58 * decompression, unless one wants to view hex dumps. Some formats misuse
59 * the terms dts and pts/cts to mean something different, these timestamps
60 * must be converted to true pts/dts before they are stored in AVPacket.
64 * Decompression time stamp in time_base units.
65 * This is the time at which the packet is decompressed.
66 * Can be AV_NOPTS_VALUE if it is not stored in the file.
74 * Duration of this packet in time_base units, 0 if unknown.
75 * Equals next_pts - this_pts in presentation order.
78 void (*destruct)(struct AVPacket *);
80 int64_t pos; ///< byte position in stream, -1 if unknown
82 #define PKT_FLAG_KEY 0x0001
84 void av_destruct_packet_nofree(AVPacket *pkt);
87 * Default packet destructor.
89 void av_destruct_packet(AVPacket *pkt);
92 * Initialize optional fields of a packet to default values.
96 void av_init_packet(AVPacket *pkt);
99 * Allocate the payload of a packet and initialize its fields to default values.
102 * @param size wanted payload size
103 * @return 0 if OK. AVERROR_xxx otherwise.
105 int av_new_packet(AVPacket *pkt, int size);
108 * Allocate and read the payload of a packet and initialize its fields to default values.
111 * @param size wanted payload size
112 * @return >0 (read size) if OK. AVERROR_xxx otherwise.
114 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
117 * @warning This is a hack - the packet memory allocation stuff is broken. The
118 * packet is allocated if it was not really allocated
120 int av_dup_packet(AVPacket *pkt);
125 * @param pkt packet to free
127 static inline void av_free_packet(AVPacket *pkt)
129 if (pkt && pkt->destruct) {
134 /*************************************************/
135 /* fractional numbers for exact pts handling */
138 * the exact value of the fractional number is: 'val + num / den'.
139 * num is assumed to be such as 0 <= num < den
140 * @deprecated Use AVRational instead
142 typedef struct AVFrac {
143 int64_t val, num, den;
144 } AVFrac attribute_deprecated;
146 /*************************************************/
147 /* input/output formats */
151 struct AVFormatContext;
153 /** this structure contains the data a format has to probe a file */
154 typedef struct AVProbeData {
155 const char *filename;
160 #define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
161 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
163 typedef struct AVFormatParameters {
164 AVRational time_base;
169 enum PixelFormat pix_fmt;
170 int channel; /**< used to select dv channel */
171 const char *standard; /**< tv standard, NTSC, PAL, SECAM */
172 unsigned int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
173 unsigned int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
174 stream packet (only meaningful if
175 mpeg2ts_raw is TRUE) */
176 unsigned int initial_pause:1; /**< do not begin to play the stream
177 immediately (RTSP only) */
178 unsigned int prealloced_context:1;
179 #if LIBAVFORMAT_VERSION_INT < (53<<16)
180 enum CodecID video_codec_id;
181 enum CodecID audio_codec_id;
183 } AVFormatParameters;
185 //! demuxer will use url_fopen, no opened file should be provided by the caller
186 #define AVFMT_NOFILE 0x0001
187 #define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
188 #define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
189 #define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
191 #define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
192 #define AVFMT_NOTIMESTAMPS 0x0080 /**< format does not need / have any timestamps */
193 #define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
194 #define AVFMT_TS_DISCONT 0x0200 /**< format allows timestamo discontinuities */
196 typedef struct AVOutputFormat {
199 * Descriptive name for the format, meant to be more human-readable
200 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
203 const char *long_name;
204 const char *mime_type;
205 const char *extensions; /**< comma separated filename extensions */
206 /** size of private data so that it can be allocated in the wrapper */
209 enum CodecID audio_codec; /**< default audio codec */
210 enum CodecID video_codec; /**< default video codec */
211 int (*write_header)(struct AVFormatContext *);
212 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
213 int (*write_trailer)(struct AVFormatContext *);
214 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
216 /** currently only used to set pixel format if not YUV420P */
217 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
218 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
221 * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
222 * the arrays are all CODEC_ID_NONE terminated
224 const struct AVCodecTag * const *codec_tag;
226 enum CodecID subtitle_codec; /**< default subtitle codec */
229 struct AVOutputFormat *next;
232 typedef struct AVInputFormat {
235 * Descriptive name for the format, meant to be more human-readable
236 * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
239 const char *long_name;
240 /** size of private data so that it can be allocated in the wrapper */
243 * Tell if a given file has a chance of being parsed by this format.
244 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
245 * big so you do not have to check for that unless you need more.
247 int (*read_probe)(AVProbeData *);
248 /** read the format header and initialize the AVFormatContext
249 structure. Return 0 if OK. 'ap' if non NULL contains
250 additional paramters. Only used in raw format right
251 now. 'av_new_stream' should be called to create new streams. */
252 int (*read_header)(struct AVFormatContext *,
253 AVFormatParameters *ap);
254 /** read one packet and put it in 'pkt'. pts and flags are also
255 set. 'av_new_stream' can be called only if the flag
256 AVFMTCTX_NOHEADER is used. */
257 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
258 /** close the stream. The AVFormatContext and AVStreams are not
259 freed by this function */
260 int (*read_close)(struct AVFormatContext *);
262 * seek to a given timestamp relative to the frames in
263 * stream component stream_index
264 * @param stream_index must not be -1
265 * @param flags selects which direction should be preferred if no exact
267 * @return >= 0 on success (but not necessarily the new offset)
269 int (*read_seek)(struct AVFormatContext *,
270 int stream_index, int64_t timestamp, int flags);
272 * gets the next timestamp in stream[stream_index].time_base units.
273 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
275 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
276 int64_t *pos, int64_t pos_limit);
277 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
279 /** if extensions are defined, then no probe is done. You should
280 usually not use extension format guessing because it is not
282 const char *extensions;
283 /** general purpose read only value that the format can use */
286 /** start/resume playing - only meaningful if using a network based format
288 int (*read_play)(struct AVFormatContext *);
290 /** pause playing - only meaningful if using a network based format
292 int (*read_pause)(struct AVFormatContext *);
294 const struct AVCodecTag * const *codec_tag;
297 struct AVInputFormat *next;
300 enum AVStreamParseType {
302 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
303 AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */
304 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */
307 typedef struct AVIndexEntry {
310 #define AVINDEX_KEYFRAME 0x0001
312 int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs 32 byte due to possible 8byte align).
313 int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
316 #define AV_DISPOSITION_DEFAULT 0x0001
317 #define AV_DISPOSITION_DUB 0x0002
318 #define AV_DISPOSITION_ORIGINAL 0x0004
319 #define AV_DISPOSITION_COMMENT 0x0008
320 #define AV_DISPOSITION_LYRICS 0x0010
321 #define AV_DISPOSITION_KARAOKE 0x0020
325 * New fields can be added to the end with minor version bumps.
326 * Removal, reordering and changes to existing fields require a major
328 * sizeof(AVStream) must not be used outside libav*.
330 typedef struct AVStream {
331 int index; /**< stream index in AVFormatContext */
332 int id; /**< format specific stream id */
333 AVCodecContext *codec; /**< codec context */
335 * Real base frame rate of the stream.
336 * This is the lowest frame rate with which all timestamps can be
337 * represented accurately (it is the least common multiple of all
338 * frame rates in the stream), Note, this value is just a guess!
339 * For example if the timebase is 1/90000 and all frames have either
340 * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1.
342 AVRational r_frame_rate;
345 /* internal data used in av_find_stream_info() */
347 /** encoding: PTS generation when outputing stream */
351 * This is the fundamental unit of time (in seconds) in terms
352 * of which frame timestamps are represented. For fixed-fps content,
353 * timebase should be 1/frame rate and timestamp increments should be
356 AVRational time_base;
357 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
358 /* ffmpeg.c private use */
359 int stream_copy; /**< if set, just copy stream */
360 enum AVDiscard discard; ///< selects which packets can be discarded at will and do not need to be demuxed
361 //FIXME move stuff to a flags field?
362 /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
363 * MN: dunno if that is the right place for it */
366 * Decoding: pts of the first frame of the stream, in stream time base.
367 * Only set this if you are absolutely 100% sure that the value you set
368 * it to really is the pts of the first frame.
369 * This may be undefined (AV_NOPTS_VALUE).
370 * @note The ASF header does NOT contain a correct start_time the ASF
371 * demuxer must NOT set this.
375 * Decoding: duration of the stream, in stream time base.
376 * If a source file does not specify a duration, but does specify
377 * a bitrate, this value will be estimates from bit rate and file size.
381 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
383 /* av_read_frame() support */
384 enum AVStreamParseType need_parsing;
385 struct AVCodecParserContext *parser;
388 int last_IP_duration;
390 /* av_seek_frame() support */
391 AVIndexEntry *index_entries; /**< only used if the format does not
392 support seeking natively */
393 int nb_index_entries;
394 unsigned int index_entries_allocated_size;
396 int64_t nb_frames; ///< number of frames in this stream if known or 0
398 #if LIBAVFORMAT_VERSION_INT < (53<<16)
402 char *filename; /**< source filename of the stream */
404 int disposition; /**< AV_DISPOSITION_* bitfield */
406 AVProbeData probe_data;
407 #define MAX_REORDER_DELAY 16
408 int64_t pts_buffer[MAX_REORDER_DELAY+1];
411 * sample aspect ratio (0 if unknown)
412 * - encoding: Set by user.
413 * - decoding: Set by libavformat.
415 AVRational sample_aspect_ratio;
418 #define AV_PROGRAM_RUNNING 1
421 * New fields can be added to the end with minor version bumps.
422 * Removal, reordering and changes to existing fields require a major
424 * sizeof(AVProgram) must not be used outside libav*.
426 typedef struct AVProgram {
428 char *provider_name; ///< Network name for DVB streams
429 char *name; ///< Service name for DVB streams
431 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
432 unsigned int *stream_index;
433 unsigned int nb_stream_indexes;
436 #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
437 (streams are added dynamically) */
439 typedef struct AVChapter {
440 int id; ///< Unique id to identify the chapter
441 AVRational time_base; ///< Timebase in which the start/end timestamps are specified
442 int64_t start, end; ///< chapter start/end time in time_base units
443 char *title; ///< chapter title
446 #define MAX_STREAMS 20
449 * format I/O context.
450 * New fields can be added to the end with minor version bumps.
451 * Removal, reordering and changes to existing fields require a major
453 * sizeof(AVFormatContext) must not be used outside libav*.
455 typedef struct AVFormatContext {
456 const AVClass *av_class; /**< set by av_alloc_format_context */
457 /* can only be iformat or oformat, not both at the same time */
458 struct AVInputFormat *iformat;
459 struct AVOutputFormat *oformat;
462 unsigned int nb_streams;
463 AVStream *streams[MAX_STREAMS];
464 char filename[1024]; /**< input or output filename */
472 int year; /**< ID3 year, 0 if none */
473 int track; /**< track number, 0 if none */
474 char genre[32]; /**< ID3 genre */
476 int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
477 /* private data for pts handling (do not modify directly) */
478 /** This buffer is only needed when packets were already buffered but
479 not decoded, for example to get the codec parameters in mpeg
481 struct AVPacketList *packet_buffer;
483 /** decoding: position of the first frame of the component, in
484 AV_TIME_BASE fractional seconds. NEVER set this value directly:
485 it is deduced from the AVStream values. */
487 /** decoding: duration of the stream, in AV_TIME_BASE fractional
488 seconds. NEVER set this value directly: it is deduced from the
491 /** decoding: total file size. 0 if unknown */
493 /** decoding: total stream bitrate in bit/s, 0 if not
494 available. Never set it directly if the file_size and the
495 duration are known as ffmpeg can compute it automatically. */
498 /* av_read_frame() support */
500 const uint8_t *cur_ptr;
504 /* av_seek_frame() support */
505 int64_t data_offset; /** offset of the first packet */
513 #define AVFMT_NOOUTPUTLOOP -1
514 #define AVFMT_INFINITEOUTPUTLOOP 0
515 /** number of times to loop output in formats that support it */
519 #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
520 #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
521 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input
524 /** decoding: size of data to probe; encoding unused */
525 unsigned int probesize;
528 * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
530 int max_analyze_duration;
535 unsigned int nb_programs;
536 AVProgram **programs;
539 * Forced video codec_id.
540 * demuxing: set by user
542 enum CodecID video_codec_id;
544 * Forced audio codec_id.
545 * demuxing: set by user
547 enum CodecID audio_codec_id;
549 * Forced subtitle codec_id.
550 * demuxing: set by user
552 enum CodecID subtitle_codec_id;
555 * Maximum amount of memory in bytes to use per stream for the index.
556 * If the needed index exceeds this size entries will be discarded as
557 * needed to maintain a smaller size. This can lead to slower or less
558 * accurate seeking (depends on demuxer).
559 * Demuxers for which a full in memory index is mandatory will ignore
562 * demuxing: set by user
564 unsigned int max_index_size;
567 * Maximum amount of memory in bytes to use for buffering frames
568 * obtained from real-time capture devices.
570 unsigned int max_picture_buffer;
572 unsigned int nb_chapters;
573 AVChapter **chapters;
576 * Flags to enable debuging.
579 #define FF_FDEBUG_TS 0x0001
582 * raw packets from the demuxer, prior to parsing and decoding.
583 * This buffer is used for buffering packets until the codec can
584 * be identified, as parsing cannot be done without knowing the
587 struct AVPacketList *raw_packet_buffer;
588 struct AVPacketList *raw_packet_buffer_end;
590 struct AVPacketList *packet_buffer_end;
593 typedef struct AVPacketList {
595 struct AVPacketList *next;
598 #if LIBAVFORMAT_VERSION_INT < (53<<16)
599 extern AVInputFormat *first_iformat;
600 extern AVOutputFormat *first_oformat;
603 AVInputFormat *av_iformat_next(AVInputFormat *f);
604 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
606 enum CodecID av_guess_image2_codec(const char *filename);
608 /* XXX: use automatic init with either ELF sections or C file parser */
612 void av_register_input_format(AVInputFormat *format);
613 void av_register_output_format(AVOutputFormat *format);
614 AVOutputFormat *guess_stream_format(const char *short_name,
615 const char *filename, const char *mime_type);
616 AVOutputFormat *guess_format(const char *short_name,
617 const char *filename, const char *mime_type);
620 * Guesses the codec id based upon muxer and filename.
622 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
623 const char *filename, const char *mime_type, enum CodecType type);
626 * Send a nice hexadecimal dump of a buffer to the specified file stream.
628 * @param f The file stream pointer where the dump should be sent to.
630 * @param size buffer size
632 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
634 void av_hex_dump(FILE *f, uint8_t *buf, int size);
637 * Send a nice hexadecimal dump of a buffer to the log.
639 * @param avcl A pointer to an arbitrary struct of which the first field is a
640 * pointer to an AVClass struct.
641 * @param level The importance level of the message, lower values signifying
644 * @param size buffer size
646 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
648 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
651 * Send a nice dump of a packet to the specified file stream.
653 * @param f The file stream pointer where the dump should be sent to.
654 * @param pkt packet to dump
655 * @param dump_payload true if the payload must be displayed too
657 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
660 * Send a nice dump of a packet to the log.
662 * @param avcl A pointer to an arbitrary struct of which the first field is a
663 * pointer to an AVClass struct.
664 * @param level The importance level of the message, lower values signifying
666 * @param pkt packet to dump
667 * @param dump_payload true if the payload must be displayed too
669 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
671 void av_register_all(void);
673 /** codec tag <-> codec id */
674 enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
675 unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
677 /* media file input */
680 * finds AVInputFormat based on input format's short name.
682 AVInputFormat *av_find_input_format(const char *short_name);
687 * @param is_opened whether the file is already opened, determines whether
688 * demuxers with or without AVFMT_NOFILE are probed
690 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
693 * Allocates all the structures needed to read an input stream.
694 * This does not open the needed codecs for decoding the stream[s].
696 int av_open_input_stream(AVFormatContext **ic_ptr,
697 ByteIOContext *pb, const char *filename,
698 AVInputFormat *fmt, AVFormatParameters *ap);
701 * Open a media file as input. The codecs are not opened. Only the file
702 * header (if present) is read.
704 * @param ic_ptr the opened media file handle is put here
705 * @param filename filename to open.
706 * @param fmt if non NULL, force the file format to use
707 * @param buf_size optional buffer size (zero if default is OK)
708 * @param ap additional parameters needed when opening the file (NULL if default)
709 * @return 0 if OK. AVERROR_xxx otherwise.
711 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
714 AVFormatParameters *ap);
716 * Allocate an AVFormatContext.
717 * Can be freed with av_free() but do not forget to free everything you
718 * explicitly allocated as well!
720 AVFormatContext *av_alloc_format_context(void);
723 * Read packets of a media file to get stream information. This
724 * is useful for file formats with no headers such as MPEG. This
725 * function also computes the real frame rate in case of mpeg2 repeat
727 * The logical file position is not changed by this function;
728 * examined packets may be buffered for later processing.
730 * @param ic media file handle
731 * @return >=0 if OK. AVERROR_xxx if error.
732 * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
734 int av_find_stream_info(AVFormatContext *ic);
737 * Read a transport packet from a media file.
739 * This function is obsolete and should never be used.
740 * Use av_read_frame() instead.
742 * @param s media file handle
743 * @param pkt is filled
744 * @return 0 if OK. AVERROR_xxx if error.
746 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
749 * Return the next frame of a stream.
751 * The returned packet is valid
752 * until the next av_read_frame() or until av_close_input_file() and
753 * must be freed with av_free_packet. For video, the packet contains
754 * exactly one frame. For audio, it contains an integer number of
755 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
756 * data). If the audio frames have a variable size (e.g. MPEG audio),
757 * then it contains one frame.
759 * pkt->pts, pkt->dts and pkt->duration are always set to correct
760 * values in AVStream.timebase units (and guessed if the format cannot
761 * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
762 * has B frames, so it is better to rely on pkt->dts if you do not
763 * decompress the payload.
765 * @return 0 if OK, < 0 if error or end of file.
767 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
770 * Seek to the key frame at timestamp.
771 * 'timestamp' in 'stream_index'.
772 * @param stream_index If stream_index is (-1), a default
773 * stream is selected, and timestamp is automatically converted
774 * from AV_TIME_BASE units to the stream specific time_base.
775 * @param timestamp timestamp in AVStream.time_base units
776 * or if there is no stream specified then in AV_TIME_BASE units
777 * @param flags flags which select direction and seeking mode
778 * @return >= 0 on success
780 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
783 * start playing a network based stream (e.g. RTSP stream) at the
786 int av_read_play(AVFormatContext *s);
789 * Pause a network based stream (e.g. RTSP stream).
791 * Use av_read_play() to resume it.
793 int av_read_pause(AVFormatContext *s);
796 * Free a AVFormatContext allocated by av_open_input_stream.
797 * @param s context to free
799 void av_close_input_stream(AVFormatContext *s);
802 * Close a media file (but not its codecs).
804 * @param s media file handle
806 void av_close_input_file(AVFormatContext *s);
809 * Add a new stream to a media file.
811 * Can only be called in the read_header() function. If the flag
812 * AVFMTCTX_NOHEADER is in the format context, then new streams
813 * can be added in read_packet too.
815 * @param s media file handle
816 * @param id file format dependent stream id
818 AVStream *av_new_stream(AVFormatContext *s, int id);
819 AVProgram *av_new_program(AVFormatContext *s, int id);
823 * This function is NOT part of the public API
824 * and should be ONLY used by demuxers.
826 * @param s media file handle
827 * @param id unique id for this chapter
828 * @param start chapter start time in time_base units
829 * @param end chapter end time in time_base units
830 * @param title chapter title
832 * @return AVChapter or NULL if error.
834 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
837 * Set the pts for a given stream.
840 * @param pts_wrap_bits number of bits effectively used by the pts
841 * (used for wrap control, 33 is the value for MPEG)
842 * @param pts_num numerator to convert to seconds (MPEG: 1)
843 * @param pts_den denominator to convert to seconds (MPEG: 90000)
845 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
846 int pts_num, int pts_den);
848 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
849 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
850 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
852 int av_find_default_stream_index(AVFormatContext *s);
855 * Gets the index for a specific timestamp.
856 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
857 * the timestamp which is <= the requested one, if backward is 0
859 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
860 * @return < 0 if no such timestamp could be found
862 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
865 * Ensures the index uses less memory than the maximum specified in
866 * AVFormatContext.max_index_size, by discarding entries if it grows
868 * This function is not part of the public API and should only be called
871 void ff_reduce_index(AVFormatContext *s, int stream_index);
874 * Add a index entry into a sorted list updateing if it is already there.
876 * @param timestamp timestamp in the timebase of the given stream
878 int av_add_index_entry(AVStream *st,
879 int64_t pos, int64_t timestamp, int size, int distance, int flags);
882 * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
883 * This is not supposed to be called directly by a user application, but by demuxers.
884 * @param target_ts target timestamp in the time base of the given stream
885 * @param stream_index stream number
887 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
890 * Updates cur_dts of all streams based on given timestamp and AVStream.
892 * Stream ref_st unchanged, others set cur_dts in their native timebase
893 * only needed for timestamp wrapping or if (dts not set and pts!=dts).
894 * @param timestamp new dts expressed in time_base of param ref_st
895 * @param ref_st reference stream giving time_base of param timestamp
897 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
900 * Does a binary search using read_timestamp().
901 * This is not supposed to be called directly by a user application, but by demuxers.
902 * @param target_ts target timestamp in the time base of the given stream
903 * @param stream_index stream number
905 int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
907 /** media file output */
908 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
911 * Allocate the stream private data and write the stream header to an
914 * @param s media file handle
915 * @return 0 if OK. AVERROR_xxx if error.
917 int av_write_header(AVFormatContext *s);
920 * Write a packet to an output media file.
922 * The packet shall contain one audio or video frame.
923 * The packet must be correctly interleaved according to the container specification,
924 * if not then av_interleaved_write_frame must be used
926 * @param s media file handle
927 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
928 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
930 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
933 * Writes a packet to an output media file ensuring correct interleaving.
935 * The packet must contain one audio or video frame.
936 * If the packets are already correctly interleaved the application should
937 * call av_write_frame() instead as it is slightly faster. It is also important
938 * to keep in mind that completely non-interleaved input will need huge amounts
939 * of memory to interleave with this, so it is preferable to interleave at the
942 * @param s media file handle
943 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
944 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
946 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
949 * Interleave a packet per DTS in an output media file.
951 * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
952 * so they cannot be used after it, note calling av_free_packet() on them is still safe.
954 * @param s media file handle
955 * @param out the interleaved packet will be output here
956 * @param in the input packet
957 * @param flush 1 if no further packets are available as input and all
958 * remaining packets should be output
959 * @return 1 if a packet was output, 0 if no packet could be output,
960 * < 0 if an error occurred
962 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
965 * @brief Write the stream trailer to an output media file and
966 * free the file private data.
968 * @param s media file handle
969 * @return 0 if OK. AVERROR_xxx if error.
971 int av_write_trailer(AVFormatContext *s);
973 void dump_format(AVFormatContext *ic,
979 * parses width and height out of string str.
980 * @deprecated Use av_parse_video_frame_size instead.
982 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
985 * Converts frame rate from string to a fraction.
986 * @deprecated Use av_parse_video_frame_rate instead.
988 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
991 * Parses \p datestr and returns a corresponding number of microseconds.
992 * @param datestr String representing a date or a duration.
993 * - If a date the syntax is:
995 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
997 * Time is localtime unless Z is appended, in which case it is
998 * interpreted as UTC.
999 * If the year-month-day part isn't specified it takes the current
1001 * Returns the number of microseconds since 1st of January, 1970 up to
1002 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1003 * successfully parsed.
1004 * - If a duration the syntax is:
1006 * [-]HH[:MM[:SS[.m...]]]
1009 * Returns the number of microseconds contained in a time interval
1010 * with the specified duration or INT64_MIN if \p datestr cannot be
1011 * successfully parsed.
1012 * @param duration Flag which tells how to interpret \p datestr, if
1013 * not zero \p datestr is interpreted as a duration, otherwise as a
1016 int64_t parse_date(const char *datestr, int duration);
1018 int64_t av_gettime(void);
1020 /* ffm specific for ffserver */
1021 #define FFM_PACKET_SIZE 4096
1022 offset_t ffm_read_write_index(int fd);
1023 void ffm_write_write_index(int fd, offset_t pos);
1024 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
1027 * Attempts to find a specific tag in a URL.
1029 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1030 * Return 1 if found.
1032 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1035 * Returns in 'buf' the path with '%d' replaced by number.
1037 * Also handles the '%0nd' format where 'n' is the total number
1038 * of digits and '%%'.
1040 * @param buf destination buffer
1041 * @param buf_size destination buffer size
1042 * @param path numbered sequence string
1043 * @param number frame number
1044 * @return 0 if OK, -1 if format error.
1046 int av_get_frame_filename(char *buf, int buf_size,
1047 const char *path, int number);
1050 * Check whether filename actually is a numbered sequence generator.
1052 * @param filename possible numbered sequence string
1053 * @return 1 if a valid numbered sequence string, 0 otherwise.
1055 int av_filename_number_test(const char *filename);
1058 * Generate an SDP for an RTP session.
1060 * @param ac array of AVFormatContexts describing the RTP streams. If the
1061 * array is composed by only one context, such context can contain
1062 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1063 * all the contexts in the array (an AVCodecContext per RTP stream)
1064 * must contain only one AVStream
1065 * @param n_files number of AVCodecContexts contained in ac
1066 * @param buff buffer where the SDP will be stored (must be allocated by
1068 * @param size the size of the buffer
1069 * @return 0 if OK. AVERROR_xxx if error.
1071 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1073 #ifdef HAVE_AV_CONFIG_H
1075 void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1078 #define dynarray_add(tab, nb_ptr, elem)\
1080 typeof(tab) _tab = (tab);\
1081 typeof(elem) _elem = (elem);\
1082 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1083 ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1086 #define dynarray_add(tab, nb_ptr, elem)\
1088 ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1092 time_t mktimegm(struct tm *tm);
1093 struct tm *brktimegm(time_t secs, struct tm *tm);
1094 const char *small_strptime(const char *p, const char *fmt,
1098 int resolve_host(struct in_addr *sin_addr, const char *hostname);
1100 void url_split(char *proto, int proto_size,
1101 char *authorization, int authorization_size,
1102 char *hostname, int hostname_size,
1104 char *path, int path_size,
1107 int match_ext(const char *filename, const char *extensions);
1109 #endif /* HAVE_AV_CONFIG_H */
1111 #endif /* AVFORMAT_AVFORMAT_H */