xref: /freebsd/contrib/file/magic/Magdir/riff (revision 4db78cacdee1b6f3b7880eb8c5560e8edaf91698)
1
2#------------------------------------------------------------------------------
3# $File: riff,v 1.33 2017/10/06 01:11:24 christos Exp $
4# riff:  file(1) magic for RIFF format
5# See
6#
7#	http://www.seanet.com/users/matts/riffmci/riffmci.htm
8#	http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
9#
10
11# audio format tag. Assume limits: max 1024 bit, 128 channels, 1 MHz
120   name    riff-wave
13>0	leshort		1		\b, Microsoft PCM
14>>14	leshort		>0
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
29>2	leshort		>2
30>>2	leshort		<128	\b, %d channels
31>4	lelong		>0
32>>4	lelong		<1000000	%d Hz
33
34# try to find "fmt "
350   name    riff-walk
36>0  string  fmt\x20
37>>4 lelong  <0x80
38>>>8 use    riff-wave
39>0  string  LIST
40>>&(4.l+4)  use riff-walk
41>0  string  DISP
42>>&(4.l+4)  use riff-walk
43>0  string  bext
44>>&(4.l+4)  use riff-walk
45>0  string  Fake
46>>&(4.l+4)  use riff-walk
47>0  string  fact
48>>&(4.l+4)  use riff-walk
49>0  string  VP8
50>>11		byte		0x9d
51>>>12		byte		0x01
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
69
70# AVI section extended by Patrik Radman <patrik+file-magic@iki.fi>
71#
720	string		RIFF		RIFF (little-endian) data
73# RIFF Palette format
74# Update: Joerg Jenderek
75# URL: https://en.wikipedia.org/wiki/Resource_Interchange_File_Format
76# Reference: http://worms2d.info/Palette_file
77>8	string		PAL\ 		\b, palette
78!:mime	application/x-riff
79# color palette by Microsoft Corporation
80!:ext	pal
81# file size =  chunk size + 8 in most cases
82>>4	ulelong+8	x		\b, %u bytes
83# Extended PAL Format
84>>12	string		plth		\b, extended
85# Simple PAL Format
86>>12	string		data
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
94>>>(22.s*4)	ubequad	x
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
101>>16	string		BM
102>>>30	leshort		12		\b, OS/2 1.x format
103>>>>34	leshort		x		\b, %d x
104>>>>36	leshort		x		%d
105>>>30	leshort		64		\b, OS/2 2.x format
106>>>>34	leshort		x		\b, %d x
107>>>>36	leshort		x		%d
108>>>30	leshort		40		\b, Windows 3.x format
109>>>>34	lelong		x		\b, %d x
110>>>>38	lelong		x		%d x
111>>>>44	leshort		x		%d
112# RIFF MIDI format
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
120!:mime	audio/x-wav
121>>12    string  >\0
122>>>12   use     riff-walk
123# Corel Draw Picture
124>8	string		CDRA		\b, Corel Draw Picture
125!:mime	image/x-coreldraw
126>8	string		CDR6		\b, Corel Draw Picture, version 6
127!:mime	image/x-coreldraw
128>8	string		NUNDROOT	\b, Steinberg CuBase
129# AVI == Audio Video Interleave
130>8	string		AVI\040		\b, AVI
131!:mime	video/x-msvideo
132>>12    string          LIST
133>>>20   string          hdrlavih
134>>>>&36 lelong          x               \b, %u x
135>>>>&40 lelong          x               %u,
136>>>>&4  lelong          >1000000        <1 fps,
137>>>>&4  lelong          1000000         1.00 fps,
138>>>>&4  lelong          500000          2.00 fps,
139>>>>&4  lelong          333333          3.00 fps,
140>>>>&4  lelong          250000          4.00 fps,
141>>>>&4  lelong          200000          5.00 fps,
142>>>>&4  lelong          166667          6.00 fps,
143>>>>&4  lelong          142857          7.00 fps,
144>>>>&4  lelong          125000          8.00 fps,
145>>>>&4  lelong          111111          9.00 fps,
146>>>>&4  lelong          100000          10.00 fps,
147# ]9.9,10.1[
148>>>>&4  lelong          <101010
149>>>>>&-4        lelong  >99010
150>>>>>>&-4       lelong  !100000         ~10 fps,
151>>>>&4  lelong          83333           12.00 fps,
152# ]11.9,12.1[
153>>>>&4  lelong          <84034
154>>>>>&-4        lelong  >82645
155>>>>>>&-4       lelong  !83333          ~12 fps,
156>>>>&4  lelong          66667           15.00 fps,
157# ]14.9,15.1[
158>>>>&4  lelong          <67114
159>>>>>&-4        lelong  >66225
160>>>>>>&-4       lelong  !66667          ~15 fps,
161>>>>&4  lelong          50000           20.00 fps,
162>>>>&4  lelong          41708           23.98 fps,
163>>>>&4  lelong          41667           24.00 fps,
164# ]23.9,24.1[
165>>>>&4  lelong          <41841
166>>>>>&-4        lelong  >41494
167>>>>>>&-4       lelong  !41708
168>>>>>>>&-4      lelong  !41667          ~24 fps,
169>>>>&4  lelong          40000           25.00 fps,
170# ]24.9,25.1[
171>>>>&4  lelong          <40161
172>>>>>&-4        lelong  >39841
173>>>>>>&-4       lelong  !40000          ~25 fps,
174>>>>&4  lelong          33367           29.97 fps,
175>>>>&4  lelong          33333           30.00 fps,
176# ]29.9,30.1[
177>>>>&4  lelong          <33445
178>>>>>&-4        lelong  >33223
179>>>>>>&-4       lelong  !33367
180>>>>>>>&-4      lelong  !33333          ~30 fps,
181>>>>&4  lelong          <32224          >30 fps,
182##>>>>&4  lelong          x               (%lu)
183##>>>>&20 lelong          x               %lu frames,
184# Note: The tests below assume that the AVI has 1 or 2 streams,
185#       "vids" optionally followed by "auds".
186#       (Should cover 99.9% of all AVIs.)
187# assuming avih length = 56
188>>>88   string  LIST
189>>>>96  string  strlstrh
190>>>>>108        string  vids    video:
191>>>>>>&0        lelong  0               uncompressed
192# skip past vids strh
193>>>>>>(104.l+108)       string  strf
194>>>>>>>(104.l+132)      lelong          1       RLE 8bpp
195>>>>>>>(104.l+132)      string/c        cvid    Cinepak
196>>>>>>>(104.l+132)      string/c        i263    Intel I.263
197>>>>>>>(104.l+132)      string/c        iv32    Indeo 3.2
198>>>>>>>(104.l+132)      string/c        iv41    Indeo 4.1
199>>>>>>>(104.l+132)      string/c        iv50    Indeo 5.0
200>>>>>>>(104.l+132)      string/c        mp42    Microsoft MPEG-4 v2
201>>>>>>>(104.l+132)      string/c        mp43    Microsoft MPEG-4 v3
202>>>>>>>(104.l+132)      string/c        fmp4    FFMpeg MPEG-4
203>>>>>>>(104.l+132)      string/c        mjpg    Motion JPEG
204>>>>>>>(104.l+132)      string/c        div3    DivX 3
205>>>>>>>>112             string/c        div3    Low-Motion
206>>>>>>>>112             string/c        div4    Fast-Motion
207>>>>>>>(104.l+132)      string/c        divx    DivX 4
208>>>>>>>(104.l+132)      string/c        dx50    DivX 5
209>>>>>>>(104.l+132)      string/c        xvid    XviD
210>>>>>>>(104.l+132)	string/c	h264	H.264
211>>>>>>>(104.l+132)      string/c        wmv3    Windows Media Video 9
212>>>>>>>(104.l+132)      string/c        h264    X.264 or H.264
213>>>>>>>(104.l+132)      lelong  0
214##>>>>>>>(104.l+132)      string  x       (%.4s)
215# skip past first (video) LIST
216>>>>(92.l+96)   string  LIST
217>>>>>(92.l+104) string  strlstrh
218>>>>>>(92.l+116)        string          auds    \b, audio:
219# auds strh length = 56:
220>>>>>>>(92.l+172)       string          strf
221>>>>>>>>(92.l+180)      leshort 0x0001  uncompressed PCM
222>>>>>>>>(92.l+180)      leshort 0x0002  ADPCM
223>>>>>>>>(92.l+180)      leshort 0x0006  aLaw
224>>>>>>>>(92.l+180)      leshort 0x0007  uLaw
225>>>>>>>>(92.l+180)      leshort 0x0050  MPEG-1 Layer 1 or 2
226>>>>>>>>(92.l+180)      leshort 0x0055  MPEG-1 Layer 3
227>>>>>>>>(92.l+180)      leshort 0x2000  Dolby AC3
228>>>>>>>>(92.l+180)      leshort 0x0161  DivX
229##>>>>>>>>(92.l+180)      leshort x       (0x%.4x)
230>>>>>>>>(92.l+182)      leshort 1       (mono,
231>>>>>>>>(92.l+182)      leshort 2       (stereo,
232>>>>>>>>(92.l+182)      leshort >2      (%d channels,
233>>>>>>>>(92.l+184)      lelong  x       %d Hz)
234# auds strh length = 64:
235>>>>>>>(92.l+180)       string          strf
236>>>>>>>>(92.l+188)      leshort 0x0001  uncompressed PCM
237>>>>>>>>(92.l+188)      leshort 0x0002  ADPCM
238>>>>>>>>(92.l+188)      leshort 0x0055  MPEG-1 Layer 3
239>>>>>>>>(92.l+188)      leshort 0x2000  Dolby AC3
240>>>>>>>>(92.l+188)      leshort 0x0161  DivX
241##>>>>>>>>(92.l+188)      leshort x       (0x%.4x)
242>>>>>>>>(92.l+190)      leshort 1       (mono,
243>>>>>>>>(92.l+190)      leshort 2       (stereo,
244>>>>>>>>(92.l+190)      leshort >2      (%d channels,
245>>>>>>>>(92.l+192)      lelong  x       %d Hz)
246# Animated Cursor format
247>8	string		ACON		\b, animated cursor
248# SoundFont 2 <mpruett@sgi.com>
249>8	string		sfbk		SoundFont/Bank
250# MPEG-1 wrapped in a RIFF, apparently
251>8      string          CDXA            \b, wrapped MPEG-1 (CDXA)
252>8	string		4XMV		\b, 4X Movie file
253# AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV
254>8	string		AMV\040		\b, AMV
255>8      string          WEBP            \b, Web/P image
256!:mime	image/webp
257>>12	use		riff-walk
258
259#
260# XXX - some of the below may only appear in little-endian form.
261#
262# Also "MV93" appears to be for one form of Macromedia Director
263# files, and "GDMF" appears to be another multimedia format.
264#
2650	string		RIFX		RIFF (big-endian) data
266# RIFF Palette format
267>8	string		PAL		\b, palette
268>>16	beshort		x		\b, version %d
269>>18	beshort		x		\b, %d entries
270# RIFF Device Independent Bitmap format
271>8	string		RDIB		\b, device-independent bitmap
272>>16	string		BM
273>>>30	beshort		12		\b, OS/2 1.x format
274>>>>34	beshort		x		\b, %d x
275>>>>36	beshort		x		%d
276>>>30	beshort		64		\b, OS/2 2.x format
277>>>>34	beshort		x		\b, %d x
278>>>>36	beshort		x		%d
279>>>30	beshort		40		\b, Windows 3.x format
280>>>>34	belong		x		\b, %d x
281>>>>38	belong		x		%d x
282>>>>44	beshort		x		%d
283# RIFF MIDI format
284>8	string		RMID		\b, MIDI
285# RIFF Multimedia Movie File format
286>8	string		RMMP		\b, multimedia movie
287# Microsoft WAVE format (*.wav)
288>8	string		WAVE		\b, WAVE audio
289>>20	leshort		1		\b, Microsoft PCM
290>>>34	leshort		>0		\b, %d bit
291>>22	beshort		=1		\b, mono
292>>22	beshort		=2		\b, stereo
293>>22	beshort		>2		\b, %d channels
294>>24	belong		>0		%d Hz
295# Corel Draw Picture
296>8	string		CDRA		\b, Corel Draw Picture
297>8	string		CDR6		\b, Corel Draw Picture, version 6
298# AVI == Audio Video Interleave
299>8	string		AVI\040		\b, AVI
300# Animated Cursor format
301>8	string		ACON		\b, animated cursor
302# Notation Interchange File Format (big-endian only)
303>8	string		NIFF		\b, Notation Interchange File Format
304# SoundFont 2 <mpruett@sgi.com>
305>8	string		sfbk		SoundFont/Bank
306
307#------------------------------------------------------------------------------
308# Sony Wave64
309# see http://www.vcs.de/fileadmin/user_upload/MBS/PDF/Whitepaper/Informations_about_Sony_Wave64.pdf
310# 128 bit RIFF-GUID { 66666972-912E-11CF-A5D6-28DB04C10000 } in little-endian
3110	string	riff\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00		Sony Wave64 RIFF data
312# 128 bit + total file size (64 bits) so 24 bytes
313# then WAVE-GUID { 65766177-ACF3-11D3-8CD1-00C04F8EDB8A }
314>24	string		wave\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A		\b, WAVE 64 audio
315!:mime	audio/x-w64
316# FMT-GUID { 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A }
317>>40	search/256	fmt\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A		\b
318>>>&10	leshort		=1		\b, mono
319>>>&10	leshort		=2		\b, stereo
320>>>&10	leshort		>2		\b, %d channels
321>>>&12	lelong		>0		%d Hz
322
323#------------------------------------------------------------------------------
324# MBWF/RF64
325# see EBU TECH 3306 http://tech.ebu.ch/docs/tech/tech3306-2009.pdf
3260	string	RF64\xff\xff\xff\xffWAVEds64		MBWF/RF64 audio
327!:mime	audio/x-wav
328>40	search/256	fmt\x20		\b
329>>&6	leshort		=1		\b, mono
330>>&6	leshort		=2		\b, stereo
331>>&6	leshort		>2		\b, %d channels
332>>&8	lelong		>0		%d Hz
333