avformat.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVFORMAT_AVFORMAT_H
22 #define AVFORMAT_AVFORMAT_H
23 
138 #include <time.h>
139 #include <stdio.h> /* FILE */
140 #include "libavcodec/avcodec.h"
141 #include "libavutil/dict.h"
142 #include "libavutil/log.h"
143 
144 #include "avio.h"
145 #include "libavformat/version.h"
146 
147 struct AVFormatContext;
148 
149 
223 #if FF_API_OLD_METADATA2
224 
231 #define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
232 #define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
233 #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
234 #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
235 #define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
236 
237 typedef attribute_deprecated AVDictionary AVMetadata;
238 typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
239 
240 typedef struct AVMetadataConv AVMetadataConv;
241 
251 av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
252 
263 attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
264 
268 attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
269  const AVMetadataConv *s_conv);
270 
279 attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
280 
284 attribute_deprecated void av_metadata_free(AVDictionary **m);
288 #endif
289 
290 
291 /* packet functions */
292 
293 
302 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
303 
304 
318 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
319 
320 /*************************************************/
321 /* fractional numbers for exact pts handling */
322 
327 typedef struct AVFrac {
328  int64_t val, num, den;
329 } AVFrac;
330 
331 /*************************************************/
332 /* input/output formats */
333 
334 struct AVCodecTag;
335 
339 typedef struct AVProbeData {
340  const char *filename;
341  unsigned char *buf;
342  int buf_size;
343 } AVProbeData;
344 
345 #define AVPROBE_SCORE_MAX 100
346 #define AVPROBE_PADDING_SIZE 32
347 
348 typedef struct AVFormatParameters {
349 #if FF_API_FORMAT_PARAMETERS
351  attribute_deprecated int sample_rate;
352  attribute_deprecated int channels;
356  attribute_deprecated int channel;
357  attribute_deprecated const char *standard;
358  attribute_deprecated unsigned int mpeg2ts_raw:1;
360  attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
361  attribute_deprecated unsigned int initial_pause:1;
363  attribute_deprecated unsigned int prealloced_context:1;
364 #endif
366 
368 #define AVFMT_NOFILE 0x0001
369 #define AVFMT_NEEDNUMBER 0x0002
370 #define AVFMT_SHOW_IDS 0x0008
371 #define AVFMT_RAWPICTURE 0x0020
373 #define AVFMT_GLOBALHEADER 0x0040
374 #define AVFMT_NOTIMESTAMPS 0x0080
375 #define AVFMT_GENERIC_INDEX 0x0100
376 #define AVFMT_TS_DISCONT 0x0200
377 #define AVFMT_VARIABLE_FPS 0x0400
378 #define AVFMT_NODIMENSIONS 0x0800
379 #define AVFMT_NOSTREAMS 0x1000
380 #define AVFMT_NOBINSEARCH 0x2000
381 #define AVFMT_NOGENSEARCH 0x4000
382 #define AVFMT_NO_BYTE_SEEK 0x8000
388 typedef struct AVOutputFormat {
389  const char *name;
395  const char *long_name;
396  const char *mime_type;
397  const char *extensions;
402  /* output support */
405  int (*write_header)(struct AVFormatContext *);
406  int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
407  int (*write_trailer)(struct AVFormatContext *);
413  int flags;
417  int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
419  AVPacket *in, int flush);
420 
425  const struct AVCodecTag * const *codec_tag;
426 
429 #if FF_API_OLD_METADATA2
430  const AVMetadataConv *metadata_conv;
431 #endif
432 
434 
441  int (*query_codec)(enum CodecID id, int std_compliance);
442 
443  /* private fields */
454 typedef struct AVInputFormat {
459  const char *name;
460 
466  const char *long_name;
467 
472 
479 
486  int (*read_header)(struct AVFormatContext *,
487  AVFormatParameters *ap);
488 
498  int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
499 
504  int (*read_close)(struct AVFormatContext *);
505 
514  int (*read_seek)(struct AVFormatContext *,
515  int stream_index, int64_t timestamp, int flags);
516 
521  int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
522  int64_t *pos, int64_t pos_limit);
523 
529  int flags;
530 
536  const char *extensions;
537 
541  int value;
542 
547  int (*read_play)(struct AVFormatContext *);
548 
553  int (*read_pause)(struct AVFormatContext *);
554 
555  const struct AVCodecTag * const *codec_tag;
556 
563  int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
564 
565 #if FF_API_OLD_METADATA2
566  const AVMetadataConv *metadata_conv;
567 #endif
568 
570 
571  /* private fields */
573 } AVInputFormat;
584 };
585 
586 typedef struct AVIndexEntry {
587  int64_t pos;
588  int64_t timestamp;
589 #define AVINDEX_KEYFRAME 0x0001
590  int flags:2;
591  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).
593 } AVIndexEntry;
594 
595 #define AV_DISPOSITION_DEFAULT 0x0001
596 #define AV_DISPOSITION_DUB 0x0002
597 #define AV_DISPOSITION_ORIGINAL 0x0004
598 #define AV_DISPOSITION_COMMENT 0x0008
599 #define AV_DISPOSITION_LYRICS 0x0010
600 #define AV_DISPOSITION_KARAOKE 0x0020
601 
607 #define AV_DISPOSITION_FORCED 0x0040
608 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
609 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
610 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
619 typedef struct AVStream {
620  int index;
621  int id;
632  void *priv_data;
633 
634 #if FF_API_REORDER_PRIVATE
635  /* internal data used in av_find_stream_info() */
636  int64_t first_dts;
637 #endif
638 
642  struct AVFrac pts;
643 
652 #if FF_API_REORDER_PRIVATE
653  int pts_wrap_bits;
654 #endif
655 #if FF_API_STREAM_COPY
656  /* ffmpeg.c private use */
657  attribute_deprecated int stream_copy;
658 #endif
660 
661 #if FF_API_AVSTREAM_QUALITY
662  //FIXME move stuff to a flags field?
667  attribute_deprecated float quality;
668 #endif
669 
676  int64_t start_time;
677 
683  int64_t duration;
684 
685 #if FF_API_REORDER_PRIVATE
686  /* av_read_frame() support */
687  enum AVStreamParseType need_parsing;
689 
690  int64_t cur_dts;
691  int last_IP_duration;
692  int64_t last_IP_pts;
693  /* av_seek_frame() support */
694  AVIndexEntry *index_entries;
696  int nb_index_entries;
697  unsigned int index_entries_allocated_size;
698 #endif
699 
700  int64_t nb_frames;
701 
704 #if FF_API_REORDER_PRIVATE
705  AVProbeData probe_data;
706 #define MAX_REORDER_DELAY 16
707  int64_t pts_buffer[MAX_REORDER_DELAY+1];
708 #endif
709 
716 
718 
719 #if FF_API_REORDER_PRIVATE
720  /* Intended mostly for av_read_frame() support. Not supposed to be used by */
721  /* external applications; try to use something else if at all possible. */
722  const uint8_t *cur_ptr;
723  int cur_len;
724  AVPacket cur_pkt;
725 
726  // Timestamp generation support:
734  int64_t reference_dts;
735 
740 #define MAX_PROBE_PACKETS 2500
741  int probe_packets;
742 
748  struct AVPacketList *last_in_packet_buffer;
749 #endif
750 
755 
756  /*****************************************************************
757  * All fields below this line are not part of the public API. They
758  * may not be used outside of libavformat and can be changed and
759  * removed at will.
760  * New public fields should be added right above.
761  *****************************************************************
762  */
763 
768 
772 #define MAX_STD_TIMEBASES (60*12+5)
773  struct {
774  int64_t last_dts;
775  int64_t duration_gcd;
777  double duration_error[MAX_STD_TIMEBASES];
780  } *info;
781 #if !FF_API_REORDER_PRIVATE
782  const uint8_t *cur_ptr;
783  int cur_len;
785 
786  // Timestamp generation support:
794  int64_t reference_dts;
795  int64_t first_dts;
796  int64_t cur_dts;
798  int64_t last_IP_pts;
799 
803 #define MAX_PROBE_PACKETS 2500
805 
811 #define MAX_REORDER_DELAY 16
812  int64_t pts_buffer[MAX_REORDER_DELAY+1];
813  /* av_read_frame() support */
816 
817  AVIndexEntry *index_entries;
821 
823 #endif
824 } AVStream;
825 
826 #define AV_PROGRAM_RUNNING 1
827 
834 typedef struct AVProgram {
835  int id;
836  int flags;
838  unsigned int *stream_index;
839  unsigned int nb_stream_indexes;
841 } AVProgram;
842 
843 #define AVFMTCTX_NOHEADER 0x0001
846 typedef struct AVChapter {
847  int id;
849  int64_t start, end;
851 } AVChapter;
852 
861 typedef struct AVFormatContext {
867 
876 
881  void *priv_data;
882 
883  /*
884  * I/O context.
885  *
886  * decoding: either set by the user before avformat_open_input() (then
887  * the user must close it manually) or set by avformat_open_input().
888  * encoding: set by the user.
889  *
890  * Do NOT set this field if AVFMT_NOFILE flag is set in
891  * iformat/oformat.flags. In such a case, the (de)muxer will handle
892  * I/O in some other way and this field will be NULL.
893  */
895 
905  unsigned int nb_streams;
907 
908  char filename[1024];
909  /* stream info */
910 #if FF_API_TIMESTAMP
911 
914  attribute_deprecated int64_t timestamp;
915 #endif
916 
917  int ctx_flags;
918 #if FF_API_REORDER_PRIVATE
919  /* private data for pts handling (do not modify directly). */
925  struct AVPacketList *packet_buffer;
926 #endif
927 
933  int64_t start_time;
934 
941  int64_t duration;
942 
943 #if FF_API_FILESIZE
944 
947  attribute_deprecated int64_t file_size;
948 #endif
949 
955  int bit_rate;
956 
957 #if FF_API_REORDER_PRIVATE
958  /* av_read_frame() support */
959  AVStream *cur_st;
960 
961  /* av_seek_frame() support */
962  int64_t data_offset;
963 #endif
964 
965 #if FF_API_MUXRATE
966 
969  attribute_deprecated int mux_rate;
970 #endif
971  unsigned int packet_size;
972 #if FF_API_PRELOAD
973  attribute_deprecated int preload;
974 #endif
976 
977 #if FF_API_LOOP_OUTPUT
978 #define AVFMT_NOOUTPUTLOOP -1
979 #define AVFMT_INFINITEOUTPUTLOOP 0
980 
986 #endif
987 
988  int flags;
989 #define AVFMT_FLAG_GENPTS 0x0001
990 #define AVFMT_FLAG_IGNIDX 0x0002
991 #define AVFMT_FLAG_NONBLOCK 0x0004
992 #define AVFMT_FLAG_IGNDTS 0x0008
993 #define AVFMT_FLAG_NOFILLIN 0x0010
994 #define AVFMT_FLAG_NOPARSE 0x0020
995 #if FF_API_FLAG_RTP_HINT
996 #define AVFMT_FLAG_RTP_HINT 0x0040
997 #endif
998 #define AVFMT_FLAG_CUSTOM_IO 0x0080
999 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
1000 
1001 #if FF_API_LOOP_INPUT
1002 
1006 #endif
1007 
1011  unsigned int probesize;
1012 
1018 
1019  const uint8_t *key;
1020  int keylen;
1021 
1022  unsigned int nb_programs;
1024 
1030 
1036 
1042 
1053  unsigned int max_index_size;
1054 
1059  unsigned int max_picture_buffer;
1060 
1061  unsigned int nb_chapters;
1063 
1067  int debug;
1068 #define FF_FDEBUG_TS 0x0001
1069 
1070 #if FF_API_REORDER_PRIVATE
1071 
1079 
1081 #endif
1082 
1084 
1085 #if FF_API_REORDER_PRIVATE
1086 
1090 #define RAW_PACKET_BUFFER_SIZE 2500000
1092 #endif
1093 
1102 
1107 
1115 
1126 
1127  /*****************************************************************
1128  * All fields below this line are not part of the public API. They
1129  * may not be used outside of libavformat and can be changed and
1130  * removed at will.
1131  * New public fields should be added right above.
1132  *****************************************************************
1133  */
1134 #if !FF_API_REORDER_PRIVATE
1135 
1146 #define RAW_PACKET_BUFFER_SIZE 2500000
1148 
1156 
1157  /* av_read_frame() support */
1159 
1160  /* av_seek_frame() support */
1161  int64_t data_offset;
1162 #endif
1163 } AVFormatContext;
1164 
1165 typedef struct AVPacketList {
1168 } AVPacketList;
1169 
1170 
1183 unsigned avformat_version(void);
1184 
1188 const char *avformat_configuration(void);
1189 
1193 const char *avformat_license(void);
1194 
1204 void av_register_all(void);
1205 
1208 
1217 int avformat_network_init(void);
1218 
1222 int avformat_network_deinit(void);
1223 
1230 
1237 
1244 
1250 
1257 const AVClass *avformat_get_class(void);
1258 
1275 
1277 
1283 #if FF_API_GUESS_IMG2_CODEC
1284 attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
1285 #endif
1286 
1287 #if FF_API_PKT_DUMP
1288 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1289 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1290  int dump_payload);
1291 #endif
1292 
1293 
1302 AVInputFormat *av_find_input_format(const char *short_name);
1303 
1310 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1311 
1323 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1324 
1341  const char *filename, void *logctx,
1342  unsigned int offset, unsigned int max_probe_size);
1343 
1344 #if FF_API_FORMAT_PARAMETERS
1345 
1350 attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
1351  AVIOContext *pb, const char *filename,
1352  AVInputFormat *fmt, AVFormatParameters *ap);
1353 
1368 attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1369  AVInputFormat *fmt,
1370  int buf_size,
1371  AVFormatParameters *ap);
1372 #endif
1373 
1393 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1394 
1395 #if FF_API_FORMAT_PARAMETERS
1396 
1412 int av_find_stream_info(AVFormatContext *ic);
1413 #endif
1414 
1437 
1463  enum AVMediaType type,
1464  int wanted_stream_nb,
1465  int related_stream,
1466  AVCodec **decoder_ret,
1467  int flags);
1468 
1480 
1506 
1518 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1519  int flags);
1520 
1547 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1548 
1554 
1561 
1562 #if FF_API_FORMAT_PARAMETERS
1563 
1569 void av_close_input_stream(AVFormatContext *s);
1570 #endif
1571 
1572 #if FF_API_CLOSE_INPUT_FILE
1573 
1580 void av_close_input_file(AVFormatContext *s);
1581 #endif
1582 
1592 #if FF_API_NEW_STREAM
1593 
1604 AVStream *av_new_stream(AVFormatContext *s, int id);
1605 #endif
1606 
1607 #if FF_API_SET_PTS_INFO
1608 
1612 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1613  unsigned int pts_num, unsigned int pts_den);
1614 #endif
1615 
1616 #define AVSEEK_FLAG_BACKWARD 1
1617 #define AVSEEK_FLAG_BYTE 2
1618 #define AVSEEK_FLAG_ANY 4
1619 #define AVSEEK_FLAG_FRAME 8
1620 
1621 #if FF_API_SEEK_PUBLIC
1623 int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1624  int64_t target_ts, int flags);
1626 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1628 int64_t av_gen_search(AVFormatContext *s, int stream_index,
1629  int64_t target_ts, int64_t pos_min,
1630  int64_t pos_max, int64_t pos_limit,
1631  int64_t ts_min, int64_t ts_max,
1632  int flags, int64_t *ts_ret,
1633  int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1634 #endif
1635 
1636 #if FF_API_FORMAT_PARAMETERS
1637 
1640 attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1641 #endif
1642 
1663 
1664 #if FF_API_FORMAT_PARAMETERS
1665 
1676 attribute_deprecated int av_write_header(AVFormatContext *s);
1677 #endif
1678 
1692 
1718 
1735  AVPacket *pkt, int flush);
1736 
1747 
1760 AVOutputFormat *av_guess_format(const char *short_name,
1761  const char *filename,
1762  const char *mime_type);
1763 
1767 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1768  const char *filename, const char *mime_type,
1769  enum AVMediaType type);
1770 
1794 void av_hex_dump(FILE *f, uint8_t *buf, int size);
1795 
1808 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1809 
1818 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1819 
1820 
1832 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1833  AVStream *st);
1834 
1842 enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1843 
1851 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1852 
1854 
1863 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1864 
1871 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1872  int size, int distance, int flags);
1873 
1874 
1894 void av_url_split(char *proto, int proto_size,
1895  char *authorization, int authorization_size,
1896  char *hostname, int hostname_size,
1897  int *port_ptr,
1898  char *path, int path_size,
1899  const char *url);
1900 
1901 #if FF_API_DUMP_FORMAT
1902 attribute_deprecated void dump_format(AVFormatContext *ic,
1903  int index,
1904  const char *url,
1905  int is_output);
1906 #endif
1907 
1909  int index,
1910  const char *url,
1911  int is_output);
1912 
1913 #if FF_API_PARSE_DATE
1914 
1922 int64_t parse_date(const char *datestr, int duration);
1923 #endif
1924 
1928 int64_t av_gettime(void);
1929 
1930 #if FF_API_FIND_INFO_TAG
1931 
1934 attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1935 #endif
1936 
1949 int av_get_frame_filename(char *buf, int buf_size,
1950  const char *path, int number);
1951 
1958 int av_filename_number_test(const char *filename);
1959 
1974 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1975 
1976 #if FF_API_SDP_CREATE
1977 attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1978 #endif
1979 
1986 int av_match_ext(const char *filename, const char *extensions);
1987 
1996 int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
1997 
2013 const struct AVCodecTag *avformat_get_riff_video_tags(void);
2017 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
2026 #endif /* AVFORMAT_AVFORMAT_H */