riff 16 KB

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