4 * Copyright (C) Thomas Östreich - June 2001
\r
5 * multiple audio track support Copyright (C) 2002 Thomas Östreich
\r
8 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
\r
10 * This file is part of transcode, a linux video stream processing tool
\r
12 * transcode is free software; you can redistribute it and/or modify
\r
13 * it under the terms of the GNU Lesser General Public License as published by
\r
14 * the Free Software Foundation; either version 2, or (at your option)
\r
15 * any later version.
\r
17 * transcode is distributed in the hope that it will be useful,
\r
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
20 * GNU Lesser General Public License for more details.
\r
22 * You should have received a copy of the GNU Lesser General Public
\r
23 * License along with this library; see the file COPYING. If not, write to
\r
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
28 #ifndef _GF_AVILIB_H_
\r
29 #define _GF_AVILIB_H_
\r
31 #include <gpac/tools.h>
\r
33 #define AVI_MAX_TRACKS 8
\r
40 } video_index_entry;
\r
47 } audio_index_entry;
\r
53 #define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex
\r
54 // array points to an index chunk
\r
55 #define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex
\r
56 // array points to a chunk in the file
\r
57 #define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is
\r
59 // bIndexSubtype codes for INDEX_OF_CHUNKS
\r
61 #define AVI_INDEX_2FIELD 0x01 // when fields within frames
\r
66 typedef struct _avisuperindex_entry {
\r
67 u64 qwOffset; // absolute file offset
\r
68 u32 dwSize; // size of index chunk at this offset
\r
69 u32 dwDuration; // time span in stream ticks
\r
70 } avisuperindex_entry;
\r
72 typedef struct _avistdindex_entry {
\r
73 u32 dwOffset; // qwBaseOffset + this is absolute file offset
\r
74 u32 dwSize; // bit 31 is set if this is NOT a keyframe
\r
75 } avistdindex_entry;
\r
78 typedef struct _avistdindex_chunk {
\r
79 char fcc[4]; // ix##
\r
80 u32 dwSize; // size of this chunk
\r
81 u16 wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
\r
82 u8 bIndexSubType; // must be 0
\r
83 u8 bIndexType; // must be AVI_INDEX_OF_CHUNKS
\r
84 u32 nEntriesInUse; //
\r
85 char dwChunkId[4]; // '##dc' or '##db' or '##wb' etc..
\r
86 u64 qwBaseOffset; // all dwOffsets in aIndex array are relative to this
\r
87 u32 dwReserved3; // must be 0
\r
88 avistdindex_entry *aIndex;
\r
89 } avistdindex_chunk;
\r
92 // Base Index Form 'indx'
\r
93 typedef struct _avisuperindex_chunk {
\r
95 u32 dwSize; // size of this chunk
\r
96 u16 wLongsPerEntry; // size of each entry in aIndex array (must be 8 for us)
\r
97 u8 bIndexSubType; // future use. must be 0
\r
98 u8 bIndexType; // one of AVI_INDEX_* codes
\r
99 u32 nEntriesInUse; // index of first unused member in aIndex array
\r
100 char dwChunkId[4]; // fcc of what is indexed
\r
101 u32 dwReserved[3]; // meaning differs for each index type/subtype.
\r
103 avisuperindex_entry *aIndex; // where are the ix## chunks
\r
104 avistdindex_chunk **stdindex; // the ix## chunks itself (array)
\r
105 } avisuperindex_chunk;
\r
109 typedef struct track_s
\r
112 long a_fmt; /* Audio format, see #defines below */
\r
113 long a_chans; /* Audio channels, 0 for no audio */
\r
114 long a_rate; /* Rate in Hz */
\r
115 long a_bits; /* bits per audio sample */
\r
116 long mp3rate; /* mp3 bitrate kbs*/
\r
117 long a_vbr; /* 0 == no Variable BitRate */
\r
118 long padrate; /* byte rate used for zero padding */
\r
120 long audio_strn; /* Audio stream number */
\r
121 u64 audio_bytes; /* Total number of bytes of audio data */
\r
122 long audio_chunks; /* Chunks of audio data in the file */
\r
124 char audio_tag[4]; /* Tag of audio data */
\r
125 long audio_posc; /* Audio position: chunk */
\r
126 long audio_posb; /* Audio position: byte within chunk */
\r
128 u64 a_codech_off; /* absolut offset of audio codec information */
\r
129 u64 a_codecf_off; /* absolut offset of audio codec information */
\r
131 audio_index_entry *audio_index;
\r
132 avisuperindex_chunk *audio_superindex;
\r
143 u32 bi_compression;
\r
145 u32 bi_x_pels_per_meter;
\r
146 u32 bi_y_pels_per_meter;
\r
148 u32 bi_clr_important;
\r
149 } alBITMAPINFOHEADER;
\r
155 u32 n_samples_per_sec;
\r
156 u32 n_avg_bytes_per_sec;
\r
158 u16 w_bits_per_sample;
\r
174 u32 dw_initial_frames;
\r
175 u32 dw_suggested_buffer_size;
\r
177 u32 dw_sample_size;
\r
182 } alAVISTREAMHEADER;
\r
187 FILE *fdes; /* File descriptor of AVI file */
\r
188 long mode; /* 0 for reading, 1 for writing */
\r
190 long width; /* Width of a video frame */
\r
191 long height; /* Height of a video frame */
\r
192 double fps; /* Frames per second */
\r
193 char compressor[8]; /* Type of compressor, 4 bytes + padding for 0 byte */
\r
194 char compressor2[8]; /* Type of compressor, 4 bytes + padding for 0 byte */
\r
195 u32 video_strn; /* Video stream number */
\r
196 long video_frames; /* Number of video frames */
\r
197 char video_tag[4]; /* Tag of video data */
\r
198 long video_pos; /* Number of next frame to be read
\r
199 (if index present) */
\r
200 alAVISTREAMHEADER video_stream_header;
\r
202 u32 max_len; /* maximum video chunk present */
\r
204 track_t track[AVI_MAX_TRACKS]; // up to AVI_MAX_TRACKS audio tracks supported
\r
206 s64 pos; /* position in file */
\r
207 long n_idx; /* number of index entries actually filled */
\r
208 long max_idx; /* number of index entries actually allocated */
\r
210 s64 v_codech_off; /* absolut offset of video codec (strh) info */
\r
211 s64 v_codecf_off; /* absolut offset of video codec (strf) info */
\r
213 u8 (*idx)[16]; /* index entries (AVI idx1 tag) */
\r
215 video_index_entry *video_index;
\r
216 avisuperindex_chunk *video_superindex; /* index of indices */
\r
217 int is_opendml; /* set to 1 if this is an odml file with multiple index chunks */
\r
219 s64 last_pos; /* Position of last frame written */
\r
220 u32 last_len; /* Length of last frame written */
\r
221 int must_use_index; /* Flag if frames are duplicated */
\r
223 int total_frames; /* total number of frames if dmlh is present */
\r
225 u32 anum; // total number of audio tracks
\r
226 u32 aptr; // current audio working track
\r
227 char *index_file; // read the avi index from this file
\r
229 alBITMAPINFOHEADER *bitmap_info_header;
\r
230 alWAVEFORMATEX *wave_format_ex[AVI_MAX_TRACKS];
\r
231 alAVISTREAMHEADER stream_headers[AVI_MAX_TRACKS];
\r
234 unsigned long extradata_size;
\r
237 #define AVI_MODE_WRITE 0
\r
238 #define AVI_MODE_READ 1
\r
240 /* The error codes delivered by avi_open_input_file */
\r
242 #define AVI_ERR_SIZELIM 1 /* The write of the data would exceed
\r
243 the maximum size of the AVI file.
\r
244 This is more a warning than an error
\r
245 since the file may be closed safely */
\r
247 #define AVI_ERR_OPEN 2 /* Error opening the AVI file - wrong path
\r
248 name or file nor readable/writable */
\r
250 #define AVI_ERR_READ 3 /* Error reading from AVI File */
\r
252 #define AVI_ERR_WRITE 4 /* Error writing to AVI File,
\r
255 #define AVI_ERR_WRITE_INDEX 5 /* Could not write index to AVI file
\r
256 during close, file may still be
\r
259 #define AVI_ERR_CLOSE 6 /* Could not write header to AVI file
\r
260 or not truncate the file during close,
\r
261 file is most probably corrupted */
\r
263 #define AVI_ERR_NOT_PERM 7 /* Operation not permitted:
\r
264 trying to read from a file open
\r
265 for writing or vice versa */
\r
267 #define AVI_ERR_NO_MEM 8 /* malloc failed */
\r
269 #define AVI_ERR_NO_AVI 9 /* Not an AVI file */
\r
271 #define AVI_ERR_NO_HDRL 10 /* AVI file has no has no header list,
\r
274 #define AVI_ERR_NO_MOVI 11 /* AVI file has no has no MOVI list,
\r
277 #define AVI_ERR_NO_VIDS 12 /* AVI file contains no video data */
\r
279 #define AVI_ERR_NO_IDX 13 /* The file has been opened with
\r
280 getIndex==0, but an operation has been
\r
281 performed that needs an index */
\r
283 /* Possible Audio formats */
\r
285 #ifndef WAVE_FORMAT_PCM
\r
286 #define WAVE_FORMAT_UNKNOWN (0x0000)
\r
287 #ifndef WAVE_FORMAT_PCM
\r
288 #define WAVE_FORMAT_PCM (0x0001)
\r
290 #define WAVE_FORMAT_ADPCM (0x0002)
\r
291 #define WAVE_FORMAT_IBM_CVSD (0x0005)
\r
292 #define WAVE_FORMAT_ALAW (0x0006)
\r
293 #define WAVE_FORMAT_MULAW (0x0007)
\r
294 #define WAVE_FORMAT_OKI_ADPCM (0x0010)
\r
295 #define WAVE_FORMAT_DVI_ADPCM (0x0011)
\r
296 #define WAVE_FORMAT_DIGISTD (0x0015)
\r
297 #define WAVE_FORMAT_DIGIFIX (0x0016)
\r
298 #define WAVE_FORMAT_YAMAHA_ADPCM (0x0020)
\r
299 #define WAVE_FORMAT_DSP_TRUESPEECH (0x0022)
\r
300 #define WAVE_FORMAT_GSM610 (0x0031)
\r
301 #define IBM_FORMAT_MULAW (0x0101)
\r
302 #define IBM_FORMAT_ALAW (0x0102)
\r
303 #define IBM_FORMAT_ADPCM (0x0103)
\r
306 avi_t* AVI_open_output_file(char * filename);
\r
307 void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);
\r
308 void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);
\r
309 int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);
\r
310 int AVI_dup_frame(avi_t *AVI);
\r
311 int AVI_write_audio(avi_t *AVI, char *data, long bytes);
\r
312 int AVI_append_audio(avi_t *AVI, char *data, long bytes);
\r
313 u64 AVI_bytes_remain(avi_t *AVI);
\r
314 int AVI_close(avi_t *AVI);
\r
315 u64 AVI_bytes_written(avi_t *AVI);
\r
317 avi_t *AVI_open_input_file(char *filename, int getIndex);
\r
318 avi_t *AVI_open_input_indexfile(char *filename, int getIndex, char *indexfile);
\r
319 avi_t *AVI_open_fd(FILE *fd, int getIndex);
\r
320 avi_t *AVI_open_indexfd(FILE *fd, int getIndex, char *indexfile);
\r
321 int avi_parse_input_file(avi_t *AVI, int getIndex);
\r
322 int avi_parse_index_from_file(avi_t *AVI, char *filename);
\r
323 long AVI_audio_mp3rate(avi_t *AVI);
\r
324 long AVI_audio_padrate(avi_t *AVI);
\r
325 long AVI_video_frames(avi_t *AVI);
\r
326 int AVI_video_width(avi_t *AVI);
\r
327 int AVI_video_height(avi_t *AVI);
\r
328 double AVI_frame_rate(avi_t *AVI);
\r
329 char* AVI_video_compressor(avi_t *AVI);
\r
331 int AVI_audio_channels(avi_t *AVI);
\r
332 int AVI_audio_bits(avi_t *AVI);
\r
333 int AVI_audio_format(avi_t *AVI);
\r
334 long AVI_audio_rate(avi_t *AVI);
\r
335 u64 AVI_audio_bytes(avi_t *AVI);
\r
336 long AVI_audio_chunks(avi_t *AVI);
\r
337 int AVI_can_read_audio(avi_t *AVI);
\r
339 long AVI_max_video_chunk(avi_t *AVI);
\r
341 long AVI_frame_size(avi_t *AVI, long frame);
\r
342 long AVI_audio_size(avi_t *AVI, long frame);
\r
343 int AVI_seek_start(avi_t *AVI);
\r
344 int AVI_set_video_position(avi_t *AVI, long frame);
\r
345 u64 AVI_get_video_position(avi_t *AVI, long frame);
\r
346 long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);
\r
348 int AVI_set_audio_position(avi_t *AVI, long byte);
\r
349 int AVI_set_audio_bitrate(avi_t *AVI, long bitrate);
\r
351 long AVI_get_audio_position_index(avi_t *AVI);
\r
352 int AVI_set_audio_position_index(avi_t *AVI, long indexpos);
\r
354 long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes, int *continuous);
\r
356 int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
\r
357 char *audbuf, long max_audbuf,
\r
360 int AVI_scan(char *name);
\r
361 int AVI_dump(char *name, int mode);
\r
363 char *AVI_codec2str(short cc);
\r
364 int AVI_file_check(char *import_file);
\r
366 void AVI_info(avi_t *avifile);
\r
367 u64 AVI_max_size(void);
\r
368 int avi_update_header(avi_t *AVI);
\r
370 int AVI_set_audio_track(avi_t *AVI, u32 track);
\r
371 int AVI_get_audio_track(avi_t *AVI);
\r
372 int AVI_audio_tracks(avi_t *AVI);
\r
374 void AVI_set_audio_vbr(avi_t *AVI, long is_vbr);
\r
375 long AVI_get_audio_vbr(avi_t *AVI);
\r
377 void AVI_set_comment_fd(avi_t *AVI, int fd);
\r
378 int AVI_get_comment_fd(avi_t *AVI);
\r
380 struct riff_struct
\r
382 u8 id[4]; /* RIFF */
\r
384 u8 wave_id[4]; /* WAVE */
\r
388 struct chunk_struct
\r
394 struct common_struct
\r
398 u32 dwSamplesPerSec;
\r
399 u32 dwAvgBytesPerSec;
\r
401 u16 wBitsPerSample; /* Only for PCM */
\r
404 struct wave_header
\r
406 struct riff_struct riff;
\r
407 struct chunk_struct format;
\r
408 struct common_struct common;
\r
409 struct chunk_struct data;
\r
413 int AVI_read_wave_header( int fd, struct wave_header * wave );
\r
414 int AVI_write_wave_header( int fd, const struct wave_header * wave );
\r
415 size_t AVI_read_wave_pcm_data( int fd, void * buffer, size_t buflen );
\r
416 size_t AVI_write_wave_pcm_data( int fd, const void * buffer, size_t buflen );
\r
419 struct AVIStreamHeader {
\r
424 long dwInitialFrames;
\r
429 long dwSuggestedBufferSize;
\r
434 #endif /*_GF_AVILIB_H_*/
\r