riff 10 KB

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