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