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

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

https://bitbucket.org/nova-atlantis/simple-server-media-player
PHP | 2246 lines | 1853 code | 222 blank | 171 comment | 182 complexity | 272dfd6e4c391f20611a11d921e66eeb 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.quicktime.php //
  12. // module for analyzing Quicktime and MP3-in-MP4 files //
  13. // dependencies: module.audio.mp3.php //
  14. // dependencies: module.tag.id3v2.php //
  15. // ///
  16. /////////////////////////////////////////////////////////////////
  17. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  18. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup
  19. class getid3_quicktime extends getid3_handler
  20. {
  21. public $ReturnAtomData = true;
  22. public $ParseAllPossibleAtoms = false;
  23. public function Analyze() {
  24. $info = &$this->getid3->info;
  25. $info['fileformat'] = 'quicktime';
  26. $info['quicktime']['hinting'] = false;
  27. $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
  28. $this->fseek($info['avdataoffset']);
  29. $offset = 0;
  30. $atomcounter = 0;
  31. $atom_data_read_buffer_size = ($info['php_memory_limit'] ? round($info['php_memory_limit'] / 2) : $this->getid3->option_fread_buffer_size * 1024); // allow [default: 32MB] if PHP configured with no memory_limit
  32. while ($offset < $info['avdataend']) {
  33. if (!getid3_lib::intValueSupported($offset)) {
  34. $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
  35. break;
  36. }
  37. $this->fseek($offset);
  38. $AtomHeader = $this->fread(8);
  39. $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
  40. $atomname = substr($AtomHeader, 4, 4);
  41. // 64-bit MOV patch by jlegateØktnc*com
  42. if ($atomsize == 1) {
  43. $atomsize = getid3_lib::BigEndian2Int($this->fread(8));
  44. }
  45. $info['quicktime'][$atomname]['name'] = $atomname;
  46. $info['quicktime'][$atomname]['size'] = $atomsize;
  47. $info['quicktime'][$atomname]['offset'] = $offset;
  48. if (($offset + $atomsize) > $info['avdataend']) {
  49. $info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
  50. return false;
  51. }
  52. if ($atomsize == 0) {
  53. // Furthermore, for historical reasons the list of atoms is optionally
  54. // terminated by a 32-bit integer set to 0. If you are writing a program
  55. // to read user data atoms, you should allow for the terminating 0.
  56. break;
  57. }
  58. $atomHierarchy = array();
  59. $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
  60. $offset += $atomsize;
  61. $atomcounter++;
  62. }
  63. if (!empty($info['avdataend_tmp'])) {
  64. // this value is assigned to a temp value and then erased because
  65. // otherwise any atoms beyond the 'mdat' atom would not get parsed
  66. $info['avdataend'] = $info['avdataend_tmp'];
  67. unset($info['avdataend_tmp']);
  68. }
  69. if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
  70. $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  71. }
  72. if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
  73. $info['audio']['bitrate'] = $info['bitrate'];
  74. }
  75. if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
  76. foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
  77. $samples_per_second = $samples_count / $info['playtime_seconds'];
  78. if ($samples_per_second > 240) {
  79. // has to be audio samples
  80. } else {
  81. $info['video']['frame_rate'] = $samples_per_second;
  82. break;
  83. }
  84. }
  85. }
  86. if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
  87. $info['fileformat'] = 'mp4';
  88. $info['mime_type'] = 'audio/mp4';
  89. unset($info['video']['dataformat']);
  90. }
  91. if (!$this->ReturnAtomData) {
  92. unset($info['quicktime']['moov']);
  93. }
  94. if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
  95. $info['audio']['dataformat'] = 'quicktime';
  96. }
  97. if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
  98. $info['video']['dataformat'] = 'quicktime';
  99. }
  100. return true;
  101. }
  102. public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  103. // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
  104. $info = &$this->getid3->info;
  105. $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717
  106. array_push($atomHierarchy, $atomname);
  107. $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
  108. $atom_structure['name'] = $atomname;
  109. $atom_structure['size'] = $atomsize;
  110. $atom_structure['offset'] = $baseoffset;
  111. switch ($atomname) {
  112. case 'moov': // MOVie container atom
  113. case 'trak': // TRAcK container atom
  114. case 'clip': // CLIPping container atom
  115. case 'matt': // track MATTe container atom
  116. case 'edts': // EDiTS container atom
  117. case 'tref': // Track REFerence container atom
  118. case 'mdia': // MeDIA container atom
  119. case 'minf': // Media INFormation container atom
  120. case 'dinf': // Data INFormation container atom
  121. case 'udta': // User DaTA container atom
  122. case 'cmov': // Compressed MOVie container atom
  123. case 'rmra': // Reference Movie Record Atom
  124. case 'rmda': // Reference Movie Descriptor Atom
  125. case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
  126. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  127. break;
  128. case 'ilst': // Item LiST container atom
  129. if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) {
  130. // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
  131. $allnumericnames = true;
  132. foreach ($atom_structure['subatoms'] as $subatomarray) {
  133. if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
  134. $allnumericnames = false;
  135. break;
  136. }
  137. }
  138. if ($allnumericnames) {
  139. $newData = array();
  140. foreach ($atom_structure['subatoms'] as $subatomarray) {
  141. foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
  142. unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
  143. $newData[$subatomarray['name']] = $newData_subatomarray;
  144. break;
  145. }
  146. }
  147. $atom_structure['data'] = $newData;
  148. unset($atom_structure['subatoms']);
  149. }
  150. }
  151. break;
  152. case "\x00\x00\x00\x01":
  153. case "\x00\x00\x00\x02":
  154. case "\x00\x00\x00\x03":
  155. case "\x00\x00\x00\x04":
  156. case "\x00\x00\x00\x05":
  157. $atomname = getid3_lib::BigEndian2Int($atomname);
  158. $atom_structure['name'] = $atomname;
  159. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  160. break;
  161. case 'stbl': // Sample TaBLe container atom
  162. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  163. $isVideo = false;
  164. $framerate = 0;
  165. $framecount = 0;
  166. foreach ($atom_structure['subatoms'] as $key => $value_array) {
  167. if (isset($value_array['sample_description_table'])) {
  168. foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
  169. if (isset($value_array2['data_format'])) {
  170. switch ($value_array2['data_format']) {
  171. case 'avc1':
  172. case 'mp4v':
  173. // video data
  174. $isVideo = true;
  175. break;
  176. case 'mp4a':
  177. // audio data
  178. break;
  179. }
  180. }
  181. }
  182. } elseif (isset($value_array['time_to_sample_table'])) {
  183. foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
  184. if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
  185. $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
  186. $framecount = $value_array2['sample_count'];
  187. }
  188. }
  189. }
  190. }
  191. if ($isVideo && $framerate) {
  192. $info['quicktime']['video']['frame_rate'] = $framerate;
  193. $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
  194. }
  195. if ($isVideo && $framecount) {
  196. $info['quicktime']['video']['frame_count'] = $framecount;
  197. }
  198. break;
  199. case 'aART': // Album ARTist
  200. case 'catg': // CaTeGory
  201. case 'covr': // COVeR artwork
  202. case 'cpil': // ComPILation
  203. case 'cprt': // CoPyRighT
  204. case 'desc': // DESCription
  205. case 'disk': // DISK number
  206. case 'egid': // Episode Global ID
  207. case 'gnre': // GeNRE
  208. case 'keyw': // KEYWord
  209. case 'ldes':
  210. case 'pcst': // PodCaST
  211. case 'pgap': // GAPless Playback
  212. case 'purd': // PURchase Date
  213. case 'purl': // Podcast URL
  214. case 'rati':
  215. case 'rndu':
  216. case 'rpdu':
  217. case 'rtng': // RaTiNG
  218. case 'stik':
  219. case 'tmpo': // TeMPO (BPM)
  220. case 'trkn': // TRacK Number
  221. case 'tves': // TV EpiSode
  222. case 'tvnn': // TV Network Name
  223. case 'tvsh': // TV SHow Name
  224. case 'tvsn': // TV SeasoN
  225. case 'akID': // iTunes store account type
  226. case 'apID':
  227. case 'atID':
  228. case 'cmID':
  229. case 'cnID':
  230. case 'geID':
  231. case 'plID':
  232. case 'sfID': // iTunes store country
  233. case "\xA9".'alb': // ALBum
  234. case "\xA9".'art': // ARTist
  235. case "\xA9".'ART':
  236. case "\xA9".'aut':
  237. case "\xA9".'cmt': // CoMmenT
  238. case "\xA9".'com': // COMposer
  239. case "\xA9".'cpy':
  240. case "\xA9".'day': // content created year
  241. case "\xA9".'dir':
  242. case "\xA9".'ed1':
  243. case "\xA9".'ed2':
  244. case "\xA9".'ed3':
  245. case "\xA9".'ed4':
  246. case "\xA9".'ed5':
  247. case "\xA9".'ed6':
  248. case "\xA9".'ed7':
  249. case "\xA9".'ed8':
  250. case "\xA9".'ed9':
  251. case "\xA9".'enc':
  252. case "\xA9".'fmt':
  253. case "\xA9".'gen': // GENre
  254. case "\xA9".'grp': // GRouPing
  255. case "\xA9".'hst':
  256. case "\xA9".'inf':
  257. case "\xA9".'lyr': // LYRics
  258. case "\xA9".'mak':
  259. case "\xA9".'mod':
  260. case "\xA9".'nam': // full NAMe
  261. case "\xA9".'ope':
  262. case "\xA9".'PRD':
  263. case "\xA9".'prd':
  264. case "\xA9".'prf':
  265. case "\xA9".'req':
  266. case "\xA9".'src':
  267. case "\xA9".'swr':
  268. case "\xA9".'too': // encoder
  269. case "\xA9".'trk': // TRacK
  270. case "\xA9".'url':
  271. case "\xA9".'wrn':
  272. case "\xA9".'wrt': // WRiTer
  273. case '----': // itunes specific
  274. if ($atom_parent == 'udta') {
  275. // User data atom handler
  276. $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  277. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
  278. $atom_structure['data'] = substr($atom_data, 4);
  279. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  280. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  281. $info['comments']['language'][] = $atom_structure['language'];
  282. }
  283. } else {
  284. // Apple item list box atom handler
  285. $atomoffset = 0;
  286. if (substr($atom_data, 2, 2) == "\x10\xB5") {
  287. // not sure what it means, but observed on iPhone4 data.
  288. // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
  289. while ($atomoffset < strlen($atom_data)) {
  290. $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2));
  291. $boxsmalltype = substr($atom_data, $atomoffset + 2, 2);
  292. $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize);
  293. if ($boxsmallsize <= 1) {
  294. $info['warning'][] = 'Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
  295. $atom_structure['data'] = null;
  296. $atomoffset = strlen($atom_data);
  297. break;
  298. }
  299. switch ($boxsmalltype) {
  300. case "\x10\xB5":
  301. $atom_structure['data'] = $boxsmalldata;
  302. break;
  303. default:
  304. $info['warning'][] = 'Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset;
  305. $atom_structure['data'] = $atom_data;
  306. break;
  307. }
  308. $atomoffset += (4 + $boxsmallsize);
  309. }
  310. } else {
  311. while ($atomoffset < strlen($atom_data)) {
  312. $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
  313. $boxtype = substr($atom_data, $atomoffset + 4, 4);
  314. $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8);
  315. if ($boxsize <= 1) {
  316. $info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
  317. $atom_structure['data'] = null;
  318. $atomoffset = strlen($atom_data);
  319. break;
  320. }
  321. $atomoffset += $boxsize;
  322. switch ($boxtype) {
  323. case 'mean':
  324. case 'name':
  325. $atom_structure[$boxtype] = substr($boxdata, 4);
  326. break;
  327. case 'data':
  328. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1));
  329. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3));
  330. switch ($atom_structure['flags_raw']) {
  331. case 0: // data flag
  332. case 21: // tmpo/cpil flag
  333. switch ($atomname) {
  334. case 'cpil':
  335. case 'pcst':
  336. case 'pgap':
  337. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  338. break;
  339. case 'tmpo':
  340. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
  341. break;
  342. case 'disk':
  343. case 'trkn':
  344. $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
  345. $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
  346. $atom_structure['data'] = empty($num) ? '' : $num;
  347. $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
  348. break;
  349. case 'gnre':
  350. $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  351. $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1);
  352. break;
  353. case 'rtng':
  354. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  355. $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
  356. break;
  357. case 'stik':
  358. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  359. $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
  360. break;
  361. case 'sfID':
  362. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  363. $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
  364. break;
  365. case 'egid':
  366. case 'purl':
  367. $atom_structure['data'] = substr($boxdata, 8);
  368. break;
  369. default:
  370. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  371. }
  372. break;
  373. case 1: // text flag
  374. case 13: // image flag
  375. default:
  376. $atom_structure['data'] = substr($boxdata, 8);
  377. if ($atomname == 'covr') {
  378. // not a foolproof check, but better than nothing
  379. if (preg_match('#^\xFF\xD8\xFF#', $atom_structure['data'])) {
  380. $atom_structure['image_mime'] = 'image/jpeg';
  381. } elseif (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $atom_structure['data'])) {
  382. $atom_structure['image_mime'] = 'image/png';
  383. } elseif (preg_match('#^GIF#', $atom_structure['data'])) {
  384. $atom_structure['image_mime'] = 'image/gif';
  385. }
  386. }
  387. break;
  388. }
  389. break;
  390. default:
  391. $info['warning'][] = 'Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset;
  392. $atom_structure['data'] = $atom_data;
  393. }
  394. }
  395. }
  396. }
  397. $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
  398. break;
  399. case 'play': // auto-PLAY atom
  400. $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  401. $info['quicktime']['autoplay'] = $atom_structure['autoplay'];
  402. break;
  403. case 'WLOC': // Window LOCation atom
  404. $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  405. $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
  406. break;
  407. case 'LOOP': // LOOPing atom
  408. case 'SelO': // play SELection Only atom
  409. case 'AllF': // play ALL Frames atom
  410. $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
  411. break;
  412. case 'name': //
  413. case 'MCPS': // Media Cleaner PRo
  414. case '@PRM': // adobe PReMiere version
  415. case '@PRQ': // adobe PRemiere Quicktime version
  416. $atom_structure['data'] = $atom_data;
  417. break;
  418. case 'cmvd': // Compressed MooV Data atom
  419. // Code by ubergeekØubergeek*tv based on information from
  420. // http://developer.apple.com/quicktime/icefloe/dispatch012.html
  421. $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  422. $CompressedFileData = substr($atom_data, 4);
  423. if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
  424. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
  425. } else {
  426. $info['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset'];
  427. }
  428. break;
  429. case 'dcom': // Data COMpression atom
  430. $atom_structure['compression_id'] = $atom_data;
  431. $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
  432. break;
  433. case 'rdrf': // Reference movie Data ReFerence atom
  434. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  435. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  436. $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
  437. $atom_structure['reference_type_name'] = substr($atom_data, 4, 4);
  438. $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  439. switch ($atom_structure['reference_type_name']) {
  440. case 'url ':
  441. $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
  442. break;
  443. case 'alis':
  444. $atom_structure['file_alias'] = substr($atom_data, 12);
  445. break;
  446. case 'rsrc':
  447. $atom_structure['resource_alias'] = substr($atom_data, 12);
  448. break;
  449. default:
  450. $atom_structure['data'] = substr($atom_data, 12);
  451. break;
  452. }
  453. break;
  454. case 'rmqu': // Reference Movie QUality atom
  455. $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
  456. break;
  457. case 'rmcs': // Reference Movie Cpu Speed atom
  458. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  459. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  460. $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  461. break;
  462. case 'rmvc': // Reference Movie Version Check atom
  463. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  464. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  465. $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4);
  466. $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  467. $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  468. $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
  469. break;
  470. case 'rmcd': // Reference Movie Component check atom
  471. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  472. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  473. $atom_structure['component_type'] = substr($atom_data, 4, 4);
  474. $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
  475. $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
  476. $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  477. $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  478. $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
  479. break;
  480. case 'rmdr': // Reference Movie Data Rate atom
  481. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  482. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  483. $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  484. $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
  485. break;
  486. case 'rmla': // Reference Movie Language Atom
  487. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  488. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  489. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  490. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  491. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  492. $info['comments']['language'][] = $atom_structure['language'];
  493. }
  494. break;
  495. case 'rmla': // Reference Movie Language Atom
  496. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  497. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  498. $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  499. break;
  500. case 'ptv ': // Print To Video - defines a movie's full screen mode
  501. // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
  502. $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  503. $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
  504. $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
  505. $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
  506. $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
  507. $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
  508. $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
  509. $ptv_lookup[0] = 'normal';
  510. $ptv_lookup[1] = 'double';
  511. $ptv_lookup[2] = 'half';
  512. $ptv_lookup[3] = 'full';
  513. $ptv_lookup[4] = 'current';
  514. if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
  515. $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
  516. } else {
  517. $info['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')';
  518. }
  519. break;
  520. case 'stsd': // Sample Table Sample Description atom
  521. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  522. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  523. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  524. $stsdEntriesDataOffset = 8;
  525. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  526. $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
  527. $stsdEntriesDataOffset += 4;
  528. $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4);
  529. $stsdEntriesDataOffset += 4;
  530. $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
  531. $stsdEntriesDataOffset += 6;
  532. $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
  533. $stsdEntriesDataOffset += 2;
  534. $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
  535. $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
  536. $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2));
  537. $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2));
  538. $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4);
  539. switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
  540. case "\x00\x00\x00\x00":
  541. // audio tracks
  542. $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2));
  543. $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2));
  544. $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2));
  545. $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2));
  546. $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
  547. // video tracks
  548. // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
  549. $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
  550. $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
  551. $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
  552. $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
  553. $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
  554. $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
  555. $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4));
  556. $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2));
  557. $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4);
  558. $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2));
  559. $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2));
  560. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  561. case '2vuY':
  562. case 'avc1':
  563. case 'cvid':
  564. case 'dvc ':
  565. case 'dvcp':
  566. case 'gif ':
  567. case 'h263':
  568. case 'jpeg':
  569. case 'kpcd':
  570. case 'mjpa':
  571. case 'mjpb':
  572. case 'mp4v':
  573. case 'png ':
  574. case 'raw ':
  575. case 'rle ':
  576. case 'rpza':
  577. case 'smc ':
  578. case 'SVQ1':
  579. case 'SVQ3':
  580. case 'tiff':
  581. case 'v210':
  582. case 'v216':
  583. case 'v308':
  584. case 'v408':
  585. case 'v410':
  586. case 'yuv2':
  587. $info['fileformat'] = 'mp4';
  588. $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
  589. // http://www.getid3.org/phpBB3/viewtopic.php?t=1550
  590. //if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers
  591. if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) {
  592. // assume that values stored here are more important than values stored in [tkhd] atom
  593. $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width'];
  594. $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height'];
  595. $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
  596. $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
  597. }
  598. break;
  599. case 'qtvr':
  600. $info['video']['dataformat'] = 'quicktimevr';
  601. break;
  602. case 'mp4a':
  603. default:
  604. $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
  605. $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
  606. $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
  607. $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
  608. $info['audio']['codec'] = $info['quicktime']['audio']['codec'];
  609. $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate'];
  610. $info['audio']['channels'] = $info['quicktime']['audio']['channels'];
  611. $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth'];
  612. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  613. case 'raw ': // PCM
  614. case 'alac': // Apple Lossless Audio Codec
  615. $info['audio']['lossless'] = true;
  616. break;
  617. default:
  618. $info['audio']['lossless'] = false;
  619. break;
  620. }
  621. break;
  622. }
  623. break;
  624. default:
  625. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  626. case 'mp4s':
  627. $info['fileformat'] = 'mp4';
  628. break;
  629. default:
  630. // video atom
  631. $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
  632. $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
  633. $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
  634. $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
  635. $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
  636. $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
  637. $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
  638. $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2));
  639. $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1));
  640. $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']);
  641. $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
  642. $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
  643. $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
  644. $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
  645. if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
  646. $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
  647. $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
  648. $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']);
  649. $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
  650. $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
  651. $info['video']['codec'] = $info['quicktime']['video']['codec'];
  652. $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
  653. }
  654. $info['video']['lossless'] = false;
  655. $info['video']['pixel_aspect_ratio'] = (float) 1;
  656. break;
  657. }
  658. break;
  659. }
  660. switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
  661. case 'mp4a':
  662. $info['audio']['dataformat'] = 'mp4';
  663. $info['quicktime']['audio']['codec'] = 'mp4';
  664. break;
  665. case '3ivx':
  666. case '3iv1':
  667. case '3iv2':
  668. $info['video']['dataformat'] = '3ivx';
  669. break;
  670. case 'xvid':
  671. $info['video']['dataformat'] = 'xvid';
  672. break;
  673. case 'mp4v':
  674. $info['video']['dataformat'] = 'mpeg4';
  675. break;
  676. case 'divx':
  677. case 'div1':
  678. case 'div2':
  679. case 'div3':
  680. case 'div4':
  681. case 'div5':
  682. case 'div6':
  683. $info['video']['dataformat'] = 'divx';
  684. break;
  685. default:
  686. // do nothing
  687. break;
  688. }
  689. unset($atom_structure['sample_description_table'][$i]['data']);
  690. }
  691. break;
  692. case 'stts': // Sample Table Time-to-Sample atom
  693. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  694. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  695. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  696. $sttsEntriesDataOffset = 8;
  697. //$FrameRateCalculatorArray = array();
  698. $frames_count = 0;
  699. $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']);
  700. if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
  701. $info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($atom_structure['number_entries'] / 1048576).'MB).';
  702. }
  703. for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
  704. $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
  705. $sttsEntriesDataOffset += 4;
  706. $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
  707. $sttsEntriesDataOffset += 4;
  708. $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
  709. // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
  710. //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
  711. // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
  712. // if ($stts_new_framerate <= 60) {
  713. // // some atoms have durations of "1" giving a very large framerate, which probably is not right
  714. // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
  715. // }
  716. //}
  717. //
  718. //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
  719. }
  720. $info['quicktime']['stts_framecount'][] = $frames_count;
  721. //$sttsFramesTotal = 0;
  722. //$sttsSecondsTotal = 0;
  723. //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
  724. // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
  725. // // not video FPS information, probably audio information
  726. // $sttsFramesTotal = 0;
  727. // $sttsSecondsTotal = 0;
  728. // break;
  729. // }
  730. // $sttsFramesTotal += $frame_count;
  731. // $sttsSecondsTotal += $frame_count / $frames_per_second;
  732. //}
  733. //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
  734. // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
  735. // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
  736. // }
  737. //}
  738. break;
  739. case 'stss': // Sample Table Sync Sample (key frames) atom
  740. if ($ParseAllPossibleAtoms) {
  741. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  742. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  743. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  744. $stssEntriesDataOffset = 8;
  745. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  746. $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
  747. $stssEntriesDataOffset += 4;
  748. }
  749. }
  750. break;
  751. case 'stsc': // Sample Table Sample-to-Chunk atom
  752. if ($ParseAllPossibleAtoms) {
  753. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  754. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  755. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  756. $stscEntriesDataOffset = 8;
  757. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  758. $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  759. $stscEntriesDataOffset += 4;
  760. $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  761. $stscEntriesDataOffset += 4;
  762. $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  763. $stscEntriesDataOffset += 4;
  764. }
  765. }
  766. break;
  767. case 'stsz': // Sample Table SiZe atom
  768. if ($ParseAllPossibleAtoms) {
  769. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  770. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  771. $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  772. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  773. $stszEntriesDataOffset = 12;
  774. if ($atom_structure['sample_size'] == 0) {
  775. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  776. $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
  777. $stszEntriesDataOffset += 4;
  778. }
  779. }
  780. }
  781. break;
  782. case 'stco': // Sample Table Chunk Offset atom
  783. if ($ParseAllPossibleAtoms) {
  784. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  785. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  786. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  787. $stcoEntriesDataOffset = 8;
  788. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  789. $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
  790. $stcoEntriesDataOffset += 4;
  791. }
  792. }
  793. break;
  794. case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
  795. if ($ParseAllPossibleAtoms) {
  796. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  797. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  798. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  799. $stcoEntriesDataOffset = 8;
  800. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  801. $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
  802. $stcoEntriesDataOffset += 8;
  803. }
  804. }
  805. break;
  806. case 'dref': // Data REFerence atom
  807. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  808. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  809. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  810. $drefDataOffset = 8;
  811. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  812. $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
  813. $drefDataOffset += 4;
  814. $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4);
  815. $drefDataOffset += 4;
  816. $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1));
  817. $drefDataOffset += 1;
  818. $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000
  819. $drefDataOffset += 3;
  820. $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
  821. $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
  822. $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
  823. }
  824. break;
  825. case 'gmin': // base Media INformation atom
  826. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  827. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  828. $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  829. $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  830. $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
  831. $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
  832. $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
  833. $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
  834. break;
  835. case 'smhd': // Sound Media information HeaDer atom
  836. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  837. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  838. $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  839. $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  840. break;
  841. case 'vmhd': // Video Media information HeaDer atom
  842. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  843. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  844. $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  845. $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  846. $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
  847. $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
  848. $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
  849. break;
  850. case 'hdlr': // HanDLeR reference atom
  851. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  852. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  853. $atom_structure['component_type'] = substr($atom_data, 4, 4);
  854. $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
  855. $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
  856. $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  857. $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  858. $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24));
  859. if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) {
  860. $info['video']['dataformat'] = 'quicktimevr';
  861. }
  862. break;
  863. case 'mdhd': // MeDia HeaDer atom
  864. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  865. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  866. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  867. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  868. $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  869. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  870. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2));
  871. $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2));
  872. if ($atom_structure['time_scale'] == 0) {
  873. $info['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
  874. return false;
  875. }
  876. $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
  877. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  878. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  879. $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
  880. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  881. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  882. $info['comments']['language'][] = $atom_structure['language'];
  883. }
  884. break;
  885. case 'pnot': // Preview atom
  886. $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format"
  887. $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00
  888. $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT'
  889. $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01
  890. $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']);
  891. break;
  892. case 'crgn': // Clipping ReGioN atom
  893. $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box,
  894. $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields
  895. $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region.
  896. break;
  897. case 'load': // track LOAD settings atom
  898. $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  899. $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  900. $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  901. $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  902. $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020);
  903. $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100);
  904. break;
  905. case 'tmcd': // TiMe CoDe atom
  906. case 'chap': // CHAPter list atom
  907. case 'sync': // SYNChronization atom
  908. case 'scpt': // tranSCriPT atom
  909. case 'ssrc': // non-primary SouRCe atom
  910. for ($i = 0; $i < strlen($atom_data); $i += 4) {
  911. @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
  912. }
  913. break;
  914. case 'elst': // Edit LiST atom
  915. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  916. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  917. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  918. for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) {
  919. $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4));
  920. $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4));
  921. $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4));
  922. }
  923. break;
  924. case 'kmat': // compressed MATte atom
  925. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  926. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  927. $atom_structure['matte_data_raw'] = substr($atom_data, 4);
  928. break;
  929. case 'ctab': // Color TABle atom
  930. $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000
  931. $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000
  932. $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
  933. for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
  934. $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2));
  935. $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2));
  936. $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2));
  937. $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2));
  938. }
  939. break;
  940. case 'mvhd': // MoVie HeaDer atom
  941. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  942. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  943. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  944. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  945. $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  946. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  947. $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4));
  948. $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2));
  949. $atom_structure['reserved'] = substr($atom_data, 26, 10);
  950. $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4));
  951. $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
  952. $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4));
  953. $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
  954. $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
  955. $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4));
  956. $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
  957. $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
  958. $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
  959. $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4));
  960. $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4));
  961. $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4));
  962. $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4));
  963. $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4));
  964. $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4));
  965. $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4));
  966. if ($atom_structure['time_scale'] == 0) {
  967. $info['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
  968. return false;
  969. }
  970. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  971. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  972. $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
  973. $info['quicktime']['display_scale'] = $atom_structure['matrix_a'];
  974. $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
  975. break;
  976. case 'tkhd': // TracK HeaDer atom
  977. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  978. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  979. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  980. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  981. $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  982. $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  983. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  984. $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8));
  985. $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2));
  986. $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2));
  987. $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2));
  988. $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
  989. // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html
  990. // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737
  991. $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
  992. $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4));
  993. $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4));
  994. $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
  995. $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4));
  996. $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4));
  997. $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
  998. $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4));
  999. $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4));
  1000. $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4));
  1001. $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4));
  1002. $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001);
  1003. $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002);
  1004. $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004);
  1005. $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008);
  1006. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  1007. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  1008. if ($atom_structure['flags']['enabled'] == 1) {
  1009. if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
  1010. $info['video']['resolution_x'] = $atom_structure['width'];
  1011. $info['video']['resolution_y'] = $atom_structure['height'];
  1012. }
  1013. $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
  1014. $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
  1015. $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
  1016. $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
  1017. } else {
  1018. // see: http://www.getid3.org/phpBB3/viewtopic.php?t=1295
  1019. //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); }
  1020. //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); }
  1021. //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); }
  1022. }
  1023. break;
  1024. case 'iods': // Initial Object DeScriptor atom
  1025. // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h
  1026. // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html
  1027. $offset = 0;
  1028. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1029. $offset += 1;
  1030. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3));
  1031. $offset += 3;
  1032. $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1033. $offset += 1;
  1034. $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
  1035. //$offset already adjusted by quicktime_read_mp4_descr_length()
  1036. $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));
  1037. $offset += 2;
  1038. $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1039. $offset += 1;
  1040. $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1041. $offset += 1;
  1042. $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1043. $offset += 1;
  1044. $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1045. $offset += 1;
  1046. $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1047. $offset += 1;
  1048. $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields
  1049. for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) {
  1050. $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1051. $offset += 1;
  1052. $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
  1053. //$offset already adjusted by quicktime_read_mp4_descr_length()
  1054. $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));
  1055. $offset += 4;
  1056. }
  1057. $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']);
  1058. $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']);
  1059. break;
  1060. case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
  1061. $atom_structure['signature'] = substr($atom_data, 0, 4);
  1062. $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1063. $atom_structure['fourcc'] = substr($atom_data, 8, 4);
  1064. break;
  1065. case 'mdat': // Media DATa atom
  1066. // 'mdat' contains the actual data for the audio/video, possibly also subtitles
  1067. /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */
  1068. // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?)
  1069. $mdat_offset = 0;
  1070. while (true) {
  1071. if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') {
  1072. $mdat_offset += 8;
  1073. } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') {
  1074. $mdat_offset += 8;
  1075. } else {
  1076. break;
  1077. }
  1078. }
  1079. // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field
  1080. while (($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2)))
  1081. && ($chapter_string_length < 1000)
  1082. && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2))
  1083. && preg_match('#^[\x20-\xFF]+$#', substr($atom_data, $mdat_offset + 2, $chapter_string_length), $chapter_matches)) {
  1084. $mdat_offset += (2 + $chapter_string_length);
  1085. @$info['quicktime']['comments']['chapters'][] = $chapter_matches[0];
  1086. }
  1087. if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
  1088. $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8;
  1089. $OldAVDataEnd = $info['avdataend'];
  1090. $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
  1091. $getid3_temp = new getID3();
  1092. $getid3_temp->openfile($this->getid3->filename);
  1093. $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1094. $getid3_temp->info['avdataend'] = $info['avdataend'];
  1095. $getid3_mp3 = new getid3_mp3($getid3_temp);
  1096. if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) {
  1097. $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
  1098. if (!empty($getid3_temp->info['warning'])) {
  1099. foreach ($getid3_temp->info['warning'] as $value) {
  1100. $info['warning'][] = $value;
  1101. }
  1102. }
  1103. if (!empty($getid3_temp->info['mpeg'])) {
  1104. $info['mpeg'] = $getid3_temp->info['mpeg'];
  1105. if (isset($info['mpeg']['audio'])) {
  1106. $info['audio']['dataformat'] = 'mp3';
  1107. $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
  1108. $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  1109. $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
  1110. $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
  1111. $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1112. $info['bitrate'] = $info['audio']['bitrate'];
  1113. }
  1114. }
  1115. }
  1116. unset($getid3_mp3, $getid3_temp);
  1117. $info['avdataend'] = $OldAVDataEnd;
  1118. unset($OldAVDataEnd);
  1119. }
  1120. unset($mdat_offset, $chapter_string_length, $chapter_matches);
  1121. break;
  1122. case 'free': // FREE space atom
  1123. case 'skip': // SKIP atom
  1124. case 'wide': // 64-bit expansion placeholder atom
  1125. // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
  1126. // When writing QuickTime files, it is sometimes necessary to update an atom's size.
  1127. // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
  1128. // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
  1129. // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
  1130. // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
  1131. // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
  1132. // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
  1133. break;
  1134. case 'nsav': // NoSAVe atom
  1135. // http://developer.apple.com/technotes/tn/tn2038.html
  1136. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  1137. break;
  1138. case 'ctyp': // Controller TYPe atom (seen on QTVR)
  1139. // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
  1140. // some controller names are:
  1141. // 0x00 + 'std' for linear movie
  1142. // 'none' for no controls
  1143. $atom_structure['ctyp'] = substr($atom_data, 0, 4);
  1144. $info['quicktime']['controller'] = $atom_structure['ctyp'];
  1145. switch ($atom_structure['ctyp']) {
  1146. case 'qtvr':
  1147. $info['video']['dataformat'] = 'quicktimevr';
  1148. break;
  1149. }
  1150. break;
  1151. case 'pano': // PANOrama track (seen on QTVR)
  1152. $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  1153. break;
  1154. case 'hint': // HINT track
  1155. case 'hinf': //
  1156. case 'hinv': //
  1157. case 'hnti': //
  1158. $info['quicktime']['hinting'] = true;
  1159. break;
  1160. case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
  1161. for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) {
  1162. $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
  1163. }
  1164. break;
  1165. // Observed-but-not-handled atom types are just listed here to prevent warnings being generated
  1166. case 'FXTC': // Something to do with Adobe After Effects (?)
  1167. case 'PrmA':
  1168. case 'code':
  1169. case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
  1170. case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html
  1171. // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838]
  1172. // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html
  1173. // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html
  1174. case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1175. case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1176. case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1177. case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1178. //$atom_structure['data'] = $atom_data;
  1179. break;
  1180. case "\xA9".'xyz': // GPS latitude+longitude+altitude
  1181. $atom_structure['data'] = $atom_data;
  1182. if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
  1183. @list($all, $latitude, $longitude, $altitude) = $matches;
  1184. $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude);
  1185. $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude);
  1186. if (!empty($altitude)) {
  1187. $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude);
  1188. }
  1189. } else {
  1190. $info['warning'][] = 'QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.';
  1191. }
  1192. break;
  1193. case 'NCDT':
  1194. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1195. // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
  1196. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
  1197. break;
  1198. case 'NCTH': // Nikon Camera THumbnail image
  1199. case 'NCVW': // Nikon Camera preVieW image
  1200. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1201. if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) {
  1202. $atom_structure['data'] = $atom_data;
  1203. $atom_structure['image_mime'] = 'image/jpeg';
  1204. $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image'));
  1205. $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']);
  1206. }
  1207. break;
  1208. case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
  1209. $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
  1210. break;
  1211. case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1212. case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1213. case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html
  1214. $atom_structure['data'] = $atom_data;
  1215. break;
  1216. case "\x00\x00\x00\x00":
  1217. case 'meta': // METAdata atom
  1218. // some kind of metacontainer, may contain a big data dump such as:
  1219. // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4
  1220. // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
  1221. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1222. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1223. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  1224. //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  1225. break;
  1226. case 'data': // metaDATA atom
  1227. // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data
  1228. $atom_structure['language'] = substr($atom_data, 4 + 0, 2);
  1229. $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2));
  1230. $atom_structure['data'] = substr($atom_data, 4 + 4);
  1231. break;
  1232. default:
  1233. $info['warning'][] = 'Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset;
  1234. $atom_structure['data'] = $atom_data;
  1235. break;
  1236. }
  1237. array_pop($atomHierarchy);
  1238. return $atom_structure;
  1239. }
  1240. public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  1241. //echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'<br><br>';
  1242. $atom_structure = false;
  1243. $subatomoffset = 0;
  1244. $subatomcounter = 0;
  1245. if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) {
  1246. return false;
  1247. }
  1248. while ($subatomoffset < strlen($atom_data)) {
  1249. $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4));
  1250. $subatomname = substr($atom_data, $subatomoffset + 4, 4);
  1251. $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8);
  1252. if ($subatomsize == 0) {
  1253. // Furthermore, for historical reasons the list of atoms is optionally
  1254. // terminated by a 32-bit integer set to 0. If you are writing a program
  1255. // to read user data atoms, you should allow for the terminating 0.
  1256. return $atom_structure;
  1257. }
  1258. $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
  1259. $subatomoffset += $subatomsize;
  1260. $subatomcounter++;
  1261. }
  1262. return $atom_structure;
  1263. }
  1264. public function quicktime_read_mp4_descr_length($data, &$offset) {
  1265. // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html
  1266. $num_bytes = 0;
  1267. $length = 0;
  1268. do {
  1269. $b = ord(substr($data, $offset++, 1));
  1270. $length = ($length << 7) | ($b & 0x7F);
  1271. } while (($b & 0x80) && ($num_bytes++ < 4));
  1272. return $length;
  1273. }
  1274. public function QuicktimeLanguageLookup($languageid) {
  1275. // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353
  1276. static $QuicktimeLanguageLookup = array();
  1277. if (empty($QuicktimeLanguageLookup)) {
  1278. $QuicktimeLanguageLookup[0] = 'English';
  1279. $QuicktimeLanguageLookup[1] = 'French';
  1280. $QuicktimeLanguageLookup[2] = 'German';
  1281. $QuicktimeLanguageLookup[3] = 'Italian';
  1282. $QuicktimeLanguageLookup[4] = 'Dutch';
  1283. $QuicktimeLanguageLookup[5] = 'Swedish';
  1284. $QuicktimeLanguageLookup[6] = 'Spanish';
  1285. $QuicktimeLanguageLookup[7] = 'Danish';
  1286. $QuicktimeLanguageLookup[8] = 'Portuguese';
  1287. $QuicktimeLanguageLookup[9] = 'Norwegian';
  1288. $QuicktimeLanguageLookup[10] = 'Hebrew';
  1289. $QuicktimeLanguageLookup[11] = 'Japanese';
  1290. $QuicktimeLanguageLookup[12] = 'Arabic';
  1291. $QuicktimeLanguageLookup[13] = 'Finnish';
  1292. $QuicktimeLanguageLookup[14] = 'Greek';
  1293. $QuicktimeLanguageLookup[15] = 'Icelandic';
  1294. $QuicktimeLanguageLookup[16] = 'Maltese';
  1295. $QuicktimeLanguageLookup[17] = 'Turkish';
  1296. $QuicktimeLanguageLookup[18] = 'Croatian';
  1297. $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
  1298. $QuicktimeLanguageLookup[20] = 'Urdu';
  1299. $QuicktimeLanguageLookup[21] = 'Hindi';
  1300. $QuicktimeLanguageLookup[22] = 'Thai';
  1301. $QuicktimeLanguageLookup[23] = 'Korean';
  1302. $QuicktimeLanguageLookup[24] = 'Lithuanian';
  1303. $QuicktimeLanguageLookup[25] = 'Polish';
  1304. $QuicktimeLanguageLookup[26] = 'Hungarian';
  1305. $QuicktimeLanguageLookup[27] = 'Estonian';
  1306. $QuicktimeLanguageLookup[28] = 'Lettish';
  1307. $QuicktimeLanguageLookup[28] = 'Latvian';
  1308. $QuicktimeLanguageLookup[29] = 'Saamisk';
  1309. $QuicktimeLanguageLookup[29] = 'Lappish';
  1310. $QuicktimeLanguageLookup[30] = 'Faeroese';
  1311. $QuicktimeLanguageLookup[31] = 'Farsi';
  1312. $QuicktimeLanguageLookup[31] = 'Persian';
  1313. $QuicktimeLanguageLookup[32] = 'Russian';
  1314. $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
  1315. $QuicktimeLanguageLookup[34] = 'Flemish';
  1316. $QuicktimeLanguageLookup[35] = 'Irish';
  1317. $QuicktimeLanguageLookup[36] = 'Albanian';
  1318. $QuicktimeLanguageLookup[37] = 'Romanian';
  1319. $QuicktimeLanguageLookup[38] = 'Czech';
  1320. $QuicktimeLanguageLookup[39] = 'Slovak';
  1321. $QuicktimeLanguageLookup[40] = 'Slovenian';
  1322. $QuicktimeLanguageLookup[41] = 'Yiddish';
  1323. $QuicktimeLanguageLookup[42] = 'Serbian';
  1324. $QuicktimeLanguageLookup[43] = 'Macedonian';
  1325. $QuicktimeLanguageLookup[44] = 'Bulgarian';
  1326. $QuicktimeLanguageLookup[45] = 'Ukrainian';
  1327. $QuicktimeLanguageLookup[46] = 'Byelorussian';
  1328. $QuicktimeLanguageLookup[47] = 'Uzbek';
  1329. $QuicktimeLanguageLookup[48] = 'Kazakh';
  1330. $QuicktimeLanguageLookup[49] = 'Azerbaijani';
  1331. $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
  1332. $QuicktimeLanguageLookup[51] = 'Armenian';
  1333. $QuicktimeLanguageLookup[52] = 'Georgian';
  1334. $QuicktimeLanguageLookup[53] = 'Moldavian';
  1335. $QuicktimeLanguageLookup[54] = 'Kirghiz';
  1336. $QuicktimeLanguageLookup[55] = 'Tajiki';
  1337. $QuicktimeLanguageLookup[56] = 'Turkmen';
  1338. $QuicktimeLanguageLookup[57] = 'Mongolian';
  1339. $QuicktimeLanguageLookup[58] = 'MongolianCyr';
  1340. $QuicktimeLanguageLookup[59] = 'Pashto';
  1341. $QuicktimeLanguageLookup[60] = 'Kurdish';
  1342. $QuicktimeLanguageLookup[61] = 'Kashmiri';
  1343. $QuicktimeLanguageLookup[62] = 'Sindhi';
  1344. $QuicktimeLanguageLookup[63] = 'Tibetan';
  1345. $QuicktimeLanguageLookup[64] = 'Nepali';
  1346. $QuicktimeLanguageLookup[65] = 'Sanskrit';
  1347. $QuicktimeLanguageLookup[66] = 'Marathi';
  1348. $QuicktimeLanguageLookup[67] = 'Bengali';
  1349. $QuicktimeLanguageLookup[68] = 'Assamese';
  1350. $QuicktimeLanguageLookup[69] = 'Gujarati';
  1351. $QuicktimeLanguageLookup[70] = 'Punjabi';
  1352. $QuicktimeLanguageLookup[71] = 'Oriya';
  1353. $QuicktimeLanguageLookup[72] = 'Malayalam';
  1354. $QuicktimeLanguageLookup[73] = 'Kannada';
  1355. $QuicktimeLanguageLookup[74] = 'Tamil';
  1356. $QuicktimeLanguageLookup[75] = 'Telugu';
  1357. $QuicktimeLanguageLookup[76] = 'Sinhalese';
  1358. $QuicktimeLanguageLookup[77] = 'Burmese';
  1359. $QuicktimeLanguageLookup[78] = 'Khmer';
  1360. $QuicktimeLanguageLookup[79] = 'Lao';
  1361. $QuicktimeLanguageLookup[80] = 'Vietnamese';
  1362. $QuicktimeLanguageLookup[81] = 'Indonesian';
  1363. $QuicktimeLanguageLookup[82] = 'Tagalog';
  1364. $QuicktimeLanguageLookup[83] = 'MalayRoman';
  1365. $QuicktimeLanguageLookup[84] = 'MalayArabic';
  1366. $QuicktimeLanguageLookup[85] = 'Amharic';
  1367. $QuicktimeLanguageLookup[86] = 'Tigrinya';
  1368. $QuicktimeLanguageLookup[87] = 'Galla';
  1369. $QuicktimeLanguageLookup[87] = 'Oromo';
  1370. $QuicktimeLanguageLookup[88] = 'Somali';
  1371. $QuicktimeLanguageLookup[89] = 'Swahili';
  1372. $QuicktimeLanguageLookup[90] = 'Ruanda';
  1373. $QuicktimeLanguageLookup[91] = 'Rundi';
  1374. $QuicktimeLanguageLookup[92] = 'Chewa';
  1375. $QuicktimeLanguageLookup[93] = 'Malagasy';
  1376. $QuicktimeLanguageLookup[94] = 'Esperanto';
  1377. $QuicktimeLanguageLookup[128] = 'Welsh';
  1378. $QuicktimeLanguageLookup[129] = 'Basque';
  1379. $QuicktimeLanguageLookup[130] = 'Catalan';
  1380. $QuicktimeLanguageLookup[131] = 'Latin';
  1381. $QuicktimeLanguageLookup[132] = 'Quechua';
  1382. $QuicktimeLanguageLookup[133] = 'Guarani';
  1383. $QuicktimeLanguageLookup[134] = 'Aymara';
  1384. $QuicktimeLanguageLookup[135] = 'Tatar';
  1385. $QuicktimeLanguageLookup[136] = 'Uighur';
  1386. $QuicktimeLanguageLookup[137] = 'Dzongkha';
  1387. $QuicktimeLanguageLookup[138] = 'JavaneseRom';
  1388. $QuicktimeLanguageLookup[32767] = 'Unspecified';
  1389. }
  1390. if (($languageid > 138) && ($languageid < 32767)) {
  1391. /*
  1392. ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php
  1393. Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field.
  1394. The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate
  1395. these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero.
  1396. One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character
  1397. and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character,
  1398. and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least
  1399. significant bits and the most significant bit set to zero.
  1400. */
  1401. $iso_language_id = '';
  1402. $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60);
  1403. $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60);
  1404. $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60);
  1405. $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id);
  1406. }
  1407. return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
  1408. }
  1409. public function QuicktimeVideoCodecLookup($codecid) {
  1410. static $QuicktimeVideoCodecLookup = array();
  1411. if (empty($QuicktimeVideoCodecLookup)) {
  1412. $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
  1413. $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
  1414. $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
  1415. $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
  1416. $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
  1417. $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC';
  1418. $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
  1419. $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
  1420. $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
  1421. $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
  1422. $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
  1423. $QuicktimeVideoCodecLookup['base'] = 'Base';
  1424. $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
  1425. $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
  1426. $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
  1427. $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
  1428. $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
  1429. $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
  1430. $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
  1431. $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
  1432. $QuicktimeVideoCodecLookup['fire'] = 'Fire';
  1433. $QuicktimeVideoCodecLookup['flic'] = 'FLC';
  1434. $QuicktimeVideoCodecLookup['gif '] = 'GIF';
  1435. $QuicktimeVideoCodecLookup['h261'] = 'H261';
  1436. $QuicktimeVideoCodecLookup['h263'] = 'H263';
  1437. $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
  1438. $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
  1439. $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
  1440. $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
  1441. $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
  1442. $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
  1443. $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
  1444. $QuicktimeVideoCodecLookup['path'] = 'Vector';
  1445. $QuicktimeVideoCodecLookup['png '] = 'PNG';
  1446. $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
  1447. $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
  1448. $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
  1449. $QuicktimeVideoCodecLookup['raw '] = 'RAW';
  1450. $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
  1451. $QuicktimeVideoCodecLookup['rpza'] = 'Video';
  1452. $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
  1453. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
  1454. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
  1455. $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
  1456. $QuicktimeVideoCodecLookup['tga '] = 'Targa';
  1457. $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
  1458. $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
  1459. $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
  1460. $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
  1461. $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
  1462. $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
  1463. $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
  1464. }
  1465. return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
  1466. }
  1467. public function QuicktimeAudioCodecLookup($codecid) {
  1468. static $QuicktimeAudioCodecLookup = array();
  1469. if (empty($QuicktimeAudioCodecLookup)) {
  1470. $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
  1471. $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
  1472. $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
  1473. $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
  1474. $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
  1475. $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
  1476. $QuicktimeAudioCodecLookup['dvca'] = 'DV';
  1477. $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
  1478. $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
  1479. $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
  1480. $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
  1481. $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
  1482. $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
  1483. $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
  1484. $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
  1485. $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
  1486. $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
  1487. $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
  1488. $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
  1489. $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
  1490. $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
  1491. $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
  1492. $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
  1493. $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
  1494. $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
  1495. $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
  1496. $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
  1497. $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
  1498. $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
  1499. $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
  1500. $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
  1501. $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
  1502. $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
  1503. $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
  1504. $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
  1505. $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
  1506. $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
  1507. $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
  1508. }
  1509. return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
  1510. }
  1511. public function QuicktimeDCOMLookup($compressionid) {
  1512. static $QuicktimeDCOMLookup = array();
  1513. if (empty($QuicktimeDCOMLookup)) {
  1514. $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
  1515. $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
  1516. }
  1517. return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
  1518. }
  1519. public function QuicktimeColorNameLookup($colordepthid) {
  1520. static $QuicktimeColorNameLookup = array();
  1521. if (empty($QuicktimeColorNameLookup)) {
  1522. $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
  1523. $QuicktimeColorNameLookup[2] = '4-color';
  1524. $QuicktimeColorNameLookup[4] = '16-color';
  1525. $QuicktimeColorNameLookup[8] = '256-color';
  1526. $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
  1527. $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
  1528. $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
  1529. $QuicktimeColorNameLookup[33] = 'black & white';
  1530. $QuicktimeColorNameLookup[34] = '4-gray';
  1531. $QuicktimeColorNameLookup[36] = '16-gray';
  1532. $QuicktimeColorNameLookup[40] = '256-gray';
  1533. }
  1534. return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
  1535. }
  1536. public function QuicktimeSTIKLookup($stik) {
  1537. static $QuicktimeSTIKLookup = array();
  1538. if (empty($QuicktimeSTIKLookup)) {
  1539. $QuicktimeSTIKLookup[0] = 'Movie';
  1540. $QuicktimeSTIKLookup[1] = 'Normal';
  1541. $QuicktimeSTIKLookup[2] = 'Audiobook';
  1542. $QuicktimeSTIKLookup[5] = 'Whacked Bookmark';
  1543. $QuicktimeSTIKLookup[6] = 'Music Video';
  1544. $QuicktimeSTIKLookup[9] = 'Short Film';
  1545. $QuicktimeSTIKLookup[10] = 'TV Show';
  1546. $QuicktimeSTIKLookup[11] = 'Booklet';
  1547. $QuicktimeSTIKLookup[14] = 'Ringtone';
  1548. $QuicktimeSTIKLookup[21] = 'Podcast';
  1549. }
  1550. return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid');
  1551. }
  1552. public function QuicktimeIODSaudioProfileName($audio_profile_id) {
  1553. static $QuicktimeIODSaudioProfileNameLookup = array();
  1554. if (empty($QuicktimeIODSaudioProfileNameLookup)) {
  1555. $QuicktimeIODSaudioProfileNameLookup = array(
  1556. 0x00 => 'ISO Reserved (0x00)',
  1557. 0x01 => 'Main Audio Profile @ Level 1',
  1558. 0x02 => 'Main Audio Profile @ Level 2',
  1559. 0x03 => 'Main Audio Profile @ Level 3',
  1560. 0x04 => 'Main Audio Profile @ Level 4',
  1561. 0x05 => 'Scalable Audio Profile @ Level 1',
  1562. 0x06 => 'Scalable Audio Profile @ Level 2',
  1563. 0x07 => 'Scalable Audio Profile @ Level 3',
  1564. 0x08 => 'Scalable Audio Profile @ Level 4',
  1565. 0x09 => 'Speech Audio Profile @ Level 1',
  1566. 0x0A => 'Speech Audio Profile @ Level 2',
  1567. 0x0B => 'Synthetic Audio Profile @ Level 1',
  1568. 0x0C => 'Synthetic Audio Profile @ Level 2',
  1569. 0x0D => 'Synthetic Audio Profile @ Level 3',
  1570. 0x0E => 'High Quality Audio Profile @ Level 1',
  1571. 0x0F => 'High Quality Audio Profile @ Level 2',
  1572. 0x10 => 'High Quality Audio Profile @ Level 3',
  1573. 0x11 => 'High Quality Audio Profile @ Level 4',
  1574. 0x12 => 'High Quality Audio Profile @ Level 5',
  1575. 0x13 => 'High Quality Audio Profile @ Level 6',
  1576. 0x14 => 'High Quality Audio Profile @ Level 7',
  1577. 0x15 => 'High Quality Audio Profile @ Level 8',
  1578. 0x16 => 'Low Delay Audio Profile @ Level 1',
  1579. 0x17 => 'Low Delay Audio Profile @ Level 2',
  1580. 0x18 => 'Low Delay Audio Profile @ Level 3',
  1581. 0x19 => 'Low Delay Audio Profile @ Level 4',
  1582. 0x1A => 'Low Delay Audio Profile @ Level 5',
  1583. 0x1B => 'Low Delay Audio Profile @ Level 6',
  1584. 0x1C => 'Low Delay Audio Profile @ Level 7',
  1585. 0x1D => 'Low Delay Audio Profile @ Level 8',
  1586. 0x1E => 'Natural Audio Profile @ Level 1',
  1587. 0x1F => 'Natural Audio Profile @ Level 2',
  1588. 0x20 => 'Natural Audio Profile @ Level 3',
  1589. 0x21 => 'Natural Audio Profile @ Level 4',
  1590. 0x22 => 'Mobile Audio Internetworking Profile @ Level 1',
  1591. 0x23 => 'Mobile Audio Internetworking Profile @ Level 2',
  1592. 0x24 => 'Mobile Audio Internetworking Profile @ Level 3',
  1593. 0x25 => 'Mobile Audio Internetworking Profile @ Level 4',
  1594. 0x26 => 'Mobile Audio Internetworking Profile @ Level 5',
  1595. 0x27 => 'Mobile Audio Internetworking Profile @ Level 6',
  1596. 0x28 => 'AAC Profile @ Level 1',
  1597. 0x29 => 'AAC Profile @ Level 2',
  1598. 0x2A => 'AAC Profile @ Level 4',
  1599. 0x2B => 'AAC Profile @ Level 5',
  1600. 0x2C => 'High Efficiency AAC Profile @ Level 2',
  1601. 0x2D => 'High Efficiency AAC Profile @ Level 3',
  1602. 0x2E => 'High Efficiency AAC Profile @ Level 4',
  1603. 0x2F => 'High Efficiency AAC Profile @ Level 5',
  1604. 0xFE => 'Not part of MPEG-4 audio profiles',
  1605. 0xFF => 'No audio capability required',
  1606. );
  1607. }
  1608. return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private');
  1609. }
  1610. public function QuicktimeIODSvideoProfileName($video_profile_id) {
  1611. static $QuicktimeIODSvideoProfileNameLookup = array();
  1612. if (empty($QuicktimeIODSvideoProfileNameLookup)) {
  1613. $QuicktimeIODSvideoProfileNameLookup = array(
  1614. 0x00 => 'Reserved (0x00) Profile',
  1615. 0x01 => 'Simple Profile @ Level 1',
  1616. 0x02 => 'Simple Profile @ Level 2',
  1617. 0x03 => 'Simple Profile @ Level 3',
  1618. 0x08 => 'Simple Profile @ Level 0',
  1619. 0x10 => 'Simple Scalable Profile @ Level 0',
  1620. 0x11 => 'Simple Scalable Profile @ Level 1',
  1621. 0x12 => 'Simple Scalable Profile @ Level 2',
  1622. 0x15 => 'AVC/H264 Profile',
  1623. 0x21 => 'Core Profile @ Level 1',
  1624. 0x22 => 'Core Profile @ Level 2',
  1625. 0x32 => 'Main Profile @ Level 2',
  1626. 0x33 => 'Main Profile @ Level 3',
  1627. 0x34 => 'Main Profile @ Level 4',
  1628. 0x42 => 'N-bit Profile @ Level 2',
  1629. 0x51 => 'Scalable Texture Profile @ Level 1',
  1630. 0x61 => 'Simple Face Animation Profile @ Level 1',
  1631. 0x62 => 'Simple Face Animation Profile @ Level 2',
  1632. 0x63 => 'Simple FBA Profile @ Level 1',
  1633. 0x64 => 'Simple FBA Profile @ Level 2',
  1634. 0x71 => 'Basic Animated Texture Profile @ Level 1',
  1635. 0x72 => 'Basic Animated Texture Profile @ Level 2',
  1636. 0x81 => 'Hybrid Profile @ Level 1',
  1637. 0x82 => 'Hybrid Profile @ Level 2',
  1638. 0x91 => 'Advanced Real Time Simple Profile @ Level 1',
  1639. 0x92 => 'Advanced Real Time Simple Profile @ Level 2',
  1640. 0x93 => 'Advanced Real Time Simple Profile @ Level 3',
  1641. 0x94 => 'Advanced Real Time Simple Profile @ Level 4',
  1642. 0xA1 => 'Core Scalable Profile @ Level1',
  1643. 0xA2 => 'Core Scalable Profile @ Level2',
  1644. 0xA3 => 'Core Scalable Profile @ Level3',
  1645. 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1',
  1646. 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2',
  1647. 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3',
  1648. 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4',
  1649. 0xC1 => 'Advanced Core Profile @ Level 1',
  1650. 0xC2 => 'Advanced Core Profile @ Level 2',
  1651. 0xD1 => 'Advanced Scalable Texture @ Level1',
  1652. 0xD2 => 'Advanced Scalable Texture @ Level2',
  1653. 0xE1 => 'Simple Studio Profile @ Level 1',
  1654. 0xE2 => 'Simple Studio Profile @ Level 2',
  1655. 0xE3 => 'Simple Studio Profile @ Level 3',
  1656. 0xE4 => 'Simple Studio Profile @ Level 4',
  1657. 0xE5 => 'Core Studio Profile @ Level 1',
  1658. 0xE6 => 'Core Studio Profile @ Level 2',
  1659. 0xE7 => 'Core Studio Profile @ Level 3',
  1660. 0xE8 => 'Core Studio Profile @ Level 4',
  1661. 0xF0 => 'Advanced Simple Profile @ Level 0',
  1662. 0xF1 => 'Advanced Simple Profile @ Level 1',
  1663. 0xF2 => 'Advanced Simple Profile @ Level 2',
  1664. 0xF3 => 'Advanced Simple Profile @ Level 3',
  1665. 0xF4 => 'Advanced Simple Profile @ Level 4',
  1666. 0xF5 => 'Advanced Simple Profile @ Level 5',
  1667. 0xF7 => 'Advanced Simple Profile @ Level 3b',
  1668. 0xF8 => 'Fine Granularity Scalable Profile @ Level 0',
  1669. 0xF9 => 'Fine Granularity Scalable Profile @ Level 1',
  1670. 0xFA => 'Fine Granularity Scalable Profile @ Level 2',
  1671. 0xFB => 'Fine Granularity Scalable Profile @ Level 3',
  1672. 0xFC => 'Fine Granularity Scalable Profile @ Level 4',
  1673. 0xFD => 'Fine Granularity Scalable Profile @ Level 5',
  1674. 0xFE => 'Not part of MPEG-4 Visual profiles',
  1675. 0xFF => 'No visual capability required',
  1676. );
  1677. }
  1678. return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile');
  1679. }
  1680. public function QuicktimeContentRatingLookup($rtng) {
  1681. static $QuicktimeContentRatingLookup = array();
  1682. if (empty($QuicktimeContentRatingLookup)) {
  1683. $QuicktimeContentRatingLookup[0] = 'None';
  1684. $QuicktimeContentRatingLookup[2] = 'Clean';
  1685. $QuicktimeContentRatingLookup[4] = 'Explicit';
  1686. }
  1687. return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid');
  1688. }
  1689. public function QuicktimeStoreAccountTypeLookup($akid) {
  1690. static $QuicktimeStoreAccountTypeLookup = array();
  1691. if (empty($QuicktimeStoreAccountTypeLookup)) {
  1692. $QuicktimeStoreAccountTypeLookup[0] = 'iTunes';
  1693. $QuicktimeStoreAccountTypeLookup[1] = 'AOL';
  1694. }
  1695. return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid');
  1696. }
  1697. public function QuicktimeStoreFrontCodeLookup($sfid) {
  1698. static $QuicktimeStoreFrontCodeLookup = array();
  1699. if (empty($QuicktimeStoreFrontCodeLookup)) {
  1700. $QuicktimeStoreFrontCodeLookup[143460] = 'Australia';
  1701. $QuicktimeStoreFrontCodeLookup[143445] = 'Austria';
  1702. $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium';
  1703. $QuicktimeStoreFrontCodeLookup[143455] = 'Canada';
  1704. $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark';
  1705. $QuicktimeStoreFrontCodeLookup[143447] = 'Finland';
  1706. $QuicktimeStoreFrontCodeLookup[143442] = 'France';
  1707. $QuicktimeStoreFrontCodeLookup[143443] = 'Germany';
  1708. $QuicktimeStoreFrontCodeLookup[143448] = 'Greece';
  1709. $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland';
  1710. $QuicktimeStoreFrontCodeLookup[143450] = 'Italy';
  1711. $QuicktimeStoreFrontCodeLookup[143462] = 'Japan';
  1712. $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg';
  1713. $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands';
  1714. $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand';
  1715. $QuicktimeStoreFrontCodeLookup[143457] = 'Norway';
  1716. $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal';
  1717. $QuicktimeStoreFrontCodeLookup[143454] = 'Spain';
  1718. $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden';
  1719. $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland';
  1720. $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom';
  1721. $QuicktimeStoreFrontCodeLookup[143441] = 'United States';
  1722. }
  1723. return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid');
  1724. }
  1725. public function QuicktimeParseNikonNCTG($atom_data) {
  1726. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
  1727. // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
  1728. // Data is stored as records of:
  1729. // * 4 bytes record type
  1730. // * 2 bytes size of data field type:
  1731. // 0x0001 = flag (size field *= 1-byte)
  1732. // 0x0002 = char (size field *= 1-byte)
  1733. // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
  1734. // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
  1735. // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
  1736. // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
  1737. // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
  1738. // * 2 bytes data size field
  1739. // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15")
  1740. // all integers are stored BigEndian
  1741. $NCTGtagName = array(
  1742. 0x00000001 => 'Make',
  1743. 0x00000002 => 'Model',
  1744. 0x00000003 => 'Software',
  1745. 0x00000011 => 'CreateDate',
  1746. 0x00000012 => 'DateTimeOriginal',
  1747. 0x00000013 => 'FrameCount',
  1748. 0x00000016 => 'FrameRate',
  1749. 0x00000022 => 'FrameWidth',
  1750. 0x00000023 => 'FrameHeight',
  1751. 0x00000032 => 'AudioChannels',
  1752. 0x00000033 => 'AudioBitsPerSample',
  1753. 0x00000034 => 'AudioSampleRate',
  1754. 0x02000001 => 'MakerNoteVersion',
  1755. 0x02000005 => 'WhiteBalance',
  1756. 0x0200000b => 'WhiteBalanceFineTune',
  1757. 0x0200001e => 'ColorSpace',
  1758. 0x02000023 => 'PictureControlData',
  1759. 0x02000024 => 'WorldTime',
  1760. 0x02000032 => 'UnknownInfo',
  1761. 0x02000083 => 'LensType',
  1762. 0x02000084 => 'Lens',
  1763. );
  1764. $offset = 0;
  1765. $datalength = strlen($atom_data);
  1766. $parsed = array();
  1767. while ($offset < $datalength) {
  1768. //echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'<br>';
  1769. $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4;
  1770. $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
  1771. $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
  1772. switch ($data_size_type) {
  1773. case 0x0001: // 0x0001 = flag (size field *= 1-byte)
  1774. $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1));
  1775. $offset += ($data_size * 1);
  1776. break;
  1777. case 0x0002: // 0x0002 = char (size field *= 1-byte)
  1778. $data = substr($atom_data, $offset, $data_size * 1);
  1779. $offset += ($data_size * 1);
  1780. $data = rtrim($data, "\x00");
  1781. break;
  1782. case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
  1783. $data = '';
  1784. for ($i = $data_size - 1; $i >= 0; $i--) {
  1785. $data .= substr($atom_data, $offset + ($i * 2), 2);
  1786. }
  1787. $data = getid3_lib::BigEndian2Int($data);
  1788. $offset += ($data_size * 2);
  1789. break;
  1790. case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
  1791. $data = '';
  1792. for ($i = $data_size - 1; $i >= 0; $i--) {
  1793. $data .= substr($atom_data, $offset + ($i * 4), 4);
  1794. }
  1795. $data = getid3_lib::BigEndian2Int($data);
  1796. $offset += ($data_size * 4);
  1797. break;
  1798. case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
  1799. $data = array();
  1800. for ($i = 0; $i < $data_size; $i++) {
  1801. $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4));
  1802. $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4));
  1803. if ($denomninator == 0) {
  1804. $data[$i] = false;
  1805. } else {
  1806. $data[$i] = (double) $numerator / $denomninator;
  1807. }
  1808. }
  1809. $offset += (8 * $data_size);
  1810. if (count($data) == 1) {
  1811. $data = $data[0];
  1812. }
  1813. break;
  1814. case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
  1815. $data = substr($atom_data, $offset, $data_size * 1);
  1816. $offset += ($data_size * 1);
  1817. break;
  1818. case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
  1819. $data = substr($atom_data, $offset, $data_size * 2);
  1820. $offset += ($data_size * 2);
  1821. break;
  1822. default:
  1823. echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>';
  1824. break 2;
  1825. }
  1826. switch ($record_type) {
  1827. case 0x00000011: // CreateDate
  1828. case 0x00000012: // DateTimeOriginal
  1829. $data = strtotime($data);
  1830. break;
  1831. case 0x0200001e: // ColorSpace
  1832. switch ($data) {
  1833. case 1:
  1834. $data = 'sRGB';
  1835. break;
  1836. case 2:
  1837. $data = 'Adobe RGB';
  1838. break;
  1839. }
  1840. break;
  1841. case 0x02000023: // PictureControlData
  1842. $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full');
  1843. $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a');
  1844. $ToningEffect = array(0x80=>'b&w', 0x81=>'sepia', 0x82=>'cyanotype', 0x83=>'red', 0x84=>'yellow', 0x85=>'green', 0x86=>'blue-green', 0x87=>'blue', 0x88=>'purple-blue', 0x89=>'red-purple', 0xff=>'n/a');
  1845. $data = array(
  1846. 'PictureControlVersion' => substr($data, 0, 4),
  1847. 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"),
  1848. 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"),
  1849. //'?' => substr($data, 44, 4),
  1850. 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))],
  1851. 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)),
  1852. 'Sharpness' => ord(substr($data, 50, 1)),
  1853. 'Contrast' => ord(substr($data, 51, 1)),
  1854. 'Brightness' => ord(substr($data, 52, 1)),
  1855. 'Saturation' => ord(substr($data, 53, 1)),
  1856. 'HueAdjustment' => ord(substr($data, 54, 1)),
  1857. 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))],
  1858. 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))],
  1859. 'ToningSaturation' => ord(substr($data, 57, 1)),
  1860. );
  1861. break;
  1862. case 0x02000024: // WorldTime
  1863. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime
  1864. // timezone is stored as offset from GMT in minutes
  1865. $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2));
  1866. if ($timezone & 0x8000) {
  1867. $timezone = 0 - (0x10000 - $timezone);
  1868. }
  1869. $timezone /= 60;
  1870. $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1));
  1871. switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) {
  1872. case 2:
  1873. $datedisplayformat = 'D/M/Y'; break;
  1874. case 1:
  1875. $datedisplayformat = 'M/D/Y'; break;
  1876. case 0:
  1877. default:
  1878. $datedisplayformat = 'Y/M/D'; break;
  1879. }
  1880. $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat);
  1881. break;
  1882. case 0x02000083: // LensType
  1883. $data = array(
  1884. //'_' => $data,
  1885. 'mf' => (bool) ($data & 0x01),
  1886. 'd' => (bool) ($data & 0x02),
  1887. 'g' => (bool) ($data & 0x04),
  1888. 'vr' => (bool) ($data & 0x08),
  1889. );
  1890. break;
  1891. }
  1892. $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT));
  1893. $parsed[$tag_name] = $data;
  1894. }
  1895. return $parsed;
  1896. }
  1897. public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') {
  1898. static $handyatomtranslatorarray = array();
  1899. if (empty($handyatomtranslatorarray)) {
  1900. $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright';
  1901. $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0
  1902. $handyatomtranslatorarray["\xA9".'dir'] = 'director';
  1903. $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1';
  1904. $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2';
  1905. $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3';
  1906. $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4';
  1907. $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5';
  1908. $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6';
  1909. $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7';
  1910. $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8';
  1911. $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9';
  1912. $handyatomtranslatorarray["\xA9".'fmt'] = 'format';
  1913. $handyatomtranslatorarray["\xA9".'inf'] = 'information';
  1914. $handyatomtranslatorarray["\xA9".'prd'] = 'producer';
  1915. $handyatomtranslatorarray["\xA9".'prf'] = 'performers';
  1916. $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements';
  1917. $handyatomtranslatorarray["\xA9".'src'] = 'source_credit';
  1918. $handyatomtranslatorarray["\xA9".'wrt'] = 'writer';
  1919. // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
  1920. $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0
  1921. $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0
  1922. $handyatomtranslatorarray["\xA9".'wrn'] = 'warning';
  1923. $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer';
  1924. $handyatomtranslatorarray["\xA9".'mak'] = 'make';
  1925. $handyatomtranslatorarray["\xA9".'mod'] = 'model';
  1926. $handyatomtranslatorarray["\xA9".'PRD'] = 'product';
  1927. $handyatomtranslatorarray["\xA9".'swr'] = 'software';
  1928. $handyatomtranslatorarray["\xA9".'aut'] = 'author';
  1929. $handyatomtranslatorarray["\xA9".'ART'] = 'artist';
  1930. $handyatomtranslatorarray["\xA9".'trk'] = 'track';
  1931. $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0
  1932. $handyatomtranslatorarray["\xA9".'com'] = 'comment';
  1933. $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0
  1934. $handyatomtranslatorarray["\xA9".'ope'] = 'composer';
  1935. $handyatomtranslatorarray["\xA9".'url'] = 'url';
  1936. $handyatomtranslatorarray["\xA9".'enc'] = 'encoder';
  1937. // http://atomicparsley.sourceforge.net/mpeg-4files.html
  1938. $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0
  1939. $handyatomtranslatorarray['aART'] = 'album_artist';
  1940. $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0
  1941. $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0
  1942. $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0
  1943. $handyatomtranslatorarray["\xA9".'too'] = 'encoder'; // iTunes 4.0
  1944. $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0
  1945. $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0?
  1946. $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0
  1947. $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0
  1948. $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0
  1949. $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2
  1950. $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9
  1951. $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9
  1952. $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9
  1953. $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9
  1954. $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9
  1955. $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9
  1956. $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0
  1957. $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0
  1958. $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0
  1959. $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0
  1960. $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0
  1961. $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0
  1962. $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2
  1963. $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0
  1964. // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt
  1965. // boxnames:
  1966. /*
  1967. $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB';
  1968. $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM';
  1969. $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params';
  1970. $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain';
  1971. $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak';
  1972. $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax';
  1973. $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID';
  1974. $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id';
  1975. $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id';
  1976. $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id';
  1977. $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id';
  1978. $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id';
  1979. // http://age.hobba.nl/audio/tag_frame_reference.html
  1980. $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
  1981. $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
  1982. */
  1983. }
  1984. $info = &$this->getid3->info;
  1985. $comment_key = '';
  1986. if ($boxname && ($boxname != $keyname)) {
  1987. $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname);
  1988. } elseif (isset($handyatomtranslatorarray[$keyname])) {
  1989. $comment_key = $handyatomtranslatorarray[$keyname];
  1990. }
  1991. if ($comment_key) {
  1992. if ($comment_key == 'picture') {
  1993. if (!is_array($data)) {
  1994. $image_mime = '';
  1995. if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) {
  1996. $image_mime = 'image/png';
  1997. } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) {
  1998. $image_mime = 'image/jpeg';
  1999. } elseif (preg_match('#^GIF#', $data)) {
  2000. $image_mime = 'image/gif';
  2001. } elseif (preg_match('#^BM#', $data)) {
  2002. $image_mime = 'image/bmp';
  2003. }
  2004. $data = array('data'=>$data, 'image_mime'=>$image_mime);
  2005. }
  2006. }
  2007. $info['quicktime']['comments'][$comment_key][] = $data;
  2008. }
  2009. return true;
  2010. }
  2011. public function NoNullString($nullterminatedstring) {
  2012. // remove the single null terminator on null terminated strings
  2013. if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
  2014. return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
  2015. }
  2016. return $nullterminatedstring;
  2017. }
  2018. public function Pascal2String($pascalstring) {
  2019. // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
  2020. return substr($pascalstring, 1);
  2021. }
  2022. }