2 #------------------------------------------------------------------------------
3 # $File: riff,v 1.35 2020/06/05 17:15:03 christos Exp $
4 # riff: file(1) magic for RIFF format
7 # https://www.seanet.com/users/matts/riffmci/riffmci.htm
8 # http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
11 # audio format tag. Assume limits: max 1024 bit, 128 channels, 1 MHz
13 >0 leshort 1 \b, Microsoft PCM
15 >>>14 leshort <1024 \b, %d bit
16 >0 leshort 2 \b, Microsoft ADPCM
17 >0 leshort 6 \b, ITU G.711 A-law
18 >0 leshort 7 \b, ITU G.711 mu-law
19 >0 leshort 8 \b, Microsoft DTS
20 >0 leshort 17 \b, IMA ADPCM
21 >0 leshort 20 \b, ITU G.723 ADPCM (Yamaha)
22 >0 leshort 49 \b, GSM 6.10
23 >0 leshort 64 \b, ITU G.721 ADPCM
24 >0 leshort 80 \b, MPEG
25 >0 leshort 85 \b, MPEG Layer 3
26 >0 leshort 0x2001 \b, DTS
27 >2 leshort =1 \b, mono
28 >2 leshort =2 \b, stereo
30 >>2 leshort <128 \b, %d channels
32 >>4 lelong <1000000 %d Hz
40 >>&(4.l+4) use riff-walk
42 >>&(4.l+4) use riff-walk
44 >>&(4.l+4) use riff-walk
46 >>&(4.l+4) use riff-walk
48 >>&(4.l+4) use riff-walk
52 >>>>13 byte 0x2a \b, VP8 encoding
53 >>>>>14 leshort&0x3fff x \b, %d
54 >>>>>16 leshort&0x3fff x \bx%d, Scaling:
55 >>>>>14 leshort&0xc000 0x0000 \b [none]
56 >>>>>14 leshort&0xc000 0x1000 \b [5/4]
57 >>>>>14 leshort&0xc000 0x2000 \b [5/3]
58 >>>>>14 leshort&0xc000 0x3000 \b [2]
59 >>>>>14 leshort&0xc000 0x0000 \bx[none]
60 >>>>>14 leshort&0xc000 0x1000 \bx[5/4]
61 >>>>>14 leshort&0xc000 0x2000 \bx[5/3]
62 >>>>>14 leshort&0xc000 0x3000 \bx[2]
63 >>>>>15 byte&0x80 =0x00 \b, YUV color
64 >>>>>15 byte&0x80 =0x80 \b, bad color specification
65 >>>>>15 byte&0x40 =0x40 \b, no clamping required
66 >>>>>15 byte&0x40 =0x00 \b, decoders should clamp
67 #>0 string x we got %s
68 #>>&(4.l+4) use riff-walk
70 # AVI section extended by Patrik Radman <patrik+file-magic@iki.fi>
72 0 string RIFF RIFF (little-endian) data
74 # Update: Joerg Jenderek
75 # URL: https://en.wikipedia.org/wiki/Resource_Interchange_File_Format
76 # Reference: https://worms2d.info/Palette_file
77 >8 string PAL\ \b, palette
78 !:mime application/x-riff
79 # color palette by Microsoft Corporation
81 # file size = chunk size + 8 in most cases
82 >>4 ulelong+8 x \b, %u bytes
84 >>12 string plth \b, extended
87 # data chunk size = color entries * 4 + 4 + sometimes extra (4) appended bytes
88 >>>16 ulelong x \b, data size %u
89 # palVersion is always 0x0300
90 #>>>20 leshort x \b, version 0x%4.4x
91 # palNumEntries specifies the number of palette color entries
92 >>>22 uleshort x \b, %u entries
93 # after palPalEntry sized (number of color entries * 4 ) vector
95 # jump relative 22 ( 8 + 16) bytes forward points after end of file or to
96 # appended extra bytes like in http://safecolours.rigdenage.com/set(ms).zip/Protan(MS).pal
97 >>>>&16 ubelong x \b, extra bytes
98 >>>>>&-4 ubelong >0 0x%8.8x
99 # RIFF Device Independent Bitmap format
100 >8 string RDIB \b, device-independent bitmap
102 >>>30 leshort 12 \b, OS/2 1.x format
103 >>>>34 leshort x \b, %d x
105 >>>30 leshort 64 \b, OS/2 2.x format
106 >>>>34 leshort x \b, %d x
108 >>>30 leshort 40 \b, Windows 3.x format
109 >>>>34 lelong x \b, %d x
113 >8 string RMID \b, MIDI
114 # RIFF Multimedia Movie File format
115 >8 string RMMP \b, multimedia movie
116 # RIFF wrapper for MP3
117 >8 string RMP3 \b, MPEG Layer 3 audio
118 # Microsoft WAVE format (*.wav)
119 >8 string WAVE \b, WAVE audio
123 # Update: Joerg Jenderek
124 # lower case for Corel Draw version 8 Bidi
126 # skip Corel CCX Clipart
130 # URL: http://fileformats.archiveteam.org/wiki/CCX_(Corel)
131 # Reference: http://mark0.net/download/triddefs_xml.7z/defs/c/ccx-corel.trid.xml
132 >>8 string =CDRXcont \b, Corel Clipart
133 !:mime application/x-corel-ccx
135 # 3rd chunk data {Corel\040Binary\040Meta\040File}
136 #>>>20 string x \b, 3rd '%-s'
137 >>>4 ulelong+8 x \b, %u bytes
138 # From: Joerg Jenderek
139 # URL: https://en.wikipedia.org/wiki/CorelDRAW
140 # Reference: http://fileformats.archiveteam.org/wiki/CorelDRAW
141 # Picture templates created by newer software start with RIFF type CDT
144 # Picture templates with version 4.4
147 # pattern created by newer software start with RIFF type PAT
150 >8 string NUNDROOT \b, Steinberg CuBase
151 # AVI == Audio Video Interleave
152 >8 string AVI\040 \b, AVI
153 !:mime video/x-msvideo
155 >>>20 string hdrlavih
156 >>>>&36 lelong x \b, %u x
158 >>>>&4 lelong >1000000 <1 fps,
159 >>>>&4 lelong 1000000 1.00 fps,
160 >>>>&4 lelong 500000 2.00 fps,
161 >>>>&4 lelong 333333 3.00 fps,
162 >>>>&4 lelong 250000 4.00 fps,
163 >>>>&4 lelong 200000 5.00 fps,
164 >>>>&4 lelong 166667 6.00 fps,
165 >>>>&4 lelong 142857 7.00 fps,
166 >>>>&4 lelong 125000 8.00 fps,
167 >>>>&4 lelong 111111 9.00 fps,
168 >>>>&4 lelong 100000 10.00 fps,
170 >>>>&4 lelong <101010
171 >>>>>&-4 lelong >99010
172 >>>>>>&-4 lelong !100000 ~10 fps,
173 >>>>&4 lelong 83333 12.00 fps,
176 >>>>>&-4 lelong >82645
177 >>>>>>&-4 lelong !83333 ~12 fps,
178 >>>>&4 lelong 66667 15.00 fps,
181 >>>>>&-4 lelong >66225
182 >>>>>>&-4 lelong !66667 ~15 fps,
183 >>>>&4 lelong 50000 20.00 fps,
184 >>>>&4 lelong 41708 23.98 fps,
185 >>>>&4 lelong 41667 24.00 fps,
188 >>>>>&-4 lelong >41494
189 >>>>>>&-4 lelong !41708
190 >>>>>>>&-4 lelong !41667 ~24 fps,
191 >>>>&4 lelong 40000 25.00 fps,
194 >>>>>&-4 lelong >39841
195 >>>>>>&-4 lelong !40000 ~25 fps,
196 >>>>&4 lelong 33367 29.97 fps,
197 >>>>&4 lelong 33333 30.00 fps,
200 >>>>>&-4 lelong >33223
201 >>>>>>&-4 lelong !33367
202 >>>>>>>&-4 lelong !33333 ~30 fps,
203 >>>>&4 lelong <32224 >30 fps,
204 ##>>>>&4 lelong x (%lu)
205 ##>>>>&20 lelong x %lu frames,
206 # Note: The tests below assume that the AVI has 1 or 2 streams,
207 # "vids" optionally followed by "auds".
208 # (Should cover 99.9% of all AVIs.)
209 # assuming avih length = 56
211 >>>>96 string strlstrh
212 >>>>>108 string vids video:
213 >>>>>>&0 lelong 0 uncompressed
214 # skip past vids strh
215 >>>>>>(104.l+108) string strf
216 >>>>>>>(104.l+132) lelong 1 RLE 8bpp
217 >>>>>>>(104.l+132) string/c cvid Cinepak
218 >>>>>>>(104.l+132) string/c i263 Intel I.263
219 >>>>>>>(104.l+132) string/c iv32 Indeo 3.2
220 >>>>>>>(104.l+132) string/c iv41 Indeo 4.1
221 >>>>>>>(104.l+132) string/c iv50 Indeo 5.0
222 >>>>>>>(104.l+132) string/c mp42 Microsoft MPEG-4 v2
223 >>>>>>>(104.l+132) string/c mp43 Microsoft MPEG-4 v3
224 >>>>>>>(104.l+132) string/c fmp4 FFMpeg MPEG-4
225 >>>>>>>(104.l+132) string/c mjpg Motion JPEG
226 >>>>>>>(104.l+132) string/c div3 DivX 3
227 >>>>>>>>112 string/c div3 Low-Motion
228 >>>>>>>>112 string/c div4 Fast-Motion
229 >>>>>>>(104.l+132) string/c divx DivX 4
230 >>>>>>>(104.l+132) string/c dx50 DivX 5
231 >>>>>>>(104.l+132) string/c xvid XviD
232 >>>>>>>(104.l+132) string/c h264 H.264
233 >>>>>>>(104.l+132) string/c wmv3 Windows Media Video 9
234 >>>>>>>(104.l+132) string/c h264 X.264 or H.264
235 >>>>>>>(104.l+132) lelong 0
236 ##>>>>>>>(104.l+132) string x (%.4s)
237 # skip past first (video) LIST
238 >>>>(92.l+96) string LIST
239 >>>>>(92.l+104) string strlstrh
240 >>>>>>(92.l+116) string auds \b, audio:
241 # auds strh length = 56:
242 >>>>>>>(92.l+172) string strf
243 >>>>>>>>(92.l+180) leshort 0x0001 uncompressed PCM
244 >>>>>>>>(92.l+180) leshort 0x0002 ADPCM
245 >>>>>>>>(92.l+180) leshort 0x0006 aLaw
246 >>>>>>>>(92.l+180) leshort 0x0007 uLaw
247 >>>>>>>>(92.l+180) leshort 0x0050 MPEG-1 Layer 1 or 2
248 >>>>>>>>(92.l+180) leshort 0x0055 MPEG-1 Layer 3
249 >>>>>>>>(92.l+180) leshort 0x2000 Dolby AC3
250 >>>>>>>>(92.l+180) leshort 0x0161 DivX
251 ##>>>>>>>>(92.l+180) leshort x (0x%.4x)
252 >>>>>>>>(92.l+182) leshort 1 (mono,
253 >>>>>>>>(92.l+182) leshort 2 (stereo,
254 >>>>>>>>(92.l+182) leshort >2 (%d channels,
255 >>>>>>>>(92.l+184) lelong x %d Hz)
256 # auds strh length = 64:
257 >>>>>>>(92.l+180) string strf
258 >>>>>>>>(92.l+188) leshort 0x0001 uncompressed PCM
259 >>>>>>>>(92.l+188) leshort 0x0002 ADPCM
260 >>>>>>>>(92.l+188) leshort 0x0055 MPEG-1 Layer 3
261 >>>>>>>>(92.l+188) leshort 0x2000 Dolby AC3
262 >>>>>>>>(92.l+188) leshort 0x0161 DivX
263 ##>>>>>>>>(92.l+188) leshort x (0x%.4x)
264 >>>>>>>>(92.l+190) leshort 1 (mono,
265 >>>>>>>>(92.l+190) leshort 2 (stereo,
266 >>>>>>>>(92.l+190) leshort >2 (%d channels,
267 >>>>>>>>(92.l+192) lelong x %d Hz)
268 # Animated Cursor format
269 >8 string ACON \b, animated cursor
270 # SoundFont 2 <mpruett@sgi.com>
271 >8 string sfbk SoundFont/Bank
272 # MPEG-1 wrapped in a RIFF, apparently
273 >8 string CDXA \b, wrapped MPEG-1 (CDXA)
274 >8 string 4XMV \b, 4X Movie file
275 # AMV-type AVI file: https://wiki.multimedia.cx/index.php?title=AMV
276 >8 string AMV\040 \b, AMV
277 >8 string WEBP \b, Web/P image
280 # From: Joerg Jenderek
281 # URL: https://en.wikipedia.org/wiki/CorelDRAW
282 # Reference: http://fileformats.archiveteam.org/wiki/CorelDRAW
283 # Note: Since version 3 CorelDraw Pictures are RIFF based
284 # but data chunks remain proprietary.
285 # Since version 14 til 15 packed as "content/riffData.cdr" and
286 # since 16 "content/root.dat" in ZIP container
287 # TODO: distinguish templates with version 12.5 from Designer illustration 12
288 # display information of RIFF based Corel Draw pictures, templates and patterns
290 # display second chunk for debugging
291 #>8 string x \b, [8]=%.8s
292 >0 string x \b, Corel Draw
293 #!:mime image/x-coreldraw
294 !:mime application/vnd.corel-draw
295 # used by newer pictures templates
297 # used by templates with newer versions since 16
298 >>>12 string =fver Picture template (root.dat)
300 # used by templates with older versions with vrsn tag
302 # used by templates with older versions 14-15
303 >>>>11 string >E Picture template (riffData.cdr)
305 # used by templates with older versions 11-13
306 >>>>11 string <F Picture template
308 # used by older templates with version 4.4
309 >>8 string CDST Picture template
311 # used by templates with version 12.5
312 >>8 string DESC Picture template
314 # used by newer patterns with version 22
315 >>8 string PAT Pattern
317 # remaining older templates, patterns, drawings
319 # pattern with old version 4.y
320 >>>26 ulelong =0x0000206C Pattern
322 # pattern with newer versions
323 >>>26 ulelong =0x00000D2C Pattern
325 # remaining older templates or pictures
327 # used by older versions 5 - 15
329 # 4th chunk size unequal 282Ch only found for CDR
330 >>>>>26 ulelong !0x0000282c Picture
332 >>>>>26 default x Picture or template
334 # used by newer versions since 16
335 >>>>12 string =fver Picture (root.dat)
337 # version marked by 1 ASCII char: space~3, ... , F~15, ... , N~22, ... R~22 template
338 >11 string x \b, version
339 >11 string >\040 '%-.1s'
341 >4 ulelong+8 x \b, %u bytes
343 # display numeric version of RIFF based Corel after 3rd RIFF tag
345 # for debugging purpose; vrsn for short content; fver for 16 byte size
346 #>12 string x \b, TAG "%-4.4s"
347 # 1st data chunk length 2 implies short content version
349 # vrsn chunk short content interpreted by MajorVersion * 100 + MinorVersion
350 >>20 uleshort/100 x %u
351 >>20 uleshort%100 >0 \b.%u
352 # for debugging purpose display next chunk like: DISP LIST
353 #>>22 string x \b, 4th "%-4.4s"
354 #>>26 ulelong x \b, 4th SIZE 0x%x
355 # for debugging purpose display 5th chunk like: LIST DISP ccmm osfp
356 #>>(26.l+30) string x \b, 5th "%-4.4s"
357 # 1st data chunk length 10h implies 16 byte content with version info
362 # XXX - some of the below may only appear in little-endian form.
364 # Also "MV93" appears to be for one form of Macromedia Director
365 # files, and "GDMF" appears to be another multimedia format.
367 0 string RIFX RIFF (big-endian) data
368 # RIFF Palette format
369 >8 string PAL \b, palette
370 >>16 beshort x \b, version %d
371 >>18 beshort x \b, %d entries
372 # RIFF Device Independent Bitmap format
373 >8 string RDIB \b, device-independent bitmap
375 >>>30 beshort 12 \b, OS/2 1.x format
376 >>>>34 beshort x \b, %d x
378 >>>30 beshort 64 \b, OS/2 2.x format
379 >>>>34 beshort x \b, %d x
381 >>>30 beshort 40 \b, Windows 3.x format
382 >>>>34 belong x \b, %d x
386 >8 string RMID \b, MIDI
387 # RIFF Multimedia Movie File format
388 >8 string RMMP \b, multimedia movie
389 # Microsoft WAVE format (*.wav)
390 >8 string WAVE \b, WAVE audio
391 >>20 leshort 1 \b, Microsoft PCM
392 >>>34 leshort >0 \b, %d bit
393 >>22 beshort =1 \b, mono
394 >>22 beshort =2 \b, stereo
395 >>22 beshort >2 \b, %d channels
397 # Corel Draw Picture big endian not tested by real examples
398 #>8 string CDRA \b, Corel Draw Picture
399 #>8 string CDR6 \b, Corel Draw Picture, version 6
403 # AVI == Audio Video Interleave
404 >8 string AVI\040 \b, AVI
405 # Animated Cursor format
406 >8 string ACON \b, animated cursor
407 # Notation Interchange File Format (big-endian only)
408 >8 string NIFF \b, Notation Interchange File Format
409 # SoundFont 2 <mpruett@sgi.com>
410 >8 string sfbk SoundFont/Bank
412 #------------------------------------------------------------------------------
414 # see http://www.vcs.de/fileadmin/user_upload/MBS/PDF/Whitepaper/Informations_about_Sony_Wave64.pdf
415 # 128 bit RIFF-GUID { 66666972-912E-11CF-A5D6-28DB04C10000 } in little-endian
416 0 string riff\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00 Sony Wave64 RIFF data
417 # 128 bit + total file size (64 bits) so 24 bytes
418 # then WAVE-GUID { 65766177-ACF3-11D3-8CD1-00C04F8EDB8A }
419 >24 string wave\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A \b, WAVE 64 audio
421 # FMT-GUID { 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A }
422 >>40 search/256 fmt\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A \b
423 >>>&10 leshort =1 \b, mono
424 >>>&10 leshort =2 \b, stereo
425 >>>&10 leshort >2 \b, %d channels
426 >>>&12 lelong >0 %d Hz
428 #------------------------------------------------------------------------------
430 # see EBU TECH 3306 https://tech.ebu.ch/docs/tech/tech3306-2009.pdf
431 0 string RF64\xff\xff\xff\xffWAVEds64 MBWF/RF64 audio
433 >40 search/256 fmt\x20 \b
434 >>&6 leshort =1 \b, mono
435 >>&6 leshort =2 \b, stereo
436 >>&6 leshort >2 \b, %d channels