00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AVFORMAT_AVFORMAT_H
00022 #define AVFORMAT_AVFORMAT_H
00023
00195 #include <time.h>
00196 #include <stdio.h>
00197 #include "libavcodec/avcodec.h"
00198 #include "libavutil/dict.h"
00199 #include "libavutil/log.h"
00200
00201 #include "avio.h"
00202 #include "libavformat/version.h"
00203
00204 #if FF_API_AV_GETTIME
00205 #include "libavutil/time.h"
00206 #endif
00207
00208 struct AVFormatContext;
00209
00210
00284
00285
00286
00295 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
00296
00297
00311 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
00312
00313
00314
00315
00320 typedef struct AVFrac {
00321 int64_t val, num, den;
00322 } AVFrac;
00323
00324
00325
00326
00327 struct AVCodecTag;
00328
00332 typedef struct AVProbeData {
00333 const char *filename;
00334 unsigned char *buf;
00335 int buf_size;
00336 } AVProbeData;
00337
00338 #define AVPROBE_SCORE_MAX 100
00339 #define AVPROBE_PADDING_SIZE 32
00340
00342 #define AVFMT_NOFILE 0x0001
00343 #define AVFMT_NEEDNUMBER 0x0002
00344 #define AVFMT_SHOW_IDS 0x0008
00345 #define AVFMT_RAWPICTURE 0x0020
00347 #define AVFMT_GLOBALHEADER 0x0040
00348 #define AVFMT_NOTIMESTAMPS 0x0080
00349 #define AVFMT_GENERIC_INDEX 0x0100
00350 #define AVFMT_TS_DISCONT 0x0200
00351 #define AVFMT_VARIABLE_FPS 0x0400
00352 #define AVFMT_NODIMENSIONS 0x0800
00353 #define AVFMT_NOSTREAMS 0x1000
00354 #define AVFMT_NOBINSEARCH 0x2000
00355 #define AVFMT_NOGENSEARCH 0x4000
00356 #define AVFMT_NO_BYTE_SEEK 0x8000
00357 #define AVFMT_ALLOW_FLUSH 0x10000
00358 #if LIBAVFORMAT_VERSION_MAJOR <= 54
00359 #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
00360 #else
00361 #define AVFMT_TS_NONSTRICT 0x20000
00362 #endif
00363
00367 #define AVFMT_SEEK_TO_PTS 0x4000000
00373 typedef struct AVOutputFormat {
00374 const char *name;
00380 const char *long_name;
00381 const char *mime_type;
00382 const char *extensions;
00383
00384 enum AVCodecID audio_codec;
00385 enum AVCodecID video_codec;
00386 enum AVCodecID subtitle_codec;
00393 int flags;
00394
00399 const struct AVCodecTag * const *codec_tag;
00400
00401
00402 const AVClass *priv_class;
00403
00404
00405
00406
00407
00408
00409
00410
00411 struct AVOutputFormat *next;
00415 int priv_data_size;
00416
00417 int (*write_header)(struct AVFormatContext *);
00425 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00426 int (*write_trailer)(struct AVFormatContext *);
00430 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00431 AVPacket *in, int flush);
00439 int (*query_codec)(enum AVCodecID id, int std_compliance);
00440
00441 void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
00442 int64_t *dts, int64_t *wall);
00443 } AVOutputFormat;
00452 typedef struct AVInputFormat {
00457 const char *name;
00458
00464 const char *long_name;
00465
00471 int flags;
00472
00478 const char *extensions;
00479
00480 const struct AVCodecTag * const *codec_tag;
00481
00482 const AVClass *priv_class;
00483
00484
00485
00486
00487
00488
00489
00490
00491 struct AVInputFormat *next;
00492
00496 int raw_codec_id;
00497
00501 int priv_data_size;
00502
00508 int (*read_probe)(AVProbeData *);
00509
00515 int (*read_header)(struct AVFormatContext *);
00516
00526 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00527
00532 int (*read_close)(struct AVFormatContext *);
00533
00542 int (*read_seek)(struct AVFormatContext *,
00543 int stream_index, int64_t timestamp, int flags);
00544
00549 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00550 int64_t *pos, int64_t pos_limit);
00551
00556 int (*read_play)(struct AVFormatContext *);
00557
00562 int (*read_pause)(struct AVFormatContext *);
00563
00570 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00571 } AVInputFormat;
00576 enum AVStreamParseType {
00577 AVSTREAM_PARSE_NONE,
00578 AVSTREAM_PARSE_FULL,
00579 AVSTREAM_PARSE_HEADERS,
00580 AVSTREAM_PARSE_TIMESTAMPS,
00581 AVSTREAM_PARSE_FULL_ONCE,
00582 AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'),
00585 };
00586
00587 typedef struct AVIndexEntry {
00588 int64_t pos;
00589 int64_t timestamp;
00595 #define AVINDEX_KEYFRAME 0x0001
00596 int flags:2;
00597 int size:30;
00598 int min_distance;
00599 } AVIndexEntry;
00600
00601 #define AV_DISPOSITION_DEFAULT 0x0001
00602 #define AV_DISPOSITION_DUB 0x0002
00603 #define AV_DISPOSITION_ORIGINAL 0x0004
00604 #define AV_DISPOSITION_COMMENT 0x0008
00605 #define AV_DISPOSITION_LYRICS 0x0010
00606 #define AV_DISPOSITION_KARAOKE 0x0020
00607
00613 #define AV_DISPOSITION_FORCED 0x0040
00614 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
00615 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
00616 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
00623 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
00624
00632 typedef struct AVStream {
00633 int index;
00639 int id;
00651 AVCodecContext *codec;
00652 #if FF_API_R_FRAME_RATE
00653
00661 AVRational r_frame_rate;
00662 #endif
00663 void *priv_data;
00664
00668 struct AVFrac pts;
00669
00679 AVRational time_base;
00680
00689 int64_t start_time;
00690
00696 int64_t duration;
00697
00698 int64_t nb_frames;
00699
00700 int disposition;
00702 enum AVDiscard discard;
00703
00709 AVRational sample_aspect_ratio;
00710
00711 AVDictionary *metadata;
00712
00716 AVRational avg_frame_rate;
00717
00725 AVPacket attached_pic;
00726
00727
00728
00729
00730
00731
00732
00733
00734
00738 #define MAX_STD_TIMEBASES (60*12+6)
00739 struct {
00740 int64_t last_dts;
00741 int64_t duration_gcd;
00742 int duration_count;
00743 double duration_error[2][2][MAX_STD_TIMEBASES];
00744 int64_t codec_info_duration;
00745 int found_decoder;
00746
00750 int64_t fps_first_dts;
00751 int fps_first_dts_idx;
00752 int64_t fps_last_dts;
00753 int fps_last_dts_idx;
00754
00755 } *info;
00756
00757 int pts_wrap_bits;
00759
00767 int64_t reference_dts;
00768 int64_t first_dts;
00769 int64_t cur_dts;
00770 int64_t last_IP_pts;
00771 int last_IP_duration;
00772
00776 #define MAX_PROBE_PACKETS 2500
00777 int probe_packets;
00778
00782 int codec_info_nb_frames;
00783
00789 int stream_identifier;
00790
00791 int64_t interleaver_chunk_size;
00792 int64_t interleaver_chunk_duration;
00793
00794
00795 enum AVStreamParseType need_parsing;
00796 struct AVCodecParserContext *parser;
00797
00801 struct AVPacketList *last_in_packet_buffer;
00802 AVProbeData probe_data;
00803 #define MAX_REORDER_DELAY 16
00804 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00805
00806 AVIndexEntry *index_entries;
00808 int nb_index_entries;
00809 unsigned int index_entries_allocated_size;
00810
00818 int request_probe;
00823 int skip_to_keyframe;
00824
00828 int skip_samples;
00829
00834 int nb_decoded_frames;
00835
00840 int64_t mux_ts_offset;
00841
00842 } AVStream;
00843
00844 #define AV_PROGRAM_RUNNING 1
00845
00852 typedef struct AVProgram {
00853 int id;
00854 int flags;
00855 enum AVDiscard discard;
00856 unsigned int *stream_index;
00857 unsigned int nb_stream_indexes;
00858 AVDictionary *metadata;
00859
00860 int program_num;
00861 int pmt_pid;
00862 int pcr_pid;
00863 } AVProgram;
00864
00865 #define AVFMTCTX_NOHEADER 0x0001
00868 typedef struct AVChapter {
00869 int id;
00870 AVRational time_base;
00871 int64_t start, end;
00872 AVDictionary *metadata;
00873 } AVChapter;
00874
00875
00880 enum AVDurationEstimationMethod {
00881 AVFMT_DURATION_FROM_PTS,
00882 AVFMT_DURATION_FROM_STREAM,
00883 AVFMT_DURATION_FROM_BITRATE
00884 };
00885
00894 typedef struct AVFormatContext {
00899 const AVClass *av_class;
00900
00907 struct AVInputFormat *iformat;
00908 struct AVOutputFormat *oformat;
00909
00914 void *priv_data;
00915
00927 AVIOContext *pb;
00928
00929
00930 int ctx_flags;
00941 unsigned int nb_streams;
00942 AVStream **streams;
00943
00944 char filename[1024];
00951 int64_t start_time;
00952
00959 int64_t duration;
00960
00966 int bit_rate;
00967
00968 unsigned int packet_size;
00969 int max_delay;
00970
00971 int flags;
00972 #define AVFMT_FLAG_GENPTS 0x0001
00973 #define AVFMT_FLAG_IGNIDX 0x0002
00974 #define AVFMT_FLAG_NONBLOCK 0x0004
00975 #define AVFMT_FLAG_IGNDTS 0x0008
00976 #define AVFMT_FLAG_NOFILLIN 0x0010
00977 #define AVFMT_FLAG_NOPARSE 0x0020
00978 #define AVFMT_FLAG_NOBUFFER 0x0040
00979 #define AVFMT_FLAG_CUSTOM_IO 0x0080
00980 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
00981 #define AVFMT_FLAG_MP4A_LATM 0x8000
00982 #define AVFMT_FLAG_SORT_DTS 0x10000
00983 #define AVFMT_FLAG_PRIV_OPT 0x20000
00984 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000
00985
00986
00989 unsigned int probesize;
00990
00995 int max_analyze_duration;
00996
00997 const uint8_t *key;
00998 int keylen;
00999
01000 unsigned int nb_programs;
01001 AVProgram **programs;
01002
01007 enum AVCodecID video_codec_id;
01008
01013 enum AVCodecID audio_codec_id;
01014
01019 enum AVCodecID subtitle_codec_id;
01020
01031 unsigned int max_index_size;
01032
01037 unsigned int max_picture_buffer;
01038
01039 unsigned int nb_chapters;
01040 AVChapter **chapters;
01041
01042 AVDictionary *metadata;
01043
01051 int64_t start_time_realtime;
01052
01056 int fps_probe_size;
01057
01064 int error_recognition;
01065
01075 AVIOInterruptCB interrupt_callback;
01076
01080 int debug;
01081 #define FF_FDEBUG_TS 0x0001
01082
01087 int ts_id;
01088
01095 int audio_preload;
01096
01103 int max_chunk_duration;
01104
01111 int max_chunk_size;
01112
01119 int use_wallclock_as_timestamps;
01120
01130 int avoid_negative_ts;
01131
01137 int avio_flags;
01138
01145 enum AVDurationEstimationMethod duration_estimation_method;
01146
01147
01148
01149
01150
01151
01152
01153
01154
01160 struct AVPacketList *packet_buffer;
01161 struct AVPacketList *packet_buffer_end;
01162
01163
01164 int64_t data_offset;
01172 struct AVPacketList *raw_packet_buffer;
01173 struct AVPacketList *raw_packet_buffer_end;
01177 struct AVPacketList *parse_queue;
01178 struct AVPacketList *parse_queue_end;
01182 #define RAW_PACKET_BUFFER_SIZE 2500000
01183 int raw_packet_buffer_remaining_size;
01184 } AVFormatContext;
01185
01191 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx);
01192
01193 typedef struct AVPacketList {
01194 AVPacket pkt;
01195 struct AVPacketList *next;
01196 } AVPacketList;
01197
01198
01211 unsigned avformat_version(void);
01212
01216 const char *avformat_configuration(void);
01217
01221 const char *avformat_license(void);
01222
01232 void av_register_all(void);
01233
01234 void av_register_input_format(AVInputFormat *format);
01235 void av_register_output_format(AVOutputFormat *format);
01236
01245 int avformat_network_init(void);
01246
01250 int avformat_network_deinit(void);
01251
01257 AVInputFormat *av_iformat_next(AVInputFormat *f);
01258
01264 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
01265
01271 AVFormatContext *avformat_alloc_context(void);
01272
01277 void avformat_free_context(AVFormatContext *s);
01278
01285 const AVClass *avformat_get_class(void);
01286
01302 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
01303
01304 AVProgram *av_new_program(AVFormatContext *s, int id);
01305
01311 #if FF_API_PKT_DUMP
01312 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
01313 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
01314 int dump_payload);
01315 #endif
01316
01317 #if FF_API_ALLOC_OUTPUT_CONTEXT
01318
01321 attribute_deprecated
01322 AVFormatContext *avformat_alloc_output_context(const char *format,
01323 AVOutputFormat *oformat,
01324 const char *filename);
01325 #endif
01326
01343 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
01344 const char *format_name, const char *filename);
01345
01354 AVInputFormat *av_find_input_format(const char *short_name);
01355
01362 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
01363
01375 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
01376
01384 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
01385
01401 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
01402 const char *filename, void *logctx,
01403 unsigned int offset, unsigned int max_probe_size);
01404
01424 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
01425
01426 attribute_deprecated
01427 int av_demuxer_open(AVFormatContext *ic);
01428
01429 #if FF_API_FORMAT_PARAMETERS
01430
01445 attribute_deprecated
01446 int av_find_stream_info(AVFormatContext *ic);
01447 #endif
01448
01470 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
01471
01482 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
01483
01508 int av_find_best_stream(AVFormatContext *ic,
01509 enum AVMediaType type,
01510 int wanted_stream_nb,
01511 int related_stream,
01512 AVCodec **decoder_ret,
01513 int flags);
01514
01515 #if FF_API_READ_PACKET
01516
01529 attribute_deprecated
01530 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
01531 #endif
01532
01557 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
01558
01570 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
01571 int flags);
01572
01599 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
01600
01605 int av_read_play(AVFormatContext *s);
01606
01612 int av_read_pause(AVFormatContext *s);
01613
01614 #if FF_API_CLOSE_INPUT_FILE
01615
01621 attribute_deprecated
01622 void av_close_input_file(AVFormatContext *s);
01623 #endif
01624
01629 void avformat_close_input(AVFormatContext **s);
01634 #if FF_API_NEW_STREAM
01635
01645 attribute_deprecated
01646 AVStream *av_new_stream(AVFormatContext *s, int id);
01647 #endif
01648
01649 #if FF_API_SET_PTS_INFO
01650
01653 attribute_deprecated
01654 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01655 unsigned int pts_num, unsigned int pts_den);
01656 #endif
01657
01658 #define AVSEEK_FLAG_BACKWARD 1
01659 #define AVSEEK_FLAG_BYTE 2
01660 #define AVSEEK_FLAG_ANY 4
01661 #define AVSEEK_FLAG_FRAME 8
01662
01663
01682 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
01683
01700 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01701
01728 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01729
01730 #if FF_API_INTERLEAVE_PACKET
01731
01735 attribute_deprecated
01736 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01737 AVPacket *pkt, int flush);
01738 #endif
01739
01749 int av_write_trailer(AVFormatContext *s);
01750
01763 AVOutputFormat *av_guess_format(const char *short_name,
01764 const char *filename,
01765 const char *mime_type);
01766
01770 enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
01771 const char *filename, const char *mime_type,
01772 enum AVMediaType type);
01773
01789 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
01790 int64_t *dts, int64_t *wall);
01791
01792
01816 void av_hex_dump(FILE *f, uint8_t *buf, int size);
01817
01830 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
01831
01840 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
01841
01842
01854 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
01855 AVStream *st);
01856
01864 enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
01865
01873 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
01874
01875 int av_find_default_stream_index(AVFormatContext *s);
01876
01885 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01886
01893 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01894 int size, int distance, int flags);
01895
01896
01916 void av_url_split(char *proto, int proto_size,
01917 char *authorization, int authorization_size,
01918 char *hostname, int hostname_size,
01919 int *port_ptr,
01920 char *path, int path_size,
01921 const char *url);
01922
01923
01924 void av_dump_format(AVFormatContext *ic,
01925 int index,
01926 const char *url,
01927 int is_output);
01928
01941 int av_get_frame_filename(char *buf, int buf_size,
01942 const char *path, int number);
01943
01950 int av_filename_number_test(const char *filename);
01951
01966 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
01967
01974 int av_match_ext(const char *filename, const char *extensions);
01975
01984 int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
01985
02001 const struct AVCodecTag *avformat_get_riff_video_tags(void);
02005 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
02006
02028 AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
02029
02043 int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
02044 const char *spec);
02045
02046 void avformat_queue_attached_pictures(AVFormatContext *s);
02047
02048
02053 #endif