[ Index ] |
WordPress 5.4.1 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 ///////////////////////////////////////////////////////////////// 4 /// getID3() by James Heinrich <info@getid3.org> // 5 // available at https://github.com/JamesHeinrich/getID3 // 6 // or https://www.getid3.org // 7 // or http://getid3.sourceforge.net // 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 18 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); 19 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup 20 21 class getid3_quicktime extends getid3_handler 22 { 23 24 public $ReturnAtomData = true; 25 public $ParseAllPossibleAtoms = false; 26 27 /** 28 * @return bool 29 */ 30 public function Analyze() { 31 $info = &$this->getid3->info; 32 33 $info['fileformat'] = 'quicktime'; 34 $info['quicktime']['hinting'] = false; 35 $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present 36 37 $this->fseek($info['avdataoffset']); 38 39 $offset = 0; 40 $atomcounter = 0; 41 $atom_data_read_buffer_size = $info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : $this->getid3->option_fread_buffer_size * 1024; // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB] 42 while ($offset < $info['avdataend']) { 43 if (!getid3_lib::intValueSupported($offset)) { 44 $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'); 45 break; 46 } 47 $this->fseek($offset); 48 $AtomHeader = $this->fread(8); 49 50 $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); 51 $atomname = substr($AtomHeader, 4, 4); 52 53 // 64-bit MOV patch by jlegateØktnc*com 54 if ($atomsize == 1) { 55 $atomsize = getid3_lib::BigEndian2Int($this->fread(8)); 56 } 57 58 $info['quicktime'][$atomname]['name'] = $atomname; 59 $info['quicktime'][$atomname]['size'] = $atomsize; 60 $info['quicktime'][$atomname]['offset'] = $offset; 61 62 if (($offset + $atomsize) > $info['avdataend']) { 63 $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'); 64 return false; 65 } 66 67 if ($atomsize == 0) { 68 // Furthermore, for historical reasons the list of atoms is optionally 69 // terminated by a 32-bit integer set to 0. If you are writing a program 70 // to read user data atoms, you should allow for the terminating 0. 71 break; 72 } 73 $atomHierarchy = array(); 74 $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms); 75 76 $offset += $atomsize; 77 $atomcounter++; 78 } 79 80 if (!empty($info['avdataend_tmp'])) { 81 // this value is assigned to a temp value and then erased because 82 // otherwise any atoms beyond the 'mdat' atom would not get parsed 83 $info['avdataend'] = $info['avdataend_tmp']; 84 unset($info['avdataend_tmp']); 85 } 86 87 if (!empty($info['quicktime']['comments']['chapters']) && is_array($info['quicktime']['comments']['chapters']) && (count($info['quicktime']['comments']['chapters']) > 0)) { 88 $durations = $this->quicktime_time_to_sample_table($info); 89 for ($i = 0; $i < count($info['quicktime']['comments']['chapters']); $i++) { 90 $bookmark = array(); 91 $bookmark['title'] = $info['quicktime']['comments']['chapters'][$i]; 92 if (isset($durations[$i])) { 93 $bookmark['duration_sample'] = $durations[$i]['sample_duration']; 94 if ($i > 0) { 95 $bookmark['start_sample'] = $info['quicktime']['bookmarks'][($i - 1)]['start_sample'] + $info['quicktime']['bookmarks'][($i - 1)]['duration_sample']; 96 } else { 97 $bookmark['start_sample'] = 0; 98 } 99 if ($time_scale = $this->quicktime_bookmark_time_scale($info)) { 100 $bookmark['duration_seconds'] = $bookmark['duration_sample'] / $time_scale; 101 $bookmark['start_seconds'] = $bookmark['start_sample'] / $time_scale; 102 } 103 } 104 $info['quicktime']['bookmarks'][] = $bookmark; 105 } 106 } 107 108 if (isset($info['quicktime']['temp_meta_key_names'])) { 109 unset($info['quicktime']['temp_meta_key_names']); 110 } 111 112 if (!empty($info['quicktime']['comments']['location.ISO6709'])) { 113 // https://en.wikipedia.org/wiki/ISO_6709 114 foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) { 115 $latitude = false; 116 $longitude = false; 117 $altitude = false; 118 if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) { 119 @list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches; 120 121 if (strlen($lat_deg) == 2) { // [+-]DD.D 122 $latitude = floatval(ltrim($lat_deg, '0').$lat_deg_dec); 123 } elseif (strlen($lat_deg) == 4) { // [+-]DDMM.M 124 $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0').$lat_deg_dec / 60); 125 } elseif (strlen($lat_deg) == 6) { // [+-]DDMMSS.S 126 $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lat_deg, 4, 2), '0').$lat_deg_dec / 3600); 127 } 128 129 if (strlen($lon_deg) == 3) { // [+-]DDD.D 130 $longitude = floatval(ltrim($lon_deg, '0').$lon_deg_dec); 131 } elseif (strlen($lon_deg) == 5) { // [+-]DDDMM.M 132 $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0').$lon_deg_dec / 60); 133 } elseif (strlen($lon_deg) == 7) { // [+-]DDDMMSS.S 134 $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lon_deg, 4, 2), '0').$lon_deg_dec / 3600); 135 } 136 137 if (strlen($alt_deg) == 3) { // [+-]DDD.D 138 $altitude = floatval(ltrim($alt_deg, '0').$alt_deg_dec); 139 } elseif (strlen($alt_deg) == 5) { // [+-]DDDMM.M 140 $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0').$alt_deg_dec / 60); 141 } elseif (strlen($alt_deg) == 7) { // [+-]DDDMMSS.S 142 $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($alt_deg, 4, 2), '0').$alt_deg_dec / 3600); 143 } 144 145 if ($latitude !== false) { 146 $info['quicktime']['comments']['gps_latitude'][] = (($lat_sign == '-') ? -1 : 1) * floatval($latitude); 147 } 148 if ($longitude !== false) { 149 $info['quicktime']['comments']['gps_longitude'][] = (($lon_sign == '-') ? -1 : 1) * floatval($longitude); 150 } 151 if ($altitude !== false) { 152 $info['quicktime']['comments']['gps_altitude'][] = (($alt_sign == '-') ? -1 : 1) * floatval($altitude); 153 } 154 } 155 if ($latitude === false) { 156 $this->warning('location.ISO6709 string not parsed correctly: "'.$ISO6709string.'", please submit as a bug'); 157 } 158 break; 159 } 160 } 161 162 if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) { 163 $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; 164 } 165 if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) { 166 $info['audio']['bitrate'] = $info['bitrate']; 167 } 168 if (!empty($info['bitrate']) && !empty($info['audio']['bitrate']) && empty($info['video']['bitrate']) && !empty($info['video']['frame_rate']) && !empty($info['video']['resolution_x']) && ($info['bitrate'] > $info['audio']['bitrate'])) { 169 $info['video']['bitrate'] = $info['bitrate'] - $info['audio']['bitrate']; 170 } 171 if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) { 172 foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) { 173 $samples_per_second = $samples_count / $info['playtime_seconds']; 174 if ($samples_per_second > 240) { 175 // has to be audio samples 176 } else { 177 $info['video']['frame_rate'] = $samples_per_second; 178 break; 179 } 180 } 181 } 182 if ($info['audio']['dataformat'] == 'mp4') { 183 $info['fileformat'] = 'mp4'; 184 if (empty($info['video']['resolution_x'])) { 185 $info['mime_type'] = 'audio/mp4'; 186 unset($info['video']['dataformat']); 187 } else { 188 $info['mime_type'] = 'video/mp4'; 189 } 190 } 191 192 if (!$this->ReturnAtomData) { 193 unset($info['quicktime']['moov']); 194 } 195 196 if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) { 197 $info['audio']['dataformat'] = 'quicktime'; 198 } 199 if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) { 200 $info['video']['dataformat'] = 'quicktime'; 201 } 202 if (isset($info['video']) && ($info['mime_type'] == 'audio/mp4') && empty($info['video']['resolution_x']) && empty($info['video']['resolution_y'])) { 203 unset($info['video']); 204 } 205 206 return true; 207 } 208 209 /** 210 * @param string $atomname 211 * @param int $atomsize 212 * @param string $atom_data 213 * @param int $baseoffset 214 * @param array $atomHierarchy 215 * @param bool $ParseAllPossibleAtoms 216 * 217 * @return array|false 218 */ 219 public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { 220 // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm 221 // https://code.google.com/p/mp4v2/wiki/iTunesMetadata 222 223 $info = &$this->getid3->info; 224 225 $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see https://www.getid3.org/phpBB3/viewtopic.php?t=1717 226 array_push($atomHierarchy, $atomname); 227 $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); 228 $atom_structure['name'] = $atomname; 229 $atom_structure['size'] = $atomsize; 230 $atom_structure['offset'] = $baseoffset; 231 if (substr($atomname, 0, 3) == "\x00\x00\x00") { 232 // https://github.com/JamesHeinrich/getID3/issues/139 233 $atomname = getid3_lib::BigEndian2Int($atomname); 234 $atom_structure['name'] = $atomname; 235 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 236 } else { 237 switch ($atomname) { 238 case 'moov': // MOVie container atom 239 case 'trak': // TRAcK container atom 240 case 'clip': // CLIPping container atom 241 case 'matt': // track MATTe container atom 242 case 'edts': // EDiTS container atom 243 case 'tref': // Track REFerence container atom 244 case 'mdia': // MeDIA container atom 245 case 'minf': // Media INFormation container atom 246 case 'dinf': // Data INFormation container atom 247 case 'udta': // User DaTA container atom 248 case 'cmov': // Compressed MOVie container atom 249 case 'rmra': // Reference Movie Record Atom 250 case 'rmda': // Reference Movie Descriptor Atom 251 case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) 252 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 253 break; 254 255 case 'ilst': // Item LiST container atom 256 if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { 257 // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted 258 $allnumericnames = true; 259 foreach ($atom_structure['subatoms'] as $subatomarray) { 260 if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { 261 $allnumericnames = false; 262 break; 263 } 264 } 265 if ($allnumericnames) { 266 $newData = array(); 267 foreach ($atom_structure['subatoms'] as $subatomarray) { 268 foreach ($subatomarray['subatoms'] as $newData_subatomarray) { 269 unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); 270 $newData[$subatomarray['name']] = $newData_subatomarray; 271 break; 272 } 273 } 274 $atom_structure['data'] = $newData; 275 unset($atom_structure['subatoms']); 276 } 277 } 278 break; 279 280 case 'stbl': // Sample TaBLe container atom 281 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 282 $isVideo = false; 283 $framerate = 0; 284 $framecount = 0; 285 foreach ($atom_structure['subatoms'] as $key => $value_array) { 286 if (isset($value_array['sample_description_table'])) { 287 foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { 288 if (isset($value_array2['data_format'])) { 289 switch ($value_array2['data_format']) { 290 case 'avc1': 291 case 'mp4v': 292 // video data 293 $isVideo = true; 294 break; 295 case 'mp4a': 296 // audio data 297 break; 298 } 299 } 300 } 301 } elseif (isset($value_array['time_to_sample_table'])) { 302 foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { 303 if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { 304 $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); 305 $framecount = $value_array2['sample_count']; 306 } 307 } 308 } 309 } 310 if ($isVideo && $framerate) { 311 $info['quicktime']['video']['frame_rate'] = $framerate; 312 $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; 313 } 314 if ($isVideo && $framecount) { 315 $info['quicktime']['video']['frame_count'] = $framecount; 316 } 317 break; 318 319 320 case "\xA9".'alb': // ALBum 321 case "\xA9".'ART': // 322 case "\xA9".'art': // ARTist 323 case "\xA9".'aut': // 324 case "\xA9".'cmt': // CoMmenT 325 case "\xA9".'com': // COMposer 326 case "\xA9".'cpy': // 327 case "\xA9".'day': // content created year 328 case "\xA9".'dir': // 329 case "\xA9".'ed1': // 330 case "\xA9".'ed2': // 331 case "\xA9".'ed3': // 332 case "\xA9".'ed4': // 333 case "\xA9".'ed5': // 334 case "\xA9".'ed6': // 335 case "\xA9".'ed7': // 336 case "\xA9".'ed8': // 337 case "\xA9".'ed9': // 338 case "\xA9".'enc': // 339 case "\xA9".'fmt': // 340 case "\xA9".'gen': // GENre 341 case "\xA9".'grp': // GRouPing 342 case "\xA9".'hst': // 343 case "\xA9".'inf': // 344 case "\xA9".'lyr': // LYRics 345 case "\xA9".'mak': // 346 case "\xA9".'mod': // 347 case "\xA9".'nam': // full NAMe 348 case "\xA9".'ope': // 349 case "\xA9".'PRD': // 350 case "\xA9".'prf': // 351 case "\xA9".'req': // 352 case "\xA9".'src': // 353 case "\xA9".'swr': // 354 case "\xA9".'too': // encoder 355 case "\xA9".'trk': // TRacK 356 case "\xA9".'url': // 357 case "\xA9".'wrn': // 358 case "\xA9".'wrt': // WRiTer 359 case '----': // itunes specific 360 case 'aART': // Album ARTist 361 case 'akID': // iTunes store account type 362 case 'apID': // Purchase Account 363 case 'atID': // 364 case 'catg': // CaTeGory 365 case 'cmID': // 366 case 'cnID': // 367 case 'covr': // COVeR artwork 368 case 'cpil': // ComPILation 369 case 'cprt': // CoPyRighT 370 case 'desc': // DESCription 371 case 'disk': // DISK number 372 case 'egid': // Episode Global ID 373 case 'geID': // 374 case 'gnre': // GeNRE 375 case 'hdvd': // HD ViDeo 376 case 'keyw': // KEYWord 377 case 'ldes': // Long DEScription 378 case 'pcst': // PodCaST 379 case 'pgap': // GAPless Playback 380 case 'plID': // 381 case 'purd': // PURchase Date 382 case 'purl': // Podcast URL 383 case 'rati': // 384 case 'rndu': // 385 case 'rpdu': // 386 case 'rtng': // RaTiNG 387 case 'sfID': // iTunes store country 388 case 'soaa': // SOrt Album Artist 389 case 'soal': // SOrt ALbum 390 case 'soar': // SOrt ARtist 391 case 'soco': // SOrt COmposer 392 case 'sonm': // SOrt NaMe 393 case 'sosn': // SOrt Show Name 394 case 'stik': // 395 case 'tmpo': // TeMPO (BPM) 396 case 'trkn': // TRacK Number 397 case 'tven': // tvEpisodeID 398 case 'tves': // TV EpiSode 399 case 'tvnn': // TV Network Name 400 case 'tvsh': // TV SHow Name 401 case 'tvsn': // TV SeasoN 402 if ($atom_parent == 'udta') { 403 // User data atom handler 404 $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); 405 $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); 406 $atom_structure['data'] = substr($atom_data, 4); 407 408 $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); 409 if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { 410 $info['comments']['language'][] = $atom_structure['language']; 411 } 412 } else { 413 // Apple item list box atom handler 414 $atomoffset = 0; 415 if (substr($atom_data, 2, 2) == "\x10\xB5") { 416 // not sure what it means, but observed on iPhone4 data. 417 // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data 418 while ($atomoffset < strlen($atom_data)) { 419 $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); 420 $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); 421 $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); 422 if ($boxsmallsize <= 1) { 423 $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); 424 $atom_structure['data'] = null; 425 $atomoffset = strlen($atom_data); 426 break; 427 } 428 switch ($boxsmalltype) { 429 case "\x10\xB5": 430 $atom_structure['data'] = $boxsmalldata; 431 break; 432 default: 433 $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); 434 $atom_structure['data'] = $atom_data; 435 break; 436 } 437 $atomoffset += (4 + $boxsmallsize); 438 } 439 } else { 440 while ($atomoffset < strlen($atom_data)) { 441 $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); 442 $boxtype = substr($atom_data, $atomoffset + 4, 4); 443 $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); 444 if ($boxsize <= 1) { 445 $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); 446 $atom_structure['data'] = null; 447 $atomoffset = strlen($atom_data); 448 break; 449 } 450 $atomoffset += $boxsize; 451 452 switch ($boxtype) { 453 case 'mean': 454 case 'name': 455 $atom_structure[$boxtype] = substr($boxdata, 4); 456 break; 457 458 case 'data': 459 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); 460 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); 461 switch ($atom_structure['flags_raw']) { 462 case 0: // data flag 463 case 21: // tmpo/cpil flag 464 switch ($atomname) { 465 case 'cpil': 466 case 'hdvd': 467 case 'pcst': 468 case 'pgap': 469 // 8-bit integer (boolean) 470 $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); 471 break; 472 473 case 'tmpo': 474 // 16-bit integer 475 $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); 476 break; 477 478 case 'disk': 479 case 'trkn': 480 // binary 481 $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); 482 $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); 483 $atom_structure['data'] = empty($num) ? '' : $num; 484 $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; 485 break; 486 487 case 'gnre': 488 // enum 489 $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); 490 $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); 491 break; 492 493 case 'rtng': 494 // 8-bit integer 495 $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); 496 $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); 497 break; 498 499 case 'stik': 500 // 8-bit integer (enum) 501 $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); 502 $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); 503 break; 504 505 case 'sfID': 506 // 32-bit integer 507 $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); 508 $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); 509 break; 510 511 case 'egid': 512 case 'purl': 513 $atom_structure['data'] = substr($boxdata, 8); 514 break; 515 516 case 'plID': 517 // 64-bit integer 518 $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8)); 519 break; 520 521 case 'covr': 522 $atom_structure['data'] = substr($boxdata, 8); 523 // not a foolproof check, but better than nothing 524 if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { 525 $atom_structure['image_mime'] = 'image/jpeg'; 526 } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { 527 $atom_structure['image_mime'] = 'image/png'; 528 } elseif (preg_match('#^GIF#', $atom_structure['data'])) { 529 $atom_structure['image_mime'] = 'image/gif'; 530 } 531 break; 532 533 case 'atID': 534 case 'cnID': 535 case 'geID': 536 case 'tves': 537 case 'tvsn': 538 default: 539 // 32-bit integer 540 $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); 541 } 542 break; 543 544 case 1: // text flag 545 case 13: // image flag 546 default: 547 $atom_structure['data'] = substr($boxdata, 8); 548 if ($atomname == 'covr') { 549 // not a foolproof check, but better than nothing 550 if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { 551 $atom_structure['image_mime'] = 'image/jpeg'; 552 } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { 553 $atom_structure['image_mime'] = 'image/png'; 554 } elseif (preg_match('#^GIF#', $atom_structure['data'])) { 555 $atom_structure['image_mime'] = 'image/gif'; 556 } 557 } 558 break; 559 560 } 561 break; 562 563 default: 564 $this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset); 565 $atom_structure['data'] = $atom_data; 566 567 } 568 } 569 } 570 } 571 $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']); 572 break; 573 574 575 case 'play': // auto-PLAY atom 576 $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 577 578 $info['quicktime']['autoplay'] = $atom_structure['autoplay']; 579 break; 580 581 582 case 'WLOC': // Window LOCation atom 583 $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); 584 $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); 585 break; 586 587 588 case 'LOOP': // LOOPing atom 589 case 'SelO': // play SELection Only atom 590 case 'AllF': // play ALL Frames atom 591 $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); 592 break; 593 594 595 case 'name': // 596 case 'MCPS': // Media Cleaner PRo 597 case '@PRM': // adobe PReMiere version 598 case '@PRQ': // adobe PRemiere Quicktime version 599 $atom_structure['data'] = $atom_data; 600 break; 601 602 603 case 'cmvd': // Compressed MooV Data atom 604 // Code by ubergeekØubergeek*tv based on information from 605 // http://developer.apple.com/quicktime/icefloe/dispatch012.html 606 $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); 607 608 $CompressedFileData = substr($atom_data, 4); 609 if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { 610 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); 611 } else { 612 $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); 613 } 614 break; 615 616 617 case 'dcom': // Data COMpression atom 618 $atom_structure['compression_id'] = $atom_data; 619 $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); 620 break; 621 622 623 case 'rdrf': // Reference movie Data ReFerence atom 624 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 625 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 626 $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); 627 628 $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); 629 $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 630 switch ($atom_structure['reference_type_name']) { 631 case 'url ': 632 $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); 633 break; 634 635 case 'alis': 636 $atom_structure['file_alias'] = substr($atom_data, 12); 637 break; 638 639 case 'rsrc': 640 $atom_structure['resource_alias'] = substr($atom_data, 12); 641 break; 642 643 default: 644 $atom_structure['data'] = substr($atom_data, 12); 645 break; 646 } 647 break; 648 649 650 case 'rmqu': // Reference Movie QUality atom 651 $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); 652 break; 653 654 655 case 'rmcs': // Reference Movie Cpu Speed atom 656 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 657 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 658 $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); 659 break; 660 661 662 case 'rmvc': // Reference Movie Version Check atom 663 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 664 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 665 $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); 666 $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 667 $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); 668 $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); 669 break; 670 671 672 case 'rmcd': // Reference Movie Component check atom 673 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 674 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 675 $atom_structure['component_type'] = substr($atom_data, 4, 4); 676 $atom_structure['component_subtype'] = substr($atom_data, 8, 4); 677 $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); 678 $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); 679 $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); 680 $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); 681 break; 682 683 684 case 'rmdr': // Reference Movie Data Rate atom 685 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 686 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 687 $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 688 689 $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; 690 break; 691 692 693 case 'rmla': // Reference Movie Language Atom 694 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 695 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 696 $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); 697 698 $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); 699 if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { 700 $info['comments']['language'][] = $atom_structure['language']; 701 } 702 break; 703 704 705 case 'ptv ': // Print To Video - defines a movie's full screen mode 706 // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm 707 $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); 708 $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 709 $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 710 $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); 711 $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); 712 713 $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; 714 $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; 715 716 $ptv_lookup[0] = 'normal'; 717 $ptv_lookup[1] = 'double'; 718 $ptv_lookup[2] = 'half'; 719 $ptv_lookup[3] = 'full'; 720 $ptv_lookup[4] = 'current'; 721 if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { 722 $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; 723 } else { 724 $this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'); 725 } 726 break; 727 728 729 case 'stsd': // Sample Table Sample Description atom 730 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 731 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 732 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 733 734 // see: https://github.com/JamesHeinrich/getID3/issues/111 735 // Some corrupt files have been known to have high bits set in the number_entries field 736 // This field shouldn't really need to be 32-bits, values stores are likely in the range 1-100000 737 // Workaround: mask off the upper byte and throw a warning if it's nonzero 738 if ($atom_structure['number_entries'] > 0x000FFFFF) { 739 if ($atom_structure['number_entries'] > 0x00FFFFFF) { 740 $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Ignoring upper byte and interpreting this as 0x'.getid3_lib::PrintHexBytes(substr($atom_data, 5, 3), true, false).' = '.($atom_structure['number_entries'] & 0x00FFFFFF)); 741 $atom_structure['number_entries'] = ($atom_structure['number_entries'] & 0x00FFFFFF); 742 } else { 743 $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Please report this to info@getid3.org referencing bug report #111'); 744 } 745 } 746 747 $stsdEntriesDataOffset = 8; 748 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 749 $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); 750 $stsdEntriesDataOffset += 4; 751 $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); 752 $stsdEntriesDataOffset += 4; 753 $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); 754 $stsdEntriesDataOffset += 6; 755 $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); 756 $stsdEntriesDataOffset += 2; 757 $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); 758 $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); 759 760 $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); 761 $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); 762 $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); 763 764 switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { 765 766 case "\x00\x00\x00\x00": 767 // audio tracks 768 $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); 769 $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); 770 $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); 771 $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); 772 $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); 773 774 // video tracks 775 // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html 776 $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); 777 $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); 778 $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); 779 $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); 780 $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); 781 $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); 782 $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4)); 783 $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2)); 784 $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4); 785 $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2)); 786 $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2)); 787 788 switch ($atom_structure['sample_description_table'][$i]['data_format']) { 789 case '2vuY': 790 case 'avc1': 791 case 'cvid': 792 case 'dvc ': 793 case 'dvcp': 794 case 'gif ': 795 case 'h263': 796 case 'jpeg': 797 case 'kpcd': 798 case 'mjpa': 799 case 'mjpb': 800 case 'mp4v': 801 case 'png ': 802 case 'raw ': 803 case 'rle ': 804 case 'rpza': 805 case 'smc ': 806 case 'SVQ1': 807 case 'SVQ3': 808 case 'tiff': 809 case 'v210': 810 case 'v216': 811 case 'v308': 812 case 'v408': 813 case 'v410': 814 case 'yuv2': 815 $info['fileformat'] = 'mp4'; 816 $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; 817 if ($this->QuicktimeVideoCodecLookup($info['video']['fourcc'])) { 818 $info['video']['fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($info['video']['fourcc']); 819 } 820 821 // https://www.getid3.org/phpBB3/viewtopic.php?t=1550 822 //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 823 if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) { 824 // assume that values stored here are more important than values stored in [tkhd] atom 825 $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; 826 $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; 827 $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; 828 $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; 829 } 830 break; 831 832 case 'qtvr': 833 $info['video']['dataformat'] = 'quicktimevr'; 834 break; 835 836 case 'mp4a': 837 default: 838 $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); 839 $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; 840 $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; 841 $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; 842 $info['audio']['codec'] = $info['quicktime']['audio']['codec']; 843 $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate']; 844 $info['audio']['channels'] = $info['quicktime']['audio']['channels']; 845 $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth']; 846 switch ($atom_structure['sample_description_table'][$i]['data_format']) { 847 case 'raw ': // PCM 848 case 'alac': // Apple Lossless Audio Codec 849 case 'sowt': // signed/two's complement (Little Endian) 850 case 'twos': // signed/two's complement (Big Endian) 851 case 'in24': // 24-bit Integer 852 case 'in32': // 32-bit Integer 853 case 'fl32': // 32-bit Floating Point 854 case 'fl64': // 64-bit Floating Point 855 $info['audio']['lossless'] = $info['quicktime']['audio']['lossless'] = true; 856 $info['audio']['bitrate'] = $info['quicktime']['audio']['bitrate'] = $info['audio']['channels'] * $info['audio']['bits_per_sample'] * $info['audio']['sample_rate']; 857 break; 858 default: 859 $info['audio']['lossless'] = false; 860 break; 861 } 862 break; 863 } 864 break; 865 866 default: 867 switch ($atom_structure['sample_description_table'][$i]['data_format']) { 868 case 'mp4s': 869 $info['fileformat'] = 'mp4'; 870 break; 871 872 default: 873 // video atom 874 $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); 875 $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); 876 $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); 877 $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); 878 $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); 879 $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); 880 $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); 881 $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); 882 $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); 883 $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']); 884 $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); 885 $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); 886 887 $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); 888 $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); 889 890 if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { 891 $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; 892 $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); 893 $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']); 894 $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; 895 $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; 896 897 $info['video']['codec'] = $info['quicktime']['video']['codec']; 898 $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth']; 899 } 900 $info['video']['lossless'] = false; 901 $info['video']['pixel_aspect_ratio'] = (float) 1; 902 break; 903 } 904 break; 905 } 906 switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { 907 case 'mp4a': 908 $info['audio']['dataformat'] = 'mp4'; 909 $info['quicktime']['audio']['codec'] = 'mp4'; 910 break; 911 912 case '3ivx': 913 case '3iv1': 914 case '3iv2': 915 $info['video']['dataformat'] = '3ivx'; 916 break; 917 918 case 'xvid': 919 $info['video']['dataformat'] = 'xvid'; 920 break; 921 922 case 'mp4v': 923 $info['video']['dataformat'] = 'mpeg4'; 924 break; 925 926 case 'divx': 927 case 'div1': 928 case 'div2': 929 case 'div3': 930 case 'div4': 931 case 'div5': 932 case 'div6': 933 $info['video']['dataformat'] = 'divx'; 934 break; 935 936 default: 937 // do nothing 938 break; 939 } 940 unset($atom_structure['sample_description_table'][$i]['data']); 941 } 942 break; 943 944 945 case 'stts': // Sample Table Time-to-Sample atom 946 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 947 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 948 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 949 $sttsEntriesDataOffset = 8; 950 //$FrameRateCalculatorArray = array(); 951 $frames_count = 0; 952 953 $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']); 954 if ($max_stts_entries_to_scan < $atom_structure['number_entries']) { 955 $this->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($this->getid3->memory_limit / 1048576).'MB).'); 956 } 957 for ($i = 0; $i < $max_stts_entries_to_scan; $i++) { 958 $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); 959 $sttsEntriesDataOffset += 4; 960 $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); 961 $sttsEntriesDataOffset += 4; 962 963 $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; 964 965 // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM 966 //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { 967 // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; 968 // if ($stts_new_framerate <= 60) { 969 // // some atoms have durations of "1" giving a very large framerate, which probably is not right 970 // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate); 971 // } 972 //} 973 // 974 //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; 975 } 976 $info['quicktime']['stts_framecount'][] = $frames_count; 977 //$sttsFramesTotal = 0; 978 //$sttsSecondsTotal = 0; 979 //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { 980 // if (($frames_per_second > 60) || ($frames_per_second < 1)) { 981 // // not video FPS information, probably audio information 982 // $sttsFramesTotal = 0; 983 // $sttsSecondsTotal = 0; 984 // break; 985 // } 986 // $sttsFramesTotal += $frame_count; 987 // $sttsSecondsTotal += $frame_count / $frames_per_second; 988 //} 989 //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { 990 // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) { 991 // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; 992 // } 993 //} 994 break; 995 996 997 case 'stss': // Sample Table Sync Sample (key frames) atom 998 if ($ParseAllPossibleAtoms) { 999 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1000 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1001 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1002 $stssEntriesDataOffset = 8; 1003 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1004 $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); 1005 $stssEntriesDataOffset += 4; 1006 } 1007 } 1008 break; 1009 1010 1011 case 'stsc': // Sample Table Sample-to-Chunk atom 1012 if ($ParseAllPossibleAtoms) { 1013 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1014 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1015 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1016 $stscEntriesDataOffset = 8; 1017 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1018 $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); 1019 $stscEntriesDataOffset += 4; 1020 $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); 1021 $stscEntriesDataOffset += 4; 1022 $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); 1023 $stscEntriesDataOffset += 4; 1024 } 1025 } 1026 break; 1027 1028 1029 case 'stsz': // Sample Table SiZe atom 1030 if ($ParseAllPossibleAtoms) { 1031 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1032 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1033 $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1034 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 1035 $stszEntriesDataOffset = 12; 1036 if ($atom_structure['sample_size'] == 0) { 1037 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1038 $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); 1039 $stszEntriesDataOffset += 4; 1040 } 1041 } 1042 } 1043 break; 1044 1045 1046 case 'stco': // Sample Table Chunk Offset atom 1047 if ($ParseAllPossibleAtoms) { 1048 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1049 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1050 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1051 $stcoEntriesDataOffset = 8; 1052 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1053 $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); 1054 $stcoEntriesDataOffset += 4; 1055 } 1056 } 1057 break; 1058 1059 1060 case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) 1061 if ($ParseAllPossibleAtoms) { 1062 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1063 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1064 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1065 $stcoEntriesDataOffset = 8; 1066 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1067 $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); 1068 $stcoEntriesDataOffset += 8; 1069 } 1070 } 1071 break; 1072 1073 1074 case 'dref': // Data REFerence atom 1075 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1076 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1077 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1078 $drefDataOffset = 8; 1079 for ($i = 0; $i < $atom_structure['number_entries']; $i++) { 1080 $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); 1081 $drefDataOffset += 4; 1082 $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); 1083 $drefDataOffset += 4; 1084 $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); 1085 $drefDataOffset += 1; 1086 $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 1087 $drefDataOffset += 3; 1088 $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); 1089 $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); 1090 1091 $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); 1092 } 1093 break; 1094 1095 1096 case 'gmin': // base Media INformation atom 1097 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1098 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1099 $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); 1100 $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); 1101 $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); 1102 $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); 1103 $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); 1104 $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); 1105 break; 1106 1107 1108 case 'smhd': // Sound Media information HeaDer atom 1109 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1110 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1111 $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); 1112 $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); 1113 break; 1114 1115 1116 case 'vmhd': // Video Media information HeaDer atom 1117 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1118 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1119 $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); 1120 $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); 1121 $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); 1122 $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); 1123 1124 $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); 1125 break; 1126 1127 1128 case 'hdlr': // HanDLeR reference atom 1129 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1130 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1131 $atom_structure['component_type'] = substr($atom_data, 4, 4); 1132 $atom_structure['component_subtype'] = substr($atom_data, 8, 4); 1133 $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); 1134 $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); 1135 $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); 1136 $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24)); 1137 1138 if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { 1139 $info['video']['dataformat'] = 'quicktimevr'; 1140 } 1141 break; 1142 1143 1144 case 'mdhd': // MeDia HeaDer atom 1145 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1146 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1147 $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1148 $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 1149 $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); 1150 $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); 1151 $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); 1152 $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); 1153 1154 if ($atom_structure['time_scale'] == 0) { 1155 $this->error('Corrupt Quicktime file: mdhd.time_scale == zero'); 1156 return false; 1157 } 1158 $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); 1159 1160 $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); 1161 $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); 1162 $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; 1163 $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); 1164 if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { 1165 $info['comments']['language'][] = $atom_structure['language']; 1166 } 1167 break; 1168 1169 1170 case 'pnot': // Preview atom 1171 $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" 1172 $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 1173 $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' 1174 $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 1175 1176 $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); 1177 break; 1178 1179 1180 case 'crgn': // Clipping ReGioN atom 1181 $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, 1182 $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields 1183 $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. 1184 break; 1185 1186 1187 case 'load': // track LOAD settings atom 1188 $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); 1189 $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1190 $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 1191 $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); 1192 1193 $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); 1194 $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); 1195 break; 1196 1197 1198 case 'tmcd': // TiMe CoDe atom 1199 case 'chap': // CHAPter list atom 1200 case 'sync': // SYNChronization atom 1201 case 'scpt': // tranSCriPT atom 1202 case 'ssrc': // non-primary SouRCe atom 1203 for ($i = 0; $i < strlen($atom_data); $i += 4) { 1204 @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); 1205 } 1206 break; 1207 1208 1209 case 'elst': // Edit LiST atom 1210 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1211 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1212 $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1213 for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) { 1214 $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); 1215 $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); 1216 $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); 1217 } 1218 break; 1219 1220 1221 case 'kmat': // compressed MATte atom 1222 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1223 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 1224 $atom_structure['matte_data_raw'] = substr($atom_data, 4); 1225 break; 1226 1227 1228 case 'ctab': // Color TABle atom 1229 $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 1230 $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 1231 $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; 1232 for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { 1233 $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); 1234 $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); 1235 $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); 1236 $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); 1237 } 1238 break; 1239 1240 1241 case 'mvhd': // MoVie HeaDer atom 1242 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1243 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1244 $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1245 $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 1246 $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); 1247 $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); 1248 $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); 1249 $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); 1250 $atom_structure['reserved'] = substr($atom_data, 26, 10); 1251 $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); 1252 $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); 1253 $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); 1254 $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); 1255 $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); 1256 $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); 1257 $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); 1258 $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); 1259 $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); 1260 $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); 1261 $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); 1262 $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); 1263 $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); 1264 $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); 1265 $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); 1266 $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); 1267 1268 if ($atom_structure['time_scale'] == 0) { 1269 $this->error('Corrupt Quicktime file: mvhd.time_scale == zero'); 1270 return false; 1271 } 1272 $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); 1273 $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); 1274 $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); 1275 $info['quicktime']['display_scale'] = $atom_structure['matrix_a']; 1276 $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; 1277 break; 1278 1279 1280 case 'tkhd': // TracK HeaDer atom 1281 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1282 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1283 $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1284 $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); 1285 $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); 1286 $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); 1287 $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); 1288 $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); 1289 $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); 1290 $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); 1291 $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); 1292 $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); 1293 // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html 1294 // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737 1295 $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); 1296 $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); 1297 $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4)); 1298 $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); 1299 $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); 1300 $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4)); 1301 $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); 1302 $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4)); 1303 $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); 1304 $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); 1305 $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); 1306 $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); 1307 $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); 1308 $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); 1309 $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); 1310 $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); 1311 $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); 1312 1313 // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 1314 // attempt to compute rotation from matrix values 1315 // 2017-Dec-28: uncertain if 90/270 are correctly oriented; values returned by FixedPoint16_16 should perhaps be -1 instead of 65535(?) 1316 $matrixRotation = 0; 1317 switch ($atom_structure['matrix_a'].':'.$atom_structure['matrix_b'].':'.$atom_structure['matrix_c'].':'.$atom_structure['matrix_d']) { 1318 case '1:0:0:1': $matrixRotation = 0; break; 1319 case '0:1:65535:0': $matrixRotation = 90; break; 1320 case '65535:0:0:65535': $matrixRotation = 180; break; 1321 case '0:65535:1:0': $matrixRotation = 270; break; 1322 default: break; 1323 } 1324 1325 // https://www.getid3.org/phpBB3/viewtopic.php?t=2468 1326 // The rotation matrix can appear in the Quicktime file multiple times, at least once for each track, 1327 // and it's possible that only the video track (or, in theory, one of the video tracks) is flagged as 1328 // rotated while the other tracks (e.g. audio) is tagged as rotation=0 (behavior noted on iPhone 8 Plus) 1329 // The correct solution would be to check if the TrackID associated with the rotation matrix is indeed 1330 // a video track (or the main video track) and only set the rotation then, but since information about 1331 // what track is what is not trivially there to be examined, the lazy solution is to set the rotation 1332 // if it is found to be nonzero, on the assumption that tracks that don't need it will have rotation set 1333 // to zero (and be effectively ignored) and the video track will have rotation set correctly, which will 1334 // either be zero and automatically correct, or nonzero and be set correctly. 1335 if (!isset($info['video']['rotate']) || (($info['video']['rotate'] == 0) && ($matrixRotation > 0))) { 1336 $info['quicktime']['video']['rotate'] = $info['video']['rotate'] = $matrixRotation; 1337 } 1338 1339 if ($atom_structure['flags']['enabled'] == 1) { 1340 if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) { 1341 $info['video']['resolution_x'] = $atom_structure['width']; 1342 $info['video']['resolution_y'] = $atom_structure['height']; 1343 } 1344 $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']); 1345 $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']); 1346 $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; 1347 $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; 1348 } else { 1349 // see: https://www.getid3.org/phpBB3/viewtopic.php?t=1295 1350 //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); } 1351 //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); } 1352 //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); } 1353 } 1354 break; 1355 1356 1357 case 'iods': // Initial Object DeScriptor atom 1358 // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h 1359 // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html 1360 $offset = 0; 1361 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1362 $offset += 1; 1363 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); 1364 $offset += 3; 1365 $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1366 $offset += 1; 1367 $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); 1368 //$offset already adjusted by quicktime_read_mp4_descr_length() 1369 $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); 1370 $offset += 2; 1371 $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1372 $offset += 1; 1373 $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1374 $offset += 1; 1375 $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1376 $offset += 1; 1377 $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1378 $offset += 1; 1379 $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1380 $offset += 1; 1381 1382 $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields 1383 for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { 1384 $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); 1385 $offset += 1; 1386 $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); 1387 //$offset already adjusted by quicktime_read_mp4_descr_length() 1388 $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); 1389 $offset += 4; 1390 } 1391 1392 $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); 1393 $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); 1394 break; 1395 1396 case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) 1397 $atom_structure['signature'] = substr($atom_data, 0, 4); 1398 $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1399 $atom_structure['fourcc'] = substr($atom_data, 8, 4); 1400 break; 1401 1402 case 'mdat': // Media DATa atom 1403 // 'mdat' contains the actual data for the audio/video, possibly also subtitles 1404 1405 /* 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 */ 1406 1407 // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?) 1408 $mdat_offset = 0; 1409 while (true) { 1410 if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') { 1411 $mdat_offset += 8; 1412 } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') { 1413 $mdat_offset += 8; 1414 } else { 1415 break; 1416 } 1417 } 1418 if (substr($atom_data, $mdat_offset, 4) == 'GPRO') { 1419 $GOPRO_chunk_length = getid3_lib::LittleEndian2Int(substr($atom_data, $mdat_offset + 4, 4)); 1420 $GOPRO_offset = 8; 1421 $atom_structure['GPRO']['raw'] = substr($atom_data, $mdat_offset + 8, $GOPRO_chunk_length - 8); 1422 $atom_structure['GPRO']['firmware'] = substr($atom_structure['GPRO']['raw'], 0, 15); 1423 $atom_structure['GPRO']['unknown1'] = substr($atom_structure['GPRO']['raw'], 15, 16); 1424 $atom_structure['GPRO']['unknown2'] = substr($atom_structure['GPRO']['raw'], 31, 32); 1425 $atom_structure['GPRO']['unknown3'] = substr($atom_structure['GPRO']['raw'], 63, 16); 1426 $atom_structure['GPRO']['camera'] = substr($atom_structure['GPRO']['raw'], 79, 32); 1427 $info['quicktime']['camera']['model'] = rtrim($atom_structure['GPRO']['camera'], "\x00"); 1428 } 1429 1430 // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field 1431 while (($mdat_offset < (strlen($atom_data) - 8)) 1432 && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) 1433 && ($chapter_string_length < 1000) 1434 && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) 1435 && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { 1436 list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; 1437 $mdat_offset += (2 + $chapter_string_length); 1438 @$info['quicktime']['comments']['chapters'][] = $chapter_string; 1439 1440 // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) 1441 if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 1442 $mdat_offset += 12; 1443 } 1444 } 1445 1446 if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) { 1447 1448 $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8; 1449 $OldAVDataEnd = $info['avdataend']; 1450 $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size']; 1451 1452 $getid3_temp = new getID3(); 1453 $getid3_temp->openfile($this->getid3->filename); 1454 $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; 1455 $getid3_temp->info['avdataend'] = $info['avdataend']; 1456 $getid3_mp3 = new getid3_mp3($getid3_temp); 1457 if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) { 1458 $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); 1459 if (!empty($getid3_temp->info['warning'])) { 1460 foreach ($getid3_temp->info['warning'] as $value) { 1461 $this->warning($value); 1462 } 1463 } 1464 if (!empty($getid3_temp->info['mpeg'])) { 1465 $info['mpeg'] = $getid3_temp->info['mpeg']; 1466 if (isset($info['mpeg']['audio'])) { 1467 $info['audio']['dataformat'] = 'mp3'; 1468 $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'))); 1469 $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; 1470 $info['audio']['channels'] = $info['mpeg']['audio']['channels']; 1471 $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; 1472 $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); 1473 $info['bitrate'] = $info['audio']['bitrate']; 1474 } 1475 } 1476 } 1477 unset($getid3_mp3, $getid3_temp); 1478 $info['avdataend'] = $OldAVDataEnd; 1479 unset($OldAVDataEnd); 1480 1481 } 1482 1483 unset($mdat_offset, $chapter_string_length, $chapter_matches); 1484 break; 1485 1486 case 'free': // FREE space atom 1487 case 'skip': // SKIP atom 1488 case 'wide': // 64-bit expansion placeholder atom 1489 // 'free', 'skip' and 'wide' are just padding, contains no useful data at all 1490 1491 // When writing QuickTime files, it is sometimes necessary to update an atom's size. 1492 // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom 1493 // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime 1494 // puts an 8-byte placeholder atom before any atoms it may have to update the size of. 1495 // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the 1496 // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. 1497 // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). 1498 break; 1499 1500 1501 case 'nsav': // NoSAVe atom 1502 // http://developer.apple.com/technotes/tn/tn2038.html 1503 $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); 1504 break; 1505 1506 case 'ctyp': // Controller TYPe atom (seen on QTVR) 1507 // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt 1508 // some controller names are: 1509 // 0x00 + 'std' for linear movie 1510 // 'none' for no controls 1511 $atom_structure['ctyp'] = substr($atom_data, 0, 4); 1512 $info['quicktime']['controller'] = $atom_structure['ctyp']; 1513 switch ($atom_structure['ctyp']) { 1514 case 'qtvr': 1515 $info['video']['dataformat'] = 'quicktimevr'; 1516 break; 1517 } 1518 break; 1519 1520 case 'pano': // PANOrama track (seen on QTVR) 1521 $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); 1522 break; 1523 1524 case 'hint': // HINT track 1525 case 'hinf': // 1526 case 'hinv': // 1527 case 'hnti': // 1528 $info['quicktime']['hinting'] = true; 1529 break; 1530 1531 case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) 1532 for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { 1533 $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); 1534 } 1535 break; 1536 1537 1538 // Observed-but-not-handled atom types are just listed here to prevent warnings being generated 1539 case 'FXTC': // Something to do with Adobe After Effects (?) 1540 case 'PrmA': 1541 case 'code': 1542 case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html 1543 case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html 1544 // tapt seems to be used to compute the video size [https://www.getid3.org/phpBB3/viewtopic.php?t=838] 1545 // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html 1546 // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html 1547 case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html 1548 case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html 1549 case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html 1550 case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html 1551 //$atom_structure['data'] = $atom_data; 1552 break; 1553 1554 case "\xA9".'xyz': // GPS latitude+longitude+altitude 1555 $atom_structure['data'] = $atom_data; 1556 if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) { 1557 @list($all, $latitude, $longitude, $altitude) = $matches; 1558 $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude); 1559 $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude); 1560 if (!empty($altitude)) { 1561 $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude); 1562 } 1563 } else { 1564 $this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.'); 1565 } 1566 break; 1567 1568 case 'NCDT': 1569 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html 1570 // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 1571 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); 1572 break; 1573 case 'NCTH': // Nikon Camera THumbnail image 1574 case 'NCVW': // Nikon Camera preVieW image 1575 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html 1576 if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) { 1577 $atom_structure['data'] = $atom_data; 1578 $atom_structure['image_mime'] = 'image/jpeg'; 1579 $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image')); 1580 $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']); 1581 } 1582 break; 1583 case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG 1584 $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data); 1585 break; 1586 case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html 1587 case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html 1588 case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html 1589 $atom_structure['data'] = $atom_data; 1590 break; 1591 1592 case "\x00\x00\x00\x00": 1593 // some kind of metacontainer, may contain a big data dump such as: 1594 // 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 1595 // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt 1596 1597 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1598 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1599 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 1600 //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 1601 break; 1602 1603 case 'meta': // METAdata atom 1604 // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html 1605 1606 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1607 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1608 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); 1609 break; 1610 1611 case 'data': // metaDATA atom 1612 static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other 1613 // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data 1614 $atom_structure['language'] = substr($atom_data, 4 + 0, 2); 1615 $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); 1616 $atom_structure['data'] = substr($atom_data, 4 + 4); 1617 $atom_structure['key_name'] = @$info['quicktime']['temp_meta_key_names'][$metaDATAkey++]; 1618 1619 if ($atom_structure['key_name'] && $atom_structure['data']) { 1620 @$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data']; 1621 } 1622 break; 1623 1624 case 'keys': // KEYS that may be present in the metadata atom. 1625 // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 1626 // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. 1627 // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys". 1628 $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); 1629 $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); 1630 $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); 1631 $keys_atom_offset = 8; 1632 for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { 1633 $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); 1634 $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); 1635 $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); 1636 $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace 1637 1638 $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value']; 1639 } 1640 break; 1641 1642 case 'gps ': 1643 // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 1644 // The 'gps ' contains simple look up table made up of 8byte rows, that point to the 'free' atoms that contains the actual GPS data. 1645 // The first row is version/metadata/notsure, I skip that. 1646 // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file. 1647 1648 $GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size 1649 if (strlen($atom_data) > 0) { 1650 if ((strlen($atom_data) % $GPS_rowsize) == 0) { 1651 $atom_structure['gps_toc'] = array(); 1652 foreach (str_split($atom_data, $GPS_rowsize) as $counter => $datapair) { 1653 $atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data, $counter * $GPS_rowsize, $GPS_rowsize)); 1654 } 1655 1656 $atom_structure['gps_entries'] = array(); 1657 $previous_offset = $this->ftell(); 1658 foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) { 1659 if ($key == 0) { 1660 // "The first row is version/metadata/notsure, I skip that." 1661 continue; 1662 } 1663 $this->fseek($gps_pointer['offset']); 1664 $GPS_free_data = $this->fread($gps_pointer['size']); 1665 1666 /* 1667 // 2017-05-10: I see some of the data, notably the Hour-Minute-Second, but cannot reconcile the rest of the data. However, the NMEA "GPRMC" line is there and relatively easy to parse, so I'm using that instead 1668 1669 // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 1670 // The structure of the GPS data atom (the 'free' atoms mentioned above) is following: 1671 // hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from('<IIIIIIssssfff',data, 48) 1672 // For those unfamiliar with python struct: 1673 // I = int 1674 // s = is string (size 1, in this case) 1675 // f = float 1676 1677 //$atom_structure['gps_entries'][$key] = unpack('Vhour/Vminute/Vsecond/Vyear/Vmonth/Vday/Vactive/Vlatitude_b/Vlongitude_b/Vunknown2/flatitude/flongitude/fspeed', substr($GPS_free_data, 48)); 1678 */ 1679 1680 // $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62 1681 // $GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67 1682 // $GPRMC,002454,A,3553.5295,N,13938.6570,E,0.0,43.1,180700,7.1,W,A*3F 1683 // $GPRMC,094347.000,A,5342.0061,N,00737.9908,W,0.01,156.75,140217,,,A*7D 1684 if (preg_match('#\\$GPRMC,([0-9\\.]*),([AV]),([0-9\\.]*),([NS]),([0-9\\.]*),([EW]),([0-9\\.]*),([0-9\\.]*),([0-9]*),([0-9\\.]*),([EW]?)(,[A])?(\\*[0-9A-F]{2})#', $GPS_free_data, $matches)) { 1685 $GPS_this_GPRMC = array(); 1686 list( 1687 $GPS_this_GPRMC['raw']['gprmc'], 1688 $GPS_this_GPRMC['raw']['timestamp'], 1689 $GPS_this_GPRMC['raw']['status'], 1690 $GPS_this_GPRMC['raw']['latitude'], 1691 $GPS_this_GPRMC['raw']['latitude_direction'], 1692 $GPS_this_GPRMC['raw']['longitude'], 1693 $GPS_this_GPRMC['raw']['longitude_direction'], 1694 $GPS_this_GPRMC['raw']['knots'], 1695 $GPS_this_GPRMC['raw']['angle'], 1696 $GPS_this_GPRMC['raw']['datestamp'], 1697 $GPS_this_GPRMC['raw']['variation'], 1698 $GPS_this_GPRMC['raw']['variation_direction'], 1699 $dummy, 1700 $GPS_this_GPRMC['raw']['checksum'], 1701 ) = $matches; 1702 1703 $hour = substr($GPS_this_GPRMC['raw']['timestamp'], 0, 2); 1704 $minute = substr($GPS_this_GPRMC['raw']['timestamp'], 2, 2); 1705 $second = substr($GPS_this_GPRMC['raw']['timestamp'], 4, 2); 1706 $ms = substr($GPS_this_GPRMC['raw']['timestamp'], 6); // may contain decimal seconds 1707 $day = substr($GPS_this_GPRMC['raw']['datestamp'], 0, 2); 1708 $month = substr($GPS_this_GPRMC['raw']['datestamp'], 2, 2); 1709 $year = substr($GPS_this_GPRMC['raw']['datestamp'], 4, 2); 1710 $year += (($year > 90) ? 1900 : 2000); // complete lack of foresight: datestamps are stored with 2-digit years, take best guess 1711 $GPS_this_GPRMC['timestamp'] = $year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second.$ms; 1712 1713 $GPS_this_GPRMC['active'] = ($GPS_this_GPRMC['raw']['status'] == 'A'); // A=Active,V=Void 1714 1715 foreach (array('latitude','longitude') as $latlon) { 1716 preg_match('#^([0-9]{1,3})([0-9]{2}\\.[0-9]+)$#', $GPS_this_GPRMC['raw'][$latlon], $matches); 1717 list($dummy, $deg, $min) = $matches; 1718 $GPS_this_GPRMC[$latlon] = $deg + ($min / 60); 1719 } 1720 $GPS_this_GPRMC['latitude'] *= (($GPS_this_GPRMC['raw']['latitude_direction'] == 'S') ? -1 : 1); 1721 $GPS_this_GPRMC['longitude'] *= (($GPS_this_GPRMC['raw']['longitude_direction'] == 'W') ? -1 : 1); 1722 1723 $GPS_this_GPRMC['heading'] = $GPS_this_GPRMC['raw']['angle']; 1724 $GPS_this_GPRMC['speed_knot'] = $GPS_this_GPRMC['raw']['knots']; 1725 $GPS_this_GPRMC['speed_kmh'] = $GPS_this_GPRMC['raw']['knots'] * 1.852; 1726 if ($GPS_this_GPRMC['raw']['variation']) { 1727 $GPS_this_GPRMC['variation'] = $GPS_this_GPRMC['raw']['variation']; 1728 $GPS_this_GPRMC['variation'] *= (($GPS_this_GPRMC['raw']['variation_direction'] == 'W') ? -1 : 1); 1729 } 1730 1731 $atom_structure['gps_entries'][$key] = $GPS_this_GPRMC; 1732 1733 @$info['quicktime']['gps_track'][$GPS_this_GPRMC['timestamp']] = array( 1734 'latitude' => (float) $GPS_this_GPRMC['latitude'], 1735 'longitude' => (float) $GPS_this_GPRMC['longitude'], 1736 'speed_kmh' => (float) $GPS_this_GPRMC['speed_kmh'], 1737 'heading' => (float) $GPS_this_GPRMC['heading'], 1738 ); 1739 1740 } else { 1741 $this->warning('Unhandled GPS format in "free" atom at offset '.$gps_pointer['offset']); 1742 } 1743 } 1744 $this->fseek($previous_offset); 1745 1746 } else { 1747 $this->warning('QuickTime atom "'.$atomname.'" is not mod-8 bytes long ('.$atomsize.' bytes) at offset '.$baseoffset); 1748 } 1749 } else { 1750 $this->warning('QuickTime atom "'.$atomname.'" is zero bytes long at offset '.$baseoffset); 1751 } 1752 break; 1753 1754 case 'loci':// 3GP location (El Loco) 1755 $loffset = 0; 1756 $info['quicktime']['comments']['gps_flags'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 0, 4))); 1757 $info['quicktime']['comments']['gps_lang'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 4, 2))); 1758 $info['quicktime']['comments']['gps_location'] = array( $this->LociString(substr($atom_data, 6), $loffset)); 1759 $loci_data = substr($atom_data, 6 + $loffset); 1760 $info['quicktime']['comments']['gps_role'] = array( getid3_lib::BigEndian2Int(substr($loci_data, 0, 1))); 1761 $info['quicktime']['comments']['gps_longitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 1, 4))); 1762 $info['quicktime']['comments']['gps_latitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 5, 4))); 1763 $info['quicktime']['comments']['gps_altitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 9, 4))); 1764 $info['quicktime']['comments']['gps_body'] = array( $this->LociString(substr($loci_data, 13 ), $loffset)); 1765 $info['quicktime']['comments']['gps_notes'] = array( $this->LociString(substr($loci_data, 13 + $loffset), $loffset)); 1766 break; 1767 1768 case 'chpl': // CHaPter List 1769 // https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf 1770 $chpl_version = getid3_lib::BigEndian2Int(substr($atom_data, 4, 1)); // Expected to be 0 1771 $chpl_flags = getid3_lib::BigEndian2Int(substr($atom_data, 5, 3)); // Reserved, set to 0 1772 $chpl_count = getid3_lib::BigEndian2Int(substr($atom_data, 8, 1)); 1773 $chpl_offset = 9; 1774 for ($i = 0; $i < $chpl_count; $i++) { 1775 if (($chpl_offset + 9) >= strlen($atom_data)) { 1776 $this->warning('QuickTime chapter '.$i.' extends beyond end of "chpl" atom'); 1777 break; 1778 } 1779 $info['quicktime']['chapters'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 8)) / 10000000; // timestamps are stored as 100-nanosecond units 1780 $chpl_offset += 8; 1781 $chpl_title_size = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 1)); 1782 $chpl_offset += 1; 1783 $info['quicktime']['chapters'][$i]['title'] = substr($atom_data, $chpl_offset, $chpl_title_size); 1784 $chpl_offset += $chpl_title_size; 1785 } 1786 break; 1787 1788 case 'FIRM': // FIRMware version(?), seen on GoPro Hero4 1789 $info['quicktime']['camera']['firmware'] = $atom_data; 1790 break; 1791 1792 case 'CAME': // FIRMware version(?), seen on GoPro Hero4 1793 $info['quicktime']['camera']['serial_hash'] = unpack('H*', $atom_data); 1794 break; 1795 1796 case 'dscp': 1797 case 'rcif': 1798 // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 1799 if (substr($atom_data, 0, 7) == "\x00\x00\x00\x00\x55\xC4".'{') { 1800 if ($json_decoded = @json_decode(rtrim(substr($atom_data, 6), "\x00"), true)) { 1801 $info['quicktime']['camera'][$atomname] = $json_decoded; 1802 if (($atomname == 'rcif') && isset($info['quicktime']['camera']['rcif']['wxcamera']['rotate'])) { 1803 $info['video']['rotate'] = $info['quicktime']['video']['rotate'] = $info['quicktime']['camera']['rcif']['wxcamera']['rotate']; 1804 } 1805 } else { 1806 $this->warning('Failed to JSON decode atom "'.$atomname.'"'); 1807 $atom_structure['data'] = $atom_data; 1808 } 1809 unset($json_decoded); 1810 } else { 1811 $this->warning('Expecting 55 C4 7B at start of atom "'.$atomname.'", found '.getid3_lib::PrintHexBytes(substr($atom_data, 4, 3)).' instead'); 1812 $atom_structure['data'] = $atom_data; 1813 } 1814 break; 1815 1816 case 'frea': 1817 // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea 1818 // may contain "scra" (PreviewImage) and/or "thma" (ThumbnailImage) 1819 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); 1820 break; 1821 case 'tima': // subatom to "frea" 1822 // no idea what this does, the one sample file I've seen has a value of 0x00000027 1823 $atom_structure['data'] = $atom_data; 1824 break; 1825 case 'ver ': // subatom to "frea" 1826 // some kind of version number, the one sample file I've seen has a value of "3.00.073" 1827 $atom_structure['data'] = $atom_data; 1828 break; 1829 case 'thma': // subatom to "frea" -- "ThumbnailImage" 1830 // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea 1831 if (strlen($atom_data) > 0) { 1832 $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg'); 1833 } 1834 break; 1835 case 'scra': // subatom to "frea" -- "PreviewImage" 1836 // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea 1837 // but the only sample file I've seen has no useful data here 1838 if (strlen($atom_data) > 0) { 1839 $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg'); 1840 } 1841 break; 1842 1843 1844 default: 1845 $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).'), '.$atomsize.' bytes at offset '.$baseoffset); 1846 $atom_structure['data'] = $atom_data; 1847 break; 1848 } 1849 } 1850 array_pop($atomHierarchy); 1851 return $atom_structure; 1852 } 1853 1854 /** 1855 * @param string $atom_data 1856 * @param int $baseoffset 1857 * @param array $atomHierarchy 1858 * @param bool $ParseAllPossibleAtoms 1859 * 1860 * @return array|false 1861 */ 1862 public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { 1863 $atom_structure = false; 1864 $subatomoffset = 0; 1865 $subatomcounter = 0; 1866 if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { 1867 return false; 1868 } 1869 while ($subatomoffset < strlen($atom_data)) { 1870 $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); 1871 $subatomname = substr($atom_data, $subatomoffset + 4, 4); 1872 $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); 1873 if ($subatomsize == 0) { 1874 // Furthermore, for historical reasons the list of atoms is optionally 1875 // terminated by a 32-bit integer set to 0. If you are writing a program 1876 // to read user data atoms, you should allow for the terminating 0. 1877 if (strlen($atom_data) > 12) { 1878 $subatomoffset += 4; 1879 continue; 1880 } 1881 return $atom_structure; 1882 } 1883 $atom_structure[$subatomcounter++] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); 1884 $subatomoffset += $subatomsize; 1885 } 1886 return $atom_structure; 1887 } 1888 1889 /** 1890 * @param string $data 1891 * @param int $offset 1892 * 1893 * @return int 1894 */ 1895 public function quicktime_read_mp4_descr_length($data, &$offset) { 1896 // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html 1897 $num_bytes = 0; 1898 $length = 0; 1899 do { 1900 $b = ord(substr($data, $offset++, 1)); 1901 $length = ($length << 7) | ($b & 0x7F); 1902 } while (($b & 0x80) && ($num_bytes++ < 4)); 1903 return $length; 1904 } 1905 1906 /** 1907 * @param int $languageid 1908 * 1909 * @return string 1910 */ 1911 public function QuicktimeLanguageLookup($languageid) { 1912 // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353 1913 static $QuicktimeLanguageLookup = array(); 1914 if (empty($QuicktimeLanguageLookup)) { 1915 $QuicktimeLanguageLookup[0] = 'English'; 1916 $QuicktimeLanguageLookup[1] = 'French'; 1917 $QuicktimeLanguageLookup[2] = 'German'; 1918 $QuicktimeLanguageLookup[3] = 'Italian'; 1919 $QuicktimeLanguageLookup[4] = 'Dutch'; 1920 $QuicktimeLanguageLookup[5] = 'Swedish'; 1921 $QuicktimeLanguageLookup[6] = 'Spanish'; 1922 $QuicktimeLanguageLookup[7] = 'Danish'; 1923 $QuicktimeLanguageLookup[8] = 'Portuguese'; 1924 $QuicktimeLanguageLookup[9] = 'Norwegian'; 1925 $QuicktimeLanguageLookup[10] = 'Hebrew'; 1926 $QuicktimeLanguageLookup[11] = 'Japanese'; 1927 $QuicktimeLanguageLookup[12] = 'Arabic'; 1928 $QuicktimeLanguageLookup[13] = 'Finnish'; 1929 $QuicktimeLanguageLookup[14] = 'Greek'; 1930 $QuicktimeLanguageLookup[15] = 'Icelandic'; 1931 $QuicktimeLanguageLookup[16] = 'Maltese'; 1932 $QuicktimeLanguageLookup[17] = 'Turkish'; 1933 $QuicktimeLanguageLookup[18] = 'Croatian'; 1934 $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; 1935 $QuicktimeLanguageLookup[20] = 'Urdu'; 1936 $QuicktimeLanguageLookup[21] = 'Hindi'; 1937 $QuicktimeLanguageLookup[22] = 'Thai'; 1938 $QuicktimeLanguageLookup[23] = 'Korean'; 1939 $QuicktimeLanguageLookup[24] = 'Lithuanian'; 1940 $QuicktimeLanguageLookup[25] = 'Polish'; 1941 $QuicktimeLanguageLookup[26] = 'Hungarian'; 1942 $QuicktimeLanguageLookup[27] = 'Estonian'; 1943 $QuicktimeLanguageLookup[28] = 'Lettish'; 1944 $QuicktimeLanguageLookup[28] = 'Latvian'; 1945 $QuicktimeLanguageLookup[29] = 'Saamisk'; 1946 $QuicktimeLanguageLookup[29] = 'Lappish'; 1947 $QuicktimeLanguageLookup[30] = 'Faeroese'; 1948 $QuicktimeLanguageLookup[31] = 'Farsi'; 1949 $QuicktimeLanguageLookup[31] = 'Persian'; 1950 $QuicktimeLanguageLookup[32] = 'Russian'; 1951 $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; 1952 $QuicktimeLanguageLookup[34] = 'Flemish'; 1953 $QuicktimeLanguageLookup[35] = 'Irish'; 1954 $QuicktimeLanguageLookup[36] = 'Albanian'; 1955 $QuicktimeLanguageLookup[37] = 'Romanian'; 1956 $QuicktimeLanguageLookup[38] = 'Czech'; 1957 $QuicktimeLanguageLookup[39] = 'Slovak'; 1958 $QuicktimeLanguageLookup[40] = 'Slovenian'; 1959 $QuicktimeLanguageLookup[41] = 'Yiddish'; 1960 $QuicktimeLanguageLookup[42] = 'Serbian'; 1961 $QuicktimeLanguageLookup[43] = 'Macedonian'; 1962 $QuicktimeLanguageLookup[44] = 'Bulgarian'; 1963 $QuicktimeLanguageLookup[45] = 'Ukrainian'; 1964 $QuicktimeLanguageLookup[46] = 'Byelorussian'; 1965 $QuicktimeLanguageLookup[47] = 'Uzbek'; 1966 $QuicktimeLanguageLookup[48] = 'Kazakh'; 1967 $QuicktimeLanguageLookup[49] = 'Azerbaijani'; 1968 $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; 1969 $QuicktimeLanguageLookup[51] = 'Armenian'; 1970 $QuicktimeLanguageLookup[52] = 'Georgian'; 1971 $QuicktimeLanguageLookup[53] = 'Moldavian'; 1972 $QuicktimeLanguageLookup[54] = 'Kirghiz'; 1973 $QuicktimeLanguageLookup[55] = 'Tajiki'; 1974 $QuicktimeLanguageLookup[56] = 'Turkmen'; 1975 $QuicktimeLanguageLookup[57] = 'Mongolian'; 1976 $QuicktimeLanguageLookup[58] = 'MongolianCyr'; 1977 $QuicktimeLanguageLookup[59] = 'Pashto'; 1978 $QuicktimeLanguageLookup[60] = 'Kurdish'; 1979 $QuicktimeLanguageLookup[61] = 'Kashmiri'; 1980 $QuicktimeLanguageLookup[62] = 'Sindhi'; 1981 $QuicktimeLanguageLookup[63] = 'Tibetan'; 1982 $QuicktimeLanguageLookup[64] = 'Nepali'; 1983 $QuicktimeLanguageLookup[65] = 'Sanskrit'; 1984 $QuicktimeLanguageLookup[66] = 'Marathi'; 1985 $QuicktimeLanguageLookup[67] = 'Bengali'; 1986 $QuicktimeLanguageLookup[68] = 'Assamese'; 1987 $QuicktimeLanguageLookup[69] = 'Gujarati'; 1988 $QuicktimeLanguageLookup[70] = 'Punjabi'; 1989 $QuicktimeLanguageLookup[71] = 'Oriya'; 1990 $QuicktimeLanguageLookup[72] = 'Malayalam'; 1991 $QuicktimeLanguageLookup[73] = 'Kannada'; 1992 $QuicktimeLanguageLookup[74] = 'Tamil'; 1993 $QuicktimeLanguageLookup[75] = 'Telugu'; 1994 $QuicktimeLanguageLookup[76] = 'Sinhalese'; 1995 $QuicktimeLanguageLookup[77] = 'Burmese'; 1996 $QuicktimeLanguageLookup[78] = 'Khmer'; 1997 $QuicktimeLanguageLookup[79] = 'Lao'; 1998 $QuicktimeLanguageLookup[80] = 'Vietnamese'; 1999 $QuicktimeLanguageLookup[81] = 'Indonesian'; 2000 $QuicktimeLanguageLookup[82] = 'Tagalog'; 2001 $QuicktimeLanguageLookup[83] = 'MalayRoman'; 2002 $QuicktimeLanguageLookup[84] = 'MalayArabic'; 2003 $QuicktimeLanguageLookup[85] = 'Amharic'; 2004 $QuicktimeLanguageLookup[86] = 'Tigrinya'; 2005 $QuicktimeLanguageLookup[87] = 'Galla'; 2006 $QuicktimeLanguageLookup[87] = 'Oromo'; 2007 $QuicktimeLanguageLookup[88] = 'Somali'; 2008 $QuicktimeLanguageLookup[89] = 'Swahili'; 2009 $QuicktimeLanguageLookup[90] = 'Ruanda'; 2010 $QuicktimeLanguageLookup[91] = 'Rundi'; 2011 $QuicktimeLanguageLookup[92] = 'Chewa'; 2012 $QuicktimeLanguageLookup[93] = 'Malagasy'; 2013 $QuicktimeLanguageLookup[94] = 'Esperanto'; 2014 $QuicktimeLanguageLookup[128] = 'Welsh'; 2015 $QuicktimeLanguageLookup[129] = 'Basque'; 2016 $QuicktimeLanguageLookup[130] = 'Catalan'; 2017 $QuicktimeLanguageLookup[131] = 'Latin'; 2018 $QuicktimeLanguageLookup[132] = 'Quechua'; 2019 $QuicktimeLanguageLookup[133] = 'Guarani'; 2020 $QuicktimeLanguageLookup[134] = 'Aymara'; 2021 $QuicktimeLanguageLookup[135] = 'Tatar'; 2022 $QuicktimeLanguageLookup[136] = 'Uighur'; 2023 $QuicktimeLanguageLookup[137] = 'Dzongkha'; 2024 $QuicktimeLanguageLookup[138] = 'JavaneseRom'; 2025 $QuicktimeLanguageLookup[32767] = 'Unspecified'; 2026 } 2027 if (($languageid > 138) && ($languageid < 32767)) { 2028 /* 2029 ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php 2030 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. 2031 The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate 2032 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. 2033 2034 One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character 2035 and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character, 2036 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 2037 significant bits and the most significant bit set to zero. 2038 */ 2039 $iso_language_id = ''; 2040 $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60); 2041 $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60); 2042 $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60); 2043 $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id); 2044 } 2045 return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'); 2046 } 2047 2048 /** 2049 * @param string $codecid 2050 * 2051 * @return string 2052 */ 2053 public function QuicktimeVideoCodecLookup($codecid) { 2054 static $QuicktimeVideoCodecLookup = array(); 2055 if (empty($QuicktimeVideoCodecLookup)) { 2056 $QuicktimeVideoCodecLookup['.SGI'] = 'SGI'; 2057 $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1'; 2058 $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2'; 2059 $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4'; 2060 $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB'; 2061 $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC'; 2062 $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG'; 2063 $QuicktimeVideoCodecLookup['b16g'] = '16Gray'; 2064 $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray'; 2065 $QuicktimeVideoCodecLookup['b48r'] = '48RGB'; 2066 $QuicktimeVideoCodecLookup['b64a'] = '64ARGB'; 2067 $QuicktimeVideoCodecLookup['base'] = 'Base'; 2068 $QuicktimeVideoCodecLookup['clou'] = 'Cloud'; 2069 $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK'; 2070 $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak'; 2071 $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG'; 2072 $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC'; 2073 $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL'; 2074 $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC'; 2075 $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL'; 2076 $QuicktimeVideoCodecLookup['fire'] = 'Fire'; 2077 $QuicktimeVideoCodecLookup['flic'] = 'FLC'; 2078 $QuicktimeVideoCodecLookup['gif '] = 'GIF'; 2079 $QuicktimeVideoCodecLookup['h261'] = 'H261'; 2080 $QuicktimeVideoCodecLookup['h263'] = 'H263'; 2081 $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4'; 2082 $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG'; 2083 $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD'; 2084 $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A'; 2085 $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B'; 2086 $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1'; 2087 $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420'; 2088 $QuicktimeVideoCodecLookup['path'] = 'Vector'; 2089 $QuicktimeVideoCodecLookup['png '] = 'PNG'; 2090 $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint'; 2091 $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX'; 2092 $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw'; 2093 $QuicktimeVideoCodecLookup['raw '] = 'RAW'; 2094 $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple'; 2095 $QuicktimeVideoCodecLookup['rpza'] = 'Video'; 2096 $QuicktimeVideoCodecLookup['smc '] = 'Graphics'; 2097 $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1'; 2098 $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3'; 2099 $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9'; 2100 $QuicktimeVideoCodecLookup['tga '] = 'Targa'; 2101 $QuicktimeVideoCodecLookup['tiff'] = 'TIFF'; 2102 $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW'; 2103 $QuicktimeVideoCodecLookup['WRLE'] = 'BMP'; 2104 $QuicktimeVideoCodecLookup['y420'] = 'YUV420'; 2105 $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo'; 2106 $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned'; 2107 $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned'; 2108 } 2109 return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : ''); 2110 } 2111 2112 /** 2113 * @param string $codecid 2114 * 2115 * @return mixed|string 2116 */ 2117 public function QuicktimeAudioCodecLookup($codecid) { 2118 static $QuicktimeAudioCodecLookup = array(); 2119 if (empty($QuicktimeAudioCodecLookup)) { 2120 $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias'; 2121 $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC'; 2122 $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1'; 2123 $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec'; 2124 $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1'; 2125 $QuicktimeAudioCodecLookup['conv'] = 'Sample Format'; 2126 $QuicktimeAudioCodecLookup['dvca'] = 'DV'; 2127 $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1'; 2128 $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer'; 2129 $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point'; 2130 $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point'; 2131 $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1'; 2132 $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer'; 2133 $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer'; 2134 $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1'; 2135 $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1'; 2136 $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1'; 2137 $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer'; 2138 $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer'; 2139 $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC'; 2140 $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM'; 2141 $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA'; 2142 $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III'; 2143 $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding'; 2144 $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice'; 2145 $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2'; 2146 $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1'; 2147 $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate'; 2148 $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate'; 2149 $QuicktimeAudioCodecLookup['raw '] = 'raw PCM'; 2150 $QuicktimeAudioCodecLookup['sour'] = 'Sound Source'; 2151 $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)'; 2152 $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II'; 2153 $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II'; 2154 $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II'; 2155 $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II'; 2156 $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)'; 2157 $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1'; 2158 } 2159 return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : ''); 2160 } 2161 2162 /** 2163 * @param string $compressionid 2164 * 2165 * @return string 2166 */ 2167 public function QuicktimeDCOMLookup($compressionid) { 2168 static $QuicktimeDCOMLookup = array(); 2169 if (empty($QuicktimeDCOMLookup)) { 2170 $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate'; 2171 $QuicktimeDCOMLookup['adec'] = 'Apple Compression'; 2172 } 2173 return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : ''); 2174 } 2175 2176 /** 2177 * @param int $colordepthid 2178 * 2179 * @return string 2180 */ 2181 public function QuicktimeColorNameLookup($colordepthid) { 2182 static $QuicktimeColorNameLookup = array(); 2183 if (empty($QuicktimeColorNameLookup)) { 2184 $QuicktimeColorNameLookup[1] = '2-color (monochrome)'; 2185 $QuicktimeColorNameLookup[2] = '4-color'; 2186 $QuicktimeColorNameLookup[4] = '16-color'; 2187 $QuicktimeColorNameLookup[8] = '256-color'; 2188 $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)'; 2189 $QuicktimeColorNameLookup[24] = 'millions (24-bit color)'; 2190 $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)'; 2191 $QuicktimeColorNameLookup[33] = 'black & white'; 2192 $QuicktimeColorNameLookup[34] = '4-gray'; 2193 $QuicktimeColorNameLookup[36] = '16-gray'; 2194 $QuicktimeColorNameLookup[40] = '256-gray'; 2195 } 2196 return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid'); 2197 } 2198 2199 /** 2200 * @param int $stik 2201 * 2202 * @return string 2203 */ 2204 public function QuicktimeSTIKLookup($stik) { 2205 static $QuicktimeSTIKLookup = array(); 2206 if (empty($QuicktimeSTIKLookup)) { 2207 $QuicktimeSTIKLookup[0] = 'Movie'; 2208 $QuicktimeSTIKLookup[1] = 'Normal'; 2209 $QuicktimeSTIKLookup[2] = 'Audiobook'; 2210 $QuicktimeSTIKLookup[5] = 'Whacked Bookmark'; 2211 $QuicktimeSTIKLookup[6] = 'Music Video'; 2212 $QuicktimeSTIKLookup[9] = 'Short Film'; 2213 $QuicktimeSTIKLookup[10] = 'TV Show'; 2214 $QuicktimeSTIKLookup[11] = 'Booklet'; 2215 $QuicktimeSTIKLookup[14] = 'Ringtone'; 2216 $QuicktimeSTIKLookup[21] = 'Podcast'; 2217 } 2218 return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid'); 2219 } 2220 2221 /** 2222 * @param int $audio_profile_id 2223 * 2224 * @return string 2225 */ 2226 public function QuicktimeIODSaudioProfileName($audio_profile_id) { 2227 static $QuicktimeIODSaudioProfileNameLookup = array(); 2228 if (empty($QuicktimeIODSaudioProfileNameLookup)) { 2229 $QuicktimeIODSaudioProfileNameLookup = array( 2230 0x00 => 'ISO Reserved (0x00)', 2231 0x01 => 'Main Audio Profile @ Level 1', 2232 0x02 => 'Main Audio Profile @ Level 2', 2233 0x03 => 'Main Audio Profile @ Level 3', 2234 0x04 => 'Main Audio Profile @ Level 4', 2235 0x05 => 'Scalable Audio Profile @ Level 1', 2236 0x06 => 'Scalable Audio Profile @ Level 2', 2237 0x07 => 'Scalable Audio Profile @ Level 3', 2238 0x08 => 'Scalable Audio Profile @ Level 4', 2239 0x09 => 'Speech Audio Profile @ Level 1', 2240 0x0A => 'Speech Audio Profile @ Level 2', 2241 0x0B => 'Synthetic Audio Profile @ Level 1', 2242 0x0C => 'Synthetic Audio Profile @ Level 2', 2243 0x0D => 'Synthetic Audio Profile @ Level 3', 2244 0x0E => 'High Quality Audio Profile @ Level 1', 2245 0x0F => 'High Quality Audio Profile @ Level 2', 2246 0x10 => 'High Quality Audio Profile @ Level 3', 2247 0x11 => 'High Quality Audio Profile @ Level 4', 2248 0x12 => 'High Quality Audio Profile @ Level 5', 2249 0x13 => 'High Quality Audio Profile @ Level 6', 2250 0x14 => 'High Quality Audio Profile @ Level 7', 2251 0x15 => 'High Quality Audio Profile @ Level 8', 2252 0x16 => 'Low Delay Audio Profile @ Level 1', 2253 0x17 => 'Low Delay Audio Profile @ Level 2', 2254 0x18 => 'Low Delay Audio Profile @ Level 3', 2255 0x19 => 'Low Delay Audio Profile @ Level 4', 2256 0x1A => 'Low Delay Audio Profile @ Level 5', 2257 0x1B => 'Low Delay Audio Profile @ Level 6', 2258 0x1C => 'Low Delay Audio Profile @ Level 7', 2259 0x1D => 'Low Delay Audio Profile @ Level 8', 2260 0x1E => 'Natural Audio Profile @ Level 1', 2261 0x1F => 'Natural Audio Profile @ Level 2', 2262 0x20 => 'Natural Audio Profile @ Level 3', 2263 0x21 => 'Natural Audio Profile @ Level 4', 2264 0x22 => 'Mobile Audio Internetworking Profile @ Level 1', 2265 0x23 => 'Mobile Audio Internetworking Profile @ Level 2', 2266 0x24 => 'Mobile Audio Internetworking Profile @ Level 3', 2267 0x25 => 'Mobile Audio Internetworking Profile @ Level 4', 2268 0x26 => 'Mobile Audio Internetworking Profile @ Level 5', 2269 0x27 => 'Mobile Audio Internetworking Profile @ Level 6', 2270 0x28 => 'AAC Profile @ Level 1', 2271 0x29 => 'AAC Profile @ Level 2', 2272 0x2A => 'AAC Profile @ Level 4', 2273 0x2B => 'AAC Profile @ Level 5', 2274 0x2C => 'High Efficiency AAC Profile @ Level 2', 2275 0x2D => 'High Efficiency AAC Profile @ Level 3', 2276 0x2E => 'High Efficiency AAC Profile @ Level 4', 2277 0x2F => 'High Efficiency AAC Profile @ Level 5', 2278 0xFE => 'Not part of MPEG-4 audio profiles', 2279 0xFF => 'No audio capability required', 2280 ); 2281 } 2282 return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private'); 2283 } 2284 2285 /** 2286 * @param int $video_profile_id 2287 * 2288 * @return string 2289 */ 2290 public function QuicktimeIODSvideoProfileName($video_profile_id) { 2291 static $QuicktimeIODSvideoProfileNameLookup = array(); 2292 if (empty($QuicktimeIODSvideoProfileNameLookup)) { 2293 $QuicktimeIODSvideoProfileNameLookup = array( 2294 0x00 => 'Reserved (0x00) Profile', 2295 0x01 => 'Simple Profile @ Level 1', 2296 0x02 => 'Simple Profile @ Level 2', 2297 0x03 => 'Simple Profile @ Level 3', 2298 0x08 => 'Simple Profile @ Level 0', 2299 0x10 => 'Simple Scalable Profile @ Level 0', 2300 0x11 => 'Simple Scalable Profile @ Level 1', 2301 0x12 => 'Simple Scalable Profile @ Level 2', 2302 0x15 => 'AVC/H264 Profile', 2303 0x21 => 'Core Profile @ Level 1', 2304 0x22 => 'Core Profile @ Level 2', 2305 0x32 => 'Main Profile @ Level 2', 2306 0x33 => 'Main Profile @ Level 3', 2307 0x34 => 'Main Profile @ Level 4', 2308 0x42 => 'N-bit Profile @ Level 2', 2309 0x51 => 'Scalable Texture Profile @ Level 1', 2310 0x61 => 'Simple Face Animation Profile @ Level 1', 2311 0x62 => 'Simple Face Animation Profile @ Level 2', 2312 0x63 => 'Simple FBA Profile @ Level 1', 2313 0x64 => 'Simple FBA Profile @ Level 2', 2314 0x71 => 'Basic Animated Texture Profile @ Level 1', 2315 0x72 => 'Basic Animated Texture Profile @ Level 2', 2316 0x81 => 'Hybrid Profile @ Level 1', 2317 0x82 => 'Hybrid Profile @ Level 2', 2318 0x91 => 'Advanced Real Time Simple Profile @ Level 1', 2319 0x92 => 'Advanced Real Time Simple Profile @ Level 2', 2320 0x93 => 'Advanced Real Time Simple Profile @ Level 3', 2321 0x94 => 'Advanced Real Time Simple Profile @ Level 4', 2322 0xA1 => 'Core Scalable Profile @ Level1', 2323 0xA2 => 'Core Scalable Profile @ Level2', 2324 0xA3 => 'Core Scalable Profile @ Level3', 2325 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1', 2326 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2', 2327 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3', 2328 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4', 2329 0xC1 => 'Advanced Core Profile @ Level 1', 2330 0xC2 => 'Advanced Core Profile @ Level 2', 2331 0xD1 => 'Advanced Scalable Texture @ Level1', 2332 0xD2 => 'Advanced Scalable Texture @ Level2', 2333 0xE1 => 'Simple Studio Profile @ Level 1', 2334 0xE2 => 'Simple Studio Profile @ Level 2', 2335 0xE3 => 'Simple Studio Profile @ Level 3', 2336 0xE4 => 'Simple Studio Profile @ Level 4', 2337 0xE5 => 'Core Studio Profile @ Level 1', 2338 0xE6 => 'Core Studio Profile @ Level 2', 2339 0xE7 => 'Core Studio Profile @ Level 3', 2340 0xE8 => 'Core Studio Profile @ Level 4', 2341 0xF0 => 'Advanced Simple Profile @ Level 0', 2342 0xF1 => 'Advanced Simple Profile @ Level 1', 2343 0xF2 => 'Advanced Simple Profile @ Level 2', 2344 0xF3 => 'Advanced Simple Profile @ Level 3', 2345 0xF4 => 'Advanced Simple Profile @ Level 4', 2346 0xF5 => 'Advanced Simple Profile @ Level 5', 2347 0xF7 => 'Advanced Simple Profile @ Level 3b', 2348 0xF8 => 'Fine Granularity Scalable Profile @ Level 0', 2349 0xF9 => 'Fine Granularity Scalable Profile @ Level 1', 2350 0xFA => 'Fine Granularity Scalable Profile @ Level 2', 2351 0xFB => 'Fine Granularity Scalable Profile @ Level 3', 2352 0xFC => 'Fine Granularity Scalable Profile @ Level 4', 2353 0xFD => 'Fine Granularity Scalable Profile @ Level 5', 2354 0xFE => 'Not part of MPEG-4 Visual profiles', 2355 0xFF => 'No visual capability required', 2356 ); 2357 } 2358 return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile'); 2359 } 2360 2361 /** 2362 * @param int $rtng 2363 * 2364 * @return string 2365 */ 2366 public function QuicktimeContentRatingLookup($rtng) { 2367 static $QuicktimeContentRatingLookup = array(); 2368 if (empty($QuicktimeContentRatingLookup)) { 2369 $QuicktimeContentRatingLookup[0] = 'None'; 2370 $QuicktimeContentRatingLookup[2] = 'Clean'; 2371 $QuicktimeContentRatingLookup[4] = 'Explicit'; 2372 } 2373 return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid'); 2374 } 2375 2376 /** 2377 * @param int $akid 2378 * 2379 * @return string 2380 */ 2381 public function QuicktimeStoreAccountTypeLookup($akid) { 2382 static $QuicktimeStoreAccountTypeLookup = array(); 2383 if (empty($QuicktimeStoreAccountTypeLookup)) { 2384 $QuicktimeStoreAccountTypeLookup[0] = 'iTunes'; 2385 $QuicktimeStoreAccountTypeLookup[1] = 'AOL'; 2386 } 2387 return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid'); 2388 } 2389 2390 /** 2391 * @param int $sfid 2392 * 2393 * @return string 2394 */ 2395 public function QuicktimeStoreFrontCodeLookup($sfid) { 2396 static $QuicktimeStoreFrontCodeLookup = array(); 2397 if (empty($QuicktimeStoreFrontCodeLookup)) { 2398 $QuicktimeStoreFrontCodeLookup[143460] = 'Australia'; 2399 $QuicktimeStoreFrontCodeLookup[143445] = 'Austria'; 2400 $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium'; 2401 $QuicktimeStoreFrontCodeLookup[143455] = 'Canada'; 2402 $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark'; 2403 $QuicktimeStoreFrontCodeLookup[143447] = 'Finland'; 2404 $QuicktimeStoreFrontCodeLookup[143442] = 'France'; 2405 $QuicktimeStoreFrontCodeLookup[143443] = 'Germany'; 2406 $QuicktimeStoreFrontCodeLookup[143448] = 'Greece'; 2407 $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland'; 2408 $QuicktimeStoreFrontCodeLookup[143450] = 'Italy'; 2409 $QuicktimeStoreFrontCodeLookup[143462] = 'Japan'; 2410 $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg'; 2411 $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands'; 2412 $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand'; 2413 $QuicktimeStoreFrontCodeLookup[143457] = 'Norway'; 2414 $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal'; 2415 $QuicktimeStoreFrontCodeLookup[143454] = 'Spain'; 2416 $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden'; 2417 $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland'; 2418 $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom'; 2419 $QuicktimeStoreFrontCodeLookup[143441] = 'United States'; 2420 } 2421 return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid'); 2422 } 2423 2424 /** 2425 * @param string $atom_data 2426 * 2427 * @return array 2428 */ 2429 public function QuicktimeParseNikonNCTG($atom_data) { 2430 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG 2431 // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 2432 // Data is stored as records of: 2433 // * 4 bytes record type 2434 // * 2 bytes size of data field type: 2435 // 0x0001 = flag (size field *= 1-byte) 2436 // 0x0002 = char (size field *= 1-byte) 2437 // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB 2438 // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD 2439 // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together 2440 // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? 2441 // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? 2442 // * 2 bytes data size field 2443 // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15") 2444 // all integers are stored BigEndian 2445 2446 $NCTGtagName = array( 2447 0x00000001 => 'Make', 2448 0x00000002 => 'Model', 2449 0x00000003 => 'Software', 2450 0x00000011 => 'CreateDate', 2451 0x00000012 => 'DateTimeOriginal', 2452 0x00000013 => 'FrameCount', 2453 0x00000016 => 'FrameRate', 2454 0x00000022 => 'FrameWidth', 2455 0x00000023 => 'FrameHeight', 2456 0x00000032 => 'AudioChannels', 2457 0x00000033 => 'AudioBitsPerSample', 2458 0x00000034 => 'AudioSampleRate', 2459 0x02000001 => 'MakerNoteVersion', 2460 0x02000005 => 'WhiteBalance', 2461 0x0200000b => 'WhiteBalanceFineTune', 2462 0x0200001e => 'ColorSpace', 2463 0x02000023 => 'PictureControlData', 2464 0x02000024 => 'WorldTime', 2465 0x02000032 => 'UnknownInfo', 2466 0x02000083 => 'LensType', 2467 0x02000084 => 'Lens', 2468 ); 2469 2470 $offset = 0; 2471 $data = null; 2472 $datalength = strlen($atom_data); 2473 $parsed = array(); 2474 while ($offset < $datalength) { 2475 $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4; 2476 $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2; 2477 $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2; 2478 switch ($data_size_type) { 2479 case 0x0001: // 0x0001 = flag (size field *= 1-byte) 2480 $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1)); 2481 $offset += ($data_size * 1); 2482 break; 2483 case 0x0002: // 0x0002 = char (size field *= 1-byte) 2484 $data = substr($atom_data, $offset, $data_size * 1); 2485 $offset += ($data_size * 1); 2486 $data = rtrim($data, "\x00"); 2487 break; 2488 case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB 2489 $data = ''; 2490 for ($i = $data_size - 1; $i >= 0; $i--) { 2491 $data .= substr($atom_data, $offset + ($i * 2), 2); 2492 } 2493 $data = getid3_lib::BigEndian2Int($data); 2494 $offset += ($data_size * 2); 2495 break; 2496 case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD 2497 $data = ''; 2498 for ($i = $data_size - 1; $i >= 0; $i--) { 2499 $data .= substr($atom_data, $offset + ($i * 4), 4); 2500 } 2501 $data = getid3_lib::BigEndian2Int($data); 2502 $offset += ($data_size * 4); 2503 break; 2504 case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together 2505 $data = array(); 2506 for ($i = 0; $i < $data_size; $i++) { 2507 $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4)); 2508 $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4)); 2509 if ($denomninator == 0) { 2510 $data[$i] = false; 2511 } else { 2512 $data[$i] = (double) $numerator / $denomninator; 2513 } 2514 } 2515 $offset += (8 * $data_size); 2516 if (count($data) == 1) { 2517 $data = $data[0]; 2518 } 2519 break; 2520 case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? 2521 $data = substr($atom_data, $offset, $data_size * 1); 2522 $offset += ($data_size * 1); 2523 break; 2524 case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? 2525 $data = substr($atom_data, $offset, $data_size * 2); 2526 $offset += ($data_size * 2); 2527 break; 2528 default: 2529 echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>'; 2530 break 2; 2531 } 2532 2533 switch ($record_type) { 2534 case 0x00000011: // CreateDate 2535 case 0x00000012: // DateTimeOriginal 2536 $data = strtotime($data); 2537 break; 2538 case 0x0200001e: // ColorSpace 2539 switch ($data) { 2540 case 1: 2541 $data = 'sRGB'; 2542 break; 2543 case 2: 2544 $data = 'Adobe RGB'; 2545 break; 2546 } 2547 break; 2548 case 0x02000023: // PictureControlData 2549 $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full'); 2550 $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a'); 2551 $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'); 2552 $data = array( 2553 'PictureControlVersion' => substr($data, 0, 4), 2554 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"), 2555 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"), 2556 //'?' => substr($data, 44, 4), 2557 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))], 2558 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)), 2559 'Sharpness' => ord(substr($data, 50, 1)), 2560 'Contrast' => ord(substr($data, 51, 1)), 2561 'Brightness' => ord(substr($data, 52, 1)), 2562 'Saturation' => ord(substr($data, 53, 1)), 2563 'HueAdjustment' => ord(substr($data, 54, 1)), 2564 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))], 2565 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))], 2566 'ToningSaturation' => ord(substr($data, 57, 1)), 2567 ); 2568 break; 2569 case 0x02000024: // WorldTime 2570 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime 2571 // timezone is stored as offset from GMT in minutes 2572 $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2)); 2573 if ($timezone & 0x8000) { 2574 $timezone = 0 - (0x10000 - $timezone); 2575 } 2576 $timezone /= 60; 2577 2578 $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1)); 2579 switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) { 2580 case 2: 2581 $datedisplayformat = 'D/M/Y'; break; 2582 case 1: 2583 $datedisplayformat = 'M/D/Y'; break; 2584 case 0: 2585 default: 2586 $datedisplayformat = 'Y/M/D'; break; 2587 } 2588 2589 $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat); 2590 break; 2591 case 0x02000083: // LensType 2592 $data = array( 2593 //'_' => $data, 2594 'mf' => (bool) ($data & 0x01), 2595 'd' => (bool) ($data & 0x02), 2596 'g' => (bool) ($data & 0x04), 2597 'vr' => (bool) ($data & 0x08), 2598 ); 2599 break; 2600 } 2601 $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT)); 2602 $parsed[$tag_name] = $data; 2603 } 2604 return $parsed; 2605 } 2606 2607 /** 2608 * @param string $keyname 2609 * @param string|array $data 2610 * @param string $boxname 2611 * 2612 * @return bool 2613 */ 2614 public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') { 2615 static $handyatomtranslatorarray = array(); 2616 if (empty($handyatomtranslatorarray)) { 2617 // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt 2618 // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt 2619 // http://atomicparsley.sourceforge.net/mpeg-4files.html 2620 // https://code.google.com/p/mp4v2/wiki/iTunesMetadata 2621 $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0 2622 $handyatomtranslatorarray["\xA9".'ART'] = 'artist'; 2623 $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0 2624 $handyatomtranslatorarray["\xA9".'aut'] = 'author'; 2625 $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0 2626 $handyatomtranslatorarray["\xA9".'com'] = 'comment'; 2627 $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright'; 2628 $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0 2629 $handyatomtranslatorarray["\xA9".'dir'] = 'director'; 2630 $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1'; 2631 $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2'; 2632 $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3'; 2633 $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4'; 2634 $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5'; 2635 $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6'; 2636 $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7'; 2637 $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8'; 2638 $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9'; 2639 $handyatomtranslatorarray["\xA9".'enc'] = 'encoded_by'; 2640 $handyatomtranslatorarray["\xA9".'fmt'] = 'format'; 2641 $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0 2642 $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2 2643 $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer'; 2644 $handyatomtranslatorarray["\xA9".'inf'] = 'information'; 2645 $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0 2646 $handyatomtranslatorarray["\xA9".'mak'] = 'make'; 2647 $handyatomtranslatorarray["\xA9".'mod'] = 'model'; 2648 $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0 2649 $handyatomtranslatorarray["\xA9".'ope'] = 'composer'; 2650 $handyatomtranslatorarray["\xA9".'prd'] = 'producer'; 2651 $handyatomtranslatorarray["\xA9".'PRD'] = 'product'; 2652 $handyatomtranslatorarray["\xA9".'prf'] = 'performers'; 2653 $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements'; 2654 $handyatomtranslatorarray["\xA9".'src'] = 'source_credit'; 2655 $handyatomtranslatorarray["\xA9".'swr'] = 'software'; 2656 $handyatomtranslatorarray["\xA9".'too'] = 'encoding_tool'; // iTunes 4.0 2657 $handyatomtranslatorarray["\xA9".'trk'] = 'track_number'; 2658 $handyatomtranslatorarray["\xA9".'url'] = 'url'; 2659 $handyatomtranslatorarray["\xA9".'wrn'] = 'warning'; 2660 $handyatomtranslatorarray["\xA9".'wrt'] = 'composer'; 2661 $handyatomtranslatorarray['aART'] = 'album_artist'; 2662 $handyatomtranslatorarray['apID'] = 'purchase_account'; 2663 $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9 2664 $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0 2665 $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0 2666 $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0? 2667 $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0 2668 $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0 2669 $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9 2670 $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0 2671 $handyatomtranslatorarray['hdvd'] = 'hd_video'; // iTunes 4.0 2672 $handyatomtranslatorarray['ldes'] = 'description_long'; // 2673 $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9 2674 $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9 2675 $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0 2676 $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2 2677 $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9 2678 $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0 2679 $handyatomtranslatorarray['soaa'] = 'sort_album_artist'; // 2680 $handyatomtranslatorarray['soal'] = 'sort_album'; // 2681 $handyatomtranslatorarray['soar'] = 'sort_artist'; // 2682 $handyatomtranslatorarray['soco'] = 'sort_composer'; // 2683 $handyatomtranslatorarray['sonm'] = 'sort_title'; // 2684 $handyatomtranslatorarray['sosn'] = 'sort_show'; // 2685 $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9 2686 $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0 2687 $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0 2688 $handyatomtranslatorarray['tven'] = 'tv_episode_id'; // 2689 $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0 2690 $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0 2691 $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0 2692 $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0 2693 2694 // boxnames: 2695 /* 2696 $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; 2697 $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; 2698 $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; 2699 $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; 2700 $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; 2701 $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; 2702 $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; 2703 $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; 2704 $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; 2705 $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; 2706 $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; 2707 $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id'; 2708 2709 // http://age.hobba.nl/audio/tag_frame_reference.html 2710 $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 2711 $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 2712 */ 2713 } 2714 $info = &$this->getid3->info; 2715 $comment_key = ''; 2716 if ($boxname && ($boxname != $keyname)) { 2717 $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname); 2718 } elseif (isset($handyatomtranslatorarray[$keyname])) { 2719 $comment_key = $handyatomtranslatorarray[$keyname]; 2720 } 2721 if ($comment_key) { 2722 if ($comment_key == 'picture') { 2723 if (!is_array($data)) { 2724 $image_mime = ''; 2725 if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) { 2726 $image_mime = 'image/png'; 2727 } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) { 2728 $image_mime = 'image/jpeg'; 2729 } elseif (preg_match('#^GIF#', $data)) { 2730 $image_mime = 'image/gif'; 2731 } elseif (preg_match('#^BM#', $data)) { 2732 $image_mime = 'image/bmp'; 2733 } 2734 $data = array('data'=>$data, 'image_mime'=>$image_mime); 2735 } 2736 } 2737 $gooddata = array($data); 2738 if ($comment_key == 'genre') { 2739 // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" 2740 $gooddata = explode(';', $data); 2741 } 2742 foreach ($gooddata as $data) { 2743 $info['quicktime']['comments'][$comment_key][] = $data; 2744 } 2745 } 2746 return true; 2747 } 2748 2749 /** 2750 * @param string $lstring 2751 * @param int $count 2752 * 2753 * @return string 2754 */ 2755 public function LociString($lstring, &$count) { 2756 // Loci strings are UTF-8 or UTF-16 and null (x00/x0000) terminated. UTF-16 has a BOM 2757 // Also need to return the number of bytes the string occupied so additional fields can be extracted 2758 $len = strlen($lstring); 2759 if ($len == 0) { 2760 $count = 0; 2761 return ''; 2762 } 2763 if ($lstring[0] == "\x00") { 2764 $count = 1; 2765 return ''; 2766 } 2767 // check for BOM 2768 if (($len > 2) && ((($lstring[0] == "\xFE") && ($lstring[1] == "\xFF")) || (($lstring[0] == "\xFF") && ($lstring[1] == "\xFE")))) { 2769 // UTF-16 2770 if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { 2771 $count = strlen($lmatches[1]) * 2 + 2; //account for 2 byte characters and trailing \x0000 2772 return getid3_lib::iconv_fallback_utf16_utf8($lmatches[1]); 2773 } else { 2774 return ''; 2775 } 2776 } 2777 // UTF-8 2778 if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { 2779 $count = strlen($lmatches[1]) + 1; //account for trailing \x00 2780 return $lmatches[1]; 2781 } 2782 return ''; 2783 } 2784 2785 /** 2786 * @param string $nullterminatedstring 2787 * 2788 * @return string 2789 */ 2790 public function NoNullString($nullterminatedstring) { 2791 // remove the single null terminator on null terminated strings 2792 if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { 2793 return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); 2794 } 2795 return $nullterminatedstring; 2796 } 2797 2798 /** 2799 * @param string $pascalstring 2800 * 2801 * @return string 2802 */ 2803 public function Pascal2String($pascalstring) { 2804 // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string 2805 return substr($pascalstring, 1); 2806 } 2807 2808 2809 /** 2810 * Helper functions for m4b audiobook chapters 2811 * code by Steffen Hartmann 2015-Nov-08. 2812 * 2813 * @param array $info 2814 * @param string $tag 2815 * @param string $history 2816 * @param array $result 2817 */ 2818 public function search_tag_by_key($info, $tag, $history, &$result) { 2819 foreach ($info as $key => $value) { 2820 $key_history = $history.'/'.$key; 2821 if ($key === $tag) { 2822 $result[] = array($key_history, $info); 2823 } else { 2824 if (is_array($value)) { 2825 $this->search_tag_by_key($value, $tag, $key_history, $result); 2826 } 2827 } 2828 } 2829 } 2830 2831 /** 2832 * @param array $info 2833 * @param string $k 2834 * @param string $v 2835 * @param string $history 2836 * @param array $result 2837 */ 2838 public function search_tag_by_pair($info, $k, $v, $history, &$result) { 2839 foreach ($info as $key => $value) { 2840 $key_history = $history.'/'.$key; 2841 if (($key === $k) && ($value === $v)) { 2842 $result[] = array($key_history, $info); 2843 } else { 2844 if (is_array($value)) { 2845 $this->search_tag_by_pair($value, $k, $v, $key_history, $result); 2846 } 2847 } 2848 } 2849 } 2850 2851 /** 2852 * @param array $info 2853 * 2854 * @return array 2855 */ 2856 public function quicktime_time_to_sample_table($info) { 2857 $res = array(); 2858 $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); 2859 foreach ($res as $value) { 2860 $stbl_res = array(); 2861 $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); 2862 if (count($stbl_res) > 0) { 2863 $stts_res = array(); 2864 $this->search_tag_by_key($value[1], 'time_to_sample_table', $value[0], $stts_res); 2865 if (count($stts_res) > 0) { 2866 return $stts_res[0][1]['time_to_sample_table']; 2867 } 2868 } 2869 } 2870 return array(); 2871 } 2872 2873 /** 2874 * @param array $info 2875 * 2876 * @return int 2877 */ 2878 public function quicktime_bookmark_time_scale($info) { 2879 $time_scale = ''; 2880 $ts_prefix_len = 0; 2881 $res = array(); 2882 $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); 2883 foreach ($res as $value) { 2884 $stbl_res = array(); 2885 $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); 2886 if (count($stbl_res) > 0) { 2887 $ts_res = array(); 2888 $this->search_tag_by_key($info['quicktime']['moov'], 'time_scale', 'quicktime/moov', $ts_res); 2889 foreach ($ts_res as $sub_value) { 2890 $prefix = substr($sub_value[0], 0, -12); 2891 if ((substr($stbl_res[0][0], 0, strlen($prefix)) === $prefix) && ($ts_prefix_len < strlen($prefix))) { 2892 $time_scale = $sub_value[1]['time_scale']; 2893 $ts_prefix_len = strlen($prefix); 2894 } 2895 } 2896 } 2897 } 2898 return $time_scale; 2899 } 2900 /* 2901 // END helper functions for m4b audiobook chapters 2902 */ 2903 2904 2905 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:51:04 2020 | Cross-referenced by PHPXref 0.7.1 |