Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <sys/types.h>
00029 #include <sys/stat.h>
00030 #include <stdio.h>
00031 #include <fcntl.h>
00032
00033
00034 #ifdef __CYGWIN__
00035 #include <sys/types.h>
00036 #elif defined WIN32
00037 #if defined __GNUWIN32__
00038 #include <stdint.h>
00039 #else
00040 #define uint32_t unsigned __int32
00041 #define uint8_t unsigned __int8
00042 #define uint16_t unsigned __int16
00043 #define uint64_t unsigned __int64
00044 #endif
00045 #else
00046 #include <unistd.h>
00047 #include <inttypes.h>
00048 #endif
00049
00050
00051 #include <limits.h>
00052 #include <stdlib.h>
00053 #include <string.h>
00054 #include <errno.h>
00055
00056 #ifndef AVILIB_H
00057 #define AVILIB_H
00058
00059 #define AVI_MAX_TRACKS 8
00060
00061 typedef struct
00062 {
00063 off_t key;
00064 off_t pos;
00065 off_t len;
00066 } video_index_entry;
00067
00068 typedef struct
00069 {
00070 off_t pos;
00071 off_t len;
00072 off_t tot;
00073 } audio_index_entry;
00074
00075 typedef struct track_s
00076 {
00077
00078 long a_fmt;
00079 long a_chans;
00080 long a_rate;
00081 long a_bits;
00082 long mp3rate;
00083
00084 long audio_strn;
00085 off_t audio_bytes;
00086 long audio_chunks;
00087
00088 char audio_tag[4];
00089 long audio_posc;
00090 long audio_posb;
00091
00092 off_t a_codech_off;
00093 off_t a_codecf_off;
00094
00095 audio_index_entry *audio_index;
00096
00097 } track_t;
00098
00099 typedef struct
00100 {
00101 uint32_t bi_size;
00102 uint32_t bi_width;
00103 uint32_t bi_height;
00104 uint16_t bi_planes;
00105 uint16_t bi_bit_count;
00106 uint32_t bi_compression;
00107 uint32_t bi_size_image;
00108 uint32_t bi_x_pels_per_meter;
00109 uint32_t bi_y_pels_per_meter;
00110 uint32_t bi_clr_used;
00111 uint32_t bi_clr_important;
00112 } BITMAPINFOHEADER_avilib;
00113
00114 typedef struct
00115 {
00116 uint16_t w_format_tag;
00117 uint16_t n_channels;
00118 uint32_t n_samples_per_sec;
00119 uint32_t n_avg_bytes_per_sec;
00120 uint16_t n_block_align;
00121 uint16_t w_bits_per_sample;
00122 uint16_t cb_size;
00123 } WAVEFORMATEX_avilib;
00124
00125 typedef struct
00126 {
00127 uint32_t fcc_type;
00128 uint32_t fcc_handler;
00129 uint32_t dw_flags;
00130 uint32_t dw_caps;
00131 uint16_t w_priority;
00132 uint16_t w_language;
00133 uint32_t dw_scale;
00134 uint32_t dw_rate;
00135 uint32_t dw_start;
00136 uint32_t dw_length;
00137 uint32_t dw_initial_frames;
00138 uint32_t dw_suggested_buffer_size;
00139 uint32_t dw_quality;
00140 uint32_t dw_sample_size;
00141 uint32_t dw_left;
00142 uint32_t dw_top;
00143 uint32_t dw_right;
00144 uint32_t dw_bottom;
00145 uint32_t dw_edit_count;
00146 uint32_t dw_format_change_count;
00147 char sz_name[64];
00148 } AVISTREAMINFO;
00149
00150 typedef struct
00151 {
00152
00153 long fdes;
00154 long mode;
00155
00156 long width;
00157 long height;
00158 double fps;
00159 char compressor[8];
00160 char compressor2[8];
00161 long video_strn;
00162 long video_frames;
00163 char video_tag[4];
00164 long video_pos;
00165
00166
00167 unsigned long max_len;
00168
00169 track_t track[AVI_MAX_TRACKS];
00170
00171 off_t pos;
00172 long n_idx;
00173 long max_idx;
00174
00175 off_t v_codech_off;
00176 off_t v_codecf_off;
00177
00178 unsigned char (*idx)[16];
00179 video_index_entry *video_index;
00180
00181 off_t last_pos;
00182 unsigned long last_len;
00183 int must_use_index;
00184 off_t movi_start;
00185
00186 int anum;
00187 int aptr;
00188
00189 BITMAPINFOHEADER_avilib *bitmap_info_header;
00190 WAVEFORMATEX_avilib *wave_format_ex[AVI_MAX_TRACKS];
00191 } avi_t;
00192
00193 #define AVI_MODE_WRITE 0
00194 #define AVI_MODE_READ 1
00195
00196
00197
00198 #define AVI_ERR_SIZELIM 1
00199
00200
00201
00202
00203 #define AVI_ERR_OPEN 2
00204
00205
00206 #define AVI_ERR_READ 3
00207
00208 #define AVI_ERR_WRITE 4
00209
00210
00211 #define AVI_ERR_WRITE_INDEX 5
00212
00213
00214
00215 #define AVI_ERR_CLOSE 6
00216
00217
00218
00219 #define AVI_ERR_NOT_PERM 7
00220
00221
00222
00223 #define AVI_ERR_NO_MEM 8
00224
00225 #define AVI_ERR_NO_AVI 9
00226
00227 #define AVI_ERR_NO_HDRL 10
00228
00229
00230 #define AVI_ERR_NO_MOVI 11
00231
00232
00233 #define AVI_ERR_NO_VIDS 12
00234
00235 #define AVI_ERR_NO_IDX 13
00236
00237
00238
00239
00240
00241 #ifndef WAVE_FORMAT_PCM
00242 #define WAVE_FORMAT_UNKNOWN (0x0000)
00243 #define WAVE_FORMAT_PCM (0x0001)
00244 #define WAVE_FORMAT_ADPCM (0x0002)
00245 #define WAVE_FORMAT_IBM_CVSD (0x0005)
00246 #define WAVE_FORMAT_ALAW (0x0006)
00247 #define WAVE_FORMAT_MULAW (0x0007)
00248 #define WAVE_FORMAT_OKI_ADPCM (0x0010)
00249 #define WAVE_FORMAT_DVI_ADPCM (0x0011)
00250 #define WAVE_FORMAT_DIGISTD (0x0015)
00251 #define WAVE_FORMAT_DIGIFIX (0x0016)
00252 #define WAVE_FORMAT_YAMAHA_ADPCM (0x0020)
00253 #define WAVE_FORMAT_DSP_TRUESPEECH (0x0022)
00254 #define WAVE_FORMAT_GSM610 (0x0031)
00255 #define IBM_FORMAT_MULAW (0x0101)
00256 #define IBM_FORMAT_ALAW (0x0102)
00257 #define IBM_FORMAT_ADPCM (0x0103)
00258 #endif
00259
00260 avi_t* AVI_open_output_file(char * filename);
00261 void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);
00262 void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);
00263 int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);
00264 int AVI_dup_frame(avi_t *AVI);
00265 int AVI_write_audio(avi_t *AVI, char *data, long bytes);
00266 int AVI_append_audio(avi_t *AVI, char *data, long bytes);
00267 long AVI_bytes_remain(avi_t *AVI);
00268 int AVI_close(avi_t *AVI);
00269 long AVI_bytes_written(avi_t *AVI);
00270
00271 avi_t *AVI_open_input_file(const char *filename, int getIndex);
00272 avi_t *AVI_open_fd(int fd, int getIndex);
00273 int avi_parse_input_file(avi_t *AVI, int getIndex);
00274 long AVI_audio_mp3rate(avi_t *AVI);
00275 long AVI_video_frames(avi_t *AVI);
00276 int AVI_video_width(avi_t *AVI);
00277 int AVI_video_height(avi_t *AVI);
00278 double AVI_frame_rate(avi_t *AVI);
00279 char* AVI_video_compressor(avi_t *AVI);
00280
00281 int AVI_audio_channels(avi_t *AVI);
00282 int AVI_audio_bits(avi_t *AVI);
00283 int AVI_audio_format(avi_t *AVI);
00284 long AVI_audio_rate(avi_t *AVI);
00285 long AVI_audio_bytes(avi_t *AVI);
00286 long AVI_audio_chunks(avi_t *AVI);
00287
00288 long AVI_max_video_chunk(avi_t *AVI);
00289
00290 long AVI_frame_size(avi_t *AVI, long frame);
00291 long AVI_audio_size(avi_t *AVI, long frame);
00292 int AVI_seek_start(avi_t *AVI);
00293 int AVI_set_video_position(avi_t *AVI, long frame);
00294 long AVI_get_video_position(avi_t *AVI, long frame);
00295 long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);
00296
00297 int AVI_set_audio_position(avi_t *AVI, long byte);
00298 int AVI_set_audio_bitrate(avi_t *AVI, long bitrate);
00299
00300 long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes);
00301 long AVI_read_audio_chunk(avi_t *AVI, char *audbuf);
00302
00303 long AVI_audio_codech_offset(avi_t *AVI);
00304 long AVI_audio_codecf_offset(avi_t *AVI);
00305 long AVI_video_codech_offset(avi_t *AVI);
00306 long AVI_video_codecf_offset(avi_t *AVI);
00307
00308 int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
00309 char *audbuf, long max_audbuf,
00310 long *len);
00311
00312 void AVI_print_error(char *str);
00313 char *AVI_strerror(void);
00314 char *AVI_syserror(void);
00315
00316 int AVI_scan(char *name);
00317 int AVI_dump(char *name, int mode);
00318
00319 char *AVI_codec2str(short cc);
00320 int AVI_file_check(char *import_file);
00321
00322 void AVI_info(avi_t *avifile);
00323 uint64_t AVI_max_size(void);
00324 int avi_update_header(avi_t *AVI);
00325
00326 int AVI_set_audio_track(avi_t *AVI, int track);
00327 int AVI_get_audio_track(avi_t *AVI);
00328 int AVI_audio_tracks(avi_t *AVI);
00329
00330
00331 struct riff_struct
00332 {
00333 unsigned char id[4];
00334 uint32_t len;
00335 unsigned char wave_id[4];
00336 };
00337
00338
00339 struct chunk_struct
00340 {
00341 unsigned char id[4];
00342 uint32_t len;
00343 };
00344
00345 struct common_struct
00346 {
00347 uint16_t wFormatTag;
00348 uint16_t wChannels;
00349 uint32_t dwSamplesPerSec;
00350 uint32_t dwAvgBytesPerSec;
00351 uint16_t wBlockAlign;
00352 uint16_t wBitsPerSample;
00353 };
00354
00355 struct wave_header
00356 {
00357 struct riff_struct riff;
00358 struct chunk_struct format;
00359 struct common_struct common;
00360 struct chunk_struct data;
00361 };
00362
00363
00364
00365 struct AVIStreamHeader {
00366 long fccType;
00367 long fccHandler;
00368 long dwFlags;
00369 long dwPriority;
00370 long dwInitialFrames;
00371 long dwScale;
00372 long dwRate;
00373 long dwStart;
00374 long dwLength;
00375 long dwSuggestedBufferSize;
00376 long dwQuality;
00377 long dwSampleSize;
00378 };
00379
00380 #endif