module.audio-video.riff.php 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. // also https://github.com/JamesHeinrich/getID3 //
  7. /////////////////////////////////////////////////////////////////
  8. // See readme.txt for more details //
  9. /////////////////////////////////////////////////////////////////
  10. // //
  11. // module.audio-video.riff.php //
  12. // module for analyzing RIFF files //
  13. // multiple formats supported by this module: //
  14. // Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX //
  15. // dependencies: module.audio.mp3.php //
  16. // module.audio.ac3.php //
  17. // module.audio.dts.php //
  18. // ///
  19. /////////////////////////////////////////////////////////////////
  20. /**
  21. * @todo Parse AC-3/DTS audio inside WAVE correctly
  22. * @todo Rewrite RIFF parser totally
  23. */
  24. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  25. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true);
  26. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true);
  27. class getid3_riff extends getid3_handler {
  28. protected $container = 'riff'; // default
  29. public function Analyze() {
  30. $info = &$this->getid3->info;
  31. // initialize these values to an empty array, otherwise they default to NULL
  32. // and you can't append array values to a NULL value
  33. $info['riff'] = array('raw'=>array());
  34. // Shortcuts
  35. $thisfile_riff = &$info['riff'];
  36. $thisfile_riff_raw = &$thisfile_riff['raw'];
  37. $thisfile_audio = &$info['audio'];
  38. $thisfile_video = &$info['video'];
  39. $thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
  40. $thisfile_riff_audio = &$thisfile_riff['audio'];
  41. $thisfile_riff_video = &$thisfile_riff['video'];
  42. $Original['avdataoffset'] = $info['avdataoffset'];
  43. $Original['avdataend'] = $info['avdataend'];
  44. $this->fseek($info['avdataoffset']);
  45. $RIFFheader = $this->fread(12);
  46. $offset = $this->ftell();
  47. $RIFFtype = substr($RIFFheader, 0, 4);
  48. $RIFFsize = substr($RIFFheader, 4, 4);
  49. $RIFFsubtype = substr($RIFFheader, 8, 4);
  50. switch ($RIFFtype) {
  51. case 'FORM': // AIFF, AIFC
  52. //$info['fileformat'] = 'aiff';
  53. $this->container = 'aiff';
  54. $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
  55. $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
  56. break;
  57. case 'RIFF': // AVI, WAV, etc
  58. case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
  59. case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
  60. //$info['fileformat'] = 'riff';
  61. $this->container = 'riff';
  62. $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
  63. if ($RIFFsubtype == 'RMP3') {
  64. // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
  65. $RIFFsubtype = 'WAVE';
  66. }
  67. if ($RIFFsubtype != 'AMV ') {
  68. // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
  69. // Handled separately in ParseRIFFAMV()
  70. $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
  71. }
  72. if (($info['avdataend'] - $info['filesize']) == 1) {
  73. // LiteWave appears to incorrectly *not* pad actual output file
  74. // to nearest WORD boundary so may appear to be short by one
  75. // byte, in which case - skip warning
  76. $info['avdataend'] = $info['filesize'];
  77. }
  78. $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset
  79. while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) {
  80. try {
  81. $this->fseek($nextRIFFoffset);
  82. } catch (getid3_exception $e) {
  83. if ($e->getCode() == 10) {
  84. //$this->warning('RIFF parser: '.$e->getMessage());
  85. $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong');
  86. $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present');
  87. break;
  88. } else {
  89. throw $e;
  90. }
  91. }
  92. $nextRIFFheader = $this->fread(12);
  93. if ($nextRIFFoffset == ($info['avdataend'] - 1)) {
  94. if (substr($nextRIFFheader, 0, 1) == "\x00") {
  95. // RIFF padded to WORD boundary, we're actually already at the end
  96. break;
  97. }
  98. }
  99. $nextRIFFheaderID = substr($nextRIFFheader, 0, 4);
  100. $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4));
  101. $nextRIFFtype = substr($nextRIFFheader, 8, 4);
  102. $chunkdata = array();
  103. $chunkdata['offset'] = $nextRIFFoffset + 8;
  104. $chunkdata['size'] = $nextRIFFsize;
  105. $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size'];
  106. switch ($nextRIFFheaderID) {
  107. case 'RIFF':
  108. $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset);
  109. if (!isset($thisfile_riff[$nextRIFFtype])) {
  110. $thisfile_riff[$nextRIFFtype] = array();
  111. }
  112. $thisfile_riff[$nextRIFFtype][] = $chunkdata;
  113. break;
  114. case 'AMV ':
  115. unset($info['riff']);
  116. $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset);
  117. break;
  118. case 'JUNK':
  119. // ignore
  120. $thisfile_riff[$nextRIFFheaderID][] = $chunkdata;
  121. break;
  122. case 'IDVX':
  123. $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size']));
  124. break;
  125. default:
  126. if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) {
  127. $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12);
  128. if (substr($DIVXTAG, -7) == 'DIVXTAG') {
  129. // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file
  130. $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway');
  131. $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG);
  132. break 2;
  133. }
  134. }
  135. $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file');
  136. break 2;
  137. }
  138. }
  139. if ($RIFFsubtype == 'WAVE') {
  140. $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
  141. }
  142. break;
  143. default:
  144. $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead');
  145. //unset($info['fileformat']);
  146. return false;
  147. }
  148. $streamindex = 0;
  149. switch ($RIFFsubtype) {
  150. // http://en.wikipedia.org/wiki/Wav
  151. case 'WAVE':
  152. $info['fileformat'] = 'wav';
  153. if (empty($thisfile_audio['bitrate_mode'])) {
  154. $thisfile_audio['bitrate_mode'] = 'cbr';
  155. }
  156. if (empty($thisfile_audio_dataformat)) {
  157. $thisfile_audio_dataformat = 'wav';
  158. }
  159. if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
  160. $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
  161. $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size'];
  162. }
  163. if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
  164. $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
  165. $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
  166. if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
  167. $info['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
  168. return false;
  169. }
  170. $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
  171. unset($thisfile_riff_audio[$streamindex]['raw']);
  172. $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
  173. $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
  174. if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
  175. $info['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
  176. }
  177. $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
  178. if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV)
  179. $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
  180. }
  181. $thisfile_audio['lossless'] = false;
  182. if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
  183. switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
  184. case 0x0001: // PCM
  185. $thisfile_audio['lossless'] = true;
  186. break;
  187. case 0x2000: // AC-3
  188. $thisfile_audio_dataformat = 'ac3';
  189. break;
  190. default:
  191. // do nothing
  192. break;
  193. }
  194. }
  195. $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
  196. $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  197. $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
  198. $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
  199. }
  200. if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
  201. // shortcuts
  202. $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
  203. $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
  204. $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
  205. $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
  206. $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
  207. $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
  208. $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2));
  209. $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2));
  210. $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
  211. $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
  212. $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
  213. $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
  214. $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
  215. $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
  216. $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
  217. $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
  218. $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
  219. $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
  220. $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
  221. if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
  222. $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
  223. $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
  224. $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
  225. }
  226. if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
  227. $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
  228. $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
  229. $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
  230. }
  231. }
  232. if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
  233. $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
  234. // This should be a good way of calculating exact playtime,
  235. // but some sample files have had incorrect number of samples,
  236. // so cannot use this method
  237. // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
  238. // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
  239. // }
  240. }
  241. if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
  242. $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
  243. }
  244. if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
  245. // shortcut
  246. $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
  247. $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
  248. $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
  249. $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
  250. $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
  251. $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
  252. $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8));
  253. $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1));
  254. $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254);
  255. $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
  256. if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
  257. if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
  258. list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date;
  259. list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
  260. $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
  261. } else {
  262. $info['warning'][] = 'RIFF.WAVE.BEXT.origin_time is invalid';
  263. }
  264. } else {
  265. $info['warning'][] = 'RIFF.WAVE.BEXT.origin_date is invalid';
  266. }
  267. $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
  268. $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
  269. }
  270. if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
  271. // shortcut
  272. $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
  273. $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
  274. $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
  275. if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
  276. $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
  277. $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
  278. $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
  279. $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
  280. }
  281. $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
  282. $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
  283. $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
  284. $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
  285. $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
  286. }
  287. if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
  288. // shortcut
  289. $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
  290. $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
  291. $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
  292. $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
  293. $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
  294. $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
  295. $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
  296. $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
  297. $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
  298. $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
  299. $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
  300. $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
  301. $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
  302. $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
  303. $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
  304. $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
  305. $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true);
  306. for ($i = 0; $i < 8; $i++) {
  307. $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
  308. $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
  309. }
  310. $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
  311. $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
  312. $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
  313. $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
  314. }
  315. if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) {
  316. // SoundMiner metadata
  317. // shortcuts
  318. $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0];
  319. $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data'];
  320. $SNDM_startoffset = 0;
  321. $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size'];
  322. while ($SNDM_startoffset < $SNDM_endoffset) {
  323. $SNDM_thisTagOffset = 0;
  324. $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4));
  325. $SNDM_thisTagOffset += 4;
  326. $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4);
  327. $SNDM_thisTagOffset += 4;
  328. $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
  329. $SNDM_thisTagOffset += 2;
  330. $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
  331. $SNDM_thisTagOffset += 2;
  332. $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize);
  333. $SNDM_thisTagOffset += $SNDM_thisTagDataSize;
  334. if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
  335. $info['warning'][] = 'RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
  336. break;
  337. } elseif ($SNDM_thisTagSize <= 0) {
  338. $info['warning'][] = 'RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
  339. break;
  340. }
  341. $SNDM_startoffset += $SNDM_thisTagSize;
  342. $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText;
  343. if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) {
  344. $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
  345. } else {
  346. $info['warning'][] = 'RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
  347. }
  348. }
  349. $tagmapping = array(
  350. 'tracktitle'=>'title',
  351. 'category' =>'genre',
  352. 'cdtitle' =>'album',
  353. 'tracktitle'=>'title',
  354. );
  355. foreach ($tagmapping as $fromkey => $tokey) {
  356. if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) {
  357. $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey];
  358. }
  359. }
  360. }
  361. if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) {
  362. // requires functions simplexml_load_string and get_object_vars
  363. if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) {
  364. $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML;
  365. if (isset($parsedXML['SPEED']['MASTER_SPEED'])) {
  366. @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']);
  367. $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000);
  368. }
  369. if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) {
  370. @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']);
  371. $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000);
  372. }
  373. if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
  374. $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
  375. $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE'];
  376. $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600);
  377. $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60);
  378. $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60));
  379. $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate'];
  380. $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f);
  381. $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f));
  382. }
  383. unset($parsedXML);
  384. }
  385. }
  386. if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
  387. $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
  388. $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
  389. }
  390. if (!empty($info['wavpack'])) {
  391. $thisfile_audio_dataformat = 'wavpack';
  392. $thisfile_audio['bitrate_mode'] = 'vbr';
  393. $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version'];
  394. // Reset to the way it was - RIFF parsing will have messed this up
  395. $info['avdataend'] = $Original['avdataend'];
  396. $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  397. $this->fseek($info['avdataoffset'] - 44);
  398. $RIFFdata = $this->fread(44);
  399. $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
  400. $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
  401. if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
  402. $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
  403. $this->fseek($info['avdataend']);
  404. $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
  405. }
  406. // move the data chunk after all other chunks (if any)
  407. // so that the RIFF parser doesn't see EOF when trying
  408. // to skip over the data chunk
  409. $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
  410. $getid3_riff = new getid3_riff($this->getid3);
  411. $getid3_riff->ParseRIFFdata($RIFFdata);
  412. unset($getid3_riff);
  413. }
  414. if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
  415. switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
  416. case 0x0001: // PCM
  417. if (!empty($info['ac3'])) {
  418. // Dolby Digital WAV files masquerade as PCM-WAV, but they're not
  419. $thisfile_audio['wformattag'] = 0x2000;
  420. $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']);
  421. $thisfile_audio['lossless'] = false;
  422. $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
  423. $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate'];
  424. }
  425. if (!empty($info['dts'])) {
  426. // Dolby DTS files masquerade as PCM-WAV, but they're not
  427. $thisfile_audio['wformattag'] = 0x2001;
  428. $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']);
  429. $thisfile_audio['lossless'] = false;
  430. $thisfile_audio['bitrate'] = $info['dts']['bitrate'];
  431. $thisfile_audio['sample_rate'] = $info['dts']['sample_rate'];
  432. }
  433. break;
  434. case 0x08AE: // ClearJump LiteWave
  435. $thisfile_audio['bitrate_mode'] = 'vbr';
  436. $thisfile_audio_dataformat = 'litewave';
  437. //typedef struct tagSLwFormat {
  438. // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
  439. // DWORD m_dwScale; // scale factor for lossy compression
  440. // DWORD m_dwBlockSize; // number of samples in encoded blocks
  441. // WORD m_wQuality; // alias for the scale factor
  442. // WORD m_wMarkDistance; // distance between marks in bytes
  443. // WORD m_wReserved;
  444. //
  445. // //following paramters are ignored if CF_FILESRC is not set
  446. // DWORD m_dwOrgSize; // original file size in bytes
  447. // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
  448. // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
  449. //
  450. // PCMWAVEFORMAT m_OrgWf; // original wave format
  451. // }SLwFormat, *PSLwFormat;
  452. // shortcut
  453. $thisfile_riff['litewave']['raw'] = array();
  454. $riff_litewave = &$thisfile_riff['litewave'];
  455. $riff_litewave_raw = &$riff_litewave['raw'];
  456. $flags = array(
  457. 'compression_method' => 1,
  458. 'compression_flags' => 1,
  459. 'm_dwScale' => 4,
  460. 'm_dwBlockSize' => 4,
  461. 'm_wQuality' => 2,
  462. 'm_wMarkDistance' => 2,
  463. 'm_wReserved' => 2,
  464. 'm_dwOrgSize' => 4,
  465. 'm_bFactExists' => 2,
  466. 'm_dwRiffChunkSize' => 4,
  467. );
  468. $litewave_offset = 18;
  469. foreach ($flags as $flag => $length) {
  470. $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length));
  471. $litewave_offset += $length;
  472. }
  473. //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20));
  474. $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality'];
  475. $riff_litewave['flags']['raw_source'] = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
  476. $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
  477. $riff_litewave['flags']['seekpoints'] = (bool) ($riff_litewave_raw['compression_flags'] & 0x04);
  478. $thisfile_audio['lossless'] = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false);
  479. $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor'];
  480. break;
  481. default:
  482. break;
  483. }
  484. }
  485. if ($info['avdataend'] > $info['filesize']) {
  486. switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') {
  487. case 'wavpack': // WavPack
  488. case 'lpac': // LPAC
  489. case 'ofr': // OptimFROG
  490. case 'ofs': // OptimFROG DualStream
  491. // lossless compressed audio formats that keep original RIFF headers - skip warning
  492. break;
  493. case 'litewave':
  494. if (($info['avdataend'] - $info['filesize']) == 1) {
  495. // LiteWave appears to incorrectly *not* pad actual output file
  496. // to nearest WORD boundary so may appear to be short by one
  497. // byte, in which case - skip warning
  498. } else {
  499. // Short by more than one byte, throw warning
  500. $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
  501. $info['avdataend'] = $info['filesize'];
  502. }
  503. break;
  504. default:
  505. if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) {
  506. // output file appears to be incorrectly *not* padded to nearest WORD boundary
  507. // Output less severe warning
  508. $info['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
  509. $info['avdataend'] = $info['filesize'];
  510. } else {
  511. // Short by more than one byte, throw warning
  512. $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
  513. $info['avdataend'] = $info['filesize'];
  514. }
  515. break;
  516. }
  517. }
  518. if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) {
  519. if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
  520. $info['avdataend']--;
  521. $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
  522. }
  523. }
  524. if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) {
  525. unset($thisfile_audio['bits_per_sample']);
  526. if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
  527. $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
  528. }
  529. }
  530. break;
  531. // http://en.wikipedia.org/wiki/Audio_Video_Interleave
  532. case 'AVI ':
  533. $info['fileformat'] = 'avi';
  534. $info['mime_type'] = 'video/avi';
  535. $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
  536. $thisfile_video['dataformat'] = 'avi';
  537. if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
  538. $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
  539. if (isset($thisfile_riff['AVIX'])) {
  540. $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size'];
  541. } else {
  542. $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size'];
  543. }
  544. if ($info['avdataend'] > $info['filesize']) {
  545. $info['warning'][] = 'Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)';
  546. $info['avdataend'] = $info['filesize'];
  547. }
  548. }
  549. if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) {
  550. //$bIndexType = array(
  551. // 0x00 => 'AVI_INDEX_OF_INDEXES',
  552. // 0x01 => 'AVI_INDEX_OF_CHUNKS',
  553. // 0x80 => 'AVI_INDEX_IS_DATA',
  554. //);
  555. //$bIndexSubtype = array(
  556. // 0x01 => array(
  557. // 0x01 => 'AVI_INDEX_2FIELD',
  558. // ),
  559. //);
  560. foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) {
  561. $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data'];
  562. $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd, 0, 2));
  563. $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($ahsisd, 2, 1));
  564. $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($ahsisd, 3, 1));
  565. $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($ahsisd, 4, 4));
  566. $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($ahsisd, 8, 4);
  567. $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($ahsisd, 12, 4));
  568. //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']];
  569. //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']];
  570. unset($ahsisd);
  571. }
  572. }
  573. if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
  574. $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
  575. // shortcut
  576. $thisfile_riff_raw['avih'] = array();
  577. $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
  578. $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L)
  579. if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
  580. $info['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
  581. return false;
  582. }
  583. $flags = array(
  584. 'dwMaxBytesPerSec', // max. transfer rate
  585. 'dwPaddingGranularity', // pad to multiples of this size; normally 2K.
  586. 'dwFlags', // the ever-present flags
  587. 'dwTotalFrames', // # frames in file
  588. 'dwInitialFrames', //
  589. 'dwStreams', //
  590. 'dwSuggestedBufferSize', //
  591. 'dwWidth', //
  592. 'dwHeight', //
  593. 'dwScale', //
  594. 'dwRate', //
  595. 'dwStart', //
  596. 'dwLength', //
  597. );
  598. $avih_offset = 4;
  599. foreach ($flags as $flag) {
  600. $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4));
  601. $avih_offset += 4;
  602. }
  603. $flags = array(
  604. 'hasindex' => 0x00000010,
  605. 'mustuseindex' => 0x00000020,
  606. 'interleaved' => 0x00000100,
  607. 'trustcktype' => 0x00000800,
  608. 'capturedfile' => 0x00010000,
  609. 'copyrighted' => 0x00020010,
  610. );
  611. foreach ($flags as $flag => $value) {
  612. $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value);
  613. }
  614. // shortcut
  615. $thisfile_riff_video[$streamindex] = array();
  616. $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
  617. if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
  618. $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
  619. $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width'];
  620. }
  621. if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
  622. $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
  623. $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height'];
  624. }
  625. if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
  626. $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
  627. $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames'];
  628. }
  629. $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
  630. $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
  631. }
  632. if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
  633. if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
  634. for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
  635. if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
  636. $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
  637. $strhfccType = substr($strhData, 0, 4);
  638. if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
  639. $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
  640. // shortcut
  641. $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
  642. switch ($strhfccType) {
  643. case 'auds':
  644. $thisfile_audio['bitrate_mode'] = 'cbr';
  645. $thisfile_audio_dataformat = 'wav';
  646. if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
  647. $streamindex = count($thisfile_riff_audio);
  648. }
  649. $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData);
  650. $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
  651. // shortcut
  652. $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
  653. $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
  654. if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
  655. unset($thisfile_audio_streams_currentstream['bits_per_sample']);
  656. }
  657. $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
  658. unset($thisfile_audio_streams_currentstream['raw']);
  659. // shortcut
  660. $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
  661. unset($thisfile_riff_audio[$streamindex]['raw']);
  662. $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
  663. $thisfile_audio['lossless'] = false;
  664. switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
  665. case 0x0001: // PCM
  666. $thisfile_audio_dataformat = 'wav';
  667. $thisfile_audio['lossless'] = true;
  668. break;
  669. case 0x0050: // MPEG Layer 2 or Layer 1
  670. $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2
  671. break;
  672. case 0x0055: // MPEG Layer 3
  673. $thisfile_audio_dataformat = 'mp3';
  674. break;
  675. case 0x00FF: // AAC
  676. $thisfile_audio_dataformat = 'aac';
  677. break;
  678. case 0x0161: // Windows Media v7 / v8 / v9
  679. case 0x0162: // Windows Media Professional v9
  680. case 0x0163: // Windows Media Lossess v9
  681. $thisfile_audio_dataformat = 'wma';
  682. break;
  683. case 0x2000: // AC-3
  684. $thisfile_audio_dataformat = 'ac3';
  685. break;
  686. case 0x2001: // DTS
  687. $thisfile_audio_dataformat = 'dts';
  688. break;
  689. default:
  690. $thisfile_audio_dataformat = 'wav';
  691. break;
  692. }
  693. $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat;
  694. $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless'];
  695. $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  696. break;
  697. case 'iavs':
  698. case 'vids':
  699. // shortcut
  700. $thisfile_riff_raw['strh'][$i] = array();
  701. $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i];
  702. $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType;
  703. $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4);
  704. $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags
  705. $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2));
  706. $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2));
  707. $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4));
  708. $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4));
  709. $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4));
  710. $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4));
  711. $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4));
  712. $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4));
  713. $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4));
  714. $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4));
  715. $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4));
  716. $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']);
  717. $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler'];
  718. if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
  719. $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
  720. $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
  721. }
  722. $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
  723. $thisfile_video['pixel_aspect_ratio'] = (float) 1;
  724. switch ($thisfile_riff_raw_strh_current['fccHandler']) {
  725. case 'HFYU': // Huffman Lossless Codec
  726. case 'IRAW': // Intel YUV Uncompressed
  727. case 'YUY2': // Uncompressed YUV 4:2:2
  728. $thisfile_video['lossless'] = true;
  729. break;
  730. default:
  731. $thisfile_video['lossless'] = false;
  732. break;
  733. }
  734. switch ($strhfccType) {
  735. case 'vids':
  736. $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff'));
  737. $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
  738. if ($thisfile_riff_video_current['codec'] == 'DV') {
  739. $thisfile_riff_video_current['dv_type'] = 2;
  740. }
  741. break;
  742. case 'iavs':
  743. $thisfile_riff_video_current['dv_type'] = 1;
  744. break;
  745. }
  746. break;
  747. default:
  748. $info['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
  749. break;
  750. }
  751. }
  752. }
  753. if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
  754. $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
  755. if (self::fourccLookup($thisfile_video['fourcc'])) {
  756. $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']);
  757. $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
  758. }
  759. switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
  760. case 'HFYU': // Huffman Lossless Codec
  761. case 'IRAW': // Intel YUV Uncompressed
  762. case 'YUY2': // Uncompressed YUV 4:2:2
  763. $thisfile_video['lossless'] = true;
  764. //$thisfile_video['bits_per_sample'] = 24;
  765. break;
  766. default:
  767. $thisfile_video['lossless'] = false;
  768. //$thisfile_video['bits_per_sample'] = 24;
  769. break;
  770. }
  771. }
  772. }
  773. }
  774. }
  775. break;
  776. case 'AMV ':
  777. $info['fileformat'] = 'amv';
  778. $info['mime_type'] = 'video/amv';
  779. $thisfile_video['bitrate_mode'] = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR
  780. $thisfile_video['dataformat'] = 'mjpeg';
  781. $thisfile_video['codec'] = 'mjpeg';
  782. $thisfile_video['lossless'] = false;
  783. $thisfile_video['bits_per_sample'] = 24;
  784. $thisfile_audio['dataformat'] = 'adpcm';
  785. $thisfile_audio['lossless'] = false;
  786. break;
  787. // http://en.wikipedia.org/wiki/CD-DA
  788. case 'CDDA':
  789. $info['fileformat'] = 'cda';
  790. unset($info['mime_type']);
  791. $thisfile_audio_dataformat = 'cda';
  792. $info['avdataoffset'] = 44;
  793. if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
  794. // shortcut
  795. $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
  796. $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2));
  797. $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2));
  798. $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4));
  799. $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4));
  800. $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4));
  801. $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4));
  802. $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4));
  803. $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
  804. $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
  805. $info['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num'];
  806. $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
  807. // hardcoded data for CD-audio
  808. $thisfile_audio['lossless'] = true;
  809. $thisfile_audio['sample_rate'] = 44100;
  810. $thisfile_audio['channels'] = 2;
  811. $thisfile_audio['bits_per_sample'] = 16;
  812. $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
  813. $thisfile_audio['bitrate_mode'] = 'cbr';
  814. }
  815. break;
  816. // http://en.wikipedia.org/wiki/AIFF
  817. case 'AIFF':
  818. case 'AIFC':
  819. $info['fileformat'] = 'aiff';
  820. $info['mime_type'] = 'audio/x-aiff';
  821. $thisfile_audio['bitrate_mode'] = 'cbr';
  822. $thisfile_audio_dataformat = 'aiff';
  823. $thisfile_audio['lossless'] = true;
  824. if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
  825. $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
  826. $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
  827. if ($info['avdataend'] > $info['filesize']) {
  828. if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) {
  829. // structures rounded to 2-byte boundary, but dumb encoders
  830. // forget to pad end of file to make this actually work
  831. } else {
  832. $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
  833. }
  834. $info['avdataend'] = $info['filesize'];
  835. }
  836. }
  837. if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
  838. // shortcut
  839. $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
  840. $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true);
  841. $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false);
  842. $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true);
  843. $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10));
  844. if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
  845. $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4);
  846. $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false);
  847. $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize);
  848. switch ($thisfile_riff_audio['codec_name']) {
  849. case 'NONE':
  850. $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
  851. $thisfile_audio['lossless'] = true;
  852. break;
  853. case '':
  854. switch ($thisfile_riff_audio['codec_fourcc']) {
  855. // http://developer.apple.com/qa/snd/snd07.html
  856. case 'sowt':
  857. $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
  858. $thisfile_audio['lossless'] = true;
  859. break;
  860. case 'twos':
  861. $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
  862. $thisfile_audio['lossless'] = true;
  863. break;
  864. default:
  865. break;
  866. }
  867. break;
  868. default:
  869. $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name'];
  870. $thisfile_audio['lossless'] = false;
  871. break;
  872. }
  873. }
  874. $thisfile_audio['channels'] = $thisfile_riff_audio['channels'];
  875. if ($thisfile_riff_audio['bits_per_sample'] > 0) {
  876. $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
  877. }
  878. $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate'];
  879. if ($thisfile_audio['sample_rate'] == 0) {
  880. $info['error'][] = 'Corrupted AIFF file: sample_rate == zero';
  881. return false;
  882. }
  883. $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
  884. }
  885. if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
  886. $offset = 0;
  887. $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
  888. $offset += 2;
  889. for ($i = 0; $i < $CommentCount; $i++) {
  890. $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false);
  891. $offset += 4;
  892. $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true);
  893. $offset += 2;
  894. $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
  895. $offset += 2;
  896. $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
  897. $offset += $CommentLength;
  898. $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']);
  899. $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment'];
  900. }
  901. }
  902. $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
  903. foreach ($CommentsChunkNames as $key => $value) {
  904. if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
  905. $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
  906. }
  907. }
  908. /*
  909. if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) {
  910. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  911. $getid3_temp = new getID3();
  912. $getid3_temp->openfile($this->getid3->filename);
  913. $getid3_id3v2 = new getid3_id3v2($getid3_temp);
  914. $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
  915. if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
  916. $info['id3v2'] = $getid3_temp->info['id3v2'];
  917. }
  918. unset($getid3_temp, $getid3_id3v2);
  919. }
  920. */
  921. break;
  922. // http://en.wikipedia.org/wiki/8SVX
  923. case '8SVX':
  924. $info['fileformat'] = '8svx';
  925. $info['mime_type'] = 'audio/8svx';
  926. $thisfile_audio['bitrate_mode'] = 'cbr';
  927. $thisfile_audio_dataformat = '8svx';
  928. $thisfile_audio['bits_per_sample'] = 8;
  929. $thisfile_audio['channels'] = 1; // overridden below, if need be
  930. if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
  931. $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
  932. $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
  933. if ($info['avdataend'] > $info['filesize']) {
  934. $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
  935. }
  936. }
  937. if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
  938. // shortcut
  939. $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
  940. $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4));
  941. $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4));
  942. $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4));
  943. $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2));
  944. $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1));
  945. $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1));
  946. $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4));
  947. $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
  948. switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
  949. case 0:
  950. $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
  951. $thisfile_audio['lossless'] = true;
  952. $ActualBitsPerSample = 8;
  953. break;
  954. case 1:
  955. $thisfile_audio['codec'] = 'Fibonacci-delta encoding';
  956. $thisfile_audio['lossless'] = false;
  957. $ActualBitsPerSample = 4;
  958. break;
  959. default:
  960. $info['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
  961. break;
  962. }
  963. }
  964. if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
  965. $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4));
  966. switch ($ChannelsIndex) {
  967. case 6: // Stereo
  968. $thisfile_audio['channels'] = 2;
  969. break;
  970. case 2: // Left channel only
  971. case 4: // Right channel only
  972. $thisfile_audio['channels'] = 1;
  973. break;
  974. default:
  975. $info['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
  976. break;
  977. }
  978. }
  979. $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
  980. foreach ($CommentsChunkNames as $key => $value) {
  981. if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
  982. $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
  983. }
  984. }
  985. $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
  986. if (!empty($thisfile_audio['bitrate'])) {
  987. $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8);
  988. }
  989. break;
  990. case 'CDXA':
  991. $info['fileformat'] = 'vcd'; // Asume Video CD
  992. $info['mime_type'] = 'video/mpeg';
  993. if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
  994. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true);
  995. $getid3_temp = new getID3();
  996. $getid3_temp->openfile($this->getid3->filename);
  997. $getid3_mpeg = new getid3_mpeg($getid3_temp);
  998. $getid3_mpeg->Analyze();
  999. if (empty($getid3_temp->info['error'])) {
  1000. $info['audio'] = $getid3_temp->info['audio'];
  1001. $info['video'] = $getid3_temp->info['video'];
  1002. $info['mpeg'] = $getid3_temp->info['mpeg'];
  1003. $info['warning'] = $getid3_temp->info['warning'];
  1004. }
  1005. unset($getid3_temp, $getid3_mpeg);
  1006. }
  1007. break;
  1008. case 'WEBP':
  1009. // https://developers.google.com/speed/webp/docs/riff_container
  1010. $info['fileformat'] = 'webp';
  1011. $info['mime_type'] = 'image/webp';
  1012. $info['error'][] = 'WebP image parsing not supported in this version of getID3()';
  1013. break;
  1014. default:
  1015. $info['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead';
  1016. //unset($info['fileformat']);
  1017. }
  1018. switch ($RIFFsubtype) {
  1019. case 'WAVE':
  1020. case 'AIFF':
  1021. case 'AIFC':
  1022. $ID3v2_key_good = 'id3 ';
  1023. $ID3v2_keys_bad = array('ID3 ', 'tag ');
  1024. foreach ($ID3v2_keys_bad as $ID3v2_key_bad) {
  1025. if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) {
  1026. $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad];
  1027. $info['warning'][] = 'mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"';
  1028. }
  1029. }
  1030. if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) {
  1031. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  1032. $getid3_temp = new getID3();
  1033. $getid3_temp->openfile($this->getid3->filename);
  1034. $getid3_id3v2 = new getid3_id3v2($getid3_temp);
  1035. $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8;
  1036. if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
  1037. $info['id3v2'] = $getid3_temp->info['id3v2'];
  1038. }
  1039. unset($getid3_temp, $getid3_id3v2);
  1040. }
  1041. break;
  1042. }
  1043. if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
  1044. $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
  1045. }
  1046. if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
  1047. self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']);
  1048. }
  1049. if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) {
  1050. self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']);
  1051. }
  1052. if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) {
  1053. $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version'];
  1054. }
  1055. if (!isset($info['playtime_seconds'])) {
  1056. $info['playtime_seconds'] = 0;
  1057. }
  1058. if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
  1059. // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie
  1060. $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
  1061. } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
  1062. $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
  1063. }
  1064. if ($info['playtime_seconds'] > 0) {
  1065. if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
  1066. if (!isset($info['bitrate'])) {
  1067. $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1068. }
  1069. } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
  1070. if (!isset($thisfile_audio['bitrate'])) {
  1071. $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1072. }
  1073. } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
  1074. if (!isset($thisfile_video['bitrate'])) {
  1075. $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1076. }
  1077. }
  1078. }
  1079. if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) {
  1080. $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1081. $thisfile_audio['bitrate'] = 0;
  1082. $thisfile_video['bitrate'] = $info['bitrate'];
  1083. foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
  1084. $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
  1085. $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
  1086. }
  1087. if ($thisfile_video['bitrate'] <= 0) {
  1088. unset($thisfile_video['bitrate']);
  1089. }
  1090. if ($thisfile_audio['bitrate'] <= 0) {
  1091. unset($thisfile_audio['bitrate']);
  1092. }
  1093. }
  1094. if (isset($info['mpeg']['audio'])) {
  1095. $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer'];
  1096. $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  1097. $thisfile_audio['channels'] = $info['mpeg']['audio']['channels'];
  1098. $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate'];
  1099. $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1100. if (!empty($info['mpeg']['audio']['codec'])) {
  1101. $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
  1102. }
  1103. if (!empty($thisfile_audio['streams'])) {
  1104. foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
  1105. if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
  1106. $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate'];
  1107. $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels'];
  1108. $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
  1109. $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  1110. $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec'];
  1111. }
  1112. }
  1113. }
  1114. $getid3_mp3 = new getid3_mp3($this->getid3);
  1115. $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions();
  1116. unset($getid3_mp3);
  1117. }
  1118. if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
  1119. switch ($thisfile_audio_dataformat) {
  1120. case 'ac3':
  1121. // ignore bits_per_sample
  1122. break;
  1123. default:
  1124. $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
  1125. break;
  1126. }
  1127. }
  1128. if (empty($thisfile_riff_raw)) {
  1129. unset($thisfile_riff['raw']);
  1130. }
  1131. if (empty($thisfile_riff_audio)) {
  1132. unset($thisfile_riff['audio']);
  1133. }
  1134. if (empty($thisfile_riff_video)) {
  1135. unset($thisfile_riff['video']);
  1136. }
  1137. return true;
  1138. }
  1139. public function ParseRIFFAMV($startoffset, $maxoffset) {
  1140. // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
  1141. // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation
  1142. //typedef struct _amvmainheader {
  1143. //FOURCC fcc; // 'amvh'
  1144. //DWORD cb;
  1145. //DWORD dwMicroSecPerFrame;
  1146. //BYTE reserve[28];
  1147. //DWORD dwWidth;
  1148. //DWORD dwHeight;
  1149. //DWORD dwSpeed;
  1150. //DWORD reserve0;
  1151. //DWORD reserve1;
  1152. //BYTE bTimeSec;
  1153. //BYTE bTimeMin;
  1154. //WORD wTimeHour;
  1155. //} AMVMAINHEADER;
  1156. $info = &$this->getid3->info;
  1157. $RIFFchunk = false;
  1158. try {
  1159. $this->fseek($startoffset);
  1160. $maxoffset = min($maxoffset, $info['avdataend']);
  1161. $AMVheader = $this->fread(284);
  1162. if (substr($AMVheader, 0, 8) != 'hdrlamvh') {
  1163. throw new Exception('expecting "hdrlamv" at offset '.($startoffset + 0).', found "'.substr($AMVheader, 0, 8).'"');
  1164. }
  1165. if (substr($AMVheader, 8, 4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes
  1166. throw new Exception('expecting "0x38000000" at offset '.($startoffset + 8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 8, 4)).'"');
  1167. }
  1168. $RIFFchunk = array();
  1169. $RIFFchunk['amvh']['us_per_frame'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 12, 4));
  1170. $RIFFchunk['amvh']['reserved28'] = substr($AMVheader, 16, 28); // null? reserved?
  1171. $RIFFchunk['amvh']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 44, 4));
  1172. $RIFFchunk['amvh']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 48, 4));
  1173. $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 52, 4));
  1174. $RIFFchunk['amvh']['reserved0'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 56, 4)); // 1? reserved?
  1175. $RIFFchunk['amvh']['reserved1'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 60, 4)); // 0? reserved?
  1176. $RIFFchunk['amvh']['runtime_sec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 64, 1));
  1177. $RIFFchunk['amvh']['runtime_min'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 65, 1));
  1178. $RIFFchunk['amvh']['runtime_hrs'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 66, 2));
  1179. $info['video']['frame_rate'] = 1000000 / $RIFFchunk['amvh']['us_per_frame'];
  1180. $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x'];
  1181. $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y'];
  1182. $info['playtime_seconds'] = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec'];
  1183. // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded
  1184. if (substr($AMVheader, 68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") {
  1185. throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset + 68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 68, 20)).'"');
  1186. }
  1187. // followed by 56 bytes of null: substr($AMVheader, 88, 56) -> 144
  1188. if (substr($AMVheader, 144, 8) != 'strf'."\x24\x00\x00\x00") {
  1189. throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144, 8)).'"');
  1190. }
  1191. // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180
  1192. if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") {
  1193. throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"');
  1194. }
  1195. // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256
  1196. if (substr($AMVheader, 256, 8) != 'strf'."\x14\x00\x00\x00") {
  1197. throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256, 8)).'"');
  1198. }
  1199. // followed by 20 bytes of a modified WAVEFORMATEX:
  1200. // typedef struct {
  1201. // WORD wFormatTag; //(Fixme: this is equal to PCM's 0x01 format code)
  1202. // WORD nChannels; //(Fixme: this is always 1)
  1203. // DWORD nSamplesPerSec; //(Fixme: for all known sample files this is equal to 22050)
  1204. // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100)
  1205. // WORD nBlockAlign; //(Fixme: this seems to be 2 in AMV files, is this correct ?)
  1206. // WORD wBitsPerSample; //(Fixme: this seems to be 16 in AMV files instead of the expected 4)
  1207. // WORD cbSize; //(Fixme: this seems to be 0 in AMV files)
  1208. // WORD reserved;
  1209. // } WAVEFORMATEX;
  1210. $RIFFchunk['strf']['wformattag'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 264, 2));
  1211. $RIFFchunk['strf']['nchannels'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 266, 2));
  1212. $RIFFchunk['strf']['nsamplespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 268, 4));
  1213. $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 272, 4));
  1214. $RIFFchunk['strf']['nblockalign'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 276, 2));
  1215. $RIFFchunk['strf']['wbitspersample'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 278, 2));
  1216. $RIFFchunk['strf']['cbsize'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 280, 2));
  1217. $RIFFchunk['strf']['reserved'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 282, 2));
  1218. $info['audio']['lossless'] = false;
  1219. $info['audio']['sample_rate'] = $RIFFchunk['strf']['nsamplespersec'];
  1220. $info['audio']['channels'] = $RIFFchunk['strf']['nchannels'];
  1221. $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample'];
  1222. $info['audio']['bitrate'] = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample'];
  1223. $info['audio']['bitrate_mode'] = 'cbr';
  1224. } catch (getid3_exception $e) {
  1225. if ($e->getCode() == 10) {
  1226. $this->warning('RIFFAMV parser: '.$e->getMessage());
  1227. } else {
  1228. throw $e;
  1229. }
  1230. }
  1231. return $RIFFchunk;
  1232. }
  1233. public function ParseRIFF($startoffset, $maxoffset) {
  1234. $info = &$this->getid3->info;
  1235. $RIFFchunk = false;
  1236. $FoundAllChunksWeNeed = false;
  1237. try {
  1238. $this->fseek($startoffset);
  1239. $maxoffset = min($maxoffset, $info['avdataend']);
  1240. while ($this->ftell() < $maxoffset) {
  1241. $chunknamesize = $this->fread(8);
  1242. //$chunkname = substr($chunknamesize, 0, 4);
  1243. $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult
  1244. $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4));
  1245. //if (strlen(trim($chunkname, "\x00")) < 4) {
  1246. if (strlen($chunkname) < 4) {
  1247. $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.');
  1248. break;
  1249. }
  1250. if (($chunksize == 0) && ($chunkname != 'JUNK')) {
  1251. $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
  1252. break;
  1253. }
  1254. if (($chunksize % 2) != 0) {
  1255. // all structures are packed on word boundaries
  1256. $chunksize++;
  1257. }
  1258. switch ($chunkname) {
  1259. case 'LIST':
  1260. $listname = $this->fread(4);
  1261. if (preg_match('#^(movi|rec )$#i', $listname)) {
  1262. $RIFFchunk[$listname]['offset'] = $this->ftell() - 4;
  1263. $RIFFchunk[$listname]['size'] = $chunksize;
  1264. if (!$FoundAllChunksWeNeed) {
  1265. $WhereWeWere = $this->ftell();
  1266. $AudioChunkHeader = $this->fread(12);
  1267. $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2);
  1268. $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2);
  1269. $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4));
  1270. if ($AudioChunkStreamType == 'wb') {
  1271. $FirstFourBytes = substr($AudioChunkHeader, 8, 4);
  1272. if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) {
  1273. // MP3
  1274. if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
  1275. $getid3_temp = new getID3();
  1276. $getid3_temp->openfile($this->getid3->filename);
  1277. $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
  1278. $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
  1279. $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
  1280. $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
  1281. if (isset($getid3_temp->info['mpeg']['audio'])) {
  1282. $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio'];
  1283. $info['audio'] = $getid3_temp->info['audio'];
  1284. $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
  1285. $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  1286. $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
  1287. $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
  1288. $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1289. //$info['bitrate'] = $info['audio']['bitrate'];
  1290. }
  1291. unset($getid3_temp, $getid3_mp3);
  1292. }
  1293. } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) {
  1294. // AC3
  1295. $getid3_temp = new getID3();
  1296. $getid3_temp->openfile($this->getid3->filename);
  1297. $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
  1298. $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
  1299. $getid3_ac3 = new getid3_ac3($getid3_temp);
  1300. $getid3_ac3->Analyze();
  1301. if (empty($getid3_temp->info['error'])) {
  1302. $info['audio'] = $getid3_temp->info['audio'];
  1303. $info['ac3'] = $getid3_temp->info['ac3'];
  1304. if (!empty($getid3_temp->info['warning'])) {
  1305. foreach ($getid3_temp->info['warning'] as $key => $value) {
  1306. $info['warning'][] = $value;
  1307. }
  1308. }
  1309. }
  1310. unset($getid3_temp, $getid3_ac3);
  1311. }
  1312. }
  1313. $FoundAllChunksWeNeed = true;
  1314. $this->fseek($WhereWeWere);
  1315. }
  1316. $this->fseek($chunksize - 4, SEEK_CUR);
  1317. } else {
  1318. if (!isset($RIFFchunk[$listname])) {
  1319. $RIFFchunk[$listname] = array();
  1320. }
  1321. $LISTchunkParent = $listname;
  1322. $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize;
  1323. if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) {
  1324. $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk);
  1325. }
  1326. }
  1327. break;
  1328. default:
  1329. if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) {
  1330. $this->fseek($chunksize, SEEK_CUR);
  1331. break;
  1332. }
  1333. $thisindex = 0;
  1334. if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) {
  1335. $thisindex = count($RIFFchunk[$chunkname]);
  1336. }
  1337. $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8;
  1338. $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize;
  1339. switch ($chunkname) {
  1340. case 'data':
  1341. $info['avdataoffset'] = $this->ftell();
  1342. $info['avdataend'] = $info['avdataoffset'] + $chunksize;
  1343. $testData = $this->fread(36);
  1344. if ($testData === '') {
  1345. break;
  1346. }
  1347. if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) {
  1348. // Probably is MP3 data
  1349. if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) {
  1350. $getid3_temp = new getID3();
  1351. $getid3_temp->openfile($this->getid3->filename);
  1352. $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1353. $getid3_temp->info['avdataend'] = $info['avdataend'];
  1354. $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
  1355. $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false);
  1356. if (empty($getid3_temp->info['error'])) {
  1357. $info['audio'] = $getid3_temp->info['audio'];
  1358. $info['mpeg'] = $getid3_temp->info['mpeg'];
  1359. }
  1360. unset($getid3_temp, $getid3_mp3);
  1361. }
  1362. } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) {
  1363. // This is probably AC-3 data
  1364. $getid3_temp = new getID3();
  1365. if ($isRegularAC3) {
  1366. $getid3_temp->openfile($this->getid3->filename);
  1367. $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1368. $getid3_temp->info['avdataend'] = $info['avdataend'];
  1369. }
  1370. $getid3_ac3 = new getid3_ac3($getid3_temp);
  1371. if ($isRegularAC3) {
  1372. $getid3_ac3->Analyze();
  1373. } else {
  1374. // Dolby Digital WAV
  1375. // AC-3 content, but not encoded in same format as normal AC-3 file
  1376. // For one thing, byte order is swapped
  1377. $ac3_data = '';
  1378. for ($i = 0; $i < 28; $i += 2) {
  1379. $ac3_data .= substr($testData, 8 + $i + 1, 1);
  1380. $ac3_data .= substr($testData, 8 + $i + 0, 1);
  1381. }
  1382. $getid3_ac3->AnalyzeString($ac3_data);
  1383. }
  1384. if (empty($getid3_temp->info['error'])) {
  1385. $info['audio'] = $getid3_temp->info['audio'];
  1386. $info['ac3'] = $getid3_temp->info['ac3'];
  1387. if (!empty($getid3_temp->info['warning'])) {
  1388. foreach ($getid3_temp->info['warning'] as $newerror) {
  1389. $this->warning('getid3_ac3() says: ['.$newerror.']');
  1390. }
  1391. }
  1392. }
  1393. unset($getid3_temp, $getid3_ac3);
  1394. } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) {
  1395. // This is probably DTS data
  1396. $getid3_temp = new getID3();
  1397. $getid3_temp->openfile($this->getid3->filename);
  1398. $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1399. $getid3_dts = new getid3_dts($getid3_temp);
  1400. $getid3_dts->Analyze();
  1401. if (empty($getid3_temp->info['error'])) {
  1402. $info['audio'] = $getid3_temp->info['audio'];
  1403. $info['dts'] = $getid3_temp->info['dts'];
  1404. $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing
  1405. if (!empty($getid3_temp->info['warning'])) {
  1406. foreach ($getid3_temp->info['warning'] as $newerror) {
  1407. $this->warning('getid3_dts() says: ['.$newerror.']');
  1408. }
  1409. }
  1410. }
  1411. unset($getid3_temp, $getid3_dts);
  1412. } elseif (substr($testData, 0, 4) == 'wvpk') {
  1413. // This is WavPack data
  1414. $info['wavpack']['offset'] = $info['avdataoffset'];
  1415. $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($testData, 4, 4));
  1416. $this->parseWavPackHeader(substr($testData, 8, 28));
  1417. } else {
  1418. // This is some other kind of data (quite possibly just PCM)
  1419. // do nothing special, just skip it
  1420. }
  1421. $nextoffset = $info['avdataend'];
  1422. $this->fseek($nextoffset);
  1423. break;
  1424. case 'iXML':
  1425. case 'bext':
  1426. case 'cart':
  1427. case 'fmt ':
  1428. case 'strh':
  1429. case 'strf':
  1430. case 'indx':
  1431. case 'MEXT':
  1432. case 'DISP':
  1433. // always read data in
  1434. case 'JUNK':
  1435. // should be: never read data in
  1436. // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc)
  1437. if ($chunksize < 1048576) {
  1438. if ($chunksize > 0) {
  1439. $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1440. if ($chunkname == 'JUNK') {
  1441. if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) {
  1442. // only keep text characters [chr(32)-chr(127)]
  1443. $info['riff']['comments']['junk'][] = trim($matches[1]);
  1444. }
  1445. // but if nothing there, ignore
  1446. // remove the key in either case
  1447. unset($RIFFchunk[$chunkname][$thisindex]['data']);
  1448. }
  1449. }
  1450. } else {
  1451. $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data');
  1452. $this->fseek($chunksize, SEEK_CUR);
  1453. }
  1454. break;
  1455. //case 'IDVX':
  1456. // $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize));
  1457. // break;
  1458. default:
  1459. if (!empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) {
  1460. $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
  1461. $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size'];
  1462. unset($RIFFchunk[$chunkname][$thisindex]['offset']);
  1463. unset($RIFFchunk[$chunkname][$thisindex]['size']);
  1464. if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) {
  1465. unset($RIFFchunk[$chunkname][$thisindex]);
  1466. }
  1467. if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) {
  1468. unset($RIFFchunk[$chunkname]);
  1469. }
  1470. $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1471. } elseif ($chunksize < 2048) {
  1472. // only read data in if smaller than 2kB
  1473. $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1474. } else {
  1475. $this->fseek($chunksize, SEEK_CUR);
  1476. }
  1477. break;
  1478. }
  1479. break;
  1480. }
  1481. }
  1482. } catch (getid3_exception $e) {
  1483. if ($e->getCode() == 10) {
  1484. $this->warning('RIFF parser: '.$e->getMessage());
  1485. } else {
  1486. throw $e;
  1487. }
  1488. }
  1489. return $RIFFchunk;
  1490. }
  1491. public function ParseRIFFdata(&$RIFFdata) {
  1492. $info = &$this->getid3->info;
  1493. if ($RIFFdata) {
  1494. $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
  1495. $fp_temp = fopen($tempfile, 'wb');
  1496. $RIFFdataLength = strlen($RIFFdata);
  1497. $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
  1498. for ($i = 0; $i < 4; $i++) {
  1499. $RIFFdata[($i + 4)] = $NewLengthString[$i];
  1500. }
  1501. fwrite($fp_temp, $RIFFdata);
  1502. fclose($fp_temp);
  1503. $getid3_temp = new getID3();
  1504. $getid3_temp->openfile($tempfile);
  1505. $getid3_temp->info['filesize'] = $RIFFdataLength;
  1506. $getid3_temp->info['filenamepath'] = $info['filenamepath'];
  1507. $getid3_temp->info['tags'] = $info['tags'];
  1508. $getid3_temp->info['warning'] = $info['warning'];
  1509. $getid3_temp->info['error'] = $info['error'];
  1510. $getid3_temp->info['comments'] = $info['comments'];
  1511. $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : array());
  1512. $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : array());
  1513. $getid3_riff = new getid3_riff($getid3_temp);
  1514. $getid3_riff->Analyze();
  1515. $info['riff'] = $getid3_temp->info['riff'];
  1516. $info['warning'] = $getid3_temp->info['warning'];
  1517. $info['error'] = $getid3_temp->info['error'];
  1518. $info['tags'] = $getid3_temp->info['tags'];
  1519. $info['comments'] = $getid3_temp->info['comments'];
  1520. unset($getid3_riff, $getid3_temp);
  1521. unlink($tempfile);
  1522. }
  1523. return false;
  1524. }
  1525. public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) {
  1526. $RIFFinfoKeyLookup = array(
  1527. 'IARL'=>'archivallocation',
  1528. 'IART'=>'artist',
  1529. 'ICDS'=>'costumedesigner',
  1530. 'ICMS'=>'commissionedby',
  1531. 'ICMT'=>'comment',
  1532. 'ICNT'=>'country',
  1533. 'ICOP'=>'copyright',
  1534. 'ICRD'=>'creationdate',
  1535. 'IDIM'=>'dimensions',
  1536. 'IDIT'=>'digitizationdate',
  1537. 'IDPI'=>'resolution',
  1538. 'IDST'=>'distributor',
  1539. 'IEDT'=>'editor',
  1540. 'IENG'=>'engineers',
  1541. 'IFRM'=>'accountofparts',
  1542. 'IGNR'=>'genre',
  1543. 'IKEY'=>'keywords',
  1544. 'ILGT'=>'lightness',
  1545. 'ILNG'=>'language',
  1546. 'IMED'=>'orignalmedium',
  1547. 'IMUS'=>'composer',
  1548. 'INAM'=>'title',
  1549. 'IPDS'=>'productiondesigner',
  1550. 'IPLT'=>'palette',
  1551. 'IPRD'=>'product',
  1552. 'IPRO'=>'producer',
  1553. 'IPRT'=>'part',
  1554. 'IRTD'=>'rating',
  1555. 'ISBJ'=>'subject',
  1556. 'ISFT'=>'software',
  1557. 'ISGN'=>'secondarygenre',
  1558. 'ISHP'=>'sharpness',
  1559. 'ISRC'=>'sourcesupplier',
  1560. 'ISRF'=>'digitizationsource',
  1561. 'ISTD'=>'productionstudio',
  1562. 'ISTR'=>'starring',
  1563. 'ITCH'=>'encoded_by',
  1564. 'IWEB'=>'url',
  1565. 'IWRI'=>'writer',
  1566. '____'=>'comment',
  1567. );
  1568. foreach ($RIFFinfoKeyLookup as $key => $value) {
  1569. if (isset($RIFFinfoArray[$key])) {
  1570. foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) {
  1571. if (trim($commentdata['data']) != '') {
  1572. if (isset($CommentsTargetArray[$value])) {
  1573. $CommentsTargetArray[$value][] = trim($commentdata['data']);
  1574. } else {
  1575. $CommentsTargetArray[$value] = array(trim($commentdata['data']));
  1576. }
  1577. }
  1578. }
  1579. }
  1580. }
  1581. return true;
  1582. }
  1583. public static function parseWAVEFORMATex($WaveFormatExData) {
  1584. // shortcut
  1585. $WaveFormatEx['raw'] = array();
  1586. $WaveFormatEx_raw = &$WaveFormatEx['raw'];
  1587. $WaveFormatEx_raw['wFormatTag'] = substr($WaveFormatExData, 0, 2);
  1588. $WaveFormatEx_raw['nChannels'] = substr($WaveFormatExData, 2, 2);
  1589. $WaveFormatEx_raw['nSamplesPerSec'] = substr($WaveFormatExData, 4, 4);
  1590. $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData, 8, 4);
  1591. $WaveFormatEx_raw['nBlockAlign'] = substr($WaveFormatExData, 12, 2);
  1592. $WaveFormatEx_raw['wBitsPerSample'] = substr($WaveFormatExData, 14, 2);
  1593. if (strlen($WaveFormatExData) > 16) {
  1594. $WaveFormatEx_raw['cbSize'] = substr($WaveFormatExData, 16, 2);
  1595. }
  1596. $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw);
  1597. $WaveFormatEx['codec'] = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
  1598. $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels'];
  1599. $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec'];
  1600. $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
  1601. $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
  1602. return $WaveFormatEx;
  1603. }
  1604. public function parseWavPackHeader($WavPackChunkData) {
  1605. // typedef struct {
  1606. // char ckID [4];
  1607. // long ckSize;
  1608. // short version;
  1609. // short bits; // added for version 2.00
  1610. // short flags, shift; // added for version 3.00
  1611. // long total_samples, crc, crc2;
  1612. // char extension [4], extra_bc, extras [3];
  1613. // } WavpackHeader;
  1614. // shortcut
  1615. $info = &$this->getid3->info;
  1616. $info['wavpack'] = array();
  1617. $thisfile_wavpack = &$info['wavpack'];
  1618. $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2));
  1619. if ($thisfile_wavpack['version'] >= 2) {
  1620. $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2));
  1621. }
  1622. if ($thisfile_wavpack['version'] >= 3) {
  1623. $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2));
  1624. $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2));
  1625. $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4));
  1626. $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4));
  1627. $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4));
  1628. $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4);
  1629. $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1));
  1630. for ($i = 0; $i <= 2; $i++) {
  1631. $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1));
  1632. }
  1633. // shortcut
  1634. $thisfile_wavpack['flags'] = array();
  1635. $thisfile_wavpack_flags = &$thisfile_wavpack['flags'];
  1636. $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001);
  1637. $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002);
  1638. $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004);
  1639. $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008);
  1640. $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010);
  1641. $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020);
  1642. $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040);
  1643. $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080);
  1644. $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100);
  1645. $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200);
  1646. $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400);
  1647. $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800);
  1648. $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000);
  1649. $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000);
  1650. $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000);
  1651. $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000);
  1652. $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000);
  1653. $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000);
  1654. $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000);
  1655. $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000);
  1656. }
  1657. return true;
  1658. }
  1659. public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
  1660. $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure
  1661. $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels
  1662. $parsed['biHeight'] = substr($BITMAPINFOHEADER, 8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
  1663. $parsed['biPlanes'] = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1
  1664. $parsed['biBitCount'] = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels
  1665. $parsed['biSizeImage'] = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
  1666. $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device
  1667. $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device
  1668. $parsed['biClrUsed'] = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
  1669. $parsed['biClrImportant'] = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
  1670. $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed);
  1671. $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier
  1672. return $parsed;
  1673. }
  1674. public static function ParseDIVXTAG($DIVXTAG, $raw=false) {
  1675. // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/
  1676. // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip
  1677. // 'Byte Layout: '1111111111111111
  1678. // '32 for Movie - 1 '1111111111111111
  1679. // '28 for Author - 6 '6666666666666666
  1680. // '4 for year - 2 '6666666666662222
  1681. // '3 for genre - 3 '7777777777777777
  1682. // '48 for Comments - 7 '7777777777777777
  1683. // '1 for Rating - 4 '7777777777777777
  1684. // '5 for Future Additions - 0 '333400000DIVXTAG
  1685. // '128 bytes total
  1686. static $DIVXTAGgenre = array(
  1687. 0 => 'Action',
  1688. 1 => 'Action/Adventure',
  1689. 2 => 'Adventure',
  1690. 3 => 'Adult',
  1691. 4 => 'Anime',
  1692. 5 => 'Cartoon',
  1693. 6 => 'Claymation',
  1694. 7 => 'Comedy',
  1695. 8 => 'Commercial',
  1696. 9 => 'Documentary',
  1697. 10 => 'Drama',
  1698. 11 => 'Home Video',
  1699. 12 => 'Horror',
  1700. 13 => 'Infomercial',
  1701. 14 => 'Interactive',
  1702. 15 => 'Mystery',
  1703. 16 => 'Music Video',
  1704. 17 => 'Other',
  1705. 18 => 'Religion',
  1706. 19 => 'Sci Fi',
  1707. 20 => 'Thriller',
  1708. 21 => 'Western',
  1709. ),
  1710. $DIVXTAGrating = array(
  1711. 0 => 'Unrated',
  1712. 1 => 'G',
  1713. 2 => 'PG',
  1714. 3 => 'PG-13',
  1715. 4 => 'R',
  1716. 5 => 'NC-17',
  1717. );
  1718. $parsed['title'] = trim(substr($DIVXTAG, 0, 32));
  1719. $parsed['artist'] = trim(substr($DIVXTAG, 32, 28));
  1720. $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4)));
  1721. $parsed['comment'] = trim(substr($DIVXTAG, 64, 48));
  1722. $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3)));
  1723. $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1));
  1724. //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null
  1725. //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG"
  1726. $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']);
  1727. $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']);
  1728. if (!$raw) {
  1729. unset($parsed['genre_id'], $parsed['rating_id']);
  1730. foreach ($parsed as $key => $value) {
  1731. if (!$value === '') {
  1732. unset($parsed['key']);
  1733. }
  1734. }
  1735. }
  1736. foreach ($parsed as $tag => $value) {
  1737. $parsed[$tag] = array($value);
  1738. }
  1739. return $parsed;
  1740. }
  1741. public static function waveSNDMtagLookup($tagshortname) {
  1742. $begin = __LINE__;
  1743. /** This is not a comment!
  1744. ©kwd keywords
  1745. ©BPM bpm
  1746. ©trt tracktitle
  1747. ©des description
  1748. ©gen category
  1749. ©fin featuredinstrument
  1750. ©LID longid
  1751. ©bex bwdescription
  1752. ©pub publisher
  1753. ©cdt cdtitle
  1754. ©alb library
  1755. ©com composer
  1756. */
  1757. return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm');
  1758. }
  1759. public static function wFormatTagLookup($wFormatTag) {
  1760. $begin = __LINE__;
  1761. /** This is not a comment!
  1762. 0x0000 Microsoft Unknown Wave Format
  1763. 0x0001 Pulse Code Modulation (PCM)
  1764. 0x0002 Microsoft ADPCM
  1765. 0x0003 IEEE Float
  1766. 0x0004 Compaq Computer VSELP
  1767. 0x0005 IBM CVSD
  1768. 0x0006 Microsoft A-Law
  1769. 0x0007 Microsoft mu-Law
  1770. 0x0008 Microsoft DTS
  1771. 0x0010 OKI ADPCM
  1772. 0x0011 Intel DVI/IMA ADPCM
  1773. 0x0012 Videologic MediaSpace ADPCM
  1774. 0x0013 Sierra Semiconductor ADPCM
  1775. 0x0014 Antex Electronics G.723 ADPCM
  1776. 0x0015 DSP Solutions DigiSTD
  1777. 0x0016 DSP Solutions DigiFIX
  1778. 0x0017 Dialogic OKI ADPCM
  1779. 0x0018 MediaVision ADPCM
  1780. 0x0019 Hewlett-Packard CU
  1781. 0x0020 Yamaha ADPCM
  1782. 0x0021 Speech Compression Sonarc
  1783. 0x0022 DSP Group TrueSpeech
  1784. 0x0023 Echo Speech EchoSC1
  1785. 0x0024 Audiofile AF36
  1786. 0x0025 Audio Processing Technology APTX
  1787. 0x0026 AudioFile AF10
  1788. 0x0027 Prosody 1612
  1789. 0x0028 LRC
  1790. 0x0030 Dolby AC2
  1791. 0x0031 Microsoft GSM 6.10
  1792. 0x0032 MSNAudio
  1793. 0x0033 Antex Electronics ADPCME
  1794. 0x0034 Control Resources VQLPC
  1795. 0x0035 DSP Solutions DigiREAL
  1796. 0x0036 DSP Solutions DigiADPCM
  1797. 0x0037 Control Resources CR10
  1798. 0x0038 Natural MicroSystems VBXADPCM
  1799. 0x0039 Crystal Semiconductor IMA ADPCM
  1800. 0x003A EchoSC3
  1801. 0x003B Rockwell ADPCM
  1802. 0x003C Rockwell Digit LK
  1803. 0x003D Xebec
  1804. 0x0040 Antex Electronics G.721 ADPCM
  1805. 0x0041 G.728 CELP
  1806. 0x0042 MSG723
  1807. 0x0050 MPEG Layer-2 or Layer-1
  1808. 0x0052 RT24
  1809. 0x0053 PAC
  1810. 0x0055 MPEG Layer-3
  1811. 0x0059 Lucent G.723
  1812. 0x0060 Cirrus
  1813. 0x0061 ESPCM
  1814. 0x0062 Voxware
  1815. 0x0063 Canopus Atrac
  1816. 0x0064 G.726 ADPCM
  1817. 0x0065 G.722 ADPCM
  1818. 0x0066 DSAT
  1819. 0x0067 DSAT Display
  1820. 0x0069 Voxware Byte Aligned
  1821. 0x0070 Voxware AC8
  1822. 0x0071 Voxware AC10
  1823. 0x0072 Voxware AC16
  1824. 0x0073 Voxware AC20
  1825. 0x0074 Voxware MetaVoice
  1826. 0x0075 Voxware MetaSound
  1827. 0x0076 Voxware RT29HW
  1828. 0x0077 Voxware VR12
  1829. 0x0078 Voxware VR18
  1830. 0x0079 Voxware TQ40
  1831. 0x0080 Softsound
  1832. 0x0081 Voxware TQ60
  1833. 0x0082 MSRT24
  1834. 0x0083 G.729A
  1835. 0x0084 MVI MV12
  1836. 0x0085 DF G.726
  1837. 0x0086 DF GSM610
  1838. 0x0088 ISIAudio
  1839. 0x0089 Onlive
  1840. 0x0091 SBC24
  1841. 0x0092 Dolby AC3 SPDIF
  1842. 0x0093 MediaSonic G.723
  1843. 0x0094 Aculab PLC Prosody 8kbps
  1844. 0x0097 ZyXEL ADPCM
  1845. 0x0098 Philips LPCBB
  1846. 0x0099 Packed
  1847. 0x00FF AAC
  1848. 0x0100 Rhetorex ADPCM
  1849. 0x0101 IBM mu-law
  1850. 0x0102 IBM A-law
  1851. 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)
  1852. 0x0111 Vivo G.723
  1853. 0x0112 Vivo Siren
  1854. 0x0123 Digital G.723
  1855. 0x0125 Sanyo LD ADPCM
  1856. 0x0130 Sipro Lab Telecom ACELP NET
  1857. 0x0131 Sipro Lab Telecom ACELP 4800
  1858. 0x0132 Sipro Lab Telecom ACELP 8V3
  1859. 0x0133 Sipro Lab Telecom G.729
  1860. 0x0134 Sipro Lab Telecom G.729A
  1861. 0x0135 Sipro Lab Telecom Kelvin
  1862. 0x0140 Windows Media Video V8
  1863. 0x0150 Qualcomm PureVoice
  1864. 0x0151 Qualcomm HalfRate
  1865. 0x0155 Ring Zero Systems TUB GSM
  1866. 0x0160 Microsoft Audio 1
  1867. 0x0161 Windows Media Audio V7 / V8 / V9
  1868. 0x0162 Windows Media Audio Professional V9
  1869. 0x0163 Windows Media Audio Lossless V9
  1870. 0x0200 Creative Labs ADPCM
  1871. 0x0202 Creative Labs Fastspeech8
  1872. 0x0203 Creative Labs Fastspeech10
  1873. 0x0210 UHER Informatic GmbH ADPCM
  1874. 0x0220 Quarterdeck
  1875. 0x0230 I-link Worldwide VC
  1876. 0x0240 Aureal RAW Sport
  1877. 0x0250 Interactive Products HSX
  1878. 0x0251 Interactive Products RPELP
  1879. 0x0260 Consistent Software CS2
  1880. 0x0270 Sony SCX
  1881. 0x0300 Fujitsu FM Towns Snd
  1882. 0x0400 BTV Digital
  1883. 0x0401 Intel Music Coder
  1884. 0x0450 QDesign Music
  1885. 0x0680 VME VMPCM
  1886. 0x0681 AT&T Labs TPC
  1887. 0x08AE ClearJump LiteWave
  1888. 0x1000 Olivetti GSM
  1889. 0x1001 Olivetti ADPCM
  1890. 0x1002 Olivetti CELP
  1891. 0x1003 Olivetti SBC
  1892. 0x1004 Olivetti OPR
  1893. 0x1100 Lernout & Hauspie Codec (0x1100)
  1894. 0x1101 Lernout & Hauspie CELP Codec (0x1101)
  1895. 0x1102 Lernout & Hauspie SBC Codec (0x1102)
  1896. 0x1103 Lernout & Hauspie SBC Codec (0x1103)
  1897. 0x1104 Lernout & Hauspie SBC Codec (0x1104)
  1898. 0x1400 Norris
  1899. 0x1401 AT&T ISIAudio
  1900. 0x1500 Soundspace Music Compression
  1901. 0x181C VoxWare RT24 Speech
  1902. 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com)
  1903. 0x2000 Dolby AC3
  1904. 0x2001 Dolby DTS
  1905. 0x2002 WAVE_FORMAT_14_4
  1906. 0x2003 WAVE_FORMAT_28_8
  1907. 0x2004 WAVE_FORMAT_COOK
  1908. 0x2005 WAVE_FORMAT_DNET
  1909. 0x674F Ogg Vorbis 1
  1910. 0x6750 Ogg Vorbis 2
  1911. 0x6751 Ogg Vorbis 3
  1912. 0x676F Ogg Vorbis 1+
  1913. 0x6770 Ogg Vorbis 2+
  1914. 0x6771 Ogg Vorbis 3+
  1915. 0x7A21 GSM-AMR (CBR, no SID)
  1916. 0x7A22 GSM-AMR (VBR, including SID)
  1917. 0xFFFE WAVE_FORMAT_EXTENSIBLE
  1918. 0xFFFF WAVE_FORMAT_DEVELOPMENT
  1919. */
  1920. return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag');
  1921. }
  1922. public static function fourccLookup($fourcc) {
  1923. $begin = __LINE__;
  1924. /** This is not a comment!
  1925. swot http://developer.apple.com/qa/snd/snd07.html
  1926. ____ No Codec (____)
  1927. _BIT BI_BITFIELDS (Raw RGB)
  1928. _JPG JPEG compressed
  1929. _PNG PNG compressed W3C/ISO/IEC (RFC-2083)
  1930. _RAW Full Frames (Uncompressed)
  1931. _RGB Raw RGB Bitmap
  1932. _RL4 RLE 4bpp RGB
  1933. _RL8 RLE 8bpp RGB
  1934. 3IV1 3ivx MPEG-4 v1
  1935. 3IV2 3ivx MPEG-4 v2
  1936. 3IVX 3ivx MPEG-4
  1937. AASC Autodesk Animator
  1938. ABYR Kensington ?ABYR?
  1939. AEMI Array Microsystems VideoONE MPEG1-I Capture
  1940. AFLC Autodesk Animator FLC
  1941. AFLI Autodesk Animator FLI
  1942. AMPG Array Microsystems VideoONE MPEG
  1943. ANIM Intel RDX (ANIM)
  1944. AP41 AngelPotion Definitive
  1945. ASV1 Asus Video v1
  1946. ASV2 Asus Video v2
  1947. ASVX Asus Video 2.0 (audio)
  1948. AUR2 AuraVision Aura 2 Codec - YUV 4:2:2
  1949. AURA AuraVision Aura 1 Codec - YUV 4:1:1
  1950. AVDJ Independent JPEG Group\'s codec (AVDJ)
  1951. AVRN Independent JPEG Group\'s codec (AVRN)
  1952. AYUV 4:4:4 YUV (AYUV)
  1953. AZPR Quicktime Apple Video (AZPR)
  1954. BGR Raw RGB32
  1955. BLZ0 Blizzard DivX MPEG-4
  1956. BTVC Conexant Composite Video
  1957. BINK RAD Game Tools Bink Video
  1958. BT20 Conexant Prosumer Video
  1959. BTCV Conexant Composite Video Codec
  1960. BW10 Data Translation Broadway MPEG Capture
  1961. CC12 Intel YUV12
  1962. CDVC Canopus DV
  1963. CFCC Digital Processing Systems DPS Perception
  1964. CGDI Microsoft Office 97 Camcorder Video
  1965. CHAM Winnov Caviara Champagne
  1966. CJPG Creative WebCam JPEG
  1967. CLJR Cirrus Logic YUV 4:1:1
  1968. CMYK Common Data Format in Printing (Colorgraph)
  1969. CPLA Weitek 4:2:0 YUV Planar
  1970. CRAM Microsoft Video 1 (CRAM)
  1971. cvid Radius Cinepak
  1972. CVID Radius Cinepak
  1973. CWLT Microsoft Color WLT DIB
  1974. CYUV Creative Labs YUV
  1975. CYUY ATI YUV
  1976. D261 H.261
  1977. D263 H.263
  1978. DIB Device Independent Bitmap
  1979. DIV1 FFmpeg OpenDivX
  1980. DIV2 Microsoft MPEG-4 v1/v2
  1981. DIV3 DivX ;-) MPEG-4 v3.x Low-Motion
  1982. DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion
  1983. DIV5 DivX MPEG-4 v5.x
  1984. DIV6 DivX ;-) (MS MPEG-4 v3.x)
  1985. DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo)
  1986. divx DivX MPEG-4
  1987. DMB1 Matrox Rainbow Runner hardware MJPEG
  1988. DMB2 Paradigm MJPEG
  1989. DSVD ?DSVD?
  1990. DUCK Duck TrueMotion 1.0
  1991. DPS0 DPS/Leitch Reality Motion JPEG
  1992. DPSC DPS/Leitch PAR Motion JPEG
  1993. DV25 Matrox DVCPRO codec
  1994. DV50 Matrox DVCPRO50 codec
  1995. DVC IEC 61834 and SMPTE 314M (DVC/DV Video)
  1996. DVCP IEC 61834 and SMPTE 314M (DVC/DV Video)
  1997. DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps
  1998. DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)
  1999. DVSL IEC Standard DV compressed in SD (SDL)
  2000. DVAN ?DVAN?
  2001. DVE2 InSoft DVE-2 Videoconferencing
  2002. dvsd IEC 61834 and SMPTE 314M DVC/DV Video
  2003. DVSD IEC 61834 and SMPTE 314M DVC/DV Video
  2004. DVX1 Lucent DVX1000SP Video Decoder
  2005. DVX2 Lucent DVX2000S Video Decoder
  2006. DVX3 Lucent DVX3000S Video Decoder
  2007. DX50 DivX v5
  2008. DXT1 Microsoft DirectX Compressed Texture (DXT1)
  2009. DXT2 Microsoft DirectX Compressed Texture (DXT2)
  2010. DXT3 Microsoft DirectX Compressed Texture (DXT3)
  2011. DXT4 Microsoft DirectX Compressed Texture (DXT4)
  2012. DXT5 Microsoft DirectX Compressed Texture (DXT5)
  2013. DXTC Microsoft DirectX Compressed Texture (DXTC)
  2014. DXTn Microsoft DirectX Compressed Texture (DXTn)
  2015. EM2V Etymonix MPEG-2 I-frame (www.etymonix.com)
  2016. EKQ0 Elsa ?EKQ0?
  2017. ELK0 Elsa ?ELK0?
  2018. ESCP Eidos Escape
  2019. ETV1 eTreppid Video ETV1
  2020. ETV2 eTreppid Video ETV2
  2021. ETVC eTreppid Video ETVC
  2022. FLIC Autodesk FLI/FLC Animation
  2023. FLV1 Sorenson Spark
  2024. FLV4 On2 TrueMotion VP6
  2025. FRWT Darim Vision Forward Motion JPEG (www.darvision.com)
  2026. FRWU Darim Vision Forward Uncompressed (www.darvision.com)
  2027. FLJP D-Vision Field Encoded Motion JPEG
  2028. FPS1 FRAPS v1
  2029. FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel
  2030. FRWD SoftLab-Nsk Forward Motion JPEG
  2031. FVF1 Iterated Systems Fractal Video Frame
  2032. GLZW Motion LZW (gabest@freemail.hu)
  2033. GPEG Motion JPEG (gabest@freemail.hu)
  2034. GWLT Microsoft Greyscale WLT DIB
  2035. H260 Intel ITU H.260 Videoconferencing
  2036. H261 Intel ITU H.261 Videoconferencing
  2037. H262 Intel ITU H.262 Videoconferencing
  2038. H263 Intel ITU H.263 Videoconferencing
  2039. H264 Intel ITU H.264 Videoconferencing
  2040. H265 Intel ITU H.265 Videoconferencing
  2041. H266 Intel ITU H.266 Videoconferencing
  2042. H267 Intel ITU H.267 Videoconferencing
  2043. H268 Intel ITU H.268 Videoconferencing
  2044. H269 Intel ITU H.269 Videoconferencing
  2045. HFYU Huffman Lossless Codec
  2046. HMCR Rendition Motion Compensation Format (HMCR)
  2047. HMRR Rendition Motion Compensation Format (HMRR)
  2048. I263 FFmpeg I263 decoder
  2049. IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")
  2050. IUYV Interlaced version of UYVY (www.leadtools.com)
  2051. IY41 Interlaced version of Y41P (www.leadtools.com)
  2052. IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
  2053. IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
  2054. IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes)
  2055. i263 Intel ITU H.263 Videoconferencing (i263)
  2056. I420 Intel Indeo 4
  2057. IAN Intel Indeo 4 (RDX)
  2058. ICLB InSoft CellB Videoconferencing
  2059. IGOR Power DVD
  2060. IJPG Intergraph JPEG
  2061. ILVC Intel Layered Video
  2062. ILVR ITU-T H.263+
  2063. IPDV I-O Data Device Giga AVI DV Codec
  2064. IR21 Intel Indeo 2.1
  2065. IRAW Intel YUV Uncompressed
  2066. IV30 Intel Indeo 3.0
  2067. IV31 Intel Indeo 3.1
  2068. IV32 Ligos Indeo 3.2
  2069. IV33 Ligos Indeo 3.3
  2070. IV34 Ligos Indeo 3.4
  2071. IV35 Ligos Indeo 3.5
  2072. IV36 Ligos Indeo 3.6
  2073. IV37 Ligos Indeo 3.7
  2074. IV38 Ligos Indeo 3.8
  2075. IV39 Ligos Indeo 3.9
  2076. IV40 Ligos Indeo Interactive 4.0
  2077. IV41 Ligos Indeo Interactive 4.1
  2078. IV42 Ligos Indeo Interactive 4.2
  2079. IV43 Ligos Indeo Interactive 4.3
  2080. IV44 Ligos Indeo Interactive 4.4
  2081. IV45 Ligos Indeo Interactive 4.5
  2082. IV46 Ligos Indeo Interactive 4.6
  2083. IV47 Ligos Indeo Interactive 4.7
  2084. IV48 Ligos Indeo Interactive 4.8
  2085. IV49 Ligos Indeo Interactive 4.9
  2086. IV50 Ligos Indeo Interactive 5.0
  2087. JBYR Kensington ?JBYR?
  2088. JPEG Still Image JPEG DIB
  2089. JPGL Pegasus Lossless Motion JPEG
  2090. KMVC Team17 Software Karl Morton\'s Video Codec
  2091. LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)
  2092. LEAD LEAD Video Codec
  2093. Ljpg LEAD MJPEG Codec
  2094. MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)
  2095. MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)
  2096. MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)
  2097. MMES Matrox MPEG-2 I-frame
  2098. MP2v Microsoft S-Mpeg 4 version 1 (MP2v)
  2099. MP42 Microsoft S-Mpeg 4 version 2 (MP42)
  2100. MP43 Microsoft S-Mpeg 4 version 3 (MP43)
  2101. MP4S Microsoft S-Mpeg 4 version 3 (MP4S)
  2102. MP4V FFmpeg MPEG-4
  2103. MPG1 FFmpeg MPEG 1/2
  2104. MPG2 FFmpeg MPEG 1/2
  2105. MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3)
  2106. MPG4 Microsoft MPEG-4
  2107. MPGI Sigma Designs MPEG
  2108. MPNG PNG images decoder
  2109. MSS1 Microsoft Windows Screen Video
  2110. MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
  2111. M261 Microsoft H.261
  2112. M263 Microsoft H.263
  2113. M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)
  2114. m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)
  2115. MC12 ATI Motion Compensation Format (MC12)
  2116. MCAM ATI Motion Compensation Format (MCAM)
  2117. MJ2C Morgan Multimedia Motion JPEG2000
  2118. mJPG IBM Motion JPEG w/ Huffman Tables
  2119. MJPG Microsoft Motion JPEG DIB
  2120. MP42 Microsoft MPEG-4 (low-motion)
  2121. MP43 Microsoft MPEG-4 (fast-motion)
  2122. MP4S Microsoft MPEG-4 (MP4S)
  2123. mp4s Microsoft MPEG-4 (mp4s)
  2124. MPEG Chromatic Research MPEG-1 Video I-Frame
  2125. MPG4 Microsoft MPEG-4 Video High Speed Compressor
  2126. MPGI Sigma Designs MPEG
  2127. MRCA FAST Multimedia Martin Regen Codec
  2128. MRLE Microsoft Run Length Encoding
  2129. MSVC Microsoft Video 1
  2130. MTX1 Matrox ?MTX1?
  2131. MTX2 Matrox ?MTX2?
  2132. MTX3 Matrox ?MTX3?
  2133. MTX4 Matrox ?MTX4?
  2134. MTX5 Matrox ?MTX5?
  2135. MTX6 Matrox ?MTX6?
  2136. MTX7 Matrox ?MTX7?
  2137. MTX8 Matrox ?MTX8?
  2138. MTX9 Matrox ?MTX9?
  2139. MV12 Motion Pixels Codec (old)
  2140. MWV1 Aware Motion Wavelets
  2141. nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)
  2142. NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)
  2143. NUV1 NuppelVideo
  2144. NTN1 Nogatech Video Compression 1
  2145. NVS0 nVidia GeForce Texture (NVS0)
  2146. NVS1 nVidia GeForce Texture (NVS1)
  2147. NVS2 nVidia GeForce Texture (NVS2)
  2148. NVS3 nVidia GeForce Texture (NVS3)
  2149. NVS4 nVidia GeForce Texture (NVS4)
  2150. NVS5 nVidia GeForce Texture (NVS5)
  2151. NVT0 nVidia GeForce Texture (NVT0)
  2152. NVT1 nVidia GeForce Texture (NVT1)
  2153. NVT2 nVidia GeForce Texture (NVT2)
  2154. NVT3 nVidia GeForce Texture (NVT3)
  2155. NVT4 nVidia GeForce Texture (NVT4)
  2156. NVT5 nVidia GeForce Texture (NVT5)
  2157. PIXL MiroXL, Pinnacle PCTV
  2158. PDVC I-O Data Device Digital Video Capture DV codec
  2159. PGVV Radius Video Vision
  2160. PHMO IBM Photomotion
  2161. PIM1 MPEG Realtime (Pinnacle Cards)
  2162. PIM2 Pegasus Imaging ?PIM2?
  2163. PIMJ Pegasus Imaging Lossless JPEG
  2164. PVEZ Horizons Technology PowerEZ
  2165. PVMM PacketVideo Corporation MPEG-4
  2166. PVW2 Pegasus Imaging Wavelet Compression
  2167. Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de)
  2168. Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de)
  2169. QPEG Q-Team QPEG 1.0
  2170. qpeq Q-Team QPEG 1.1
  2171. RGB Raw BGR32
  2172. RGBA Raw RGB w/ Alpha
  2173. RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)
  2174. ROQV Id RoQ File Video Decoder
  2175. RPZA Quicktime Apple Video (RPZA)
  2176. RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/)
  2177. RV10 RealVideo 1.0 (aka RealVideo 5.0)
  2178. RV13 RealVideo 1.0 (RV13)
  2179. RV20 RealVideo G2
  2180. RV30 RealVideo 8
  2181. RV40 RealVideo 9
  2182. RGBT Raw RGB w/ Transparency
  2183. RLE Microsoft Run Length Encoder
  2184. RLE4 Run Length Encoded (4bpp, 16-color)
  2185. RLE8 Run Length Encoded (8bpp, 256-color)
  2186. RT21 Intel Indeo RealTime Video 2.1
  2187. rv20 RealVideo G2
  2188. rv30 RealVideo 8
  2189. RVX Intel RDX (RVX )
  2190. SMC Apple Graphics (SMC )
  2191. SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2
  2192. SPIG Radius Spigot
  2193. SVQ3 Sorenson Video 3 (Apple Quicktime 5)
  2194. s422 Tekram VideoCap C210 YUV 4:2:2
  2195. SDCC Sun Communication Digital Camera Codec
  2196. SFMC CrystalNet Surface Fitting Method
  2197. SMSC Radius SMSC
  2198. SMSD Radius SMSD
  2199. smsv WorldConnect Wavelet Video
  2200. SPIG Radius Spigot
  2201. SPLC Splash Studios ACM Audio Codec (www.splashstudios.net)
  2202. SQZ2 Microsoft VXTreme Video Codec V2
  2203. STVA ST Microelectronics CMOS Imager Data (Bayer)
  2204. STVB ST Microelectronics CMOS Imager Data (Nudged Bayer)
  2205. STVC ST Microelectronics CMOS Imager Data (Bunched)
  2206. STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)
  2207. STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)
  2208. SV10 Sorenson Video R1
  2209. SVQ1 Sorenson Video
  2210. T420 Toshiba YUV 4:2:0
  2211. TM2A Duck TrueMotion Archiver 2.0 (www.duck.com)
  2212. TVJP Pinnacle/Truevision Targa 2000 board (TVJP)
  2213. TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ)
  2214. TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com)
  2215. TY2C Trident Decompression Driver
  2216. TLMS TeraLogic Motion Intraframe Codec (TLMS)
  2217. TLST TeraLogic Motion Intraframe Codec (TLST)
  2218. TM20 Duck TrueMotion 2.0
  2219. TM2X Duck TrueMotion 2X
  2220. TMIC TeraLogic Motion Intraframe Codec (TMIC)
  2221. TMOT Horizons Technology TrueMotion S
  2222. tmot Horizons TrueMotion Video Compression
  2223. TR20 Duck TrueMotion RealTime 2.0
  2224. TSCC TechSmith Screen Capture Codec
  2225. TV10 Tecomac Low-Bit Rate Codec
  2226. TY2N Trident ?TY2N?
  2227. U263 UB Video H.263/H.263+/H.263++ Decoder
  2228. UMP4 UB Video MPEG 4 (www.ubvideo.com)
  2229. UYNV Nvidia UYVY packed 4:2:2
  2230. UYVP Evans & Sutherland YCbCr 4:2:2 extended precision
  2231. UCOD eMajix.com ClearVideo
  2232. ULTI IBM Ultimotion
  2233. UYVY UYVY packed 4:2:2
  2234. V261 Lucent VX2000S
  2235. VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/)
  2236. VIV1 FFmpeg H263+ decoder
  2237. VIV2 Vivo H.263
  2238. VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)
  2239. VTLP Alaris VideoGramPiX
  2240. VYU9 ATI YUV (VYU9)
  2241. VYUY ATI YUV (VYUY)
  2242. V261 Lucent VX2000S
  2243. V422 Vitec Multimedia 24-bit YUV 4:2:2 Format
  2244. V655 Vitec Multimedia 16-bit YUV 4:2:2 Format
  2245. VCR1 ATI Video Codec 1
  2246. VCR2 ATI Video Codec 2
  2247. VCR3 ATI VCR 3.0
  2248. VCR4 ATI VCR 4.0
  2249. VCR5 ATI VCR 5.0
  2250. VCR6 ATI VCR 6.0
  2251. VCR7 ATI VCR 7.0
  2252. VCR8 ATI VCR 8.0
  2253. VCR9 ATI VCR 9.0
  2254. VDCT Vitec Multimedia Video Maker Pro DIB
  2255. VDOM VDOnet VDOWave
  2256. VDOW VDOnet VDOLive (H.263)
  2257. VDTZ Darim Vison VideoTizer YUV
  2258. VGPX Alaris VideoGramPiX
  2259. VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422
  2260. VIVO Vivo H.263 v2.00
  2261. vivo Vivo H.263
  2262. VIXL Miro/Pinnacle Video XL
  2263. VLV1 VideoLogic/PURE Digital Videologic Capture
  2264. VP30 On2 VP3.0
  2265. VP31 On2 VP3.1
  2266. VP6F On2 TrueMotion VP6
  2267. VX1K Lucent VX1000S Video Codec
  2268. VX2K Lucent VX2000S Video Codec
  2269. VXSP Lucent VX1000SP Video Codec
  2270. WBVC Winbond W9960
  2271. WHAM Microsoft Video 1 (WHAM)
  2272. WINX Winnov Software Compression
  2273. WJPG AverMedia Winbond JPEG
  2274. WMV1 Windows Media Video V7
  2275. WMV2 Windows Media Video V8
  2276. WMV3 Windows Media Video V9
  2277. WNV1 Winnov Hardware Compression
  2278. XYZP Extended PAL format XYZ palette (www.riff.org)
  2279. x263 Xirlink H.263
  2280. XLV0 NetXL Video Decoder
  2281. XMPG Xing MPEG (I-Frame only)
  2282. XVID XviD MPEG-4 (www.xvid.org)
  2283. XXAN ?XXAN?
  2284. YU92 Intel YUV (YU92)
  2285. YUNV Nvidia Uncompressed YUV 4:2:2
  2286. YUVP Extended PAL format YUV palette (www.riff.org)
  2287. Y211 YUV 2:1:1 Packed
  2288. Y411 YUV 4:1:1 Packed
  2289. Y41B Weitek YUV 4:1:1 Planar
  2290. Y41P Brooktree PC1 YUV 4:1:1 Packed
  2291. Y41T Brooktree PC1 YUV 4:1:1 with transparency
  2292. Y42B Weitek YUV 4:2:2 Planar
  2293. Y42T Brooktree UYUV 4:2:2 with transparency
  2294. Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera
  2295. Y800 Simple, single Y plane for monochrome images
  2296. Y8 Grayscale video
  2297. YC12 Intel YUV 12 codec
  2298. YUV8 Winnov Caviar YUV8
  2299. YUV9 Intel YUV9
  2300. YUY2 Uncompressed YUV 4:2:2
  2301. YUYV Canopus YUV
  2302. YV12 YVU12 Planar
  2303. YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)
  2304. YVYU YVYU 4:2:2 Packed
  2305. ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
  2306. ZPEG Metheus Video Zipper
  2307. */
  2308. return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc');
  2309. }
  2310. private function EitherEndian2Int($byteword, $signed=false) {
  2311. if ($this->container == 'riff') {
  2312. return getid3_lib::LittleEndian2Int($byteword, $signed);
  2313. }
  2314. return getid3_lib::BigEndian2Int($byteword, false, $signed);
  2315. }
  2316. }