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 #define LIBAVFORMAT_VERSION_MAJOR 52
00025 #define LIBAVFORMAT_VERSION_MINOR 61
00026 #define LIBAVFORMAT_VERSION_MICRO 0
00027
00028 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
00029 LIBAVFORMAT_VERSION_MINOR, \
00030 LIBAVFORMAT_VERSION_MICRO)
00031 #define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
00032 LIBAVFORMAT_VERSION_MINOR, \
00033 LIBAVFORMAT_VERSION_MICRO)
00034 #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
00035
00036 #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
00037
00042 unsigned avformat_version(void);
00043
00047 const char *avformat_configuration(void);
00048
00052 const char *avformat_license(void);
00053
00054 #include <time.h>
00055 #include <stdio.h>
00056 #include "libavcodec/avcodec.h"
00057
00058 #include "avio.h"
00059
00060 struct AVFormatContext;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 #define AV_METADATA_MATCH_CASE 1
00119 #define AV_METADATA_IGNORE_SUFFIX 2
00120 #define AV_METADATA_DONT_STRDUP_KEY 4
00121 #define AV_METADATA_DONT_STRDUP_VAL 8
00122 #define AV_METADATA_DONT_OVERWRITE 16
00123
00124 typedef struct {
00125 char *key;
00126 char *value;
00127 }AVMetadataTag;
00128
00129 typedef struct AVMetadata AVMetadata;
00130 typedef struct AVMetadataConv AVMetadataConv;
00131
00139 AVMetadataTag *
00140 av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
00141
00142 #if LIBAVFORMAT_VERSION_MAJOR == 52
00143
00149 int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
00150 #endif
00151
00158 int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
00159
00167 void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
00168 const AVMetadataConv *s_conv);
00169
00173 void av_metadata_free(AVMetadata **m);
00174
00175
00176
00177
00178
00187 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
00188
00189
00190
00191
00192
00197 typedef struct AVFrac {
00198 int64_t val, num, den;
00199 } AVFrac;
00200
00201
00202
00203
00204 struct AVCodecTag;
00205
00207 typedef struct AVProbeData {
00208 const char *filename;
00209 unsigned char *buf;
00210 int buf_size;
00211 } AVProbeData;
00212
00213 #define AVPROBE_SCORE_MAX 100
00214 #define AVPROBE_PADDING_SIZE 32
00215
00216 typedef struct AVFormatParameters {
00217 AVRational time_base;
00218 int sample_rate;
00219 int channels;
00220 int width;
00221 int height;
00222 enum PixelFormat pix_fmt;
00223 int channel;
00224 const char *standard;
00225 unsigned int mpeg2ts_raw:1;
00226 unsigned int mpeg2ts_compute_pcr:1;
00229 unsigned int initial_pause:1;
00231 unsigned int prealloced_context:1;
00232 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00233 enum CodecID video_codec_id;
00234 enum CodecID audio_codec_id;
00235 #endif
00236 } AVFormatParameters;
00237
00239 #define AVFMT_NOFILE 0x0001
00240 #define AVFMT_NEEDNUMBER 0x0002
00241 #define AVFMT_SHOW_IDS 0x0008
00242 #define AVFMT_RAWPICTURE 0x0020
00244 #define AVFMT_GLOBALHEADER 0x0040
00245 #define AVFMT_NOTIMESTAMPS 0x0080
00246 #define AVFMT_GENERIC_INDEX 0x0100
00247 #define AVFMT_TS_DISCONT 0x0200
00248 #define AVFMT_VARIABLE_FPS 0x0400
00249 #define AVFMT_NODIMENSIONS 0x0800
00251 typedef struct AVOutputFormat {
00252 const char *name;
00258 const char *long_name;
00259 const char *mime_type;
00260 const char *extensions;
00262 int priv_data_size;
00263
00264 enum CodecID audio_codec;
00265 enum CodecID video_codec;
00266 int (*write_header)(struct AVFormatContext *);
00267 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00268 int (*write_trailer)(struct AVFormatContext *);
00270 int flags;
00272 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
00273 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00274 AVPacket *in, int flush);
00275
00280 const struct AVCodecTag * const *codec_tag;
00281
00282 enum CodecID subtitle_codec;
00284 const AVMetadataConv *metadata_conv;
00285
00286
00287 struct AVOutputFormat *next;
00288 } AVOutputFormat;
00289
00290 typedef struct AVInputFormat {
00291 const char *name;
00297 const char *long_name;
00299 int priv_data_size;
00305 int (*read_probe)(AVProbeData *);
00310 int (*read_header)(struct AVFormatContext *,
00311 AVFormatParameters *ap);
00318 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00321 int (*read_close)(struct AVFormatContext *);
00322
00323 #if LIBAVFORMAT_VERSION_MAJOR < 53
00324
00332 int (*read_seek)(struct AVFormatContext *,
00333 int stream_index, int64_t timestamp, int flags);
00334 #endif
00335
00339 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00340 int64_t *pos, int64_t pos_limit);
00342 int flags;
00346 const char *extensions;
00348 int value;
00349
00352 int (*read_play)(struct AVFormatContext *);
00353
00356 int (*read_pause)(struct AVFormatContext *);
00357
00358 const struct AVCodecTag * const *codec_tag;
00359
00366 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00367
00368 const AVMetadataConv *metadata_conv;
00369
00370
00371 struct AVInputFormat *next;
00372 } AVInputFormat;
00373
00374 enum AVStreamParseType {
00375 AVSTREAM_PARSE_NONE,
00376 AVSTREAM_PARSE_FULL,
00377 AVSTREAM_PARSE_HEADERS,
00378 AVSTREAM_PARSE_TIMESTAMPS,
00379 };
00380
00381 typedef struct AVIndexEntry {
00382 int64_t pos;
00383 int64_t timestamp;
00384 #define AVINDEX_KEYFRAME 0x0001
00385 int flags:2;
00386 int size:30;
00387 int min_distance;
00388 } AVIndexEntry;
00389
00390 #define AV_DISPOSITION_DEFAULT 0x0001
00391 #define AV_DISPOSITION_DUB 0x0002
00392 #define AV_DISPOSITION_ORIGINAL 0x0004
00393 #define AV_DISPOSITION_COMMENT 0x0008
00394 #define AV_DISPOSITION_LYRICS 0x0010
00395 #define AV_DISPOSITION_KARAOKE 0x0020
00396
00404 typedef struct AVStream {
00405 int index;
00406 int id;
00407 AVCodecContext *codec;
00416 AVRational r_frame_rate;
00417 void *priv_data;
00418
00419
00420 int64_t first_dts;
00422 struct AVFrac pts;
00423
00429 AVRational time_base;
00430 int pts_wrap_bits;
00431
00432 int stream_copy;
00433 enum AVDiscard discard;
00434
00437 float quality;
00446 int64_t start_time;
00452 int64_t duration;
00453
00454 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00455 char language[4];
00456 #endif
00457
00458
00459 enum AVStreamParseType need_parsing;
00460 struct AVCodecParserContext *parser;
00461
00462 int64_t cur_dts;
00463 int last_IP_duration;
00464 int64_t last_IP_pts;
00465
00466 AVIndexEntry *index_entries;
00468 int nb_index_entries;
00469 unsigned int index_entries_allocated_size;
00470
00471 int64_t nb_frames;
00472
00473 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00474 int64_t unused[4+1];
00475
00476 char *filename;
00477 #endif
00478
00479 int disposition;
00481 AVProbeData probe_data;
00482 #define MAX_REORDER_DELAY 16
00483 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00484
00490 AVRational sample_aspect_ratio;
00491
00492 AVMetadata *metadata;
00493
00494
00495 const uint8_t *cur_ptr;
00496 int cur_len;
00497 AVPacket cur_pkt;
00498
00499
00507 int64_t reference_dts;
00508
00513 #define MAX_PROBE_PACKETS 2500
00514 int probe_packets;
00515
00520 struct AVPacketList *last_in_packet_buffer;
00521
00525 AVRational avg_frame_rate;
00526
00530 int codec_info_nb_frames;
00531 } AVStream;
00532
00533 #define AV_PROGRAM_RUNNING 1
00534
00541 typedef struct AVProgram {
00542 int id;
00543 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00544 char *provider_name;
00545 char *name;
00546 #endif
00547 int flags;
00548 enum AVDiscard discard;
00549 unsigned int *stream_index;
00550 unsigned int nb_stream_indexes;
00551 AVMetadata *metadata;
00552 } AVProgram;
00553
00554 #define AVFMTCTX_NOHEADER 0x0001
00557 typedef struct AVChapter {
00558 int id;
00559 AVRational time_base;
00560 int64_t start, end;
00561 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00562 char *title;
00563 #endif
00564 AVMetadata *metadata;
00565 } AVChapter;
00566
00567 #if LIBAVFORMAT_VERSION_MAJOR < 53
00568 #define MAX_STREAMS 20
00569 #else
00570 #define MAX_STREAMS 100
00571 #endif
00572
00580 typedef struct AVFormatContext {
00581 const AVClass *av_class;
00582
00583 struct AVInputFormat *iformat;
00584 struct AVOutputFormat *oformat;
00585 void *priv_data;
00586 ByteIOContext *pb;
00587 unsigned int nb_streams;
00588 AVStream *streams[MAX_STREAMS];
00589 char filename[1024];
00590
00591 int64_t timestamp;
00592 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00593 char title[512];
00594 char author[512];
00595 char copyright[512];
00596 char comment[512];
00597 char album[512];
00598 int year;
00599 int track;
00600 char genre[32];
00601 #endif
00602
00603 int ctx_flags;
00604
00608 struct AVPacketList *packet_buffer;
00609
00613 int64_t start_time;
00618 int64_t duration;
00620 int64_t file_size;
00624 int bit_rate;
00625
00626
00627 AVStream *cur_st;
00628 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00629 const uint8_t *cur_ptr_deprecated;
00630 int cur_len_deprecated;
00631 AVPacket cur_pkt_deprecated;
00632 #endif
00633
00634
00635 int64_t data_offset;
00636 int index_built;
00637
00638 int mux_rate;
00639 unsigned int packet_size;
00640 int preload;
00641 int max_delay;
00642
00643 #define AVFMT_NOOUTPUTLOOP -1
00644 #define AVFMT_INFINITEOUTPUTLOOP 0
00645
00646 int loop_output;
00647
00648 int flags;
00649 #define AVFMT_FLAG_GENPTS 0x0001
00650 #define AVFMT_FLAG_IGNIDX 0x0002
00651 #define AVFMT_FLAG_NONBLOCK 0x0004
00652 #define AVFMT_FLAG_IGNDTS 0x0008
00653 #define AVFMT_FLAG_NOFILLIN 0x0010
00654 #define AVFMT_FLAG_NOPARSE 0x0020
00655
00656 int loop_input;
00658 unsigned int probesize;
00659
00664 int max_analyze_duration;
00665
00666 const uint8_t *key;
00667 int keylen;
00668
00669 unsigned int nb_programs;
00670 AVProgram **programs;
00671
00676 enum CodecID video_codec_id;
00681 enum CodecID audio_codec_id;
00686 enum CodecID subtitle_codec_id;
00687
00698 unsigned int max_index_size;
00699
00704 unsigned int max_picture_buffer;
00705
00706 unsigned int nb_chapters;
00707 AVChapter **chapters;
00708
00712 int debug;
00713 #define FF_FDEBUG_TS 0x0001
00714
00721 struct AVPacketList *raw_packet_buffer;
00722 struct AVPacketList *raw_packet_buffer_end;
00723
00724 struct AVPacketList *packet_buffer_end;
00725
00726 AVMetadata *metadata;
00727
00732 #define RAW_PACKET_BUFFER_SIZE 2500000
00733 int raw_packet_buffer_remaining_size;
00734
00742 int64_t start_time_realtime;
00743 } AVFormatContext;
00744
00745 typedef struct AVPacketList {
00746 AVPacket pkt;
00747 struct AVPacketList *next;
00748 } AVPacketList;
00749
00750 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00751 extern AVInputFormat *first_iformat;
00752 extern AVOutputFormat *first_oformat;
00753 #endif
00754
00760 AVInputFormat *av_iformat_next(AVInputFormat *f);
00761
00767 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
00768
00769 enum CodecID av_guess_image2_codec(const char *filename);
00770
00771
00772
00773
00774
00775 void av_register_input_format(AVInputFormat *format);
00776 void av_register_output_format(AVOutputFormat *format);
00777 #if LIBAVFORMAT_VERSION_MAJOR < 53
00778 attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
00779 const char *filename,
00780 const char *mime_type);
00781
00785 attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
00786 const char *filename,
00787 const char *mime_type);
00788 #endif
00789
00802 AVOutputFormat *av_guess_format(const char *short_name,
00803 const char *filename,
00804 const char *mime_type);
00805
00809 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
00810 const char *filename, const char *mime_type,
00811 enum AVMediaType type);
00812
00822 void av_hex_dump(FILE *f, uint8_t *buf, int size);
00823
00836 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
00837
00845 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
00846
00857 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
00858
00868 void av_register_all(void);
00869
00871 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
00872 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
00873
00874
00875
00879 AVInputFormat *av_find_input_format(const char *short_name);
00880
00887 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
00888
00893 int av_open_input_stream(AVFormatContext **ic_ptr,
00894 ByteIOContext *pb, const char *filename,
00895 AVInputFormat *fmt, AVFormatParameters *ap);
00896
00909 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
00910 AVInputFormat *fmt,
00911 int buf_size,
00912 AVFormatParameters *ap);
00913
00914 #if LIBAVFORMAT_VERSION_MAJOR < 53
00915
00918 attribute_deprecated AVFormatContext *av_alloc_format_context(void);
00919 #endif
00920
00926 AVFormatContext *avformat_alloc_context(void);
00927
00941 int av_find_stream_info(AVFormatContext *ic);
00942
00953 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
00954
00974 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
00975
00987 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
00988 int flags);
00989
01016 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
01017
01022 int av_read_play(AVFormatContext *s);
01023
01029 int av_read_pause(AVFormatContext *s);
01030
01035 void av_close_input_stream(AVFormatContext *s);
01036
01042 void av_close_input_file(AVFormatContext *s);
01043
01054 AVStream *av_new_stream(AVFormatContext *s, int id);
01055 AVProgram *av_new_program(AVFormatContext *s, int id);
01056
01070 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
01071 int64_t start, int64_t end, const char *title);
01072
01082 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01083 unsigned int pts_num, unsigned int pts_den);
01084
01085 #define AVSEEK_FLAG_BACKWARD 1
01086 #define AVSEEK_FLAG_BYTE 2
01087 #define AVSEEK_FLAG_ANY 4
01088 #define AVSEEK_FLAG_FRAME 8
01089
01090 int av_find_default_stream_index(AVFormatContext *s);
01091
01100 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01101
01109 void ff_reduce_index(AVFormatContext *s, int stream_index);
01110
01117 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01118 int size, int distance, int flags);
01119
01128 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
01129 int64_t target_ts, int flags);
01130
01139 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
01140
01148 int64_t av_gen_search(AVFormatContext *s, int stream_index,
01149 int64_t target_ts, int64_t pos_min,
01150 int64_t pos_max, int64_t pos_limit,
01151 int64_t ts_min, int64_t ts_max,
01152 int flags, int64_t *ts_ret,
01153 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
01154
01156 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
01157
01165 int av_write_header(AVFormatContext *s);
01166
01179 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01180
01196 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01197
01213 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01214 AVPacket *pkt, int flush);
01215
01225 int av_write_trailer(AVFormatContext *s);
01226
01227 void dump_format(AVFormatContext *ic,
01228 int index,
01229 const char *url,
01230 int is_output);
01231
01232 #if LIBAVFORMAT_VERSION_MAJOR < 53
01233
01237 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
01238 const char *str);
01239
01244 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
01245 const char *arg);
01246 #endif
01247
01274 int64_t parse_date(const char *datestr, int duration);
01275
01277 int64_t av_gettime(void);
01278
01279
01280 #define FFM_PACKET_SIZE 4096
01281 int64_t ffm_read_write_index(int fd);
01282 int ffm_write_write_index(int fd, int64_t pos);
01283 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
01284
01291 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
01292
01305 int av_get_frame_filename(char *buf, int buf_size,
01306 const char *path, int number);
01307
01314 int av_filename_number_test(const char *filename);
01315
01330 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
01331
01338 int av_match_ext(const char *filename, const char *extensions);
01339
01340 #endif