FFmpeg  1.2.12
avformat.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 
201 #include <time.h>
202 #include <stdio.h> /* FILE */
203 #include "libavcodec/avcodec.h"
204 #include "libavutil/dict.h"
205 #include "libavutil/log.h"
206 
207 #include "avio.h"
208 #include "libavformat/version.h"
209 
210 #if FF_API_AV_GETTIME
211 #include "libavutil/time.h"
212 #endif
213 
214 struct AVFormatContext;
215 
216 
290 /* packet functions */
291 
292 
301 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
302 
303 
318 
319 /*************************************************/
320 /* fractional numbers for exact pts handling */
321 
326 typedef struct AVFrac {
327  int64_t val, num, den;
328 } AVFrac;
329 
330 /*************************************************/
331 /* input/output formats */
332 
333 struct AVCodecTag;
334 
338 typedef struct AVProbeData {
339  const char *filename;
340  unsigned char *buf;
341  int buf_size;
342 } AVProbeData;
343 
344 #define AVPROBE_SCORE_MAX 100
345 #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
346 #define AVPROBE_PADDING_SIZE 32
347 
348 
349 #define AVFMT_NOFILE 0x0001
350 #define AVFMT_NEEDNUMBER 0x0002
351 #define AVFMT_SHOW_IDS 0x0008
352 #define AVFMT_RAWPICTURE 0x0020
354 #define AVFMT_GLOBALHEADER 0x0040
355 #define AVFMT_NOTIMESTAMPS 0x0080
356 #define AVFMT_GENERIC_INDEX 0x0100
357 #define AVFMT_TS_DISCONT 0x0200
358 #define AVFMT_VARIABLE_FPS 0x0400
359 #define AVFMT_NODIMENSIONS 0x0800
360 #define AVFMT_NOSTREAMS 0x1000
361 #define AVFMT_NOBINSEARCH 0x2000
362 #define AVFMT_NOGENSEARCH 0x4000
363 #define AVFMT_NO_BYTE_SEEK 0x8000
364 #define AVFMT_ALLOW_FLUSH 0x10000
365 #if LIBAVFORMAT_VERSION_MAJOR <= 54
366 #define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
367 #else
368 #define AVFMT_TS_NONSTRICT 0x20000
369 #endif
370 
374 #define AVFMT_SEEK_TO_PTS 0x4000000
380 typedef struct AVOutputFormat {
381  const char *name;
387  const char *long_name;
388  const char *mime_type;
389  const char *extensions;
390  /* output support */
400  int flags;
401 
406  const struct AVCodecTag * const *codec_tag;
407 
408 
410 
411  /*****************************************************************
412  * No fields below this line are part of the public API. They
413  * may not be used outside of libavformat and can be changed and
414  * removed at will.
415  * New public fields should be added right above.
416  *****************************************************************
417  */
423 
424  int (*write_header)(struct AVFormatContext *);
433  int (*write_trailer)(struct AVFormatContext *);
438  AVPacket *in, int flush);
446  int (*query_codec)(enum AVCodecID id, int std_compliance);
447 
448  void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
449  int64_t *dts, int64_t *wall);
459 typedef struct AVInputFormat {
464  const char *name;
465 
471  const char *long_name;
472 
478  int flags;
479 
485  const char *extensions;
486 
487  const struct AVCodecTag * const *codec_tag;
488 
490 
491  /*****************************************************************
492  * No fields below this line are part of the public API. They
493  * may not be used outside of libavformat and can be changed and
494  * removed at will.
495  * New public fields should be added right above.
496  *****************************************************************
497  */
499 
504 
509 
516 
522  int (*read_header)(struct AVFormatContext *);
523 
534 
539  int (*read_close)(struct AVFormatContext *);
540 
549  int (*read_seek)(struct AVFormatContext *,
550  int stream_index, int64_t timestamp, int flags);
551 
556  int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
557  int64_t *pos, int64_t pos_limit);
558 
563  int (*read_play)(struct AVFormatContext *);
564 
569  int (*read_pause)(struct AVFormatContext *);
570 
577  int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
578 } AVInputFormat;
592 };
593 
594 typedef struct AVIndexEntry {
595  int64_t pos;
596  int64_t timestamp;
602 #define AVINDEX_KEYFRAME 0x0001
603  int flags:2;
604  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).
606 } AVIndexEntry;
607 
608 #define AV_DISPOSITION_DEFAULT 0x0001
609 #define AV_DISPOSITION_DUB 0x0002
610 #define AV_DISPOSITION_ORIGINAL 0x0004
611 #define AV_DISPOSITION_COMMENT 0x0008
612 #define AV_DISPOSITION_LYRICS 0x0010
613 #define AV_DISPOSITION_KARAOKE 0x0020
614 
620 #define AV_DISPOSITION_FORCED 0x0040
621 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
622 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
623 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
630 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
631 
635 #define AV_PTS_WRAP_IGNORE 0
636 #define AV_PTS_WRAP_ADD_OFFSET 1
637 #define AV_PTS_WRAP_SUB_OFFSET -1
638 
639 
646 typedef struct AVStream {
647  int index;
653  int id;
666 #if FF_API_R_FRAME_RATE
667 
675  AVRational r_frame_rate;
676 #endif
677  void *priv_data;
678 
682  struct AVFrac pts;
683 
694 
703  int64_t start_time;
704 
710  int64_t duration;
711 
712  int64_t nb_frames;
713 
717 
724 
726 
731 
740 
741  /*****************************************************************
742  * All fields below this line are not part of the public API. They
743  * may not be used outside of libavformat and can be changed and
744  * removed at will.
745  * New public fields should be added right above.
746  *****************************************************************
747  */
748 
752 #define MAX_STD_TIMEBASES (60*12+6)
753  struct {
754  int64_t last_dts;
755  int64_t duration_gcd;
761 
762  int64_t last_duration;
763 
767  int64_t fps_first_dts;
769  int64_t fps_last_dts;
771 
772  } *info;
773 
776  // Timestamp generation support:
784  int64_t reference_dts;
785  int64_t first_dts;
786  int64_t cur_dts;
787  int64_t last_IP_pts;
789 
793 #define MAX_PROBE_PACKETS 2500
795 
800 
807 
810 
811  /* av_read_frame() support */
814 
820 #define MAX_REORDER_DELAY 16
822 
827 
841 
846 
852 
857  int64_t mux_ts_offset;
858 
863 
875 
876 } AVStream;
877 
878 #define AV_PROGRAM_RUNNING 1
879 
886 typedef struct AVProgram {
887  int id;
888  int flags;
890  unsigned int *stream_index;
891  unsigned int nb_stream_indexes;
893 
895  int pmt_pid;
896  int pcr_pid;
897 
898  /*****************************************************************
899  * All fields below this line are not part of the public API. They
900  * may not be used outside of libavformat and can be changed and
901  * removed at will.
902  * New public fields should be added right above.
903  *****************************************************************
904  */
905  int64_t start_time;
906  int64_t end_time;
907 
910 } AVProgram;
911 
912 #define AVFMTCTX_NOHEADER 0x0001
915 typedef struct AVChapter {
916  int id;
918  int64_t start, end;
920 } AVChapter;
921 
922 
931 };
932 
941 typedef struct AVFormatContext {
947 
956 
961  void *priv_data;
962 
975 
976  /* stream info */
977  int ctx_flags;
988  unsigned int nb_streams;
990 
991  char filename[1024];
998  int64_t start_time;
999 
1006  int64_t duration;
1007 
1014 
1015  unsigned int packet_size;
1017 
1018  int flags;
1019 #define AVFMT_FLAG_GENPTS 0x0001
1020 #define AVFMT_FLAG_IGNIDX 0x0002
1021 #define AVFMT_FLAG_NONBLOCK 0x0004
1022 #define AVFMT_FLAG_IGNDTS 0x0008
1023 #define AVFMT_FLAG_NOFILLIN 0x0010
1024 #define AVFMT_FLAG_NOPARSE 0x0020
1025 #define AVFMT_FLAG_NOBUFFER 0x0040
1026 #define AVFMT_FLAG_CUSTOM_IO 0x0080
1027 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
1028 #define AVFMT_FLAG_MP4A_LATM 0x8000
1029 #define AVFMT_FLAG_SORT_DTS 0x10000
1030 #define AVFMT_FLAG_PRIV_OPT 0x20000
1031 #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000
1032 
1033 
1036  unsigned int probesize;
1037 
1043 
1044  const uint8_t *key;
1045  int keylen;
1046 
1047  unsigned int nb_programs;
1049 
1055 
1061 
1067 
1078  unsigned int max_index_size;
1079 
1084  unsigned int max_picture_buffer;
1085 
1086  unsigned int nb_chapters;
1088 
1090 
1099 
1104 
1112 
1123 
1127  int debug;
1128 #define FF_FDEBUG_TS 0x0001
1129 
1134  int ts_id;
1135 
1143 
1151 
1159 
1167 
1178 
1185 
1193 
1199  unsigned int skip_initial_bytes;
1200 
1206  unsigned int correct_ts_overflow;
1207 
1214 
1215  /*****************************************************************
1216  * All fields below this line are not part of the public API. They
1217  * may not be used outside of libavformat and can be changed and
1218  * removed at will.
1219  * New public fields should be added right above.
1220  *****************************************************************
1221  */
1222 
1230 
1231  /* av_seek_frame() support */
1232  int64_t data_offset;
1250 #define RAW_PACKET_BUFFER_SIZE 2500000
1252 } AVFormatContext;
1253 
1260 
1261 typedef struct AVPacketList {
1264 } AVPacketList;
1265 
1266 
1279 unsigned avformat_version(void);
1280 
1284 const char *avformat_configuration(void);
1285 
1289 const char *avformat_license(void);
1290 
1299 void av_register_all(void);
1300 
1303 
1312 int avformat_network_init(void);
1313 
1317 int avformat_network_deinit(void);
1318 
1325 
1332 
1339 
1345 
1352 const AVClass *avformat_get_class(void);
1353 
1370 
1372 
1378 #if FF_API_PKT_DUMP
1379 attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1380 attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
1381  int dump_payload);
1382 #endif
1383 
1384 #if FF_API_ALLOC_OUTPUT_CONTEXT
1385 
1389 AVFormatContext *avformat_alloc_output_context(const char *format,
1390  AVOutputFormat *oformat,
1391  const char *filename);
1392 #endif
1393 
1411  const char *format_name, const char *filename);
1412 
1421 AVInputFormat *av_find_input_format(const char *short_name);
1422 
1429 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1430 
1442 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1443 
1451 AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
1452 
1469  const char *filename, void *logctx,
1470  unsigned int offset, unsigned int max_probe_size);
1471 
1491 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1492 
1495 
1496 #if FF_API_FORMAT_PARAMETERS
1497 
1513 int av_find_stream_info(AVFormatContext *ic);
1514 #endif
1515 
1538 
1550 
1576  enum AVMediaType type,
1577  int wanted_stream_nb,
1578  int related_stream,
1579  AVCodec **decoder_ret,
1580  int flags);
1581 
1582 #if FF_API_READ_PACKET
1583 
1597 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1598 #endif
1599 
1625 
1637 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1638  int flags);
1639 
1666 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1667 
1673 
1680 
1681 #if FF_API_CLOSE_INPUT_FILE
1682 
1689 void av_close_input_file(AVFormatContext *s);
1690 #endif
1691 
1701 #if FF_API_NEW_STREAM
1702 
1713 AVStream *av_new_stream(AVFormatContext *s, int id);
1714 #endif
1715 
1716 #if FF_API_SET_PTS_INFO
1717 
1721 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1722  unsigned int pts_num, unsigned int pts_den);
1723 #endif
1724 
1725 #define AVSEEK_FLAG_BACKWARD 1
1726 #define AVSEEK_FLAG_BYTE 2
1727 #define AVSEEK_FLAG_ANY 4
1728 #define AVSEEK_FLAG_FRAME 8
1729 
1730 
1750 
1768 
1796 
1797 #if FF_API_INTERLEAVE_PACKET
1798 
1803 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1804  AVPacket *pkt, int flush);
1805 #endif
1806 
1817 
1830 AVOutputFormat *av_guess_format(const char *short_name,
1831  const char *filename,
1832  const char *mime_type);
1833 
1837 enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1838  const char *filename, const char *mime_type,
1839  enum AVMediaType type);
1840 
1856 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
1857  int64_t *dts, int64_t *wall);
1858 
1859 
1883 void av_hex_dump(FILE *f, const uint8_t *buf, int size);
1884 
1897 void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
1898 
1907 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1908 
1909 
1921 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1922  AVStream *st);
1923 
1931 enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1932 
1940 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
1941 
1951 int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
1952  unsigned int *tag);
1953 
1955 
1964 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1965 
1972 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1973  int size, int distance, int flags);
1974 
1975 
1995 void av_url_split(char *proto, int proto_size,
1996  char *authorization, int authorization_size,
1997  char *hostname, int hostname_size,
1998  int *port_ptr,
1999  char *path, int path_size,
2000  const char *url);
2001 
2002 
2004  int index,
2005  const char *url,
2006  int is_output);
2007 
2020 int av_get_frame_filename(char *buf, int buf_size,
2021  const char *path, int number);
2022 
2029 int av_filename_number_test(const char *filename);
2030 
2048 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
2049 
2056 int av_match_ext(const char *filename, const char *extensions);
2057 
2066 int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
2067 
2083 const struct AVCodecTag *avformat_get_riff_video_tags(void);
2087 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
2088 
2111 
2126  const char *spec);
2127 
2129 
2130 
2135 #endif /* AVFORMAT_AVFORMAT_H */