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 struct AVFormatContext;
00205
00206
00280
00281
00282
00291 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
00292
00293
00307 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
00308
00309
00310
00311
00316 typedef struct AVFrac {
00317 int64_t val, num, den;
00318 } AVFrac;
00319
00320
00321
00322
00323 struct AVCodecTag;
00324
00328 typedef struct AVProbeData {
00329 const char *filename;
00330 unsigned char *buf;
00331 int buf_size;
00332 } AVProbeData;
00333
00334 #define AVPROBE_SCORE_MAX 100
00335 #define AVPROBE_PADDING_SIZE 32
00336
00338 #define AVFMT_NOFILE 0x0001
00339 #define AVFMT_NEEDNUMBER 0x0002
00340 #define AVFMT_SHOW_IDS 0x0008
00341 #define AVFMT_RAWPICTURE 0x0020
00343 #define AVFMT_GLOBALHEADER 0x0040
00344 #define AVFMT_NOTIMESTAMPS 0x0080
00345 #define AVFMT_GENERIC_INDEX 0x0100
00346 #define AVFMT_TS_DISCONT 0x0200
00347 #define AVFMT_VARIABLE_FPS 0x0400
00348 #define AVFMT_NODIMENSIONS 0x0800
00349 #define AVFMT_NOSTREAMS 0x1000
00350 #define AVFMT_NOBINSEARCH 0x2000
00351 #define AVFMT_NOGENSEARCH 0x4000
00352 #define AVFMT_NO_BYTE_SEEK 0x8000
00353 #define AVFMT_ALLOW_FLUSH 0x10000
00354 #if LIBAVFORMAT_VERSION_MAJOR <= 54
00355 #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
00356 #else
00357 #define AVFMT_TS_NONSTRICT 0x20000
00358 #endif
00359
00363 #define AVFMT_SEEK_TO_PTS 0x4000000
00369 typedef struct AVOutputFormat {
00370 const char *name;
00376 const char *long_name;
00377 const char *mime_type;
00378 const char *extensions;
00379
00380 enum CodecID audio_codec;
00381 enum CodecID video_codec;
00382 enum CodecID subtitle_codec;
00389 int flags;
00390
00395 const struct AVCodecTag * const *codec_tag;
00396
00397
00398 const AVClass *priv_class;
00399
00400
00401
00402
00403
00404
00405
00406
00407 struct AVOutputFormat *next;
00411 int priv_data_size;
00412
00413 int (*write_header)(struct AVFormatContext *);
00421 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00422 int (*write_trailer)(struct AVFormatContext *);
00426 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00427 AVPacket *in, int flush);
00434 int (*query_codec)(enum CodecID id, int std_compliance);
00435
00436 void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
00437 int64_t *dts, int64_t *wall);
00438 } AVOutputFormat;
00447 typedef struct AVInputFormat {
00452 const char *name;
00453
00459 const char *long_name;
00460
00466 int flags;
00467
00473 const char *extensions;
00474
00475 const struct AVCodecTag * const *codec_tag;
00476
00477 const AVClass *priv_class;
00478
00479
00480
00481
00482
00483
00484
00485
00486 struct AVInputFormat *next;
00487
00491 int raw_codec_id;
00492
00496 int priv_data_size;
00497
00503 int (*read_probe)(AVProbeData *);
00504
00510 int (*read_header)(struct AVFormatContext *);
00511
00521 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00522
00527 int (*read_close)(struct AVFormatContext *);
00528
00537 int (*read_seek)(struct AVFormatContext *,
00538 int stream_index, int64_t timestamp, int flags);
00539
00544 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00545 int64_t *pos, int64_t pos_limit);
00546
00551 int (*read_play)(struct AVFormatContext *);
00552
00557 int (*read_pause)(struct AVFormatContext *);
00558
00565 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00566 } AVInputFormat;
00571 enum AVStreamParseType {
00572 AVSTREAM_PARSE_NONE,
00573 AVSTREAM_PARSE_FULL,
00574 AVSTREAM_PARSE_HEADERS,
00575 AVSTREAM_PARSE_TIMESTAMPS,
00576 AVSTREAM_PARSE_FULL_ONCE,
00577 AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'),
00578 };
00579
00580 typedef struct AVIndexEntry {
00581 int64_t pos;
00582 int64_t timestamp;
00588 #define AVINDEX_KEYFRAME 0x0001
00589 int flags:2;
00590 int size:30;
00591 int min_distance;
00592 } AVIndexEntry;
00593
00594 #define AV_DISPOSITION_DEFAULT 0x0001
00595 #define AV_DISPOSITION_DUB 0x0002
00596 #define AV_DISPOSITION_ORIGINAL 0x0004
00597 #define AV_DISPOSITION_COMMENT 0x0008
00598 #define AV_DISPOSITION_LYRICS 0x0010
00599 #define AV_DISPOSITION_KARAOKE 0x0020
00600
00606 #define AV_DISPOSITION_FORCED 0x0040
00607 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
00608 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
00609 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
00616 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
00617
00625 typedef struct AVStream {
00626 int index;
00632 int id;
00644 AVCodecContext *codec;
00653 AVRational r_frame_rate;
00654 void *priv_data;
00655
00659 struct AVFrac pts;
00660
00670 AVRational time_base;
00671
00680 int64_t start_time;
00681
00687 int64_t duration;
00688
00689 int64_t nb_frames;
00690
00691 int disposition;
00693 enum AVDiscard discard;
00694
00700 AVRational sample_aspect_ratio;
00701
00702 AVDictionary *metadata;
00703
00707 AVRational avg_frame_rate;
00708
00716 AVPacket attached_pic;
00717
00718
00719
00720
00721
00722
00723
00724
00725
00729 #define MAX_STD_TIMEBASES (60*12+5)
00730 struct {
00731 int64_t last_dts;
00732 int64_t duration_gcd;
00733 int duration_count;
00734 double duration_error[2][2][MAX_STD_TIMEBASES];
00735 int64_t codec_info_duration;
00736 int nb_decoded_frames;
00737 int found_decoder;
00738 } *info;
00739
00740 int pts_wrap_bits;
00742
00750 int64_t reference_dts;
00751 int64_t first_dts;
00752 int64_t cur_dts;
00753 int64_t last_IP_pts;
00754 int last_IP_duration;
00755
00759 #define MAX_PROBE_PACKETS 2500
00760 int probe_packets;
00761
00765 int codec_info_nb_frames;
00766
00772 int stream_identifier;
00773
00774 int64_t interleaver_chunk_size;
00775 int64_t interleaver_chunk_duration;
00776
00777
00778 enum AVStreamParseType need_parsing;
00779 struct AVCodecParserContext *parser;
00780
00784 struct AVPacketList *last_in_packet_buffer;
00785 AVProbeData probe_data;
00786 #define MAX_REORDER_DELAY 16
00787 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00788
00789 AVIndexEntry *index_entries;
00791 int nb_index_entries;
00792 unsigned int index_entries_allocated_size;
00793
00798 int request_probe;
00803 int skip_to_keyframe;
00804 } AVStream;
00805
00806 #define AV_PROGRAM_RUNNING 1
00807
00814 typedef struct AVProgram {
00815 int id;
00816 int flags;
00817 enum AVDiscard discard;
00818 unsigned int *stream_index;
00819 unsigned int nb_stream_indexes;
00820 AVDictionary *metadata;
00821
00822 int program_num;
00823 int pmt_pid;
00824 int pcr_pid;
00825 } AVProgram;
00826
00827 #define AVFMTCTX_NOHEADER 0x0001
00830 typedef struct AVChapter {
00831 int id;
00832 AVRational time_base;
00833 int64_t start, end;
00834 AVDictionary *metadata;
00835 } AVChapter;
00836
00845 typedef struct AVFormatContext {
00850 const AVClass *av_class;
00851
00858 struct AVInputFormat *iformat;
00859 struct AVOutputFormat *oformat;
00860
00865 void *priv_data;
00866
00878 AVIOContext *pb;
00879
00880
00881 int ctx_flags;
00892 unsigned int nb_streams;
00893 AVStream **streams;
00894
00895 char filename[1024];
00902 int64_t start_time;
00903
00910 int64_t duration;
00911
00917 int bit_rate;
00918
00919 unsigned int packet_size;
00920 int max_delay;
00921
00922 int flags;
00923 #define AVFMT_FLAG_GENPTS 0x0001
00924 #define AVFMT_FLAG_IGNIDX 0x0002
00925 #define AVFMT_FLAG_NONBLOCK 0x0004
00926 #define AVFMT_FLAG_IGNDTS 0x0008
00927 #define AVFMT_FLAG_NOFILLIN 0x0010
00928 #define AVFMT_FLAG_NOPARSE 0x0020
00929 #define AVFMT_FLAG_CUSTOM_IO 0x0080
00930 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
00931 #define AVFMT_FLAG_MP4A_LATM 0x8000
00932 #define AVFMT_FLAG_SORT_DTS 0x10000
00933 #define AVFMT_FLAG_PRIV_OPT 0x20000
00934 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000
00935
00936
00939 unsigned int probesize;
00940
00945 int max_analyze_duration;
00946
00947 const uint8_t *key;
00948 int keylen;
00949
00950 unsigned int nb_programs;
00951 AVProgram **programs;
00952
00957 enum CodecID video_codec_id;
00958
00963 enum CodecID audio_codec_id;
00964
00969 enum CodecID subtitle_codec_id;
00970
00981 unsigned int max_index_size;
00982
00987 unsigned int max_picture_buffer;
00988
00989 unsigned int nb_chapters;
00990 AVChapter **chapters;
00991
00992 AVDictionary *metadata;
00993
01001 int64_t start_time_realtime;
01002
01006 int fps_probe_size;
01007
01014 int error_recognition;
01015
01025 AVIOInterruptCB interrupt_callback;
01026
01030 int debug;
01031 #define FF_FDEBUG_TS 0x0001
01032
01037 int ts_id;
01038
01045 int audio_preload;
01046
01053 int max_chunk_duration;
01054
01061 int max_chunk_size;
01062
01063
01064
01065
01066
01067
01068
01069
01070
01076 struct AVPacketList *packet_buffer;
01077 struct AVPacketList *packet_buffer_end;
01078
01079
01080 int64_t data_offset;
01088 struct AVPacketList *raw_packet_buffer;
01089 struct AVPacketList *raw_packet_buffer_end;
01093 struct AVPacketList *parse_queue;
01094 struct AVPacketList *parse_queue_end;
01098 #define RAW_PACKET_BUFFER_SIZE 2500000
01099 int raw_packet_buffer_remaining_size;
01100
01101 int avio_flags;
01102 } AVFormatContext;
01103
01104 typedef struct AVPacketList {
01105 AVPacket pkt;
01106 struct AVPacketList *next;
01107 } AVPacketList;
01108
01109
01122 unsigned avformat_version(void);
01123
01127 const char *avformat_configuration(void);
01128
01132 const char *avformat_license(void);
01133
01143 void av_register_all(void);
01144
01145 void av_register_input_format(AVInputFormat *format);
01146 void av_register_output_format(AVOutputFormat *format);
01147
01156 int avformat_network_init(void);
01157
01161 int avformat_network_deinit(void);
01162
01168 AVInputFormat *av_iformat_next(AVInputFormat *f);
01169
01175 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
01176
01182 AVFormatContext *avformat_alloc_context(void);
01183
01188 void avformat_free_context(AVFormatContext *s);
01189
01196 const AVClass *avformat_get_class(void);
01197
01213 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
01214
01215 AVProgram *av_new_program(AVFormatContext *s, int id);
01216
01222 #if FF_API_PKT_DUMP
01223 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
01224 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
01225 int dump_payload);
01226 #endif
01227
01228 #if FF_API_ALLOC_OUTPUT_CONTEXT
01229
01232 attribute_deprecated
01233 AVFormatContext *avformat_alloc_output_context(const char *format,
01234 AVOutputFormat *oformat,
01235 const char *filename);
01236 #endif
01237
01254 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
01255 const char *format_name, const char *filename);
01256
01265 AVInputFormat *av_find_input_format(const char *short_name);
01266
01273 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
01274
01286 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
01287
01295 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
01296
01312 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
01313 const char *filename, void *logctx,
01314 unsigned int offset, unsigned int max_probe_size);
01315
01335 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
01336
01337 attribute_deprecated
01338 int av_demuxer_open(AVFormatContext *ic);
01339
01340 #if FF_API_FORMAT_PARAMETERS
01341
01356 attribute_deprecated
01357 int av_find_stream_info(AVFormatContext *ic);
01358 #endif
01359
01381 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
01382
01393 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
01394
01419 int av_find_best_stream(AVFormatContext *ic,
01420 enum AVMediaType type,
01421 int wanted_stream_nb,
01422 int related_stream,
01423 AVCodec **decoder_ret,
01424 int flags);
01425
01426 #if FF_API_READ_PACKET
01427
01440 attribute_deprecated
01441 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
01442 #endif
01443
01468 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
01469
01481 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
01482 int flags);
01483
01510 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
01511
01516 int av_read_play(AVFormatContext *s);
01517
01523 int av_read_pause(AVFormatContext *s);
01524
01525 #if FF_API_CLOSE_INPUT_FILE
01526
01532 attribute_deprecated
01533 void av_close_input_file(AVFormatContext *s);
01534 #endif
01535
01540 void avformat_close_input(AVFormatContext **s);
01545 #if FF_API_NEW_STREAM
01546
01556 attribute_deprecated
01557 AVStream *av_new_stream(AVFormatContext *s, int id);
01558 #endif
01559
01560 #if FF_API_SET_PTS_INFO
01561
01564 attribute_deprecated
01565 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01566 unsigned int pts_num, unsigned int pts_den);
01567 #endif
01568
01569 #define AVSEEK_FLAG_BACKWARD 1
01570 #define AVSEEK_FLAG_BYTE 2
01571 #define AVSEEK_FLAG_ANY 4
01572 #define AVSEEK_FLAG_FRAME 8
01573
01574
01593 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
01594
01611 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01612
01639 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01640
01641 #if FF_API_INTERLEAVE_PACKET
01642
01646 attribute_deprecated
01647 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01648 AVPacket *pkt, int flush);
01649 #endif
01650
01660 int av_write_trailer(AVFormatContext *s);
01661
01674 AVOutputFormat *av_guess_format(const char *short_name,
01675 const char *filename,
01676 const char *mime_type);
01677
01681 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
01682 const char *filename, const char *mime_type,
01683 enum AVMediaType type);
01684
01700 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
01701 int64_t *dts, int64_t *wall);
01702
01703
01727 void av_hex_dump(FILE *f, uint8_t *buf, int size);
01728
01741 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
01742
01751 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
01752
01753
01765 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
01766 AVStream *st);
01767
01775 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
01776
01784 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
01785
01786 int av_find_default_stream_index(AVFormatContext *s);
01787
01796 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01797
01804 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01805 int size, int distance, int flags);
01806
01807
01827 void av_url_split(char *proto, int proto_size,
01828 char *authorization, int authorization_size,
01829 char *hostname, int hostname_size,
01830 int *port_ptr,
01831 char *path, int path_size,
01832 const char *url);
01833
01834
01835 void av_dump_format(AVFormatContext *ic,
01836 int index,
01837 const char *url,
01838 int is_output);
01839
01843 int64_t av_gettime(void);
01844
01857 int av_get_frame_filename(char *buf, int buf_size,
01858 const char *path, int number);
01859
01866 int av_filename_number_test(const char *filename);
01867
01882 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
01883
01890 int av_match_ext(const char *filename, const char *extensions);
01891
01900 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
01901
01917 const struct AVCodecTag *avformat_get_riff_video_tags(void);
01921 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
01922
01940 AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
01941
01950 #endif