avformat.h 8.66 KB
Newer Older
Fabrice Bellard's avatar
Fabrice Bellard committed
1

2 3
#define LIBAV_VERSION_INT 0x000406  
#define LIBAV_VERSION     "0.4.6"
4
#define LIBAV_BUILD       4601
5

Fabrice Bellard's avatar
Fabrice Bellard committed
6 7 8 9 10 11 12 13 14 15 16 17
#include "avcodec.h"

#include "avio.h"

/* packet functions */

typedef struct AVPacket {
    INT64 pts;
    UINT8 *data;
    int size;
    int stream_index;
    int flags;
18
    int duration;       
Fabrice Bellard's avatar
Fabrice Bellard committed
19
#define PKT_FLAG_KEY   0x0001
20
#define PKT_FLAG_DROPPED_FRAME   0x0002
Fabrice Bellard's avatar
Fabrice Bellard committed
21 22 23 24 25 26
} AVPacket; 

int av_new_packet(AVPacket *pkt, int size);
void av_free_packet(AVPacket *pkt);

/*************************************************/
27
/* input/output formats */
Fabrice Bellard's avatar
Fabrice Bellard committed
28 29

struct AVFormatContext;
30 31 32 33 34 35 36 37 38

/* this structure contains the data a format has to probe a file */
typedef struct AVProbeData {
    char *filename;
    unsigned char *buf;
    int buf_size;
} AVProbeData;

#define AVPROBE_SCORE_MAX 100
Fabrice Bellard's avatar
Fabrice Bellard committed
39 40 41 42 43 44 45

typedef struct AVFormatParameters {
    int frame_rate;
    int sample_rate;
    int channels;
    int width;
    int height;
46
    enum PixelFormat pix_fmt;
Fabrice Bellard's avatar
Fabrice Bellard committed
47 48
} AVFormatParameters;

49 50 51 52 53 54 55 56 57
#define AVFMT_NOFILE        0x0001 /* no file should be opened */
#define AVFMT_NEEDNUMBER    0x0002 /* needs '%d' in filename */ 
#define AVFMT_NOHEADER      0x0004 /* signal that no header is present
                                      (streams are added dynamically) */
#define AVFMT_SHOW_IDS      0x0008 /* show format stream IDs numbers */
#define AVFMT_RGB24         0x0010 /* force RGB24 output for ppm (hack
                                      - need better api) */

typedef struct AVOutputFormat {
Fabrice Bellard's avatar
Fabrice Bellard committed
58 59 60 61
    const char *name;
    const char *long_name;
    const char *mime_type;
    const char *extensions; /* comma separated extensions */
62 63
    /* size of private data so that it can be allocated in the wrapper */
    int priv_data_size;
Fabrice Bellard's avatar
Fabrice Bellard committed
64 65 66 67 68 69
    /* output support */
    enum CodecID audio_codec; /* default audio codec */
    enum CodecID video_codec; /* default video codec */
    int (*write_header)(struct AVFormatContext *);
    int (*write_packet)(struct AVFormatContext *, 
                        int stream_index,
70
                        unsigned char *buf, int size, int force_pts);
Fabrice Bellard's avatar
Fabrice Bellard committed
71
    int (*write_trailer)(struct AVFormatContext *);
72 73 74 75 76
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
    int flags;
    /* private fields */
    struct AVOutputFormat *next;
} AVOutputFormat;
Fabrice Bellard's avatar
Fabrice Bellard committed
77

78 79 80 81 82 83 84 85
typedef struct AVInputFormat {
    const char *name;
    const char *long_name;
    /* size of private data so that it can be allocated in the wrapper */
    int priv_data_size;
    /* tell if a given file has a chance of being parsing by this format */
    int (*read_probe)(AVProbeData *);
    /* read the format header and initialize the AVFormatContext
Fabrice Bellard's avatar
Fabrice Bellard committed
86
       structure. Return 0 if OK. 'ap' if non NULL contains
87 88
       additionnal paramters. Only used in raw format right
       now. 'av_new_stream' should be called to create new streams.  */
Fabrice Bellard's avatar
Fabrice Bellard committed
89 90
    int (*read_header)(struct AVFormatContext *,
                       AVFormatParameters *ap);
91 92 93
    /* read one packet and put it in 'pkt'. pts and flags are also
       set. 'av_new_stream' can be called only if the flag
       AVFMT_NOHEADER is used. */
Fabrice Bellard's avatar
Fabrice Bellard committed
94 95 96 97 98 99 100
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
    /* close the stream. The AVFormatContext and AVStreams are not
       freed by this function */
    int (*read_close)(struct AVFormatContext *);
    /* seek at or before a given pts (given in microsecond). The pts
       origin is defined by the stream */
    int (*read_seek)(struct AVFormatContext *, INT64 pts);
101
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
Fabrice Bellard's avatar
Fabrice Bellard committed
102
    int flags;
103 104 105 106 107 108 109 110 111
    /* if extensions are defined, then no probe is done. You should
       usually not use extension format guessing because it is not
       reliable enough */
    const char *extensions;
    /* general purpose read only value that the format can use */
    int value;
    /* private fields */
    struct AVInputFormat *next;
} AVInputFormat;
Fabrice Bellard's avatar
Fabrice Bellard committed
112 113

typedef struct AVStream {
114 115
    int index;    /* stream index in AVFormatContext */
    int id;       /* format specific stream id */
Fabrice Bellard's avatar
Fabrice Bellard committed
116
    AVCodecContext codec; /* codec context */
117
    int r_frame_rate;     /* real frame rate of the stream */
Fabrice Bellard's avatar
Fabrice Bellard committed
118
    void *priv_data;
119 120 121 122
    /* internal data used in av_find_stream_info() */
    int codec_info_state;     
    int codec_info_nb_repeat_frames;
    int codec_info_nb_real_frames;
Fabrice Bellard's avatar
Fabrice Bellard committed
123 124 125 126 127 128
} AVStream;

#define MAX_STREAMS 20

/* format I/O context */
typedef struct AVFormatContext {
129 130 131
    /* can only be iformat or oformat, not both at the same time */
    struct AVInputFormat *iformat;
    struct AVOutputFormat *oformat;
Fabrice Bellard's avatar
Fabrice Bellard committed
132 133 134 135 136 137 138 139 140 141
    void *priv_data;
    ByteIOContext pb;
    int nb_streams;
    AVStream *streams[MAX_STREAMS];
    char filename[1024]; /* input or output filename */
    /* stream info */
    char title[512];
    char author[512];
    char copyright[512];
    char comment[512];
142
    int flags; /* format specific flags */
Fabrice Bellard's avatar
Fabrice Bellard committed
143 144 145 146 147 148 149 150 151 152 153
    /* This buffer is only needed when packets were already buffered but
       not decoded, for example to get the codec parameters in mpeg
       streams */
   struct AVPacketList *packet_buffer;
} AVFormatContext;

typedef struct AVPacketList {
    AVPacket pkt;
    struct AVPacketList *next;
} AVPacketList;

154 155
extern AVInputFormat *first_iformat;
extern AVOutputFormat *first_oformat;
Fabrice Bellard's avatar
Fabrice Bellard committed
156

157 158
/* XXX: use automatic init with either ELF sections or C file parser */
/* modules */
Fabrice Bellard's avatar
Fabrice Bellard committed
159

160
/* mpeg.c */
161
#define AVF_FLAG_VCD   0x00000001   /* VCD compatible MPEG-PS */
162 163 164 165 166
int mpegps_init(void);

/* mpegts.c */
extern AVInputFormat mpegts_demux;
int mpegts_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
167

168 169 170 171 172 173 174 175 176 177 178
/* rm.c */
int rm_init(void);

/* crc.c */
int crc_init(void);

/* img.c */
int img_init(void);

/* asf.c */
int asf_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
179 180

/* avienc.c */
181
int avienc_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
182

183 184
/* avidec.c */
int avidec_init(void);
185

186 187 188 189 190
/* swf.c */
int swf_init(void);

/* mov.c */
int mov_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
191

192 193
/* jpeg.c */
int jpeg_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
194

195
/* gif.c */
196 197
int gif_init(void);

198
/* au.c */
199
int au_init(void);
200

Fabrice Bellard's avatar
Fabrice Bellard committed
201
/* wav.c */
202
int wav_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
203 204

/* raw.c */
205
int raw_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
206 207

/* ffm.c */
208
int ffm_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
209

210
/* utils.c */
Fabrice Bellard's avatar
Fabrice Bellard committed
211 212 213
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))

214 215 216 217
void av_register_input_format(AVInputFormat *format);
void av_register_output_format(AVOutputFormat *format);
AVOutputFormat *guess_format(const char *short_name, 
                             const char *filename, const char *mime_type);
Fabrice Bellard's avatar
Fabrice Bellard committed
218 219

int strstart(const char *str, const char *val, const char **ptr);
220 221
void pstrcpy(char *buf, int buf_size, const char *str);

Fabrice Bellard's avatar
Fabrice Bellard committed
222
int match_ext(const char *filename, const char *extensions);
223
void av_hex_dump(UINT8 *buf, int size);
Fabrice Bellard's avatar
Fabrice Bellard committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

void register_all(void);

INT64 gettime(void);

typedef struct FifoBuffer {
    UINT8 *buffer;
    UINT8 *rptr, *wptr, *end;
} FifoBuffer;

int fifo_init(FifoBuffer *f, int size);
void fifo_free(FifoBuffer *f);
int fifo_size(FifoBuffer *f, UINT8 *rptr);
int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
/* media file input */
AVInputFormat *av_find_input_format(const char *short_name);
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 
                       AVInputFormat *fmt,
                       int buf_size,
                       AVFormatParameters *ap);

#define AVERROR_UNKNOWN     (-1)  /* unknown error */
#define AVERROR_IO          (-2)  /* i/o error */
#define AVERROR_NUMEXPECTED (-3)  /* number syntax expected in filename */
#define AVERROR_INVALIDDATA (-4)  /* invalid data found */
#define AVERROR_NOMEM       (-5)  /* not enough memory */
#define AVERROR_NOFMT       (-6)  /* unknown format */

int av_find_stream_info(AVFormatContext *ic);
Fabrice Bellard's avatar
Fabrice Bellard committed
255 256
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
void av_close_input_file(AVFormatContext *s);
257
AVStream *av_new_stream(AVFormatContext *s, int id);
Fabrice Bellard's avatar
Fabrice Bellard committed
258

259 260
/* media file output */
int av_write_header(AVFormatContext *s);
261
int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
262
int av_write_trailer(AVFormatContext *s);
Fabrice Bellard's avatar
Fabrice Bellard committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279

void dump_format(AVFormatContext *ic,
                 int index, 
                 const char *url,
                 int is_output);
int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
INT64 gettime(void);
INT64 parse_date(const char *datestr, int duration);

/* ffm specific for ffserver */
#define FFM_PACKET_SIZE 4096
offset_t ffm_read_write_index(int fd);
void ffm_write_write_index(int fd, offset_t pos);
void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);

int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);

Fabrice Bellard's avatar
Fabrice Bellard committed
280 281
int get_frame_filename(char *buf, int buf_size,
                       const char *path, int number);
282
int filename_number_test(const char *filename);
283

284 285 286
/* grab specific */
int video_grab_init(void);
int audio_init(void);
287 288 289

extern const char *v4l_device;
extern const char *audio_device;