riff 11 KB

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