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
00201 #include <time.h>
00202 #include <stdio.h>
00203 #include "libavcodec/avcodec.h"
00204 #include "libavutil/dict.h"
00205 #include "libavutil/log.h"
00206
00207 #include "avio.h"
00208 #include "libavformat/version.h"
00209
00210 #if FF_API_AV_GETTIME
00211 #include "libavutil/time.h"
00212 #endif
00213
00214 struct AVFormatContext;
00215
00216
00290
00291
00292
00301 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
00302
00303
00317 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
00318
00319
00320
00321
00326 typedef struct AVFrac {
00327 int64_t val, num, den;
00328 } AVFrac;
00329
00330
00331
00332
00333 struct AVCodecTag;
00334
00338 typedef struct AVProbeData {
00339 const char *filename;
00340 unsigned char *buf;
00341 int buf_size;
00342 } AVProbeData;
00343
00344 #define AVPROBE_SCORE_MAX 100
00345 #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
00346 #define AVPROBE_PADDING_SIZE 32
00347
00349 #define AVFMT_NOFILE 0x0001
00350 #define AVFMT_NEEDNUMBER 0x0002
00351 #define AVFMT_SHOW_IDS 0x0008
00352 #define AVFMT_RAWPICTURE 0x0020
00354 #define AVFMT_GLOBALHEADER 0x0040
00355 #define AVFMT_NOTIMESTAMPS 0x0080
00356 #define AVFMT_GENERIC_INDEX 0x0100
00357 #define AVFMT_TS_DISCONT 0x0200
00358 #define AVFMT_VARIABLE_FPS 0x0400
00359 #define AVFMT_NODIMENSIONS 0x0800
00360 #define AVFMT_NOSTREAMS 0x1000
00361 #define AVFMT_NOBINSEARCH 0x2000
00362 #define AVFMT_NOGENSEARCH 0x4000
00363 #define AVFMT_NO_BYTE_SEEK 0x8000
00364 #define AVFMT_ALLOW_FLUSH 0x10000
00365 #if LIBAVFORMAT_VERSION_MAJOR <= 54
00366 #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
00367 #else
00368 #define AVFMT_TS_NONSTRICT 0x20000
00369 #endif
00370
00374 #define AVFMT_SEEK_TO_PTS 0x4000000
00380 typedef struct AVOutputFormat {
00381 const char *name;
00387 const char *long_name;
00388 const char *mime_type;
00389 const char *extensions;
00390
00391 enum AVCodecID audio_codec;
00392 enum AVCodecID video_codec;
00393 enum AVCodecID subtitle_codec;
00400 int flags;
00401
00406 const struct AVCodecTag * const *codec_tag;
00407
00408
00409 const AVClass *priv_class;
00410
00411
00412
00413
00414
00415
00416
00417
00418 struct AVOutputFormat *next;
00422 int priv_data_size;
00423
00424 int (*write_header)(struct AVFormatContext *);
00432 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00433 int (*write_trailer)(struct AVFormatContext *);
00437 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00438 AVPacket *in, int flush);
00446 int (*query_codec)(enum AVCodecID id, int std_compliance);
00447
00448 void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
00449 int64_t *dts, int64_t *wall);
00450 } AVOutputFormat;
00459 typedef struct AVInputFormat {
00464 const char *name;
00465
00471 const char *long_name;
00472
00478 int flags;
00479
00485 const char *extensions;
00486
00487 const struct AVCodecTag * const *codec_tag;
00488
00489 const AVClass *priv_class;
00490
00491
00492
00493
00494
00495
00496
00497
00498 struct AVInputFormat *next;
00499
00503 int raw_codec_id;
00504
00508 int priv_data_size;
00509
00515 int (*read_probe)(AVProbeData *);
00516
00522 int (*read_header)(struct AVFormatContext *);
00523
00533 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00534
00539 int (*read_close)(struct AVFormatContext *);
00540
00549 int (*read_seek)(struct AVFormatContext *,
00550 int stream_index, int64_t timestamp, int flags);
00551
00556 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00557 int64_t *pos, int64_t pos_limit);
00558
00563 int (*read_play)(struct AVFormatContext *);
00564
00569 int (*read_pause)(struct AVFormatContext *);
00570
00577 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00578 } AVInputFormat;
00583 enum AVStreamParseType {
00584 AVSTREAM_PARSE_NONE,
00585 AVSTREAM_PARSE_FULL,
00586 AVSTREAM_PARSE_HEADERS,
00587 AVSTREAM_PARSE_TIMESTAMPS,
00588 AVSTREAM_PARSE_FULL_ONCE,
00589 AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'),
00592 };
00593
00594 typedef struct AVIndexEntry {
00595 int64_t pos;
00596 int64_t timestamp;
00602 #define AVINDEX_KEYFRAME 0x0001
00603 int flags:2;
00604 int size:30;
00605 int min_distance;
00606 } AVIndexEntry;
00607
00608 #define AV_DISPOSITION_DEFAULT 0x0001
00609 #define AV_DISPOSITION_DUB 0x0002
00610 #define AV_DISPOSITION_ORIGINAL 0x0004
00611 #define AV_DISPOSITION_COMMENT 0x0008
00612 #define AV_DISPOSITION_LYRICS 0x0010
00613 #define AV_DISPOSITION_KARAOKE 0x0020
00614
00620 #define AV_DISPOSITION_FORCED 0x0040
00621 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
00622 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
00623 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
00630 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
00631
00635 #define AV_PTS_WRAP_IGNORE 0
00636 #define AV_PTS_WRAP_ADD_OFFSET 1
00637 #define AV_PTS_WRAP_SUB_OFFSET -1
00638
00639
00646 typedef struct AVStream {
00647 int index;
00653 int id;
00665 AVCodecContext *codec;
00666 #if FF_API_R_FRAME_RATE
00667
00675 AVRational r_frame_rate;
00676 #endif
00677 void *priv_data;
00678
00682 struct AVFrac pts;
00683
00693 AVRational time_base;
00694
00703 int64_t start_time;
00704
00710 int64_t duration;
00711
00712 int64_t nb_frames;
00713
00714 int disposition;
00716 enum AVDiscard discard;
00717
00723 AVRational sample_aspect_ratio;
00724
00725 AVDictionary *metadata;
00726
00730 AVRational avg_frame_rate;
00731
00739 AVPacket attached_pic;
00740
00741
00742
00743
00744
00745
00746
00747
00748
00752 #define MAX_STD_TIMEBASES (60*12+6)
00753 struct {
00754 int64_t last_dts;
00755 int64_t duration_gcd;
00756 int duration_count;
00757 double duration_error[2][2][MAX_STD_TIMEBASES];
00758 int64_t codec_info_duration;
00759 int64_t codec_info_duration_fields;
00760 int found_decoder;
00761
00765 int64_t fps_first_dts;
00766 int fps_first_dts_idx;
00767 int64_t fps_last_dts;
00768 int fps_last_dts_idx;
00769
00770 } *info;
00771
00772 int pts_wrap_bits;
00774
00782 int64_t reference_dts;
00783 int64_t first_dts;
00784 int64_t cur_dts;
00785 int64_t last_IP_pts;
00786 int last_IP_duration;
00787
00791 #define MAX_PROBE_PACKETS 2500
00792 int probe_packets;
00793
00797 int codec_info_nb_frames;
00798
00804 int stream_identifier;
00805
00806 int64_t interleaver_chunk_size;
00807 int64_t interleaver_chunk_duration;
00808
00809
00810 enum AVStreamParseType need_parsing;
00811 struct AVCodecParserContext *parser;
00812
00816 struct AVPacketList *last_in_packet_buffer;
00817 AVProbeData probe_data;
00818 #define MAX_REORDER_DELAY 16
00819 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00820
00821 AVIndexEntry *index_entries;
00823 int nb_index_entries;
00824 unsigned int index_entries_allocated_size;
00825
00833 int request_probe;
00838 int skip_to_keyframe;
00839
00843 int skip_samples;
00844
00849 int nb_decoded_frames;
00850
00855 int64_t mux_ts_offset;
00856
00860 int64_t pts_wrap_reference;
00861
00872 int pts_wrap_behavior;
00873
00874 } AVStream;
00875
00876 #define AV_PROGRAM_RUNNING 1
00877
00884 typedef struct AVProgram {
00885 int id;
00886 int flags;
00887 enum AVDiscard discard;
00888 unsigned int *stream_index;
00889 unsigned int nb_stream_indexes;
00890 AVDictionary *metadata;
00891
00892 int program_num;
00893 int pmt_pid;
00894 int pcr_pid;
00895
00896
00897
00898
00899
00900
00901
00902
00903 int64_t start_time;
00904 int64_t end_time;
00905
00906 int64_t pts_wrap_reference;
00907 int pts_wrap_behavior;
00908 } AVProgram;
00909
00910 #define AVFMTCTX_NOHEADER 0x0001
00913 typedef struct AVChapter {
00914 int id;
00915 AVRational time_base;
00916 int64_t start, end;
00917 AVDictionary *metadata;
00918 } AVChapter;
00919
00920
00925 enum AVDurationEstimationMethod {
00926 AVFMT_DURATION_FROM_PTS,
00927 AVFMT_DURATION_FROM_STREAM,
00928 AVFMT_DURATION_FROM_BITRATE
00929 };
00930
00939 typedef struct AVFormatContext {
00944 const AVClass *av_class;
00945
00952 struct AVInputFormat *iformat;
00953 struct AVOutputFormat *oformat;
00954
00959 void *priv_data;
00960
00972 AVIOContext *pb;
00973
00974
00975 int ctx_flags;
00986 unsigned int nb_streams;
00987 AVStream **streams;
00988
00989 char filename[1024];
00996 int64_t start_time;
00997
01004 int64_t duration;
01005
01011 int bit_rate;
01012
01013 unsigned int packet_size;
01014 int max_delay;
01015
01016 int flags;
01017 #define AVFMT_FLAG_GENPTS 0x0001
01018 #define AVFMT_FLAG_IGNIDX 0x0002
01019 #define AVFMT_FLAG_NONBLOCK 0x0004
01020 #define AVFMT_FLAG_IGNDTS 0x0008
01021 #define AVFMT_FLAG_NOFILLIN 0x0010
01022 #define AVFMT_FLAG_NOPARSE 0x0020
01023 #define AVFMT_FLAG_NOBUFFER 0x0040
01024 #define AVFMT_FLAG_CUSTOM_IO 0x0080
01025 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
01026 #define AVFMT_FLAG_MP4A_LATM 0x8000
01027 #define AVFMT_FLAG_SORT_DTS 0x10000
01028 #define AVFMT_FLAG_PRIV_OPT 0x20000
01029 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000
01030
01031
01034 unsigned int probesize;
01035
01040 int max_analyze_duration;
01041
01042 const uint8_t *key;
01043 int keylen;
01044
01045 unsigned int nb_programs;
01046 AVProgram **programs;
01047
01052 enum AVCodecID video_codec_id;
01053
01058 enum AVCodecID audio_codec_id;
01059
01064 enum AVCodecID subtitle_codec_id;
01065
01076 unsigned int max_index_size;
01077
01082 unsigned int max_picture_buffer;
01083
01084 unsigned int nb_chapters;
01085 AVChapter **chapters;
01086
01087 AVDictionary *metadata;
01088
01096 int64_t start_time_realtime;
01097
01101 int fps_probe_size;
01102
01109 int error_recognition;
01110
01120 AVIOInterruptCB interrupt_callback;
01121
01125 int debug;
01126 #define FF_FDEBUG_TS 0x0001
01127
01132 int ts_id;
01133
01140 int audio_preload;
01141
01148 int max_chunk_duration;
01149
01156 int max_chunk_size;
01157
01164 int use_wallclock_as_timestamps;
01165
01175 int avoid_negative_ts;
01176
01182 int avio_flags;
01183
01190 enum AVDurationEstimationMethod duration_estimation_method;
01191
01197 unsigned int skip_initial_bytes;
01198
01204 unsigned int correct_ts_overflow;
01205
01206
01207
01208
01209
01210
01211
01212
01213
01219 struct AVPacketList *packet_buffer;
01220 struct AVPacketList *packet_buffer_end;
01221
01222
01223 int64_t data_offset;
01231 struct AVPacketList *raw_packet_buffer;
01232 struct AVPacketList *raw_packet_buffer_end;
01236 struct AVPacketList *parse_queue;
01237 struct AVPacketList *parse_queue_end;
01241 #define RAW_PACKET_BUFFER_SIZE 2500000
01242 int raw_packet_buffer_remaining_size;
01243 } AVFormatContext;
01244
01250 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx);
01251
01252 typedef struct AVPacketList {
01253 AVPacket pkt;
01254 struct AVPacketList *next;
01255 } AVPacketList;
01256
01257
01270 unsigned avformat_version(void);
01271
01275 const char *avformat_configuration(void);
01276
01280 const char *avformat_license(void);
01281
01290 void av_register_all(void);
01291
01292 void av_register_input_format(AVInputFormat *format);
01293 void av_register_output_format(AVOutputFormat *format);
01294
01303 int avformat_network_init(void);
01304
01308 int avformat_network_deinit(void);
01309
01315 AVInputFormat *av_iformat_next(AVInputFormat *f);
01316
01322 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
01323
01329 AVFormatContext *avformat_alloc_context(void);
01330
01335 void avformat_free_context(AVFormatContext *s);
01336
01343 const AVClass *avformat_get_class(void);
01344
01360 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
01361
01362 AVProgram *av_new_program(AVFormatContext *s, int id);
01363
01369 #if FF_API_PKT_DUMP
01370 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
01371 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
01372 int dump_payload);
01373 #endif
01374
01375 #if FF_API_ALLOC_OUTPUT_CONTEXT
01376
01379 attribute_deprecated
01380 AVFormatContext *avformat_alloc_output_context(const char *format,
01381 AVOutputFormat *oformat,
01382 const char *filename);
01383 #endif
01384
01401 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
01402 const char *format_name, const char *filename);
01403
01412 AVInputFormat *av_find_input_format(const char *short_name);
01413
01420 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
01421
01433 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
01434
01442 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
01443
01459 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
01460 const char *filename, void *logctx,
01461 unsigned int offset, unsigned int max_probe_size);
01462
01482 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
01483
01484 attribute_deprecated
01485 int av_demuxer_open(AVFormatContext *ic);
01486
01487 #if FF_API_FORMAT_PARAMETERS
01488
01503 attribute_deprecated
01504 int av_find_stream_info(AVFormatContext *ic);
01505 #endif
01506
01528 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
01529
01540 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
01541
01566 int av_find_best_stream(AVFormatContext *ic,
01567 enum AVMediaType type,
01568 int wanted_stream_nb,
01569 int related_stream,
01570 AVCodec **decoder_ret,
01571 int flags);
01572
01573 #if FF_API_READ_PACKET
01574
01587 attribute_deprecated
01588 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
01589 #endif
01590
01615 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
01616
01628 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
01629 int flags);
01630
01657 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
01658
01663 int av_read_play(AVFormatContext *s);
01664
01670 int av_read_pause(AVFormatContext *s);
01671
01672 #if FF_API_CLOSE_INPUT_FILE
01673
01679 attribute_deprecated
01680 void av_close_input_file(AVFormatContext *s);
01681 #endif
01682
01687 void avformat_close_input(AVFormatContext **s);
01692 #if FF_API_NEW_STREAM
01693
01703 attribute_deprecated
01704 AVStream *av_new_stream(AVFormatContext *s, int id);
01705 #endif
01706
01707 #if FF_API_SET_PTS_INFO
01708
01711 attribute_deprecated
01712 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01713 unsigned int pts_num, unsigned int pts_den);
01714 #endif
01715
01716 #define AVSEEK_FLAG_BACKWARD 1
01717 #define AVSEEK_FLAG_BYTE 2
01718 #define AVSEEK_FLAG_ANY 4
01719 #define AVSEEK_FLAG_FRAME 8
01720
01721
01740 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
01741
01758 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01759
01786 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01787
01788 #if FF_API_INTERLEAVE_PACKET
01789
01793 attribute_deprecated
01794 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01795 AVPacket *pkt, int flush);
01796 #endif
01797
01807 int av_write_trailer(AVFormatContext *s);
01808
01821 AVOutputFormat *av_guess_format(const char *short_name,
01822 const char *filename,
01823 const char *mime_type);
01824
01828 enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
01829 const char *filename, const char *mime_type,
01830 enum AVMediaType type);
01831
01847 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
01848 int64_t *dts, int64_t *wall);
01849
01850
01874 void av_hex_dump(FILE *f, const uint8_t *buf, int size);
01875
01888 void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
01889
01898 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
01899
01900
01912 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
01913 AVStream *st);
01914
01922 enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
01923
01931 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
01932
01933 int av_find_default_stream_index(AVFormatContext *s);
01934
01943 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01944
01951 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01952 int size, int distance, int flags);
01953
01954
01974 void av_url_split(char *proto, int proto_size,
01975 char *authorization, int authorization_size,
01976 char *hostname, int hostname_size,
01977 int *port_ptr,
01978 char *path, int path_size,
01979 const char *url);
01980
01981
01982 void av_dump_format(AVFormatContext *ic,
01983 int index,
01984 const char *url,
01985 int is_output);
01986
01999 int av_get_frame_filename(char *buf, int buf_size,
02000 const char *path, int number);
02001
02008 int av_filename_number_test(const char *filename);
02009
02027 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
02028
02035 int av_match_ext(const char *filename, const char *extensions);
02036
02045 int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
02046
02062 const struct AVCodecTag *avformat_get_riff_video_tags(void);
02066 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
02067
02089 AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
02090
02104 int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
02105 const char *spec);
02106
02107 void avformat_queue_attached_pictures(AVFormatContext *s);
02108
02109
02114 #endif