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 31
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
00041 unsigned avformat_version(void);
00042
00043 #include <time.h>
00044 #include <stdio.h>
00045 #include "libavcodec/avcodec.h"
00046
00047 #include "avio.h"
00048
00049 struct AVFormatContext;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #define AV_METADATA_MATCH_CASE 1
00073 #define AV_METADATA_IGNORE_SUFFIX 2
00074
00075 typedef struct {
00076 char *key;
00077 char *value;
00078 }AVMetadataTag;
00079
00080 typedef struct AVMetadata AVMetadata;
00081 typedef struct AVMetadataConv AVMetadataConv;
00082
00089 AVMetadataTag *
00090 av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
00091
00098 int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
00099
00106 void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
00107 const AVMetadataConv *s_conv);
00108
00112 void av_metadata_free(AVMetadata **m);
00113
00114
00115
00116
00117 typedef struct AVPacket {
00127 int64_t pts;
00133 int64_t dts;
00134 uint8_t *data;
00135 int size;
00136 int stream_index;
00137 int flags;
00142 int duration;
00143 void (*destruct)(struct AVPacket *);
00144 void *priv;
00145 int64_t pos;
00146
00162 int64_t convergence_duration;
00163 } AVPacket;
00164 #define PKT_FLAG_KEY 0x0001
00165
00166 void av_destruct_packet_nofree(AVPacket *pkt);
00167
00171 void av_destruct_packet(AVPacket *pkt);
00172
00178 void av_init_packet(AVPacket *pkt);
00179
00188 int av_new_packet(AVPacket *pkt, int size);
00189
00198 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
00199
00204 int av_dup_packet(AVPacket *pkt);
00205
00211 static inline void av_free_packet(AVPacket *pkt)
00212 {
00213 if (pkt && pkt->destruct) {
00214 pkt->destruct(pkt);
00215 }
00216 }
00217
00218
00219
00220
00225 typedef struct AVFrac {
00226 int64_t val, num, den;
00227 } AVFrac;
00228
00229
00230
00231
00232 struct AVCodecTag;
00233
00235 typedef struct AVProbeData {
00236 const char *filename;
00237 unsigned char *buf;
00238 int buf_size;
00239 } AVProbeData;
00240
00241 #define AVPROBE_SCORE_MAX 100
00242 #define AVPROBE_PADDING_SIZE 32
00243
00244 typedef struct AVFormatParameters {
00245 AVRational time_base;
00246 int sample_rate;
00247 int channels;
00248 int width;
00249 int height;
00250 enum PixelFormat pix_fmt;
00251 int channel;
00252 const char *standard;
00253 unsigned int mpeg2ts_raw:1;
00254 unsigned int mpeg2ts_compute_pcr:1;
00257 unsigned int initial_pause:1;
00259 unsigned int prealloced_context:1;
00260 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00261 enum CodecID video_codec_id;
00262 enum CodecID audio_codec_id;
00263 #endif
00264 } AVFormatParameters;
00265
00267 #define AVFMT_NOFILE 0x0001
00268 #define AVFMT_NEEDNUMBER 0x0002
00269 #define AVFMT_SHOW_IDS 0x0008
00270 #define AVFMT_RAWPICTURE 0x0020
00272 #define AVFMT_GLOBALHEADER 0x0040
00273 #define AVFMT_NOTIMESTAMPS 0x0080
00274 #define AVFMT_GENERIC_INDEX 0x0100
00275 #define AVFMT_TS_DISCONT 0x0200
00276 #define AVFMT_VARIABLE_FPS 0x0400
00278 typedef struct AVOutputFormat {
00279 const char *name;
00285 const char *long_name;
00286 const char *mime_type;
00287 const char *extensions;
00289 int priv_data_size;
00290
00291 enum CodecID audio_codec;
00292 enum CodecID video_codec;
00293 int (*write_header)(struct AVFormatContext *);
00294 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00295 int (*write_trailer)(struct AVFormatContext *);
00297 int flags;
00299 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
00300 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
00301 AVPacket *in, int flush);
00302
00307 const struct AVCodecTag * const *codec_tag;
00308
00309 enum CodecID subtitle_codec;
00311 const AVMetadataConv *metadata_conv;
00312
00313
00314 struct AVOutputFormat *next;
00315 } AVOutputFormat;
00316
00317 typedef struct AVInputFormat {
00318 const char *name;
00324 const char *long_name;
00326 int priv_data_size;
00332 int (*read_probe)(AVProbeData *);
00337 int (*read_header)(struct AVFormatContext *,
00338 AVFormatParameters *ap);
00342 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00345 int (*read_close)(struct AVFormatContext *);
00346
00347 #if LIBAVFORMAT_VERSION_MAJOR < 53
00348
00356 int (*read_seek)(struct AVFormatContext *,
00357 int stream_index, int64_t timestamp, int flags);
00358 #endif
00359
00363 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00364 int64_t *pos, int64_t pos_limit);
00366 int flags;
00370 const char *extensions;
00372 int value;
00373
00376 int (*read_play)(struct AVFormatContext *);
00377
00380 int (*read_pause)(struct AVFormatContext *);
00381
00382 const struct AVCodecTag * const *codec_tag;
00383
00390 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00391
00392 const AVMetadataConv *metadata_conv;
00393
00394
00395 struct AVInputFormat *next;
00396 } AVInputFormat;
00397
00398 enum AVStreamParseType {
00399 AVSTREAM_PARSE_NONE,
00400 AVSTREAM_PARSE_FULL,
00401 AVSTREAM_PARSE_HEADERS,
00402 AVSTREAM_PARSE_TIMESTAMPS,
00403 };
00404
00405 typedef struct AVIndexEntry {
00406 int64_t pos;
00407 int64_t timestamp;
00408 #define AVINDEX_KEYFRAME 0x0001
00409 int flags:2;
00410 int size:30;
00411 int min_distance;
00412 } AVIndexEntry;
00413
00414 #define AV_DISPOSITION_DEFAULT 0x0001
00415 #define AV_DISPOSITION_DUB 0x0002
00416 #define AV_DISPOSITION_ORIGINAL 0x0004
00417 #define AV_DISPOSITION_COMMENT 0x0008
00418 #define AV_DISPOSITION_LYRICS 0x0010
00419 #define AV_DISPOSITION_KARAOKE 0x0020
00420
00428 typedef struct AVStream {
00429 int index;
00430 int id;
00431 AVCodecContext *codec;
00440 AVRational r_frame_rate;
00441 void *priv_data;
00442
00443
00444 int64_t first_dts;
00446 struct AVFrac pts;
00447
00453 AVRational time_base;
00454 int pts_wrap_bits;
00455
00456 int stream_copy;
00457 enum AVDiscard discard;
00458
00461 float quality;
00470 int64_t start_time;
00476 int64_t duration;
00477
00478 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00479 char language[4];
00480 #endif
00481
00482
00483 enum AVStreamParseType need_parsing;
00484 struct AVCodecParserContext *parser;
00485
00486 int64_t cur_dts;
00487 int last_IP_duration;
00488 int64_t last_IP_pts;
00489
00490 AVIndexEntry *index_entries;
00492 int nb_index_entries;
00493 unsigned int index_entries_allocated_size;
00494
00495 int64_t nb_frames;
00496
00497 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00498 int64_t unused[4+1];
00499
00500 char *filename;
00501 #endif
00502
00503 int disposition;
00505 AVProbeData probe_data;
00506 #define MAX_REORDER_DELAY 16
00507 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00508
00514 AVRational sample_aspect_ratio;
00515
00516 AVMetadata *metadata;
00517
00518
00519 const uint8_t *cur_ptr;
00520 int cur_len;
00521 AVPacket cur_pkt;
00522
00523
00531 int64_t reference_dts;
00532 } AVStream;
00533
00534 #define AV_PROGRAM_RUNNING 1
00535
00542 typedef struct AVProgram {
00543 int id;
00544 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00545 char *provider_name;
00546 char *name;
00547 #endif
00548 int flags;
00549 enum AVDiscard discard;
00550 unsigned int *stream_index;
00551 unsigned int nb_stream_indexes;
00552 AVMetadata *metadata;
00553 } AVProgram;
00554
00555 #define AVFMTCTX_NOHEADER 0x0001
00558 typedef struct AVChapter {
00559 int id;
00560 AVRational time_base;
00561 int64_t start, end;
00562 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00563 char *title;
00564 #endif
00565 AVMetadata *metadata;
00566 } AVChapter;
00567
00568 #define MAX_STREAMS 20
00569
00577 typedef struct AVFormatContext {
00578 const AVClass *av_class;
00579
00580 struct AVInputFormat *iformat;
00581 struct AVOutputFormat *oformat;
00582 void *priv_data;
00583 ByteIOContext *pb;
00584 unsigned int nb_streams;
00585 AVStream *streams[MAX_STREAMS];
00586 char filename[1024];
00587
00588 int64_t timestamp;
00589 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00590 char title[512];
00591 char author[512];
00592 char copyright[512];
00593 char comment[512];
00594 char album[512];
00595 int year;
00596 int track;
00597 char genre[32];
00598 #endif
00599
00600 int ctx_flags;
00601
00605 struct AVPacketList *packet_buffer;
00606
00610 int64_t start_time;
00614 int64_t duration;
00616 int64_t file_size;
00620 int bit_rate;
00621
00622
00623 AVStream *cur_st;
00624 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00625 const uint8_t *cur_ptr_deprecated;
00626 int cur_len_deprecated;
00627 AVPacket cur_pkt_deprecated;
00628 #endif
00629
00630
00631 int64_t data_offset;
00632 int index_built;
00633
00634 int mux_rate;
00635 int packet_size;
00636 int preload;
00637 int max_delay;
00638
00639 #define AVFMT_NOOUTPUTLOOP -1
00640 #define AVFMT_INFINITEOUTPUTLOOP 0
00641
00642 int loop_output;
00643
00644 int flags;
00645 #define AVFMT_FLAG_GENPTS 0x0001
00646 #define AVFMT_FLAG_IGNIDX 0x0002
00647 #define AVFMT_FLAG_NONBLOCK 0x0004
00648
00649 int loop_input;
00651 unsigned int probesize;
00652
00657 int max_analyze_duration;
00658
00659 const uint8_t *key;
00660 int keylen;
00661
00662 unsigned int nb_programs;
00663 AVProgram **programs;
00664
00669 enum CodecID video_codec_id;
00674 enum CodecID audio_codec_id;
00679 enum CodecID subtitle_codec_id;
00680
00691 unsigned int max_index_size;
00692
00697 unsigned int max_picture_buffer;
00698
00699 unsigned int nb_chapters;
00700 AVChapter **chapters;
00701
00705 int debug;
00706 #define FF_FDEBUG_TS 0x0001
00707
00714 struct AVPacketList *raw_packet_buffer;
00715 struct AVPacketList *raw_packet_buffer_end;
00716
00717 struct AVPacketList *packet_buffer_end;
00718
00719 AVMetadata *metadata;
00720 } AVFormatContext;
00721
00722 typedef struct AVPacketList {
00723 AVPacket pkt;
00724 struct AVPacketList *next;
00725 } AVPacketList;
00726
00727 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00728 extern AVInputFormat *first_iformat;
00729 extern AVOutputFormat *first_oformat;
00730 #endif
00731
00737 AVInputFormat *av_iformat_next(AVInputFormat *f);
00738
00744 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
00745
00746 enum CodecID av_guess_image2_codec(const char *filename);
00747
00748
00749
00750
00751
00752 void av_register_input_format(AVInputFormat *format);
00753 void av_register_output_format(AVOutputFormat *format);
00754 AVOutputFormat *guess_stream_format(const char *short_name,
00755 const char *filename,
00756 const char *mime_type);
00757 AVOutputFormat *guess_format(const char *short_name,
00758 const char *filename,
00759 const char *mime_type);
00760
00764 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
00765 const char *filename, const char *mime_type,
00766 enum CodecType type);
00767
00777 void av_hex_dump(FILE *f, uint8_t *buf, int size);
00778
00791 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
00792
00800 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
00801
00812 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
00813
00823 void av_register_all(void);
00824
00826 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
00827 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
00828
00829
00830
00834 AVInputFormat *av_find_input_format(const char *short_name);
00835
00842 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
00843
00848 int av_open_input_stream(AVFormatContext **ic_ptr,
00849 ByteIOContext *pb, const char *filename,
00850 AVInputFormat *fmt, AVFormatParameters *ap);
00851
00864 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
00865 AVInputFormat *fmt,
00866 int buf_size,
00867 AVFormatParameters *ap);
00868
00869 #if LIBAVFORMAT_VERSION_MAJOR < 53
00870
00873 attribute_deprecated AVFormatContext *av_alloc_format_context(void);
00874 #endif
00875
00881 AVFormatContext *avformat_alloc_context(void);
00882
00896 int av_find_stream_info(AVFormatContext *ic);
00897
00908 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
00909
00929 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
00930
00942 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
00943 int flags);
00944
00971 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
00972
00977 int av_read_play(AVFormatContext *s);
00978
00984 int av_read_pause(AVFormatContext *s);
00985
00990 void av_close_input_stream(AVFormatContext *s);
00991
00997 void av_close_input_file(AVFormatContext *s);
00998
01009 AVStream *av_new_stream(AVFormatContext *s, int id);
01010 AVProgram *av_new_program(AVFormatContext *s, int id);
01011
01025 AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
01026 int64_t start, int64_t end, const char *title);
01027
01037 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
01038 unsigned int pts_num, unsigned int pts_den);
01039
01040 #define AVSEEK_FLAG_BACKWARD 1
01041 #define AVSEEK_FLAG_BYTE 2
01042 #define AVSEEK_FLAG_ANY 4
01043
01044 int av_find_default_stream_index(AVFormatContext *s);
01045
01054 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
01055
01063 void ff_reduce_index(AVFormatContext *s, int stream_index);
01064
01071 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
01072 int size, int distance, int flags);
01073
01082 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
01083 int64_t target_ts, int flags);
01084
01093 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
01094
01102 int64_t av_gen_search(AVFormatContext *s, int stream_index,
01103 int64_t target_ts, int64_t pos_min,
01104 int64_t pos_max, int64_t pos_limit,
01105 int64_t ts_min, int64_t ts_max,
01106 int flags, int64_t *ts_ret,
01107 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
01108
01110 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
01111
01119 int av_write_header(AVFormatContext *s);
01120
01133 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
01134
01150 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
01151
01167 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
01168 AVPacket *pkt, int flush);
01169
01179 int av_write_trailer(AVFormatContext *s);
01180
01181 void dump_format(AVFormatContext *ic,
01182 int index,
01183 const char *url,
01184 int is_output);
01185
01186 #if LIBAVFORMAT_VERSION_MAJOR < 53
01187
01191 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
01192 const char *str);
01193
01198 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
01199 const char *arg);
01200 #endif
01201
01228 int64_t parse_date(const char *datestr, int duration);
01229
01231 int64_t av_gettime(void);
01232
01233
01234 #define FFM_PACKET_SIZE 4096
01235 int64_t ffm_read_write_index(int fd);
01236 int ffm_write_write_index(int fd, int64_t pos);
01237 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
01238
01245 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
01246
01259 int av_get_frame_filename(char *buf, int buf_size,
01260 const char *path, int number);
01261
01268 int av_filename_number_test(const char *filename);
01269
01284 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
01285
01286 #ifdef HAVE_AV_CONFIG_H
01287
01288 void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
01289
01290 #ifdef __GNUC__
01291 #define dynarray_add(tab, nb_ptr, elem)\
01292 do {\
01293 __typeof__(tab) _tab = (tab);\
01294 __typeof__(elem) _elem = (elem);\
01295 (void)sizeof(**_tab == _elem); \
01296 ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
01297 } while(0)
01298 #else
01299 #define dynarray_add(tab, nb_ptr, elem)\
01300 do {\
01301 ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
01302 } while(0)
01303 #endif
01304
01305 time_t mktimegm(struct tm *tm);
01306 struct tm *brktimegm(time_t secs, struct tm *tm);
01307 const char *small_strptime(const char *p, const char *fmt,
01308 struct tm *dt);
01309
01310 struct in_addr;
01311 int resolve_host(struct in_addr *sin_addr, const char *hostname);
01312
01313 void url_split(char *proto, int proto_size,
01314 char *authorization, int authorization_size,
01315 char *hostname, int hostname_size,
01316 int *port_ptr,
01317 char *path, int path_size,
01318 const char *url);
01319
01320 int match_ext(const char *filename, const char *extensions);
01321
01322 #endif
01323
01324 #endif