module.audio-video.riff.php 120 KB

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