• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Makefile.amH A D29-Mar-2004363 177

Makefile.inH A D03-May-20228.8 KiB324249

README.avilibH A D17-Aug-20026.7 KiB222138

avidump.cH A D02-Nov-200422.8 KiB898690

avilib.cH A D02-Nov-2004103.7 KiB3,6752,466

avilib.hH A D02-Nov-200415.2 KiB459316

avimisc.cH A D02-Nov-20043.4 KiB14388

xio.cH A D02-Nov-20042.1 KiB11074

xio.hH A D29-Mar-20041.4 KiB4215

README.avilib

1avilib: Reading and writing avi files
2=====================================
3
4Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
5
6avilib is a open source library for dealing with AVI
7files under Linux or other UNIX operating systems.
8
9It provides a framework for extracting or adding raw
10audio and single raw (=compressed) frames from/to AVI Files.
11
12It does not deal with any compression issues which have to be
13handled on a higher level by the user of avilib.
14
15AVI files may have several video and audiotracks.
16
17avilib writes only one video track and (optionally) one
18audio track and also extracts only the first video and audio
19track (but input files may contain more than one track, the others
20just being ingored).
21
22The interface to avilib is kept similar to the quicktime4linux interface
23(by Adam Williams) with the following important differences:
24
25- since only the first track of video and audio is considered,
26  there is no track argument in any of the routines.
27
28- audio is generally considered as a byte stream and therefore
29  all size arguments used in reading/writing audio are in bytes
30  and not in samples.
31
32- as mentioned above, there are no routines dealing with compression issues.
33
34
35Compiling:
36==========
37
38Since the library consists only of one c source file, I have not provided
39a Makefile or similar, just compile with
40
41cc -c <your favorite options> avilib.c
42
43
44Portability:
45============
46
47AVI-Files use little endian numbers throughout the file, I have tried
48to read/write these numbers in a way which doesn't depent on endianness.
49This library should therefore also be useable on big endian machines.
50This feature is not so heavily tested, however.
51
52
53Usage:
54======
55
56Basics, opening, closing
57------------------------
58
59Include "avilib.h" in your source and declare a pointer:
60
61   avi_t *avifile;
62
63Open the AVI file with:
64
65   avifile = AVI_open_input_file("xxx.avi",1);
66
67or
68
69   avifile = AVI_open_output_file("xxx.avi");
70
71You may either only read from the input file (leaving it unchanged)
72or create a completly new AVI file. There is no editing or append
73mode available.
74
75Both routines will either return a pointer to avi_t or a zero pointer
76in the case of an error.
77
78For closing the file, use:
79
80   int  AVI_close(avi_t *AVI);
81
82Files you have written MUST be closed (the header is written at close time),
83else they will not be readable by any other software.
84
85Files opened for reading should be closed to free the file descriptor
86and some data (unless your program is finishing anyway).
87
88
89Error handling:
90---------------
91
92Most routines (besides open/close) will return 0 or a usefull number if successfull
93and a -1 in the case of an error. If an error occured, the external variable
94AVI_errno is set. See avilib.h for the meaning of the error codes in AVI_errno.
95
96There is also a routine (which acts like perror) to output a description
97of the last error to stderr:
98
99AVI_print_error(char *str)
100
101
102
103Reading from an AVI file:
104-------------------------
105
106After opening the file, you can obtain the parameters of the AVI
107with the following routines:
108
109long AVI_video_frames(avi_t *AVI);
110   number of video frames in the file
111
112int  AVI_video_width(avi_t *AVI);
113int  AVI_video_height(avi_t *AVI);
114   width and height of the video in pixels
115
116double AVI_frame_rate(avi_t *AVI);
117   frame rate in frames per second, notice that this is a double value!
118
119char* AVI_video_compressor(avi_t *AVI);
120   string describing the compressor
121
122int  AVI_audio_channels(avi_t *AVI);
123   number of audio channels, 1 for mono, 2 for stereo, 0 if no audio present
124
125int  AVI_audio_bits(avi_t *AVI);
126   audio bits, usually 8 or 16
127
128int  AVI_audio_format(avi_t *AVI);
129   audio format, most common is 1 for raw PCM, look into avilib.h for others
130
131long AVI_audio_rate(avi_t *AVI);
132   audio rate in samples/second
133
134long AVI_audio_bytes(avi_t *AVI);
135   total number of audio bytes in the file
136
137
138In order to read the video frame by frame, use
139(frame numbers are starting from 0 !!!!!)
140
141long AVI_frame_size(avi_t *AVI, long frame);
142   to get the size of frame with number "frame"
143
144long AVI_read_frame(avi_t *AVI, char *vidbuf);
145   to read the next  frame (frame posittion is advanced by 1 after the read)
146
147int  AVI_seek_start(avi_t *AVI);
148int  AVI_set_video_position(avi_t *AVI, long frame);
149   to position in the AVI file
150   (for reading the frames out of order)
151
152
153Read audio with
154
155int  AVI_set_audio_position(avi_t *AVI, long byte);
156   to position to an arbitrary byte position within the audio stream
157
158long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes);
159   to actually read "bytes" number of audio bytes.
160   the audio position is advanced by "bytes", so there is no
161   need to reposition before every call when reading in order.
162
163
164Avoiding lengthy index searches:
165--------------------------------
166
167When opening the AVI file, avilib looks if the file has an index attached
168and if this is not the case, it creates one by reading through the whole file.
169
170If you want to read through the file only once, creation of an index is
171not necessary in that case. You may use AVI_open_input_file with the second
172argument set to 0 and then use AVI_read_data for readin through the file.
173
174Look to the source for the arguments of AVI_read_data.
175
176
177Writing to an AVI file:
178-----------------------
179
180After you have opened the file, use the following routines to set
181the properties of the AVI file:
182
183void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);
184void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format);
185
186with:
187
188width, height   width and height of the video in pixels
189
190fps             frame rate in frames per second, notice that this is a double value!
191
192compressor      string describing the compressor
193
194channels        number of audio channels, 1 for mono, 2 for stereo, 0 if no audio present
195
196rate            audio rate in samples/second
197
198bits            audio bits, usually 8 or 16, 0 if no audio present
199
200format          audio format, most common is 1 for raw PCM, look into avilib.h for others
201
202
203to write video frames or audio, use:
204
205int  AVI_write_frame(avi_t *AVI, char *data, long bytes);
206int  AVI_write_audio(avi_t *AVI, char *data, long bytes);
207
208there is also a feature to duplicate the index entry of the last
209frame without writing the data again to the file, this should
210used with care since I don't know if all AVI players can handle
211the resulting file (xanim can do it!):
212
213int  AVI_dup_frame(avi_t *AVI);
214
215AVI files have a 2 GB limit (as has the Linux ext2 file system),
216avilib will return an error if you try to add more data to the file
217(and it cares that the file still can be correctly closed).
218If you want to check yourself how far you are away from that limit
219(for example to synchronize the amount of audio and video data) use:
220
221long AVI_bytes_remain(avi_t *AVI);
222