Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2001 Fabrice Bellard 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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> /* FILE */ 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 /* packet functions */ 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 /* fractional numbers for exact pts handling */ 00216 00221 typedef struct AVFrac { 00222 int64_t val, num, den; 00223 } AVFrac; 00224 00225 /*************************************************/ 00226 /* input/output formats */ 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 ///< maximum score, half of that is used for file-extension-based detection 00240 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer 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 00277 typedef struct AVOutputFormat { 00278 const char *name; 00284 const char *long_name; 00285 const char *mime_type; 00286 const char *extensions; 00290 int priv_data_size; 00291 /* output support */ 00292 enum CodecID audio_codec; 00293 enum CodecID video_codec; 00294 int (*write_header)(struct AVFormatContext *); 00295 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); 00296 int (*write_trailer)(struct AVFormatContext *); 00302 int flags; 00306 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *); 00307 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, 00308 AVPacket *in, int flush); 00309 00314 const struct AVCodecTag * const *codec_tag; 00315 00316 enum CodecID subtitle_codec; 00318 #if FF_API_OLD_METADATA2 00319 const AVMetadataConv *metadata_conv; 00320 #endif 00321 00322 const AVClass *priv_class; 00323 00324 /* private fields */ 00325 struct AVOutputFormat *next; 00326 } AVOutputFormat; 00327 00328 typedef struct AVInputFormat { 00333 const char *name; 00334 00340 const char *long_name; 00341 00345 int priv_data_size; 00346 00352 int (*read_probe)(AVProbeData *); 00353 00360 int (*read_header)(struct AVFormatContext *, 00361 AVFormatParameters *ap); 00362 00372 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); 00373 00378 int (*read_close)(struct AVFormatContext *); 00379 00380 #if FF_API_READ_SEEK 00381 00389 attribute_deprecated int (*read_seek)(struct AVFormatContext *, 00390 int stream_index, int64_t timestamp, int flags); 00391 #endif 00392 00396 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, 00397 int64_t *pos, int64_t pos_limit); 00398 00402 int flags; 00403 00409 const char *extensions; 00410 00414 int value; 00415 00420 int (*read_play)(struct AVFormatContext *); 00421 00426 int (*read_pause)(struct AVFormatContext *); 00427 00428 const struct AVCodecTag * const *codec_tag; 00429 00436 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); 00437 00438 #if FF_API_OLD_METADATA2 00439 const AVMetadataConv *metadata_conv; 00440 #endif 00441 00442 const AVClass *priv_class; 00443 00444 /* private fields */ 00445 struct AVInputFormat *next; 00446 } AVInputFormat; 00447 00448 enum AVStreamParseType { 00449 AVSTREAM_PARSE_NONE, 00450 AVSTREAM_PARSE_FULL, 00451 AVSTREAM_PARSE_HEADERS, 00452 AVSTREAM_PARSE_TIMESTAMPS, 00453 AVSTREAM_PARSE_FULL_ONCE, 00454 }; 00455 00456 typedef struct AVIndexEntry { 00457 int64_t pos; 00458 int64_t timestamp; 00459 #define AVINDEX_KEYFRAME 0x0001 00460 int flags:2; 00461 int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment). 00462 int min_distance; 00463 } AVIndexEntry; 00464 00465 #define AV_DISPOSITION_DEFAULT 0x0001 00466 #define AV_DISPOSITION_DUB 0x0002 00467 #define AV_DISPOSITION_ORIGINAL 0x0004 00468 #define AV_DISPOSITION_COMMENT 0x0008 00469 #define AV_DISPOSITION_LYRICS 0x0010 00470 #define AV_DISPOSITION_KARAOKE 0x0020 00471 00477 #define AV_DISPOSITION_FORCED 0x0040 00478 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 00479 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 00480 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 00489 typedef struct AVStream { 00490 int index; 00491 int id; 00492 AVCodecContext *codec; 00501 AVRational r_frame_rate; 00502 void *priv_data; 00503 00504 /* internal data used in av_find_stream_info() */ 00505 int64_t first_dts; 00506 00510 struct AVFrac pts; 00511 00519 AVRational time_base; 00520 int pts_wrap_bits; 00521 /* ffmpeg.c private use */ 00522 int stream_copy; 00523 enum AVDiscard discard; 00524 00525 //FIXME move stuff to a flags field? 00530 float quality; 00531 00538 int64_t start_time; 00539 00545 int64_t duration; 00546 00547 /* av_read_frame() support */ 00548 enum AVStreamParseType need_parsing; 00549 struct AVCodecParserContext *parser; 00550 00551 int64_t cur_dts; 00552 int last_IP_duration; 00553 int64_t last_IP_pts; 00554 /* av_seek_frame() support */ 00555 AVIndexEntry *index_entries; 00557 int nb_index_entries; 00558 unsigned int index_entries_allocated_size; 00559 00560 int64_t nb_frames; 00561 00562 int disposition; 00564 AVProbeData probe_data; 00565 #define MAX_REORDER_DELAY 16 00566 int64_t pts_buffer[MAX_REORDER_DELAY+1]; 00567 00573 AVRational sample_aspect_ratio; 00574 00575 AVDictionary *metadata; 00576 00577 /* Intended mostly for av_read_frame() support. Not supposed to be used by */ 00578 /* external applications; try to use something else if at all possible. */ 00579 const uint8_t *cur_ptr; 00580 int cur_len; 00581 AVPacket cur_pkt; 00582 00583 // Timestamp generation support: 00591 int64_t reference_dts; 00592 00597 #define MAX_PROBE_PACKETS 2500 00598 int probe_packets; 00599 00604 struct AVPacketList *last_in_packet_buffer; 00605 00609 AVRational avg_frame_rate; 00610 00614 int codec_info_nb_frames; 00615 00619 #define MAX_STD_TIMEBASES (60*12+5) 00620 struct { 00621 int64_t last_dts; 00622 int64_t duration_gcd; 00623 int duration_count; 00624 double duration_error[MAX_STD_TIMEBASES]; 00625 int64_t codec_info_duration; 00626 } *info; 00627 } AVStream; 00628 00629 #define AV_PROGRAM_RUNNING 1 00630 00637 typedef struct AVProgram { 00638 int id; 00639 int flags; 00640 enum AVDiscard discard; 00641 unsigned int *stream_index; 00642 unsigned int nb_stream_indexes; 00643 AVDictionary *metadata; 00644 } AVProgram; 00645 00646 #define AVFMTCTX_NOHEADER 0x0001 00649 typedef struct AVChapter { 00650 int id; 00651 AVRational time_base; 00652 int64_t start, end; 00653 AVDictionary *metadata; 00654 } AVChapter; 00655 00663 typedef struct AVFormatContext { 00664 const AVClass *av_class; 00665 /* Can only be iformat or oformat, not both at the same time. */ 00666 struct AVInputFormat *iformat; 00667 struct AVOutputFormat *oformat; 00668 void *priv_data; 00669 AVIOContext *pb; 00670 unsigned int nb_streams; 00671 AVStream **streams; 00672 char filename[1024]; 00673 /* stream info */ 00674 int64_t timestamp; 00675 00676 int ctx_flags; 00677 /* private data for pts handling (do not modify directly). */ 00683 struct AVPacketList *packet_buffer; 00684 00690 int64_t start_time; 00691 00698 int64_t duration; 00699 00703 int64_t file_size; 00704 00710 int bit_rate; 00711 00712 /* av_read_frame() support */ 00713 AVStream *cur_st; 00714 00715 /* av_seek_frame() support */ 00716 int64_t data_offset; 00718 int mux_rate; 00719 unsigned int packet_size; 00720 int preload; 00721 int max_delay; 00722 00723 #define AVFMT_NOOUTPUTLOOP -1 00724 #define AVFMT_INFINITEOUTPUTLOOP 0 00725 00728 int loop_output; 00729 00730 int flags; 00731 #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames. 00732 #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index. 00733 #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input. 00734 #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS 00735 #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container 00736 #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled 00737 #if FF_API_FLAG_RTP_HINT 00738 #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead 00739 #endif 00740 #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it. 00741 00742 int loop_input; 00743 00747 unsigned int probesize; 00748 00753 int max_analyze_duration; 00754 00755 const uint8_t *key; 00756 int keylen; 00757 00758 unsigned int nb_programs; 00759 AVProgram **programs; 00760 00765 enum CodecID video_codec_id; 00766 00771 enum CodecID audio_codec_id; 00772 00777 enum CodecID subtitle_codec_id; 00778 00789 unsigned int max_index_size; 00790 00795 unsigned int max_picture_buffer; 00796 00797 unsigned int nb_chapters; 00798 AVChapter **chapters; 00799 00803 int debug; 00804 #define FF_FDEBUG_TS 0x0001 00805 00812 struct AVPacketList *raw_packet_buffer; 00813 struct AVPacketList *raw_packet_buffer_end; 00814 00815 struct AVPacketList *packet_buffer_end; 00816 00817 AVDictionary *metadata; 00818 00823 #define RAW_PACKET_BUFFER_SIZE 2500000 00824 int raw_packet_buffer_remaining_size; 00825 00833 int64_t start_time_realtime; 00834 00838 int fps_probe_size; 00839 } AVFormatContext; 00840 00841 typedef struct AVPacketList { 00842 AVPacket pkt; 00843 struct AVPacketList *next; 00844 } AVPacketList; 00845 00851 AVInputFormat *av_iformat_next(AVInputFormat *f); 00852 00858 AVOutputFormat *av_oformat_next(AVOutputFormat *f); 00859 00860 #if FF_API_GUESS_IMG2_CODEC 00861 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename); 00862 #endif 00863 00864 /* XXX: Use automatic init with either ELF sections or C file parser */ 00865 /* modules. */ 00866 00867 /* utils.c */ 00868 void av_register_input_format(AVInputFormat *format); 00869 void av_register_output_format(AVOutputFormat *format); 00870 00883 AVOutputFormat *av_guess_format(const char *short_name, 00884 const char *filename, 00885 const char *mime_type); 00886 00890 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, 00891 const char *filename, const char *mime_type, 00892 enum AVMediaType type); 00893 00903 void av_hex_dump(FILE *f, uint8_t *buf, int size); 00904 00917 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size); 00918 00927 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st); 00928 00929 00941 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, 00942 AVStream *st); 00943 00944 #if FF_API_PKT_DUMP 00945 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); 00946 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, 00947 int dump_payload); 00948 #endif 00949 00959 void av_register_all(void); 00960 00968 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag); 00969 00977 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id); 00978 00979 /* media file input */ 00980 00984 AVInputFormat *av_find_input_format(const char *short_name); 00985 00992 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened); 00993 01005 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max); 01006 01022 int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, 01023 const char *filename, void *logctx, 01024 unsigned int offset, unsigned int max_probe_size); 01025 01026 #if FF_API_FORMAT_PARAMETERS 01027 01032 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr, 01033 AVIOContext *pb, const char *filename, 01034 AVInputFormat *fmt, AVFormatParameters *ap); 01035 01050 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 01051 AVInputFormat *fmt, 01052 int buf_size, 01053 AVFormatParameters *ap); 01054 #endif 01055 01075 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options); 01076 01082 AVFormatContext *avformat_alloc_context(void); 01083 01097 int av_find_stream_info(AVFormatContext *ic); 01098 01123 int av_find_best_stream(AVFormatContext *ic, 01124 enum AVMediaType type, 01125 int wanted_stream_nb, 01126 int related_stream, 01127 AVCodec **decoder_ret, 01128 int flags); 01129 01140 int av_read_packet(AVFormatContext *s, AVPacket *pkt); 01141 01166 int av_read_frame(AVFormatContext *s, AVPacket *pkt); 01167 01179 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, 01180 int flags); 01181 01208 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); 01209 01214 int av_read_play(AVFormatContext *s); 01215 01221 int av_read_pause(AVFormatContext *s); 01222 01227 void av_close_input_stream(AVFormatContext *s); 01228 01234 void av_close_input_file(AVFormatContext *s); 01235 01240 void avformat_free_context(AVFormatContext *s); 01241 01252 AVStream *av_new_stream(AVFormatContext *s, int id); 01253 AVProgram *av_new_program(AVFormatContext *s, int id); 01254 01265 void av_set_pts_info(AVStream *s, int pts_wrap_bits, 01266 unsigned int pts_num, unsigned int pts_den); 01267 01268 #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward 01269 #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes 01270 #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes 01271 #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number 01272 01273 int av_find_default_stream_index(AVFormatContext *s); 01274 01283 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); 01284 01291 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, 01292 int size, int distance, int flags); 01293 01302 int av_seek_frame_binary(AVFormatContext *s, int stream_index, 01303 int64_t target_ts, int flags); 01304 01313 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); 01314 01322 int64_t av_gen_search(AVFormatContext *s, int stream_index, 01323 int64_t target_ts, int64_t pos_min, 01324 int64_t pos_max, int64_t pos_limit, 01325 int64_t ts_min, int64_t ts_max, 01326 int flags, int64_t *ts_ret, 01327 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); 01328 01332 #if FF_API_FORMAT_PARAMETERS 01333 01336 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); 01337 #endif 01338 01358 void av_url_split(char *proto, int proto_size, 01359 char *authorization, int authorization_size, 01360 char *hostname, int hostname_size, 01361 int *port_ptr, 01362 char *path, int path_size, 01363 const char *url); 01364 01380 int avformat_write_header(AVFormatContext *s, AVDictionary **options); 01381 01382 #if FF_API_FORMAT_PARAMETERS 01383 01394 attribute_deprecated int av_write_header(AVFormatContext *s); 01395 #endif 01396 01409 int av_write_frame(AVFormatContext *s, AVPacket *pkt); 01410 01426 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt); 01427 01443 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, 01444 AVPacket *pkt, int flush); 01445 01455 int av_write_trailer(AVFormatContext *s); 01456 01457 #if FF_API_DUMP_FORMAT 01458 attribute_deprecated void dump_format(AVFormatContext *ic, 01459 int index, 01460 const char *url, 01461 int is_output); 01462 #endif 01463 01464 void av_dump_format(AVFormatContext *ic, 01465 int index, 01466 const char *url, 01467 int is_output); 01468 01469 #if FF_API_PARSE_DATE 01470 01477 attribute_deprecated 01478 int64_t parse_date(const char *datestr, int duration); 01479 #endif 01480 01484 int64_t av_gettime(void); 01485 01486 #if FF_API_FIND_INFO_TAG 01487 01490 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); 01491 #endif 01492 01505 int av_get_frame_filename(char *buf, int buf_size, 01506 const char *path, int number); 01507 01514 int av_filename_number_test(const char *filename); 01515 01530 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size); 01531 01532 #if FF_API_SDP_CREATE 01533 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size); 01534 #endif 01535 01542 int av_match_ext(const char *filename, const char *extensions); 01543 01544 #endif /* AVFORMAT_AVFORMAT_H */