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 
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 
317 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
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_PADDING_SIZE 32
346 
347 
348 #define AVFMT_NOFILE 0x0001
349 #define AVFMT_NEEDNUMBER 0x0002
350 #define AVFMT_SHOW_IDS 0x0008
351 #define AVFMT_RAWPICTURE 0x0020
353 #define AVFMT_GLOBALHEADER 0x0040
354 #define AVFMT_NOTIMESTAMPS 0x0080
355 #define AVFMT_GENERIC_INDEX 0x0100
356 #define AVFMT_TS_DISCONT 0x0200
357 #define AVFMT_VARIABLE_FPS 0x0400
358 #define AVFMT_NODIMENSIONS 0x0800
359 #define AVFMT_NOSTREAMS 0x1000
360 #define AVFMT_NOBINSEARCH 0x2000
361 #define AVFMT_NOGENSEARCH 0x4000
362 #define AVFMT_NO_BYTE_SEEK 0x8000
363 #define AVFMT_ALLOW_FLUSH 0x10000
364 #define AVFMT_TS_NONSTRICT 0x20000
372 typedef struct AVOutputFormat {
373  const char *name;
379  const char *long_name;
380  const char *mime_type;
381  const char *extensions;
382  /* output support */
392  int flags;
393 
398  const struct AVCodecTag * const *codec_tag;
399 
400 
402 
403  /*****************************************************************
404  * No fields below this line are part of the public API. They
405  * may not be used outside of libavformat and can be changed and
406  * removed at will.
407  * New public fields should be added right above.
408  *****************************************************************
409  */
415 
416  int (*write_header)(struct AVFormatContext *);
424  int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
425  int (*write_trailer)(struct AVFormatContext *);
430  AVPacket *in, int flush);
437  int (*query_codec)(enum AVCodecID id, int std_compliance);
447 typedef struct AVInputFormat {
452  const char *name;
453 
459  const char *long_name;
460 
466  int flags;
467 
473  const char *extensions;
474 
475  const struct AVCodecTag * const *codec_tag;
476 
478 
479  /*****************************************************************
480  * No fields below this line are part of the public API. They
481  * may not be used outside of libavformat and can be changed and
482  * removed at will.
483  * New public fields should be added right above.
484  *****************************************************************
485  */
487 
492 
497 
504 
510  int (*read_header)(struct AVFormatContext *);
511 
521  int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
522 
527  int (*read_close)(struct AVFormatContext *);
528 
537  int (*read_seek)(struct AVFormatContext *,
538  int stream_index, int64_t timestamp, int flags);
539 
544  int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
545  int64_t *pos, int64_t pos_limit);
546 
551  int (*read_play)(struct AVFormatContext *);
552 
557  int (*read_pause)(struct AVFormatContext *);
558 
565  int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
566 } AVInputFormat;
577 };
578 
579 typedef struct AVIndexEntry {
580  int64_t pos;
581  int64_t timestamp;
582 #define AVINDEX_KEYFRAME 0x0001
583  int flags:2;
584  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).
586 } AVIndexEntry;
587 
588 #define AV_DISPOSITION_DEFAULT 0x0001
589 #define AV_DISPOSITION_DUB 0x0002
590 #define AV_DISPOSITION_ORIGINAL 0x0004
591 #define AV_DISPOSITION_COMMENT 0x0008
592 #define AV_DISPOSITION_LYRICS 0x0010
593 #define AV_DISPOSITION_KARAOKE 0x0020
594 
600 #define AV_DISPOSITION_FORCED 0x0040
601 #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080
602 #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100
603 #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200
610 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
611 
619 typedef struct AVStream {
620  int index;
626  int id;
639 #if FF_API_R_FRAME_RATE
640 
648  AVRational r_frame_rate;
649 #endif
650  void *priv_data;
651 
655  struct AVFrac pts;
656 
667 
674  int64_t start_time;
675 
681  int64_t duration;
682 
683  int64_t nb_frames;
684 
688 
695 
697 
702 
711 
712  /*****************************************************************
713  * All fields below this line are not part of the public API. They
714  * may not be used outside of libavformat and can be changed and
715  * removed at will.
716  * New public fields should be added right above.
717  *****************************************************************
718  */
719 
723 #define MAX_STD_TIMEBASES (60*12+5)
724  struct {
725 #if FF_API_R_FRAME_RATE
726  int64_t last_dts;
727  int64_t duration_gcd;
728  int duration_count;
729  double duration_error[MAX_STD_TIMEBASES];
730 #endif
733 
737  int64_t fps_first_dts;
739  int64_t fps_last_dts;
741 
742  } *info;
743 
746  // Timestamp generation support:
754  int64_t reference_dts;
755  int64_t first_dts;
756  int64_t cur_dts;
757  int64_t last_IP_pts;
759 
763 #define MAX_PROBE_PACKETS 2500
765 
770 
771  /* av_read_frame() support */
774 
780 #define MAX_REORDER_DELAY 16
782 
787 } AVStream;
788 
789 #define AV_PROGRAM_RUNNING 1
790 
797 typedef struct AVProgram {
798  int id;
799  int flags;
801  unsigned int *stream_index;
802  unsigned int nb_stream_indexes;
804 } AVProgram;
805 
806 #define AVFMTCTX_NOHEADER 0x0001
809 typedef struct AVChapter {
810  int id;
812  int64_t start, end;
814 } AVChapter;
815 
824 typedef struct AVFormatContext {
830 
839 
844  void *priv_data;
845 
858 
859  /* stream info */
860  int ctx_flags;
871  unsigned int nb_streams;
873 
874  char filename[1024];
881  int64_t start_time;
882 
889  int64_t duration;
890 
896  int bit_rate;
897 
898  unsigned int packet_size;
900 
901  int flags;
902 #define AVFMT_FLAG_GENPTS 0x0001
903 #define AVFMT_FLAG_IGNIDX 0x0002
904 #define AVFMT_FLAG_NONBLOCK 0x0004
905 #define AVFMT_FLAG_IGNDTS 0x0008
906 #define AVFMT_FLAG_NOFILLIN 0x0010
907 #define AVFMT_FLAG_NOPARSE 0x0020
908 #define AVFMT_FLAG_NOBUFFER 0x0040
909 #define AVFMT_FLAG_CUSTOM_IO 0x0080
910 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100
911 
912 
915  unsigned int probesize;
916 
922 
923  const uint8_t *key;
924  int keylen;
925 
926  unsigned int nb_programs;
928 
934 
940 
946 
957  unsigned int max_index_size;
958 
963  unsigned int max_picture_buffer;
964 
965  unsigned int nb_chapters;
967 
969 
978 
983 
991 
1002 
1006  int debug;
1007 #define FF_FDEBUG_TS 0x0001
1008  /*****************************************************************
1009  * All fields below this line are not part of the public API. They
1010  * may not be used outside of libavformat and can be changed and
1011  * removed at will.
1012  * New public fields should be added right above.
1013  *****************************************************************
1014  */
1015 
1023 
1024  /* av_seek_frame() support */
1025  int64_t data_offset;
1043 #define RAW_PACKET_BUFFER_SIZE 2500000
1045 } AVFormatContext;
1046 
1047 typedef struct AVPacketList {
1050 } AVPacketList;
1051 
1052 
1065 unsigned avformat_version(void);
1066 
1070 const char *avformat_configuration(void);
1071 
1075 const char *avformat_license(void);
1076 
1086 void av_register_all(void);
1087 
1090 
1099 int avformat_network_init(void);
1100 
1104 int avformat_network_deinit(void);
1105 
1112 
1119 
1126 
1132 
1139 const AVClass *avformat_get_class(void);
1140 
1157 
1159 
1173 AVInputFormat *av_find_input_format(const char *short_name);
1174 
1181 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1182 
1194 AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1195 
1212  const char *filename, void *logctx,
1213  unsigned int offset, unsigned int max_probe_size);
1214 
1234 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
1235 
1258 
1284  enum AVMediaType type,
1285  int wanted_stream_nb,
1286  int related_stream,
1287  AVCodec **decoder_ret,
1288  int flags);
1289 
1290 #if FF_API_READ_PACKET
1291 
1305 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1306 #endif
1307 
1333 
1345 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1346  int flags);
1347 
1374 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1375 
1381 
1388 
1389 #if FF_API_CLOSE_INPUT_FILE
1390 
1397 void av_close_input_file(AVFormatContext *s);
1398 #endif
1399 
1409 #define AVSEEK_FLAG_BACKWARD 1
1410 #define AVSEEK_FLAG_BYTE 2
1411 #define AVSEEK_FLAG_ANY 4
1412 #define AVSEEK_FLAG_FRAME 8
1413 
1414 
1434 
1452 
1480 
1481 #if FF_API_INTERLEAVE_PACKET
1482 
1487 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1488  AVPacket *pkt, int flush);
1489 #endif
1490 
1501 
1514 AVOutputFormat *av_guess_format(const char *short_name,
1515  const char *filename,
1516  const char *mime_type);
1517 
1521 enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
1522  const char *filename, const char *mime_type,
1523  enum AVMediaType type);
1524 
1548 void av_hex_dump(FILE *f, const uint8_t *buf, int size);
1549 
1562 void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
1563 
1572 void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
1573 
1574 
1586 void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
1587  AVStream *st);
1588 
1596 enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1597 
1605 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
1606 
1608 
1617 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1618 
1625 int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1626  int size, int distance, int flags);
1627 
1628 
1648 void av_url_split(char *proto, int proto_size,
1649  char *authorization, int authorization_size,
1650  char *hostname, int hostname_size,
1651  int *port_ptr,
1652  char *path, int path_size,
1653  const char *url);
1654 
1655 
1657  int index,
1658  const char *url,
1659  int is_output);
1660 
1673 int av_get_frame_filename(char *buf, int buf_size,
1674  const char *path, int number);
1675 
1682 int av_filename_number_test(const char *filename);
1683 
1701 int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
1702 
1709 int av_match_ext(const char *filename, const char *extensions);
1710 
1719 int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
1720 
1736 const struct AVCodecTag *avformat_get_riff_video_tags(void);
1740 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
1749 #endif /* AVFORMAT_AVFORMAT_H */