avformat.h 6.11 KB
Newer Older
Fabrice Bellard's avatar
Fabrice Bellard committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

#include "avcodec.h"

#include "avio.h"

/* packet functions */

typedef struct AVPacket {
    INT64 pts;
    UINT8 *data;
    int size;
    int stream_index;
    int flags;
#define PKT_FLAG_KEY   0x0001
} AVPacket; 

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

/*************************************************/
/* output formats */

struct AVFormatContext;
struct AVFormatInputContext;

typedef struct AVFormatParameters {
    int frame_rate;
    int sample_rate;
    int channels;
    int width;
    int height;
    int pix_fmt;
} AVFormatParameters;

typedef struct AVFormat {
    const char *name;
    const char *long_name;
    const char *mime_type;
    const char *extensions; /* comma separated extensions */

    /* 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,
47
                        unsigned char *buf, int size, int force_pts);
Fabrice Bellard's avatar
Fabrice Bellard committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    int (*write_trailer)(struct AVFormatContext *);

    /* optional input support */
    /* read the format header and initialize the AVFormatInputContext
       structure. Return 0 if OK. 'ap' if non NULL contains
       additionnal paramters. Only used in raw format right now */
    int (*read_header)(struct AVFormatContext *,
                       AVFormatParameters *ap);
    /* read one packet and put it in 'pkt'. pts and flags are also set */
    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);
    int flags;
Fabrice Bellard's avatar
Fabrice Bellard committed
65 66
#define AVFMT_NOFILE        0x0001 /* no file should be opened */
#define AVFMT_NEEDNUMBER    0x0002 /* needs '%d' in filename */ 
Fabrice Bellard's avatar
Fabrice Bellard committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    struct AVFormat *next;
} AVFormat;

typedef struct AVStream {
    int id;       /* internal stream id */
    AVCodecContext codec; /* codec context */
    void *priv_data;
} AVStream;

#define MAX_STREAMS 20

/* format I/O context */
typedef struct AVFormatContext {
    struct AVFormat *format;
    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];
    /* 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;

extern AVFormat *first_format;

/* rv10enc.c */
extern AVFormat rm_format;

/* mpegmux.c */
extern AVFormat mpeg_mux_format;

/* asfenc.c */
extern AVFormat asf_format;

/* avienc.c */
extern AVFormat avi_format;

/* jpegenc.c */
extern AVFormat mpjpeg_format;
extern AVFormat jpeg_format;
119
extern AVFormat single_jpeg_format;
Fabrice Bellard's avatar
Fabrice Bellard committed
120 121 122 123 124 125 126 127 128

/* swfenc.c */
extern AVFormat swf_format;

/* wav.c */
extern AVFormat wav_format;

/* img.c */
extern AVFormat pgm_format;
129
extern AVFormat ppm_format;
Fabrice Bellard's avatar
Fabrice Bellard committed
130 131
extern AVFormat pgmyuv_format;
extern AVFormat imgyuv_format;
132

Fabrice Bellard's avatar
Fabrice Bellard committed
133
extern AVFormat pgmpipe_format;
134 135
extern AVFormat pgmyuvpipe_format;
extern AVFormat ppmpipe_format;
Fabrice Bellard's avatar
Fabrice Bellard committed
136 137 138 139 140 141

/* raw.c */
extern AVFormat mp2_format;
extern AVFormat ac3_format;
extern AVFormat h263_format;
extern AVFormat mpeg1video_format;
142
extern AVFormat mjpeg_format;
Fabrice Bellard's avatar
Fabrice Bellard committed
143 144 145 146 147 148 149 150
extern AVFormat pcm_s16le_format;
extern AVFormat pcm_s16be_format;
extern AVFormat pcm_u16le_format;
extern AVFormat pcm_u16be_format;
extern AVFormat pcm_s8_format;
extern AVFormat pcm_u8_format;
extern AVFormat pcm_mulaw_format;
extern AVFormat pcm_alaw_format;
Fabrice Bellard's avatar
Fabrice Bellard committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
extern AVFormat rawvideo_format;

/* ffm.c */
extern AVFormat ffm_format;

/* formats.c */

#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))

void register_avformat(AVFormat *format);
AVFormat *guess_format(const char *short_name, const char *filename, const char *mime_type);

int strstart(const char *str, const char *val, const char **ptr);
void nstrcpy(char *buf, int buf_size, const char *str);
int match_ext(const char *filename, const char *extensions);

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);

183 184 185 186
AVFormatContext *av_open_input_file(const char *filename, 
                                    const char *format_name,
                                    int buf_size,
                                    AVFormatParameters *ap);
Fabrice Bellard's avatar
Fabrice Bellard committed
187 188 189
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
void av_close_input_file(AVFormatContext *s);

190
int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
Fabrice Bellard's avatar
Fabrice Bellard committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

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
208 209
int get_frame_filename(char *buf, int buf_size,
                       const char *path, int number);
210 211 212 213 214 215 216

/* grab/output specific */
extern AVFormat video_grab_device_format;
extern AVFormat audio_device_format;

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