PageRenderTime 67ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Vendor/getid3/module.audio-video.riff.php

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