-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrdavi2.h
More file actions
430 lines (348 loc) · 11.2 KB
/
rdavi2.h
File metadata and controls
430 lines (348 loc) · 11.2 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*
RdAvi2.exe - Copyright (c) 2025 by Dennis Hawkins. All rights reserved.
Inspired by: ReadAvi.exe by Michael Kohn<mike@mikekohn.net> (http://www.mikekohn.net/)
BSD License
Redistribution and use in source and binary forms are permitted provided
that the above copyright notice and this paragraph are duplicated in all
such forms and that any documentation, advertising materials, and other
materials related to such distribution and use acknowledge that the
software was developed by the copyright holder. The name of the copyright
holder may not be used to endorse or promote products derived from this
software without specific prior written permission. THIS SOFTWARE IS
PROVIDED `'AS IS? AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE.
Although not required, attribution is requested for any source code
used by others.
*/
//#define VERSION "1.0.1"
//#define RELEASE_DATE "July 23, 2024"
#define VERSION "1.0.2"
#define RELEASE_DATE "February 9, 2026"
#define COPYRIGHT "2024-2026"
#if defined(__GNUC__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__TINYC__)
#pragma GCC diagnostic ignored "-Wmultichar"
// Large File Support for MinGW/Linux
#define _FILE_OFFSET_BITS 64
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE 1
#endif
// Use standard types to avoid "redefinition" errors
#include <stdint.h>
typedef uint64_t QWORD;
typedef int64_t QINT;
typedef int32_t LONG; // Guaranteed 4 bytes regardless of 32/64 bit
typedef uint32_t FOURCC;
typedef uint32_t DWORD;
#define ASSERT_SIZE(type, expected_size) \
_Static_assert(sizeof(type) == (expected_size), #type " size mismatch")
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#if defined(__TINYC__)
static inline uint32_t __builtin_bswap32(uint32_t x)
{
__asm__ ("bswap %0" : "=r" (x) : "0" (x));
return x;
}
#endif
#define FIX_LIT(n) ((uint32_t)__builtin_bswap32(n))
#define FCC2STR(n) Fcc2Str(n)
#endif
#if defined(__BORLANDC__)
// Borland C is a 32bit compiler.
typedef unsigned __int64 QWORD; // different
typedef signed __int64 QINT;
typedef long LONG; // long is 8 bytes on 64bit compilers, must be 4 bytes here.
typedef unsigned int FOURCC;
typedef unsigned int DWORD;
#define ASSERT_SIZE(type, expected_size) \
typedef char type##_size_check[(sizeof(type) == (expected_size)) ? 1 : -1]
#define FIX_LIT(n) (n)
#define FCC2STR(n) ((char *)&(n))
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#define FALSE 0
#define TRUE !FALSE
typedef unsigned short WORD;
typedef unsigned char BYTE;
#ifdef __GNUC__
#pragma pack(push, 1)
#elif defined(__BORLANDC__)
/* Switch to 1-byte alignment */
#pragma option -a1
#endif
ASSERT_SIZE(QWORD, 8);
ASSERT_SIZE(DWORD, 4);
ASSERT_SIZE(LONG, 4);
ASSERT_SIZE(WORD, 2);
ASSERT_SIZE(BYTE, 1);
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
typedef struct
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
typedef struct
{
WORD Left;
WORD Top;
WORD Right;
WORD Bottom;
} SMALL_RECT;
typedef struct
{
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} GUID;
typedef struct
{
FILE *fp;
QWORD SeekBase; // Base File Pointer
} MFILE;
typedef struct
{
DWORD MicroSecPerFrame; // frame display rate (or 0)
DWORD MaxBytesPerSec; // max. transfer rate
DWORD PaddingGranularity; // pad to multiples of this size;
DWORD Flags; // the ever-present flags
DWORD TotalFrames; // # frames in file
DWORD InitialFrames;
DWORD NumStreams;
DWORD SuggestedBufferSize;
DWORD Width;
DWORD Height;
DWORD Reserved[4];
} MainAVIHeader;
// Flags for MainAVIHeader
#define AVIF_HASINDEX 0x00000010
#define AVIF_MUSTUSEINDEX 0x00000020
#define AVIF_ISINTERLEAVED 0x00000100
#define AVIF_TRUSTCKTYPE 0x00000800
#define AVIF_WASCAPTUREFILE 0x00010000
#define AVIF_COPYRIGHTED 0x00020000
// Due to multiple definitions of AVI Stream Header we have to define all three.
typedef struct // strh - compact version - 48 bytes
{
FOURCC fccType; // Can be 'auds', 'mids', 'txts', or 'vids'
FOURCC fccHandler;
DWORD Flags;
WORD Priority;
WORD Language;
DWORD InitialFrames;
DWORD TimeScale;
DWORD Rate; /* Rate / TimeScale == samples/second */
DWORD StartTime;
DWORD Length; /* In units above... */
DWORD SuggestedBufferSize;
DWORD Quality;
DWORD SampleSize;
} AVIStreamHeader48;
typedef struct // strh - mid sized version - 56 bytes
{
FOURCC fccType; // Can be 'auds', 'mids', 'txts', or 'vids'
FOURCC fccHandler;
DWORD Flags;
WORD Priority;
WORD Language;
DWORD InitialFrames;
DWORD TimeScale;
DWORD Rate; /* Rate / TimeScale == samples/second */
DWORD StartTime;
DWORD Length; /* In units above... */
DWORD SuggestedBufferSize;
DWORD Quality;
DWORD SampleSize;
SMALL_RECT Frame;
} AVIStreamHeader56;
typedef struct // strh - large version - 64 bytes
{
FOURCC fccType; // Can be 'auds', 'mids', 'txts', or 'vids'
FOURCC fccHandler;
DWORD Flags;
WORD Priority;
WORD Language;
DWORD InitialFrames;
DWORD TimeScale;
DWORD Rate; /* Rate / TimeScale == samples/second */
DWORD StartTime;
DWORD Length; /* In units above... */
DWORD SuggestedBufferSize;
DWORD Quality;
DWORD SampleSize;
RECT Frame;
} AVIStreamHeader64;
// Flags for AVIStreamHeader
#define AVISF_DISABLED 0x00000001
#define AVISF_VIDEO_PALCHANGES 0x00010000
typedef struct // used when format is 'vids'
{ // bmih
DWORD header_size;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD bits_per_pixel;
DWORD biCompression;
DWORD biSizeImage; // total bytes in image
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
// Palette goes here
} STREAMFORMATVID; // size=40 + palette size
typedef struct
{ // rgbq
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} VIDPALETTE; // palette for STREAMFORMATVIDS
struct stream_header_auds_t
{
int format_type;
int number_of_channels;
int sample_rate;
int bytes_per_second;
int block_size_of_data;
int bits_per_sample;
int byte_count_extended;
};
typedef struct
{
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} STREAMFORMATAUD; // same as WAVEFORMATEX size=18 bytes
typedef struct // 22 bytes
{
union
{
WORD wValidBitsPerSample;
WORD wSamplesPerBlock;
WORD wReserved;
} Samples;
DWORD dwChannelMask;
GUID SubFormat; // 16 bytes
} AUDIOEXTENSION;
typedef struct // 12 bytes - for use when wFormatTag = 0x0055 (MP3)
{
WORD wID;
DWORD fdwFlags;
WORD nBlockSize;
WORD nFramesPerBlock;
WORD nCodecDelay;
} MP3EXT;
typedef struct // legacy index structure
{
DWORD ckid;
DWORD dwFlags;
DWORD dwChunkOffset;
DWORD dwChunkLength;
} AVIINDEXENTRY;
typedef struct
{
DWORD CompressedBMHeight;
DWORD CompressedBMWidth;
DWORD ValidBMHeight;
DWORD ValidBMWidth;
DWORD ValidBMXOffset;
DWORD ValidBMYOffset;
DWORD VideoXOffsetInT;
DWORD VideoYValidStartLine;
} VIDEO_FIELD_DESC;
typedef struct
{
DWORD VideoFormatToken;
DWORD VideoStandard;
DWORD dwVerticalRefreshRate;
DWORD dwHTotalInT;
DWORD dwVTotalInLines;
DWORD dwFrameAspectRatio;
DWORD dwFrameWidthInPixels;
DWORD dwFrameHeightInLines;
DWORD nbFieldPerFrame;
VIDEO_FIELD_DESC FieldInfo[]; // nbFieldPerFrame
} VideoPropHeader;
typedef struct
{
DWORD dwTotalFrames; // total frames in all riffs combined.
// DWORD dwReserved[61]; // junk not used - note the spec doesn't actually have this
} AVIEXTHEADER;
// bIndexType codes
#define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex array points to an index chunk
#define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex array points to a chunk in the file
#define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is really the data
// bIndexSubtype codes for INDEX_OF_CHUNKS
#define AVI_INDEX_STANDARD 0x00 // Standard index chunks
#define AVI_INDEX_2FIELD 0x01 // when fields within frames are also indexed
typedef struct
{
WORD wLongsPerEntry; // size of each entry in aIndex array
BYTE bIndexSubType; // future use. must be 0
BYTE bIndexType; // one of AVI_INDEX_* codes
DWORD nEntriesInUse; // index of first unused member in aIndex array
DWORD dwChunkId; // fcc of what is indexed
QWORD qwBaseOffset; // offsets in aIndex array are relative to this
DWORD dwReserved; // must be 0
} INDX_CHUNK;
typedef struct
{
DWORD dwOffset; // qwBaseOffset + this is absolute file offset
DWORD dwSize; // bit 31 is set if this is NOT a keyframe
} STDINDEXENTRY;
typedef struct
{
DWORD dwOffset;
DWORD dwSize; // size of all fields (bit 31 set for NON-keyframes)
DWORD dwOffsetField2; // offset to second field
} FIELDINDEXENTRY;
typedef struct
{
QWORD qwOffset; // absolute file offset, offset 0 is unused entry??
DWORD dwSize; // size of index chunk at this offset
DWORD dwDuration; // time span in stream ticks
} SUPERINDEXENTRY;
#ifdef __GNUC__
#pragma pack(pop)
#elif defined(__BORLANDC__)
/* Restore to default alignment (usually 4 or 8) */
#pragma option -a.
#endif
// codecs.c prototypes
char *LookupFourCC(DWORD InFcc);
char *LookupFormat(DWORD FmtNum);
char *LookupINFO(DWORD Info);
// File64.c prototypes
// Exported functions
void File64SetBase(MFILE *fp, QWORD NewBase);
QWORD File64GetBase(MFILE *fp);
MFILE *File64Open(char *fname, char *mode);
int File64Close(MFILE *mfp);
size_t File64Read(MFILE *mfp, void *buffer, int len);
size_t File64Write(MFILE *mfp, void *buffer, int len);
int File64Qseek(MFILE *mfp, QWORD AbsAddr);
int File64SetPos(MFILE *mfp, LONG offset, int whence);
DWORD File64GetPos(MFILE *mfp);
BYTE File64Getchar(MFILE *mfp);
BYTE File64Putchar(MFILE *mfp, BYTE ch);
FOURCC ReadFCC(MFILE *in, int *StreamNum);
int WriteFCC(MFILE *out, FOURCC fccval, int StreamNum);
DWORD ReverseLiteral(DWORD val);
// FileUtil.c prototypes
char *QWORD2HEX(QWORD val);
DWORD ReadDWORD(MFILE *in);
//FOURCC ReadFCC(FILE *in, int *StreamNum);