2 #------------------------------------------------------------------------------
3 # $File: riff,v 1.30 2014/09/23 17:02:12 christos Exp $
4 # riff: file(1) magic for RIFF format
7 # http://www.seanet.com/users/matts/riffmci/riffmci.htm
10 # audio format tag. Assume limits: max 1024 bit, 128 channels, 1 MHz
12 >0 leshort 1 \b, Microsoft PCM
14 >>>14 leshort <1024 \b, %d bit
15 >0 leshort 2 \b, Microsoft ADPCM
16 >0 leshort 6 \b, ITU G.711 A-law
17 >0 leshort 7 \b, ITU G.711 mu-law
18 >0 leshort 8 \b, Microsoft DTS
19 >0 leshort 17 \b, IMA ADPCM
20 >0 leshort 20 \b, ITU G.723 ADPCM (Yamaha)
21 >0 leshort 49 \b, GSM 6.10
22 >0 leshort 64 \b, ITU G.721 ADPCM
23 >0 leshort 80 \b, MPEG
24 >0 leshort 85 \b, MPEG Layer 3
25 >0 leshort 0x2001 \b, DTS
26 >2 leshort =1 \b, mono
27 >2 leshort =2 \b, stereo
29 >>2 leshort <128 \b, %d channels
31 >>4 lelong <1000000 %d Hz
39 >>&(4.l+4) use riff-walk
41 >>&(4.l+4) use riff-walk
43 >>&(4.l+4) use riff-walk
45 >>&(4.l+4) use riff-walk
47 >>&(4.l+4) use riff-walk
51 >>>>13 byte 0x2a \b, VP8 encoding
52 >>>>>14 leshort&0x3fff x \b, %d
53 >>>>>16 leshort&0x3fff x \bx%d, Scaling:
54 >>>>>14 leshort&0xc000 0x0000 \b [none]
55 >>>>>14 leshort&0xc000 0x1000 \b [5/4]
56 >>>>>14 leshort&0xc000 0x2000 \b [5/3]
57 >>>>>14 leshort&0xc000 0x3000 \b [2]
58 >>>>>14 leshort&0xc000 0x0000 \bx[none]
59 >>>>>14 leshort&0xc000 0x1000 \bx[5/4]
60 >>>>>14 leshort&0xc000 0x2000 \bx[5/3]
61 >>>>>14 leshort&0xc000 0x3000 \bx[2]
62 >>>>>15 byte&0x80 =0x00 \b, YUV color
63 >>>>>15 byte&0x80 =0x80 \b, bad color specification
64 >>>>>15 byte&0x40 =0x40 \b, no clamping required
65 >>>>>15 byte&0x40 =0x00 \b, decoders should clamp
66 #>0 string x we got %s
67 #>>&(4.l+4) use riff-walk
69 # AVI section extended by Patrik Radman <patrik+file-magic@iki.fi>
71 0 string RIFF RIFF (little-endian) data
73 >8 string PAL \b, palette
74 >>16 leshort x \b, version %d
75 >>18 leshort x \b, %d entries
76 # RIFF Device Independent Bitmap format
77 >8 string RDIB \b, device-independent bitmap
79 >>>30 leshort 12 \b, OS/2 1.x format
80 >>>>34 leshort x \b, %d x
82 >>>30 leshort 64 \b, OS/2 2.x format
83 >>>>34 leshort x \b, %d x
85 >>>30 leshort 40 \b, Windows 3.x format
86 >>>>34 lelong x \b, %d x
90 >8 string RMID \b, MIDI
91 # RIFF Multimedia Movie File format
92 >8 string RMMP \b, multimedia movie
93 # RIFF wrapper for MP3
94 >8 string RMP3 \b, MPEG Layer 3 audio
95 # Microsoft WAVE format (*.wav)
96 >8 string WAVE \b, WAVE audio
101 >8 string CDRA \b, Corel Draw Picture
102 !:mime image/x-coreldraw
103 >8 string CDR6 \b, Corel Draw Picture, version 6
104 !:mime image/x-coreldraw
105 >8 string NUNDROOT \b, Steinberg CuBase
106 # AVI == Audio Video Interleave
107 >8 string AVI\040 \b, AVI
108 !:mime video/x-msvideo
110 >>>20 string hdrlavih
111 >>>>&36 lelong x \b, %u x
113 >>>>&4 lelong >1000000 <1 fps,
114 >>>>&4 lelong 1000000 1.00 fps,
115 >>>>&4 lelong 500000 2.00 fps,
116 >>>>&4 lelong 333333 3.00 fps,
117 >>>>&4 lelong 250000 4.00 fps,
118 >>>>&4 lelong 200000 5.00 fps,
119 >>>>&4 lelong 166667 6.00 fps,
120 >>>>&4 lelong 142857 7.00 fps,
121 >>>>&4 lelong 125000 8.00 fps,
122 >>>>&4 lelong 111111 9.00 fps,
123 >>>>&4 lelong 100000 10.00 fps,
125 >>>>&4 lelong <101010
126 >>>>>&-4 lelong >99010
127 >>>>>>&-4 lelong !100000 ~10 fps,
128 >>>>&4 lelong 83333 12.00 fps,
131 >>>>>&-4 lelong >82645
132 >>>>>>&-4 lelong !83333 ~12 fps,
133 >>>>&4 lelong 66667 15.00 fps,
136 >>>>>&-4 lelong >66225
137 >>>>>>&-4 lelong !66667 ~15 fps,
138 >>>>&4 lelong 50000 20.00 fps,
139 >>>>&4 lelong 41708 23.98 fps,
140 >>>>&4 lelong 41667 24.00 fps,
143 >>>>>&-4 lelong >41494
144 >>>>>>&-4 lelong !41708
145 >>>>>>>&-4 lelong !41667 ~24 fps,
146 >>>>&4 lelong 40000 25.00 fps,
149 >>>>>&-4 lelong >39841
150 >>>>>>&-4 lelong !40000 ~25 fps,
151 >>>>&4 lelong 33367 29.97 fps,
152 >>>>&4 lelong 33333 30.00 fps,
155 >>>>>&-4 lelong >33223
156 >>>>>>&-4 lelong !33367
157 >>>>>>>&-4 lelong !33333 ~30 fps,
158 >>>>&4 lelong <32224 >30 fps,
159 ##>>>>&4 lelong x (%lu)
160 ##>>>>&20 lelong x %lu frames,
161 # Note: The tests below assume that the AVI has 1 or 2 streams,
162 # "vids" optionally followed by "auds".
163 # (Should cover 99.9% of all AVIs.)
164 # assuming avih length = 56
166 >>>>96 string strlstrh
167 >>>>>108 string vids video:
168 >>>>>>&0 lelong 0 uncompressed
169 # skip past vids strh
170 >>>>>>(104.l+108) string strf
171 >>>>>>>(104.l+132) lelong 1 RLE 8bpp
172 >>>>>>>(104.l+132) string/c cvid Cinepak
173 >>>>>>>(104.l+132) string/c i263 Intel I.263
174 >>>>>>>(104.l+132) string/c iv32 Indeo 3.2
175 >>>>>>>(104.l+132) string/c iv41 Indeo 4.1
176 >>>>>>>(104.l+132) string/c iv50 Indeo 5.0
177 >>>>>>>(104.l+132) string/c mp42 Microsoft MPEG-4 v2
178 >>>>>>>(104.l+132) string/c mp43 Microsoft MPEG-4 v3
179 >>>>>>>(104.l+132) string/c fmp4 FFMpeg MPEG-4
180 >>>>>>>(104.l+132) string/c mjpg Motion JPEG
181 >>>>>>>(104.l+132) string/c div3 DivX 3
182 >>>>>>>>112 string/c div3 Low-Motion
183 >>>>>>>>112 string/c div4 Fast-Motion
184 >>>>>>>(104.l+132) string/c divx DivX 4
185 >>>>>>>(104.l+132) string/c dx50 DivX 5
186 >>>>>>>(104.l+132) string/c xvid XviD
187 >>>>>>>(104.l+132) string/c h264 H.264
188 >>>>>>>(104.l+132) string/c wmv3 Windows Media Video 9
189 >>>>>>>(104.l+132) string/c h264 X.264 or H.264
190 >>>>>>>(104.l+132) lelong 0
191 ##>>>>>>>(104.l+132) string x (%.4s)
192 # skip past first (video) LIST
193 >>>>(92.l+96) string LIST
194 >>>>>(92.l+104) string strlstrh
195 >>>>>>(92.l+116) string auds \b, audio:
196 # auds strh length = 56:
197 >>>>>>>(92.l+172) string strf
198 >>>>>>>>(92.l+180) leshort 0x0001 uncompressed PCM
199 >>>>>>>>(92.l+180) leshort 0x0002 ADPCM
200 >>>>>>>>(92.l+180) leshort 0x0006 aLaw
201 >>>>>>>>(92.l+180) leshort 0x0007 uLaw
202 >>>>>>>>(92.l+180) leshort 0x0050 MPEG-1 Layer 1 or 2
203 >>>>>>>>(92.l+180) leshort 0x0055 MPEG-1 Layer 3
204 >>>>>>>>(92.l+180) leshort 0x2000 Dolby AC3
205 >>>>>>>>(92.l+180) leshort 0x0161 DivX
206 ##>>>>>>>>(92.l+180) leshort x (0x%.4x)
207 >>>>>>>>(92.l+182) leshort 1 (mono,
208 >>>>>>>>(92.l+182) leshort 2 (stereo,
209 >>>>>>>>(92.l+182) leshort >2 (%d channels,
210 >>>>>>>>(92.l+184) lelong x %d Hz)
211 # auds strh length = 64:
212 >>>>>>>(92.l+180) string strf
213 >>>>>>>>(92.l+188) leshort 0x0001 uncompressed PCM
214 >>>>>>>>(92.l+188) leshort 0x0002 ADPCM
215 >>>>>>>>(92.l+188) leshort 0x0055 MPEG-1 Layer 3
216 >>>>>>>>(92.l+188) leshort 0x2000 Dolby AC3
217 >>>>>>>>(92.l+188) leshort 0x0161 DivX
218 ##>>>>>>>>(92.l+188) leshort x (0x%.4x)
219 >>>>>>>>(92.l+190) leshort 1 (mono,
220 >>>>>>>>(92.l+190) leshort 2 (stereo,
221 >>>>>>>>(92.l+190) leshort >2 (%d channels,
222 >>>>>>>>(92.l+192) lelong x %d Hz)
223 # Animated Cursor format
224 >8 string ACON \b, animated cursor
225 # SoundFont 2 <mpruett@sgi.com>
226 >8 string sfbk SoundFont/Bank
227 # MPEG-1 wrapped in a RIFF, apparently
228 >8 string CDXA \b, wrapped MPEG-1 (CDXA)
229 >8 string 4XMV \b, 4X Movie file
230 # AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV
231 >8 string AMV\040 \b, AMV
232 >8 string WEBP \b, Web/P image
236 # XXX - some of the below may only appear in little-endian form.
238 # Also "MV93" appears to be for one form of Macromedia Director
239 # files, and "GDMF" appears to be another multimedia format.
241 0 string RIFX RIFF (big-endian) data
242 # RIFF Palette format
243 >8 string PAL \b, palette
244 >>16 beshort x \b, version %d
245 >>18 beshort x \b, %d entries
246 # RIFF Device Independent Bitmap format
247 >8 string RDIB \b, device-independent bitmap
249 >>>30 beshort 12 \b, OS/2 1.x format
250 >>>>34 beshort x \b, %d x
252 >>>30 beshort 64 \b, OS/2 2.x format
253 >>>>34 beshort x \b, %d x
255 >>>30 beshort 40 \b, Windows 3.x format
256 >>>>34 belong x \b, %d x
260 >8 string RMID \b, MIDI
261 # RIFF Multimedia Movie File format
262 >8 string RMMP \b, multimedia movie
263 # Microsoft WAVE format (*.wav)
264 >8 string WAVE \b, WAVE audio
265 >>20 leshort 1 \b, Microsoft PCM
266 >>>34 leshort >0 \b, %d bit
267 >>22 beshort =1 \b, mono
268 >>22 beshort =2 \b, stereo
269 >>22 beshort >2 \b, %d channels
272 >8 string CDRA \b, Corel Draw Picture
273 >8 string CDR6 \b, Corel Draw Picture, version 6
274 # AVI == Audio Video Interleave
275 >8 string AVI\040 \b, AVI
276 # Animated Cursor format
277 >8 string ACON \b, animated cursor
278 # Notation Interchange File Format (big-endian only)
279 >8 string NIFF \b, Notation Interchange File Format
280 # SoundFont 2 <mpruett@sgi.com>
281 >8 string sfbk SoundFont/Bank
283 #------------------------------------------------------------------------------
285 # see http://www.vcs.de/fileadmin/user_upload/MBS/PDF/Whitepaper/Informations_about_Sony_Wave64.pdf
286 # 128 bit RIFF-GUID { 66666972-912E-11CF-A5D6-28DB04C10000 } in little-endian
287 0 string riff\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00 Sony Wave64 RIFF data
288 # 128 bit + total file size (64 bits) so 24 bytes
289 # then WAVE-GUID { 65766177-ACF3-11D3-8CD1-00C04F8EDB8A }
290 >24 string wave\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A \b, WAVE 64 audio
292 # FMT-GUID { 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A }
293 >>40 search/256 fmt\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A \b
294 >>>&10 leshort =1 \b, mono
295 >>>&10 leshort =2 \b, stereo
296 >>>&10 leshort >2 \b, %d channels
297 >>>&12 lelong >0 %d Hz
299 #------------------------------------------------------------------------------
301 # see EBU TECH 3306 http://tech.ebu.ch/docs/tech/tech3306-2009.pdf
302 0 string RF64\xff\xff\xff\xffWAVEds64 MBWF/RF64 audio
304 >40 search/256 fmt\x20 \b
305 >>&6 leshort =1 \b, mono
306 >>&6 leshort =2 \b, stereo
307 >>&6 leshort >2 \b, %d channels