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