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
00024
00028 unsigned avformat_version(void);
00029
00033 const char *avformat_configuration(void);
00034
00038 const char *avformat_license(void);
00039
00040 #include <time.h>
00041 #include <stdio.h>
00042 #include "libavcodec/avcodec.h"
00043 #include "libavutil/dict.h"
00044
00045 #include "avio.h"
00046 #include "libavformat/version.h"
00047
00048 struct AVFormatContext;
00049
00050
00117 #if FF_API_OLD_METADATA2
00118
00125 #define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
00126 #define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
00127 #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
00128 #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
00129 #define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
00130
00131 typedef attribute_deprecated AVDictionary AVMetadata;
00132 typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
00133
00134 typedef struct AVMetadataConv AVMetadataConv;
00135
00144 attribute_deprecated AVDictionaryEntry *
00145 av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
00146
00157 attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
00158
00162 attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
00163 const AVMetadataConv *s_conv);
00164
00173 attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
00174
00178 attribute_deprecated void av_metadata_free(AVDictionary **m);
00182 #endif
00183
00184
00185
00186
00187
00196 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
00197
00198
00212 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
00213
00214
00215
00216
00221 typedef struct AVFrac {
00222 int64_t val, num, den;
00223 } AVFrac;
00224
00225
00226
00227
00228 struct AVCodecTag;
00229
00233 typedef struct AVProbeData {
00234 const char *filename;
00235 unsigned char *buf;
00236 int buf_size;
00237 } AVProbeData;
00238
00239 #define AVPROBE_SCORE_MAX 100
00240 #define AVPROBE_PADDING_SIZE 32
00241
00242 typedef struct AVFormatParameters {
00243 #if FF_API_FORMAT_PARAMETERS
00244 attribute_deprecated AVRational time_base;
00245 attribute_deprecated int sample_rate;
00246 attribute_deprecated int channels;
00247 attribute_deprecated int width;
00248 attribute_deprecated int height;
00249 attribute_deprecated enum PixelFormat pix_fmt;
00250 attribute_deprecated int channel;
00251 attribute_deprecated const char *standard;
00252 attribute_deprecated unsigned int mpeg2ts_raw:1;
00254 attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
00255 attribute_deprecated unsigned int initial_pause:1;
00257 attribute_deprecated unsigned int prealloced_context:1;
00258 #endif
00259 } AVFormatParameters;
00260
00262 #define AVFMT_NOFILE 0x0001
00263 #define AVFMT_NEEDNUMBER 0x0002
00264 #define AVFMT_SHOW_IDS 0x0008
00265 #define AVFMT_RAWPICTURE 0x0020
00267 #define AVFMT_GLOBALHEADER 0x0040
00268 #define AVFMT_NOTIMESTAMPS 0x0080
00269 #define AVFMT_GENERIC_INDEX 0x0100
00270 #define AVFMT_TS_DISCONT 0x0200
00271 #define AVFMT_VARIABLE_FPS 0x0400
00272 #define AVFMT_NODIMENSIONS 0x0800
00273 #define AVFMT_NOSTREAMS 0x1000
00274 #define AVFMT_NOBINSEARCH 0x2000
00275 #define AVFMT_NOGENSEARCH 0x4000
00276 #define AVFMT_TS_NONSTRICT 0x8000
00280 typedef struct AVOutputFormat {
00281 const char *name;
00287 const char *long_name;
00288 const char *mime_type;
00289 const char *extensions;
00293 int priv_data_size;
00294
00295 enum CodecID audio_codec;
00296 enum CodecID video_codec;
00297 int (*write_header)(struct AVFormatContext *);
00298 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00299 int (*write_trailer)(struct AVFormatContext *);
00305 int flags;
00306
00307 void *dummy;
00308
00309 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00310 AVPacket *in, int flush);
00311
00316 const struct AVCodecTag * const *codec_tag;
00317
00318 enum CodecID subtitle_codec;
00320 #if FF_API_OLD_METADATA2
00321 const AVMetadataConv *metadata_conv;
00322 #endif
00323
00324 const AVClass *priv_class;
00325
00326
00327 struct AVOutputFormat *next;
00328 } AVOutputFormat;
00329
00330 typedef struct AVInputFormat {
00335 const char *name;
00336
00342 const char *long_name;
00343
00347 int priv_data_size;
00348
00354 int (*read_probe)(AVProbeData *);
00355
00362 int (*read_header)(struct AVFormatContext *,
00363 AVFormatParameters *ap);
00364
00374 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00375
00380 int (*read_close)(struct AVFormatContext *);
00381
00382 #if FF_API_READ_SEEK
00383
00391 attribute_deprecated int (*read_seek)(struct AVFormatContext *,
00392 int stream_index, int64_t timestamp, int flags);
00393 #endif
00394
00398 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00399 int64_t *pos, int64_t pos_limit);
00400
00404 int flags;
00405
00411 const char *extensions;
00412
00416 int value;
00417
00422 int (*read_play)(struct AVFormatContext *);
00423
00428 int (*read_pause)(struct AVFormatContext *);
00429
00430 const struct AVCodecTag * const *codec_tag;
00431
00438 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00439
00440 #if FF_API_OLD_METADATA2
00441 const AVMetadataConv *metadata_conv;
00442 #endif
00443
00444 const AVClass *priv_class;
00445
00446
00447 struct AVInputFormat *next;
00448 } AVInputFormat;
00449
00450 enum AVStreamParseType {
00451 AVSTREAM_PARSE_NONE,
00452 AVSTREAM_PARSE_FULL,
00453 AVSTREAM_PARSE_HEADERS,
00454 AVSTREAM_PARSE_TIMESTAMPS,
00455 AVSTREAM_PARSE_FULL_ONCE,
00456 };
00457
00458 typedef struct AVIndexEntry {
00459 int64_t pos;
00460 int64_t timestamp;
00461 #define AVINDEX_KEYFRAME 0x0001
00462 int flags:2;
00463 int size:30;
00464 int min_distance;
00465 } AVIndexEntry;
00466
00467 #define AV_DISPOSITION_DEFAULT 0x0001
00468 #define AV_DISPOSITION_DUB 0x0002
00469 #define AV_DISPOSITION_ORIGINAL 0x0004
00470 #define AV_DISPOSITION_COMMENT 0x0008
00471 #define AV_DISPOSITION_LYRICS 0x0010
00472 #define AV_DISPOSITION_KARAOKE 0x0020
00473
00479 #define AV_DISPOSITION_FORCED 0x0040
00480 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
00481 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
00482 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
00491 typedef struct AVStream {
00492 int index;
00493 int id;
00494 AVCodecContext *codec;
00503 AVRational r_frame_rate;
00504 void *priv_data;
00505
00506
00507 int64_t first_dts;
00508
00512 struct AVFrac pts;
00513
00521 AVRational time_base;
00522 int pts_wrap_bits;
00523
00524 int stream_copy;
00525 enum AVDiscard discard;
00526
00527
00532 float quality;
00533
00542 int64_t start_time;
00543
00549 int64_t duration;
00550
00551
00552 enum AVStreamParseType need_parsing;
00553 struct AVCodecParserContext *parser;
00554
00555 int64_t cur_dts;
00556 int last_IP_duration;
00557 int64_t last_IP_pts;
00558
00559 AVIndexEntry *index_entries;
00561 int nb_index_entries;
00562 unsigned int index_entries_allocated_size;
00563
00564 int64_t nb_frames;
00565
00566 int disposition;
00568 AVProbeData probe_data;
00569 #define MAX_REORDER_DELAY 16
00570 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00571
00577 AVRational sample_aspect_ratio;
00578
00579 AVDictionary *metadata;
00580
00581
00582
00583 const uint8_t *cur_ptr;
00584 int cur_len;
00585 AVPacket cur_pkt;
00586
00587
00595 int64_t reference_dts;
00596
00601 #define MAX_PROBE_PACKETS 2500
00602 int probe_packets;
00603
00608 struct AVPacketList *last_in_packet_buffer;
00609
00613 AVRational avg_frame_rate;
00614
00618 int codec_info_nb_frames;
00619
00625 int stream_identifier;
00626
00630 #define MAX_STD_TIMEBASES (60*12+5)
00631 struct {
00632 int64_t last_dts;
00633 int64_t duration_gcd;
00634 int duration_count;
00635 double duration_error[MAX_STD_TIMEBASES];
00636 int64_t codec_info_duration;
00637 } *info;
00638
00643 int request_probe;
00644 } AVStream;
00645
00646 #define AV_PROGRAM_RUNNING 1
00647
00654 typedef struct AVProgram {
00655 int id;
00656 int flags;
00657 enum AVDiscard discard;
00658 unsigned int *stream_index;
00659 unsigned int nb_stream_indexes;
00660 AVDictionary *metadata;
00661
00662 int program_num;
00663 int pmt_pid;
00664 int pcr_pid;
00665 } AVProgram;
00666
00667 #define AVFMTCTX_NOHEADER 0x0001
00670 typedef struct AVChapter {
00671 int id;
00672 AVRational time_base;
00673 int64_t start, end;
00674 AVDictionary *metadata;
00675 } AVChapter;
00676
00684 typedef struct AVFormatContext {
00685 const AVClass *av_class;
00686
00687 struct AVInputFormat *iformat;
00688 struct AVOutputFormat *oformat;
00689 void *priv_data;
00690 AVIOContext *pb;
00691 unsigned int nb_streams;
00692 AVStream **streams;
00693 char filename[1024];
00694
00695 int64_t timestamp;
00696
00697 int ctx_flags;
00698
00704 struct AVPacketList *packet_buffer;
00705
00711 int64_t start_time;
00712
00719 int64_t duration;
00720
00724 int64_t file_size;
00725
00731 int bit_rate;
00732
00733
00734 AVStream *cur_st;
00735
00736
00737 int64_t data_offset;
00739 int mux_rate;
00740 unsigned int packet_size;
00741 int preload;
00742 int max_delay;
00743
00744 #define AVFMT_NOOUTPUTLOOP -1
00745 #define AVFMT_INFINITEOUTPUTLOOP 0
00746
00749 int loop_output;
00750
00751 int flags;
00752 #define AVFMT_FLAG_GENPTS 0x0001
00753 #define AVFMT_FLAG_IGNIDX 0x0002
00754 #define AVFMT_FLAG_NONBLOCK 0x0004
00755 #define AVFMT_FLAG_IGNDTS 0x0008
00756 #define AVFMT_FLAG_NOFILLIN 0x0010
00757 #define AVFMT_FLAG_NOPARSE 0x0020
00758 #if FF_API_FLAG_RTP_HINT
00759 #define AVFMT_FLAG_RTP_HINT 0x0040
00760 #endif
00761 #define AVFMT_FLAG_CUSTOM_IO 0x0080
00762 #define AVFMT_FLAG_MP4A_LATM 0x8000
00763 #define AVFMT_FLAG_SORT_DTS 0x10000
00764 #define AVFMT_FLAG_PRIV_OPT 0x20000
00765 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000
00766
00767 int loop_input;
00768
00772 unsigned int probesize;
00773
00778 int max_analyze_duration;
00779
00780 const uint8_t *key;
00781 int keylen;
00782
00783 unsigned int nb_programs;
00784 AVProgram **programs;
00785
00790 enum CodecID video_codec_id;
00791
00796 enum CodecID audio_codec_id;
00797
00802 enum CodecID subtitle_codec_id;
00803
00814 unsigned int max_index_size;
00815
00820 unsigned int max_picture_buffer;
00821
00822 unsigned int nb_chapters;
00823 AVChapter **chapters;
00824
00828 int debug;
00829 #define FF_FDEBUG_TS 0x0001
00830
00837 struct AVPacketList *raw_packet_buffer;
00838 struct AVPacketList *raw_packet_buffer_end;
00839
00840 struct AVPacketList *packet_buffer_end;
00841
00842 AVDictionary *metadata;
00843
00848 #define RAW_PACKET_BUFFER_SIZE 2500000
00849 int raw_packet_buffer_remaining_size;
00850
00858 int64_t start_time_realtime;
00859
00863 int fps_probe_size;
00864
00869 int ts_id;
00870 } AVFormatContext;
00871
00872 typedef struct AVPacketList {
00873 AVPacket pkt;
00874 struct AVPacketList *next;
00875 } AVPacketList;
00876
00882 AVInputFormat *av_iformat_next(AVInputFormat *f);
00883
00889 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
00890
00891 #if FF_API_GUESS_IMG2_CODEC
00892 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
00893 #endif
00894
00895
00896
00897
00898
00899 void av_register_input_format(AVInputFormat *format);
00900 void av_register_output_format(AVOutputFormat *format);
00901
00914 AVOutputFormat *av_guess_format(const char *short_name,
00915 const char *filename,
00916 const char *mime_type);
00917
00921 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
00922 const char *filename, const char *mime_type,
00923 enum AVMediaType type);
00924
00934 void av_hex_dump(FILE *f, uint8_t *buf, int size);
00935
00948 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
00949
00958 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
00959
00960
00972 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
00973 AVStream *st);
00974
00975 #if FF_API_PKT_DUMP
00976 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
00977 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
00978 int dump_payload);
00979 #endif
00980
00990 void av_register_all(void);
00991
00999 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
01000
01008 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
01009
01010
01011
01015 AVInputFormat *av_find_input_format(const char *short_name);
01016
01023 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
01024
01036 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
01037
01045 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
01046
01062 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
01063 const char *filename, void *logctx,
01064 unsigned int offset, unsigned int max_probe_size);
01065
01066 #if FF_API_FORMAT_PARAMETERS
01067
01072 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
01073 AVIOContext *pb, const char *filename,
01074 AVInputFormat *fmt, AVFormatParameters *ap);
01075
01090 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
01091 AVInputFormat *fmt,
01092 int buf_size,
01093 AVFormatParameters *ap);
01094 #endif
01095
01115 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
01116
01117 int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
01118
01124 AVFormatContext *avformat_alloc_context(void);
01125
01126 #if FF_API_ALLOC_OUTPUT_CONTEXT
01127
01130 attribute_deprecated
01131 AVFormatContext *avformat_alloc_output_context(const char *format,
01132 AVOutputFormat *oformat,
01133 const char *filename);
01134 #endif
01135
01152 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
01153 const char *format_name, const char *filename);
01154
01155 #if FF_API_FORMAT_PARAMETERS
01156
01171 int av_find_stream_info(AVFormatContext *ic);
01172 #endif
01173
01195 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
01196
01221 int av_find_best_stream(AVFormatContext *ic,
01222 enum AVMediaType type,
01223 int wanted_stream_nb,
01224 int related_stream,
01225 AVCodec **decoder_ret,
01226 int flags);
01227
01238 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
01239
01264 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
01265
01277 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
01278 int flags);
01279
01306 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
01307
01312 int av_read_play(AVFormatContext *s);
01313
01319 int av_read_pause(AVFormatContext *s);
01320
01325 void av_close_input_stream(AVFormatContext *s);
01326
01332 void av_close_input_file(AVFormatContext *s);
01333
01338 void avformat_free_context(AVFormatContext *s);
01339
01350 AVStream *av_new_stream(AVFormatContext *s, int id);
01351 AVProgram *av_new_program(AVFormatContext *s, int id);
01352
01363 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01364 unsigned int pts_num, unsigned int pts_den);
01365
01366 #define AVSEEK_FLAG_BACKWARD 1
01367 #define AVSEEK_FLAG_BYTE 2
01368 #define AVSEEK_FLAG_ANY 4
01369 #define AVSEEK_FLAG_FRAME 8
01370
01371 int av_find_default_stream_index(AVFormatContext *s);
01372
01381 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01382
01389 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01390 int size, int distance, int flags);
01391
01400 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
01401 int64_t target_ts, int flags);
01402
01411 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
01412
01420 int64_t av_gen_search(AVFormatContext *s, int stream_index,
01421 int64_t target_ts, int64_t pos_min,
01422 int64_t pos_max, int64_t pos_limit,
01423 int64_t ts_min, int64_t ts_max,
01424 int flags, int64_t *ts_ret,
01425 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
01426
01430 #if FF_API_FORMAT_PARAMETERS
01431
01434 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
01435 #endif
01436
01456 void av_url_split(char *proto, int proto_size,
01457 char *authorization, int authorization_size,
01458 char *hostname, int hostname_size,
01459 int *port_ptr,
01460 char *path, int path_size,
01461 const char *url);
01462
01478 int avformat_write_header(AVFormatContext *s, AVDictionary **options);
01479
01480 #if FF_API_FORMAT_PARAMETERS
01481
01492 attribute_deprecated int av_write_header(AVFormatContext *s);
01493 #endif
01494
01507 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01508
01524 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01525
01541 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01542 AVPacket *pkt, int flush);
01543
01553 int av_write_trailer(AVFormatContext *s);
01554
01555 #if FF_API_DUMP_FORMAT
01556
01559 attribute_deprecated void dump_format(AVFormatContext *ic,
01560 int index,
01561 const char *url,
01562 int is_output);
01563 #endif
01564
01565 void av_dump_format(AVFormatContext *ic,
01566 int index,
01567 const char *url,
01568 int is_output);
01569
01570 #if FF_API_PARSE_DATE
01571
01578 attribute_deprecated
01579 int64_t parse_date(const char *datestr, int duration);
01580 #endif
01581
01585 int64_t av_gettime(void);
01586
01587 #if FF_API_FIND_INFO_TAG
01588
01591 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
01592 #endif
01593
01606 int av_get_frame_filename(char *buf, int buf_size,
01607 const char *path, int number);
01608
01615 int av_filename_number_test(const char *filename);
01616
01631 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
01632
01633 #if FF_API_SDP_CREATE
01634 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
01635 #endif
01636
01643 int av_match_ext(const char *filename, const char *extensions);
01644
01645 #endif