riff 12 KB

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