2 * avi.h library for AVI file format i/o
3 * Copyright (C) 2000 - 2002 Arne Schirmacher <arne@schirmacher.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 /** Common AVI declarations
22 Some of this comes from the public domain AVI specification, which
23 explains the microsoft-style definitions.
34 #define PACKED(x) __attribute__((packed)) x
36 #define AVI_SMALL_INDEX (0x01)
37 #define AVI_LARGE_INDEX (0x02)
38 #define KINO_AVI_INDEX_OF_INDEXES (0x00)
39 #define KINO_AVI_INDEX_OF_CHUNKS (0x01)
40 #define AVI_INDEX_2FIELD (0x01)
42 enum { AVI_PAL, AVI_NTSC, AVI_AUDIO_48KHZ, AVI_AUDIO_44KHZ, AVI_AUDIO_32KHZ };
44 /** Declarations of the main AVI file header
46 The contents of this struct goes into the 'avih' chunk. */
50 /// frame display rate (or 0L)
51 DWORD dwMicroSecPerFrame;
53 /// max. transfer rate
54 DWORD dwMaxBytesPerSec;
56 /// pad to multiples of this size, normally 2K
57 DWORD dwPaddingGranularity;
59 /// the ever-present flags
64 DWORD dwInitialFrames;
66 DWORD dwSuggestedBufferSize;
71 DWORD dwReserved[ 4 ];
73 PACKED(MainAVIHeader);
77 WORD top, bottom, left, right;
81 /** Declaration of a stream header
83 The contents of this struct goes into the 'strh' header. */
89 DWORD dwFlags; /* Contains AVITF_* flags */
92 DWORD dwInitialFrames;
94 DWORD dwRate; /* dwRate / dwScale == samples/second */
96 DWORD dwLength; /* In units above... */
97 DWORD dwSuggestedBufferSize;
102 PACKED(AVIStreamHeader);
112 DWORD dwDVReserved[ 2 ];
125 LONG biXPelsPerMeter;
126 LONG biYPelsPerMeter;
128 DWORD biClrImportant;
131 PACKED(BITMAPINFOHEADER);
137 DWORD nSamplesPerSec;
138 DWORD nAvgBytesPerSec;
144 PACKED(WAVEFORMATEX);
153 DWORD dwReserved[ 3 ];
154 struct avisuperindex_entry
162 PACKED(AVISuperIndex);
171 QUADWORD qwBaseOffset;
173 struct avifieldindex_entry
184 struct avisimpleindex_entry
194 PACKED(AVISimpleIndex);
200 DWORD dirEntryLength;
201 size_t dirEntryOffset;
202 int dirEntryWrittenFlag;
203 int dirEntryParentList;
208 /** base class for all AVI type files
210 It contains methods and members which are the same in all AVI type files regardless of the particular compression, number
213 The AVIFile class also contains methods for handling several indexes to the video frame content. */
215 class AVIFile : public RIFFFile
219 AVIFile( const AVIFile& );
221 virtual AVIFile& operator=( const AVIFile& );
223 virtual void Init( int format, int sampleFrequency, int indexType );
224 virtual int GetDVFrameInfo( off_t &offset, int &size, int frameNum );
225 virtual int GetFrameInfo( off_t &offset, int &size, int frameNum, FOURCC chunkID );
226 virtual int GetDVFrame( uint8_t *data, int frameNum );
227 virtual int getFrame( void *data, int frameNum, FOURCC chunkID );
228 virtual int GetTotalFrames() const;
229 virtual void PrintDirectoryEntryData( const RIFFDirEntry &entry ) const;
230 //virtual bool WriteFrame( const Frame &frame ) { return false; }
231 virtual void ParseList( int parent );
232 virtual void ParseRIFF( void );
233 virtual void ReadIndex( void );
234 virtual void WriteRIFF( void )
236 virtual void FlushIndx( int stream );
237 virtual void UpdateIndx( int stream, int chunk, int duration );
238 virtual void UpdateIdx1( int chunk, int flags );
239 virtual bool verifyStreamFormat( FOURCC type );
240 virtual bool verifyStream( FOURCC type );
241 virtual bool isOpenDML( void );
242 virtual void setDVINFO( DVINFO& )
244 virtual void setFccHandler( FOURCC type, FOURCC handler );
245 virtual bool getStreamFormat( void* data, FOURCC type );
248 MainAVIHeader mainHdr;
249 AVISimpleIndex *idx1;
258 AVIStreamHeader streamHdr[ 2 ];
259 AVISuperIndex *indx[ 2 ];
260 AVIStdIndex *ix[ 2 ];
278 /** writing Type 1 DV AVIs
282 class AVI1File : public AVIFile
288 virtual void Init( int format, int sampleFrequency, int indexType );
289 //virtual bool WriteFrame( const Frame &frame );
290 virtual void WriteRIFF( void );
291 virtual void setDVINFO( DVINFO& );
296 AVI1File( const AVI1File& );
297 AVI1File& operator=( const AVI1File& );
301 /** writing Type 2 (separate audio data) DV AVIs
303 This file type contains both audio and video tracks. It is therefore more compatible
304 to certain Windows programs, which expect any AVI having both audio and video tracks.
305 The video tracks contain the raw DV data (as in type 1) and the extracted audio tracks.
307 Note that because the DV data contains audio information anyway, this means duplication
308 of data and a slight increase of file size.
312 class AVI2File : public AVIFile
318 virtual void Init( int format, int sampleFrequency, int indexType );
319 //virtual bool WriteFrame( const Frame &frame );
320 virtual void WriteRIFF( void );
321 virtual void setDVINFO( DVINFO& );
324 BITMAPINFOHEADER bitmapinfo;
325 WAVEFORMATEX waveformatex;
327 AVI2File( const AVI2File& );
328 AVI2File& operator=( const AVI2File& );