added GIF image format (both read and write)
[libav.git] / libavformat / avformat.h
CommitLineData
fb025625
FB
1#ifndef AVFORMAT_H
2#define AVFORMAT_H
de6d9b64 3
02d697aa
ZK
4#ifdef __cplusplus
5extern "C" {
6#endif
7
94988531
FB
8#define LIBAVFORMAT_VERSION_INT 0x000406
9#define LIBAVFORMAT_VERSION "0.4.6"
290c5fa6 10#define LIBAVFORMAT_BUILD 4603
4b1f4f23 11
de6d9b64
FB
12#include "avcodec.h"
13
de6d9b64
FB
14#include "avio.h"
15
16/* packet functions */
17
fb025625
FB
18#define AV_NOPTS_VALUE 0
19
de6d9b64 20typedef struct AVPacket {
916c80e9 21 INT64 pts; /* presentation time stamp in stream units (set av_set_pts_info) */
de6d9b64
FB
22 UINT8 *data;
23 int size;
24 int stream_index;
25 int flags;
6d9872f4 26 int duration;
de6d9b64
FB
27#define PKT_FLAG_KEY 0x0001
28} AVPacket;
29
30int av_new_packet(AVPacket *pkt, int size);
31void av_free_packet(AVPacket *pkt);
32
33/*************************************************/
916c80e9
FB
34/* fractional numbers for exact pts handling */
35
36/* the exact value of the fractional number is: 'val + num / den'. num
37 is assumed to be such as 0 <= num < den */
38typedef struct AVFrac {
39 INT64 val, num, den;
40} AVFrac;
41
42void av_frac_init(AVFrac *f, INT64 val, INT64 num, INT64 den);
43void av_frac_add(AVFrac *f, INT64 incr);
44void av_frac_set(AVFrac *f, INT64 val);
45
46/*************************************************/
b9a281db 47/* input/output formats */
de6d9b64
FB
48
49struct AVFormatContext;
b9a281db
FB
50
51/* this structure contains the data a format has to probe a file */
52typedef struct AVProbeData {
53 char *filename;
54 unsigned char *buf;
55 int buf_size;
56} AVProbeData;
57
58#define AVPROBE_SCORE_MAX 100
de6d9b64
FB
59
60typedef struct AVFormatParameters {
61 int frame_rate;
62 int sample_rate;
63 int channels;
64 int width;
65 int height;
4606ac8d 66 enum PixelFormat pix_fmt;
290c5fa6 67 struct AVImageFormat *image_format;
7f172339
FB
68 int channel; /* used to select dv channel */
69 const char *device; /* video4linux, audio or DV device */
de6d9b64
FB
70} AVFormatParameters;
71
b9a281db
FB
72#define AVFMT_NOFILE 0x0001 /* no file should be opened */
73#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
74#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
75 (streams are added dynamically) */
76#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
fb025625
FB
77#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
78 raw picture data */
b9a281db
FB
79
80typedef struct AVOutputFormat {
de6d9b64
FB
81 const char *name;
82 const char *long_name;
83 const char *mime_type;
84 const char *extensions; /* comma separated extensions */
b9a281db
FB
85 /* size of private data so that it can be allocated in the wrapper */
86 int priv_data_size;
de6d9b64
FB
87 /* output support */
88 enum CodecID audio_codec; /* default audio codec */
89 enum CodecID video_codec; /* default video codec */
90 int (*write_header)(struct AVFormatContext *);
1e51d801 91 /* XXX: change prototype for 64 bit pts */
de6d9b64
FB
92 int (*write_packet)(struct AVFormatContext *,
93 int stream_index,
10bb7023 94 unsigned char *buf, int size, int force_pts);
de6d9b64 95 int (*write_trailer)(struct AVFormatContext *);
b9a281db
FB
96 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
97 int flags;
290c5fa6
FB
98 /* currently only used to set pixel format if not YUV420P */
99 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
b9a281db
FB
100 /* private fields */
101 struct AVOutputFormat *next;
102} AVOutputFormat;
de6d9b64 103
b9a281db
FB
104typedef struct AVInputFormat {
105 const char *name;
106 const char *long_name;
107 /* size of private data so that it can be allocated in the wrapper */
108 int priv_data_size;
109 /* tell if a given file has a chance of being parsing by this format */
110 int (*read_probe)(AVProbeData *);
111 /* read the format header and initialize the AVFormatContext
de6d9b64 112 structure. Return 0 if OK. 'ap' if non NULL contains
b9a281db
FB
113 additionnal paramters. Only used in raw format right
114 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
115 int (*read_header)(struct AVFormatContext *,
116 AVFormatParameters *ap);
b9a281db
FB
117 /* read one packet and put it in 'pkt'. pts and flags are also
118 set. 'av_new_stream' can be called only if the flag
119 AVFMT_NOHEADER is used. */
de6d9b64
FB
120 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
121 /* close the stream. The AVFormatContext and AVStreams are not
122 freed by this function */
123 int (*read_close)(struct AVFormatContext *);
124 /* seek at or before a given pts (given in microsecond). The pts
125 origin is defined by the stream */
126 int (*read_seek)(struct AVFormatContext *, INT64 pts);
b9a281db 127 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
de6d9b64 128 int flags;
b9a281db
FB
129 /* if extensions are defined, then no probe is done. You should
130 usually not use extension format guessing because it is not
131 reliable enough */
132 const char *extensions;
133 /* general purpose read only value that the format can use */
134 int value;
135 /* private fields */
136 struct AVInputFormat *next;
137} AVInputFormat;
de6d9b64
FB
138
139typedef struct AVStream {
b9a281db
FB
140 int index; /* stream index in AVFormatContext */
141 int id; /* format specific stream id */
de6d9b64 142 AVCodecContext codec; /* codec context */
76c0441b 143 int r_frame_rate; /* real frame rate of the stream */
2a10020b 144 uint64_t time_length; /* real length of the stream in miliseconds */
de6d9b64 145 void *priv_data;
b9a281db
FB
146 /* internal data used in av_find_stream_info() */
147 int codec_info_state;
148 int codec_info_nb_repeat_frames;
149 int codec_info_nb_real_frames;
1e51d801
FB
150 /* PTS generation when outputing stream */
151 AVFrac pts;
a48b7a6b
FB
152 /* ffmpeg.c private use */
153 int stream_copy; /* if TRUE, just copy stream */
1e491e29
MN
154 /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
155 * MN:dunno if thats the right place, for it */
156 float quality;
de6d9b64
FB
157} AVStream;
158
159#define MAX_STREAMS 20
160
161/* format I/O context */
162typedef struct AVFormatContext {
b9a281db
FB
163 /* can only be iformat or oformat, not both at the same time */
164 struct AVInputFormat *iformat;
165 struct AVOutputFormat *oformat;
de6d9b64
FB
166 void *priv_data;
167 ByteIOContext pb;
168 int nb_streams;
169 AVStream *streams[MAX_STREAMS];
170 char filename[1024]; /* input or output filename */
171 /* stream info */
172 char title[512];
173 char author[512];
174 char copyright[512];
175 char comment[512];
92b3e125 176 int flags; /* format specific flags */
916c80e9
FB
177 /* private data for pts handling (do not modify directly) */
178 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
179 int pts_num, pts_den; /* value to convert to seconds */
de6d9b64
FB
180 /* This buffer is only needed when packets were already buffered but
181 not decoded, for example to get the codec parameters in mpeg
182 streams */
183 struct AVPacketList *packet_buffer;
184} AVFormatContext;
185
186typedef struct AVPacketList {
187 AVPacket pkt;
188 struct AVPacketList *next;
189} AVPacketList;
190
b9a281db
FB
191extern AVInputFormat *first_iformat;
192extern AVOutputFormat *first_oformat;
de6d9b64 193
290c5fa6
FB
194/* still image support */
195struct AVInputImageContext;
196typedef struct AVInputImageContext AVInputImageContext;
197
198typedef struct AVImageInfo {
199 enum PixelFormat pix_fmt; /* requested pixel format */
200 int width; /* requested width */
201 int height; /* requested height */
202 AVPicture pict; /* returned allocated image */
203} AVImageInfo;
204
205typedef struct AVImageFormat {
206 const char *name;
207 const char *extensions;
208 /* tell if a given file has a chance of being parsing by this format */
209 int (*img_probe)(AVProbeData *);
210 /* read a whole image. 'alloc_cb' is called when the image size is
211 known so that the caller can allocate the image. If 'allo_cb'
212 returns non zero, then the parsing is aborted. Return '0' if
213 OK. */
214 int (*img_read)(ByteIOContext *,
215 int (*alloc_cb)(void *, AVImageInfo *info), void *);
216 /* write the image */
217 int supported_pixel_formats; /* mask of supported formats for output */
218 int (*img_write)(ByteIOContext *, AVImageInfo *);
219 struct AVImageFormat *next;
220} AVImageFormat;
221
222void av_register_image_format(AVImageFormat *img_fmt);
223AVImageFormat *av_probe_image_format(AVProbeData *pd);
224AVImageFormat *guess_image_format(const char *filename);
225int av_read_image(ByteIOContext *pb, const char *filename,
226 AVImageFormat *fmt,
227 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
228int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
229
230extern AVImageFormat *first_image_format;
231
232extern AVImageFormat pnm_image_format;
233extern AVImageFormat pbm_image_format;
234extern AVImageFormat pgm_image_format;
235extern AVImageFormat ppm_image_format;
236extern AVImageFormat pgmyuv_image_format;
237extern AVImageFormat yuv_image_format;
0e04e4e9 238extern AVImageFormat png_image_format;
0250738f 239extern AVImageFormat jpeg_image_format;
cdc90af0 240extern AVImageFormat gif_image_format;
290c5fa6 241
b9a281db
FB
242/* XXX: use automatic init with either ELF sections or C file parser */
243/* modules */
de6d9b64 244
b9a281db 245/* mpeg.c */
b9a281db
FB
246int mpegps_init(void);
247
248/* mpegts.c */
249extern AVInputFormat mpegts_demux;
250int mpegts_init(void);
de6d9b64 251
b9a281db
FB
252/* rm.c */
253int rm_init(void);
254
255/* crc.c */
256int crc_init(void);
257
258/* img.c */
259int img_init(void);
260
261/* asf.c */
262int asf_init(void);
de6d9b64
FB
263
264/* avienc.c */
b9a281db 265int avienc_init(void);
de6d9b64 266
b9a281db
FB
267/* avidec.c */
268int avidec_init(void);
6cea494e 269
b9a281db
FB
270/* swf.c */
271int swf_init(void);
272
273/* mov.c */
274int mov_init(void);
de6d9b64 275
b9a281db
FB
276/* jpeg.c */
277int jpeg_init(void);
de6d9b64 278
6cea494e 279/* gif.c */
b9a281db
FB
280int gif_init(void);
281
6cea494e 282/* au.c */
b9a281db 283int au_init(void);
6cea494e 284
de6d9b64 285/* wav.c */
b9a281db 286int wav_init(void);
de6d9b64
FB
287
288/* raw.c */
b9a281db 289int raw_init(void);
de6d9b64 290
81e0d0b4
MH
291/* ogg.c */
292int ogg_init(void);
293
f20dca40
FB
294/* dv.c */
295int dv_init(void);
296
de6d9b64 297/* ffm.c */
b9a281db 298int ffm_init(void);
de6d9b64 299
fb025625
FB
300/* rtsp.c */
301extern AVInputFormat redir_demux;
302int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
303
304#include "rtp.h"
305
306#include "rtsp.h"
307
290c5fa6
FB
308/* yuv4mpeg.c */
309extern AVOutputFormat yuv4mpegpipe_oformat;
310
b9a281db 311/* utils.c */
de6d9b64
FB
312#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
313#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
314
b9a281db
FB
315void av_register_input_format(AVInputFormat *format);
316void av_register_output_format(AVOutputFormat *format);
36ada60c
PG
317AVOutputFormat *guess_stream_format(const char *short_name,
318 const char *filename, const char *mime_type);
b9a281db
FB
319AVOutputFormat *guess_format(const char *short_name,
320 const char *filename, const char *mime_type);
de6d9b64 321
b9a281db 322void av_hex_dump(UINT8 *buf, int size);
de6d9b64 323
94988531 324void av_register_all(void);
de6d9b64
FB
325
326typedef struct FifoBuffer {
327 UINT8 *buffer;
328 UINT8 *rptr, *wptr, *end;
329} FifoBuffer;
330
331int fifo_init(FifoBuffer *f, int size);
332void fifo_free(FifoBuffer *f);
333int fifo_size(FifoBuffer *f, UINT8 *rptr);
334int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
335void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
336
b9a281db
FB
337/* media file input */
338AVInputFormat *av_find_input_format(const char *short_name);
94988531 339AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
b9a281db
FB
340int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
341 AVInputFormat *fmt,
342 int buf_size,
343 AVFormatParameters *ap);
344
345#define AVERROR_UNKNOWN (-1) /* unknown error */
346#define AVERROR_IO (-2) /* i/o error */
347#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
348#define AVERROR_INVALIDDATA (-4) /* invalid data found */
349#define AVERROR_NOMEM (-5) /* not enough memory */
350#define AVERROR_NOFMT (-6) /* unknown format */
351
352int av_find_stream_info(AVFormatContext *ic);
de6d9b64
FB
353int av_read_packet(AVFormatContext *s, AVPacket *pkt);
354void av_close_input_file(AVFormatContext *s);
b9a281db 355AVStream *av_new_stream(AVFormatContext *s, int id);
916c80e9
FB
356void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
357 int pts_num, int pts_den);
de6d9b64 358
b9a281db 359/* media file output */
290c5fa6 360int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
b9a281db 361int av_write_header(AVFormatContext *s);
1e51d801
FB
362int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
363 int size);
b9a281db 364int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
365
366void dump_format(AVFormatContext *ic,
367 int index,
368 const char *url,
369 int is_output);
370int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
de6d9b64
FB
371INT64 parse_date(const char *datestr, int duration);
372
94988531
FB
373INT64 av_gettime(void);
374
de6d9b64
FB
375/* ffm specific for ffserver */
376#define FFM_PACKET_SIZE 4096
377offset_t ffm_read_write_index(int fd);
378void ffm_write_write_index(int fd, offset_t pos);
379void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
380
381int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
382
813cae4b
FB
383int get_frame_filename(char *buf, int buf_size,
384 const char *path, int number);
b9a281db 385int filename_number_test(const char *filename);
96baaa6a 386
b9a281db
FB
387/* grab specific */
388int video_grab_init(void);
389int audio_init(void);
96baaa6a 390
86fd51fb
FB
391/* DV1394 */
392int dv1394_init(void);
fb025625
FB
393
394#ifdef HAVE_AV_CONFIG_H
395int strstart(const char *str, const char *val, const char **ptr);
396int stristart(const char *str, const char *val, const char **ptr);
397void pstrcpy(char *buf, int buf_size, const char *str);
398char *pstrcat(char *buf, int buf_size, const char *s);
fb025625
FB
399
400struct in_addr;
401int resolve_host(struct in_addr *sin_addr, const char *hostname);
402
403void url_split(char *proto, int proto_size,
404 char *hostname, int hostname_size,
405 int *port_ptr,
406 char *path, int path_size,
407 const char *url);
408
a941f391
FB
409int match_ext(const char *filename, const char *extensions);
410
fb025625
FB
411#endif /* HAVE_AV_CONFIG_H */
412
02d697aa
ZK
413#ifdef __cplusplus
414}
415#endif
416
fb025625 417#endif /* AVFORMAT_H */