module.audio-video.riff.php 136 KB

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