module.audio-video.riff.php 131 KB

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