| Conditions | 426 | 
| Paths | 782 | 
| Total Lines | 1757 | 
| Lines | 267 | 
| Ratio | 15.2 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 216 | 	public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { | ||
| 217 | // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm | ||
| 218 | // https://code.google.com/p/mp4v2/wiki/iTunesMetadata | ||
| 219 | |||
| 220 | $info = &$this->getid3->info; | ||
| 221 | |||
| 222 | $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see https://www.getid3.org/phpBB3/viewtopic.php?t=1717 | ||
| 223 | array_push($atomHierarchy, $atomname); | ||
| 224 | $atom_structure = array(); | ||
| 225 | 		$atom_structure['hierarchy'] = implode(' ', $atomHierarchy); | ||
| 226 | $atom_structure['name'] = $atomname; | ||
| 227 | $atom_structure['size'] = $atomsize; | ||
| 228 | $atom_structure['offset'] = $baseoffset; | ||
| 229 | 		if (substr($atomname, 0, 3) == "\x00\x00\x00") { | ||
| 230 | // https://github.com/JamesHeinrich/getID3/issues/139 | ||
| 231 | $atomname = getid3_lib::BigEndian2Int($atomname); | ||
| 232 | $atom_structure['name'] = $atomname; | ||
| 233 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 234 | 		} else { | ||
| 235 | 			switch ($atomname) { | ||
| 236 | case 'moov': // MOVie container atom | ||
| 237 | case 'trak': // TRAcK container atom | ||
| 238 | case 'clip': // CLIPping container atom | ||
| 239 | case 'matt': // track MATTe container atom | ||
| 240 | case 'edts': // EDiTS container atom | ||
| 241 | case 'tref': // Track REFerence container atom | ||
| 242 | case 'mdia': // MeDIA container atom | ||
| 243 | case 'minf': // Media INFormation container atom | ||
| 244 | case 'dinf': // Data INFormation container atom | ||
| 245 | case 'nmhd': // Null Media HeaDer container atom | ||
| 246 | case 'udta': // User DaTA container atom | ||
| 247 | case 'cmov': // Compressed MOVie container atom | ||
| 248 | case 'rmra': // Reference Movie Record Atom | ||
| 249 | case 'rmda': // Reference Movie Descriptor Atom | ||
| 250 | case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) | ||
| 251 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 252 | break; | ||
| 253 | |||
| 254 | case 'ilst': // Item LiST container atom | ||
| 255 | 					if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { | ||
| 256 | // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted | ||
| 257 | $allnumericnames = true; | ||
| 258 | 						foreach ($atom_structure['subatoms'] as $subatomarray) { | ||
| 259 | 							if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { | ||
| 260 | $allnumericnames = false; | ||
| 261 | break; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | 						if ($allnumericnames) { | ||
| 265 | $newData = array(); | ||
| 266 | 							foreach ($atom_structure['subatoms'] as $subatomarray) { | ||
| 267 | 								foreach ($subatomarray['subatoms'] as $newData_subatomarray) { | ||
| 268 | unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); | ||
| 269 | $newData[$subatomarray['name']] = $newData_subatomarray; | ||
| 270 | break; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | $atom_structure['data'] = $newData; | ||
| 274 | unset($atom_structure['subatoms']); | ||
| 275 | } | ||
| 276 | } | ||
| 277 | break; | ||
| 278 | |||
| 279 | case 'stbl': // Sample TaBLe container atom | ||
| 280 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 281 | $isVideo = false; | ||
| 282 | $framerate = 0; | ||
| 283 | $framecount = 0; | ||
| 284 | 					foreach ($atom_structure['subatoms'] as $key => $value_array) { | ||
| 285 | 						if (isset($value_array['sample_description_table'])) { | ||
| 286 | 							foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { | ||
| 287 | 								if (isset($value_array2['data_format'])) { | ||
| 288 | 									switch ($value_array2['data_format']) { | ||
| 289 | case 'avc1': | ||
| 290 | case 'mp4v': | ||
| 291 | // video data | ||
| 292 | $isVideo = true; | ||
| 293 | break; | ||
| 294 | case 'mp4a': | ||
| 295 | // audio data | ||
| 296 | break; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | } | ||
| 300 | 						} elseif (isset($value_array['time_to_sample_table'])) { | ||
| 301 | 							foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { | ||
| 302 | 								if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { | ||
| 303 | $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); | ||
| 304 | $framecount = $value_array2['sample_count']; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | } | ||
| 308 | } | ||
| 309 | 					if ($isVideo && $framerate) { | ||
| 310 | $info['quicktime']['video']['frame_rate'] = $framerate; | ||
| 311 | $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; | ||
| 312 | } | ||
| 313 | 					if ($isVideo && $framecount) { | ||
| 314 | $info['quicktime']['video']['frame_count'] = $framecount; | ||
| 315 | } | ||
| 316 | break; | ||
| 317 | |||
| 318 | |||
| 319 | case "\xA9".'alb': // ALBum | ||
| 320 | case "\xA9".'ART': // | ||
| 321 | case "\xA9".'art': // ARTist | ||
| 322 | case "\xA9".'aut': // | ||
| 323 | case "\xA9".'cmt': // CoMmenT | ||
| 324 | case "\xA9".'com': // COMposer | ||
| 325 | case "\xA9".'cpy': // | ||
| 326 | case "\xA9".'day': // content created year | ||
| 327 | case "\xA9".'dir': // | ||
| 328 | case "\xA9".'ed1': // | ||
| 329 | case "\xA9".'ed2': // | ||
| 330 | case "\xA9".'ed3': // | ||
| 331 | case "\xA9".'ed4': // | ||
| 332 | case "\xA9".'ed5': // | ||
| 333 | case "\xA9".'ed6': // | ||
| 334 | case "\xA9".'ed7': // | ||
| 335 | case "\xA9".'ed8': // | ||
| 336 | case "\xA9".'ed9': // | ||
| 337 | case "\xA9".'enc': // | ||
| 338 | case "\xA9".'fmt': // | ||
| 339 | case "\xA9".'gen': // GENre | ||
| 340 | case "\xA9".'grp': // GRouPing | ||
| 341 | case "\xA9".'hst': // | ||
| 342 | case "\xA9".'inf': // | ||
| 343 | case "\xA9".'lyr': // LYRics | ||
| 344 | case "\xA9".'mak': // | ||
| 345 | case "\xA9".'mod': // | ||
| 346 | case "\xA9".'nam': // full NAMe | ||
| 347 | case "\xA9".'ope': // | ||
| 348 | case "\xA9".'PRD': // | ||
| 349 | case "\xA9".'prf': // | ||
| 350 | case "\xA9".'req': // | ||
| 351 | case "\xA9".'src': // | ||
| 352 | case "\xA9".'swr': // | ||
| 353 | case "\xA9".'too': // encoder | ||
| 354 | case "\xA9".'trk': // TRacK | ||
| 355 | case "\xA9".'url': // | ||
| 356 | case "\xA9".'wrn': // | ||
| 357 | case "\xA9".'wrt': // WRiTer | ||
| 358 | case '----': // itunes specific | ||
| 359 | case 'aART': // Album ARTist | ||
| 360 | case 'akID': // iTunes store account type | ||
| 361 | case 'apID': // Purchase Account | ||
| 362 | case 'atID': // | ||
| 363 | case 'catg': // CaTeGory | ||
| 364 | case 'cmID': // | ||
| 365 | case 'cnID': // | ||
| 366 | case 'covr': // COVeR artwork | ||
| 367 | case 'cpil': // ComPILation | ||
| 368 | case 'cprt': // CoPyRighT | ||
| 369 | case 'desc': // DESCription | ||
| 370 | case 'disk': // DISK number | ||
| 371 | case 'egid': // Episode Global ID | ||
| 372 | case 'geID': // | ||
| 373 | case 'gnre': // GeNRE | ||
| 374 | case 'hdvd': // HD ViDeo | ||
| 375 | case 'keyw': // KEYWord | ||
| 376 | case 'ldes': // Long DEScription | ||
| 377 | case 'pcst': // PodCaST | ||
| 378 | case 'pgap': // GAPless Playback | ||
| 379 | case 'plID': // | ||
| 380 | case 'purd': // PURchase Date | ||
| 381 | case 'purl': // Podcast URL | ||
| 382 | case 'rati': // | ||
| 383 | case 'rndu': // | ||
| 384 | case 'rpdu': // | ||
| 385 | case 'rtng': // RaTiNG | ||
| 386 | case 'sfID': // iTunes store country | ||
| 387 | case 'soaa': // SOrt Album Artist | ||
| 388 | case 'soal': // SOrt ALbum | ||
| 389 | case 'soar': // SOrt ARtist | ||
| 390 | case 'soco': // SOrt COmposer | ||
| 391 | case 'sonm': // SOrt NaMe | ||
| 392 | case 'sosn': // SOrt Show Name | ||
| 393 | case 'stik': // | ||
| 394 | case 'tmpo': // TeMPO (BPM) | ||
| 395 | case 'trkn': // TRacK Number | ||
| 396 | case 'tven': // tvEpisodeID | ||
| 397 | case 'tves': // TV EpiSode | ||
| 398 | case 'tvnn': // TV Network Name | ||
| 399 | case 'tvsh': // TV SHow Name | ||
| 400 | case 'tvsn': // TV SeasoN | ||
| 401 | 					if ($atom_parent == 'udta') { | ||
| 402 | // User data atom handler | ||
| 403 | $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); | ||
| 404 | $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); | ||
| 405 | $atom_structure['data'] = substr($atom_data, 4); | ||
| 406 | |||
| 407 | $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); | ||
| 408 | View Code Duplication | 						if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { | |
| 409 | $info['comments']['language'][] = $atom_structure['language']; | ||
| 410 | } | ||
| 411 | 					} else { | ||
| 412 | // Apple item list box atom handler | ||
| 413 | $atomoffset = 0; | ||
| 414 | 						if (substr($atom_data, 2, 2) == "\x10\xB5") { | ||
| 415 | // not sure what it means, but observed on iPhone4 data. | ||
| 416 | // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data | ||
| 417 | 							while ($atomoffset < strlen($atom_data)) { | ||
| 418 | $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); | ||
| 419 | $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); | ||
| 420 | $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); | ||
| 421 | View Code Duplication | 								if ($boxsmallsize <= 1) { | |
| 422 | 									$this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); | ||
| 423 | $atom_structure['data'] = null; | ||
| 424 | $atomoffset = strlen($atom_data); | ||
| 425 | break; | ||
| 426 | } | ||
| 427 | 								switch ($boxsmalltype) { | ||
| 428 | case "\x10\xB5": | ||
| 429 | $atom_structure['data'] = $boxsmalldata; | ||
| 430 | break; | ||
| 431 | View Code Duplication | default: | |
| 432 | 										$this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); | ||
| 433 | $atom_structure['data'] = $atom_data; | ||
| 434 | break; | ||
| 435 | } | ||
| 436 | $atomoffset += (4 + $boxsmallsize); | ||
| 437 | } | ||
| 438 | 						} else { | ||
| 439 | 							while ($atomoffset < strlen($atom_data)) { | ||
| 440 | $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); | ||
| 441 | $boxtype = substr($atom_data, $atomoffset + 4, 4); | ||
| 442 | $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); | ||
| 443 | View Code Duplication | 								if ($boxsize <= 1) { | |
| 444 | 									$this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); | ||
| 445 | $atom_structure['data'] = null; | ||
| 446 | $atomoffset = strlen($atom_data); | ||
| 447 | break; | ||
| 448 | } | ||
| 449 | $atomoffset += $boxsize; | ||
| 450 | |||
| 451 | 								switch ($boxtype) { | ||
| 452 | case 'mean': | ||
| 453 | case 'name': | ||
| 454 | $atom_structure[$boxtype] = substr($boxdata, 4); | ||
| 455 | break; | ||
| 456 | |||
| 457 | case 'data': | ||
| 458 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); | ||
| 459 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); | ||
| 460 | 										switch ($atom_structure['flags_raw']) { | ||
| 461 | case 0: // data flag | ||
| 462 | case 21: // tmpo/cpil flag | ||
| 463 | 												switch ($atomname) { | ||
| 464 | case 'cpil': | ||
| 465 | case 'hdvd': | ||
| 466 | case 'pcst': | ||
| 467 | case 'pgap': | ||
| 468 | // 8-bit integer (boolean) | ||
| 469 | $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); | ||
| 470 | break; | ||
| 471 | |||
| 472 | case 'tmpo': | ||
| 473 | // 16-bit integer | ||
| 474 | $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); | ||
| 475 | break; | ||
| 476 | |||
| 477 | case 'disk': | ||
| 478 | case 'trkn': | ||
| 479 | // binary | ||
| 480 | $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); | ||
| 481 | $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); | ||
| 482 | $atom_structure['data'] = empty($num) ? '' : $num; | ||
| 483 | $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; | ||
| 484 | break; | ||
| 485 | |||
| 486 | case 'gnre': | ||
| 487 | // enum | ||
| 488 | $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); | ||
| 489 | $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); | ||
| 490 | break; | ||
| 491 | |||
| 492 | View Code Duplication | case 'rtng': | |
| 493 | // 8-bit integer | ||
| 494 | $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); | ||
| 495 | $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); | ||
| 496 | break; | ||
| 497 | |||
| 498 | View Code Duplication | case 'stik': | |
| 499 | // 8-bit integer (enum) | ||
| 500 | $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); | ||
| 501 | $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); | ||
| 502 | break; | ||
| 503 | |||
| 504 | View Code Duplication | case 'sfID': | |
| 505 | // 32-bit integer | ||
| 506 | $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); | ||
| 507 | $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); | ||
| 508 | break; | ||
| 509 | |||
| 510 | case 'egid': | ||
| 511 | case 'purl': | ||
| 512 | $atom_structure['data'] = substr($boxdata, 8); | ||
| 513 | break; | ||
| 514 | |||
| 515 | case 'plID': | ||
| 516 | // 64-bit integer | ||
| 517 | $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8)); | ||
| 518 | break; | ||
| 519 | |||
| 520 | View Code Duplication | case 'covr': | |
| 521 | $atom_structure['data'] = substr($boxdata, 8); | ||
| 522 | // not a foolproof check, but better than nothing | ||
| 523 | 														if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { | ||
| 524 | $atom_structure['image_mime'] = 'image/jpeg'; | ||
| 525 | 														} elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { | ||
| 526 | $atom_structure['image_mime'] = 'image/png'; | ||
| 527 | 														} elseif (preg_match('#^GIF#', $atom_structure['data'])) { | ||
| 528 | $atom_structure['image_mime'] = 'image/gif'; | ||
| 529 | } | ||
| 530 | break; | ||
| 531 | |||
| 532 | case 'atID': | ||
| 533 | case 'cnID': | ||
| 534 | case 'geID': | ||
| 535 | case 'tves': | ||
| 536 | case 'tvsn': | ||
| 537 | default: | ||
| 538 | // 32-bit integer | ||
| 539 | $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); | ||
| 540 | } | ||
| 541 | break; | ||
| 542 | |||
| 543 | case 1: // text flag | ||
| 544 | case 13: // image flag | ||
| 545 | View Code Duplication | default: | |
| 546 | $atom_structure['data'] = substr($boxdata, 8); | ||
| 547 | 												if ($atomname == 'covr') { | ||
| 548 | // not a foolproof check, but better than nothing | ||
| 549 | 													if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { | ||
| 550 | $atom_structure['image_mime'] = 'image/jpeg'; | ||
| 551 | 													} elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { | ||
| 552 | $atom_structure['image_mime'] = 'image/png'; | ||
| 553 | 													} elseif (preg_match('#^GIF#', $atom_structure['data'])) { | ||
| 554 | $atom_structure['image_mime'] = 'image/gif'; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | break; | ||
| 558 | |||
| 559 | } | ||
| 560 | break; | ||
| 561 | |||
| 562 | View Code Duplication | default: | |
| 563 | 										$this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset); | ||
| 564 | $atom_structure['data'] = $atom_data; | ||
| 565 | |||
| 566 | } | ||
| 567 | } | ||
| 568 | } | ||
| 569 | } | ||
| 570 | $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']); | ||
| 571 | break; | ||
| 572 | |||
| 573 | |||
| 574 | case 'play': // auto-PLAY atom | ||
| 575 | $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 576 | |||
| 577 | $info['quicktime']['autoplay'] = $atom_structure['autoplay']; | ||
| 578 | break; | ||
| 579 | |||
| 580 | |||
| 581 | View Code Duplication | case 'WLOC': // Window LOCation atom | |
| 582 | $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); | ||
| 583 | $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); | ||
| 584 | break; | ||
| 585 | |||
| 586 | |||
| 587 | case 'LOOP': // LOOPing atom | ||
| 588 | case 'SelO': // play SELection Only atom | ||
| 589 | case 'AllF': // play ALL Frames atom | ||
| 590 | $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); | ||
| 591 | break; | ||
| 592 | |||
| 593 | |||
| 594 | case 'name': // | ||
| 595 | case 'MCPS': // Media Cleaner PRo | ||
| 596 | case '@PRM': // adobe PReMiere version | ||
| 597 | case '@PRQ': // adobe PRemiere Quicktime version | ||
| 598 | $atom_structure['data'] = $atom_data; | ||
| 599 | break; | ||
| 600 | |||
| 601 | |||
| 602 | case 'cmvd': // Compressed MooV Data atom | ||
| 603 | // Code by ubergeekØubergeek*tv based on information from | ||
| 604 | // http://developer.apple.com/quicktime/icefloe/dispatch012.html | ||
| 605 | $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); | ||
| 606 | |||
| 607 | $CompressedFileData = substr($atom_data, 4); | ||
| 608 | 					if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { | ||
| 609 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 610 | 					} else { | ||
| 611 | 						$this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); | ||
| 612 | } | ||
| 613 | break; | ||
| 614 | |||
| 615 | |||
| 616 | case 'dcom': // Data COMpression atom | ||
| 617 | $atom_structure['compression_id'] = $atom_data; | ||
| 618 | $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); | ||
| 619 | break; | ||
| 620 | |||
| 621 | |||
| 622 | case 'rdrf': // Reference movie Data ReFerence atom | ||
| 623 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 624 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 625 | $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); | ||
| 626 | |||
| 627 | $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); | ||
| 628 | $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 629 | 					switch ($atom_structure['reference_type_name']) { | ||
| 630 | case 'url ': | ||
| 631 | $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); | ||
| 632 | break; | ||
| 633 | |||
| 634 | case 'alis': | ||
| 635 | $atom_structure['file_alias'] = substr($atom_data, 12); | ||
| 636 | break; | ||
| 637 | |||
| 638 | case 'rsrc': | ||
| 639 | $atom_structure['resource_alias'] = substr($atom_data, 12); | ||
| 640 | break; | ||
| 641 | |||
| 642 | default: | ||
| 643 | $atom_structure['data'] = substr($atom_data, 12); | ||
| 644 | break; | ||
| 645 | } | ||
| 646 | break; | ||
| 647 | |||
| 648 | |||
| 649 | case 'rmqu': // Reference Movie QUality atom | ||
| 650 | $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); | ||
| 651 | break; | ||
| 652 | |||
| 653 | |||
| 654 | View Code Duplication | case 'rmcs': // Reference Movie Cpu Speed atom | |
| 655 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 656 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 657 | $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); | ||
| 658 | break; | ||
| 659 | |||
| 660 | |||
| 661 | case 'rmvc': // Reference Movie Version Check atom | ||
| 662 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 663 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 664 | $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); | ||
| 665 | $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 666 | $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); | ||
| 667 | $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); | ||
| 668 | break; | ||
| 669 | |||
| 670 | |||
| 671 | case 'rmcd': // Reference Movie Component check atom | ||
| 672 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 673 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 674 | $atom_structure['component_type'] = substr($atom_data, 4, 4); | ||
| 675 | $atom_structure['component_subtype'] = substr($atom_data, 8, 4); | ||
| 676 | $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); | ||
| 677 | $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); | ||
| 678 | $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); | ||
| 679 | $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); | ||
| 680 | break; | ||
| 681 | |||
| 682 | |||
| 683 | View Code Duplication | case 'rmdr': // Reference Movie Data Rate atom | |
| 684 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 685 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 686 | $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 687 | |||
| 688 | $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; | ||
| 689 | break; | ||
| 690 | |||
| 691 | |||
| 692 | case 'rmla': // Reference Movie Language Atom | ||
| 693 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 694 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 695 | $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); | ||
| 696 | |||
| 697 | $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); | ||
| 698 | View Code Duplication | 					if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { | |
| 699 | $info['comments']['language'][] = $atom_structure['language']; | ||
| 700 | } | ||
| 701 | break; | ||
| 702 | |||
| 703 | |||
| 704 | case 'ptv ': // Print To Video - defines a movie's full screen mode | ||
| 705 | // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm | ||
| 706 | $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); | ||
| 707 | $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 | ||
| 708 | $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 | ||
| 709 | $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); | ||
| 710 | $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); | ||
| 711 | |||
| 712 | $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; | ||
| 713 | $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; | ||
| 714 | |||
| 715 | $ptv_lookup[0] = 'normal'; | ||
| 716 | $ptv_lookup[1] = 'double'; | ||
| 717 | $ptv_lookup[2] = 'half'; | ||
| 718 | $ptv_lookup[3] = 'full'; | ||
| 719 | $ptv_lookup[4] = 'current'; | ||
| 720 | 					if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { | ||
| 721 | $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; | ||
| 722 | 					} else { | ||
| 723 | 						$this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'); | ||
| 724 | } | ||
| 725 | break; | ||
| 726 | |||
| 727 | |||
| 728 | case 'stsd': // Sample Table Sample Description atom | ||
| 729 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 730 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 731 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 732 | |||
| 733 | // see: https://github.com/JamesHeinrich/getID3/issues/111 | ||
| 734 | // Some corrupt files have been known to have high bits set in the number_entries field | ||
| 735 | // This field shouldn't really need to be 32-bits, values stores are likely in the range 1-100000 | ||
| 736 | // Workaround: mask off the upper byte and throw a warning if it's nonzero | ||
| 737 | 					if ($atom_structure['number_entries'] > 0x000FFFFF) { | ||
| 738 | 						if ($atom_structure['number_entries'] > 0x00FFFFFF) { | ||
| 739 | 							$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)); | ||
| 740 | $atom_structure['number_entries'] = ($atom_structure['number_entries'] & 0x00FFFFFF); | ||
| 741 | View Code Duplication | 						} else { | |
| 742 | 							$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 [email protected] referencing bug report #111'); | ||
| 743 | } | ||
| 744 | } | ||
| 745 | |||
| 746 | $stsdEntriesDataOffset = 8; | ||
| 747 | 					for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 748 | $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); | ||
| 749 | $stsdEntriesDataOffset += 4; | ||
| 750 | $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); | ||
| 751 | $stsdEntriesDataOffset += 4; | ||
| 752 | $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); | ||
| 753 | $stsdEntriesDataOffset += 6; | ||
| 754 | $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); | ||
| 755 | $stsdEntriesDataOffset += 2; | ||
| 756 | $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); | ||
| 757 | $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); | ||
| 758 | |||
| 759 | $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); | ||
| 760 | $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); | ||
| 761 | $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); | ||
| 762 | |||
| 763 | 						switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { | ||
| 764 | |||
| 765 | case "\x00\x00\x00\x00": | ||
| 766 | // audio tracks | ||
| 767 | $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); | ||
| 768 | $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); | ||
| 769 | $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); | ||
| 770 | $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); | ||
| 771 | $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); | ||
| 772 | |||
| 773 | // video tracks | ||
| 774 | // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html | ||
| 775 | $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); | ||
| 776 | $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); | ||
| 777 | $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); | ||
| 778 | $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); | ||
| 779 | $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); | ||
| 780 | $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); | ||
| 781 | $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4)); | ||
| 782 | $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2)); | ||
| 783 | $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4); | ||
| 784 | $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2)); | ||
| 785 | $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2)); | ||
| 786 | |||
| 787 | 								switch ($atom_structure['sample_description_table'][$i]['data_format']) { | ||
| 788 | case '2vuY': | ||
| 789 | case 'avc1': | ||
| 790 | case 'cvid': | ||
| 791 | case 'dvc ': | ||
| 792 | case 'dvcp': | ||
| 793 | case 'gif ': | ||
| 794 | case 'h263': | ||
| 795 | case 'jpeg': | ||
| 796 | case 'kpcd': | ||
| 797 | case 'mjpa': | ||
| 798 | case 'mjpb': | ||
| 799 | case 'mp4v': | ||
| 800 | case 'png ': | ||
| 801 | case 'raw ': | ||
| 802 | case 'rle ': | ||
| 803 | case 'rpza': | ||
| 804 | case 'smc ': | ||
| 805 | case 'SVQ1': | ||
| 806 | case 'SVQ3': | ||
| 807 | case 'tiff': | ||
| 808 | case 'v210': | ||
| 809 | case 'v216': | ||
| 810 | case 'v308': | ||
| 811 | case 'v408': | ||
| 812 | case 'v410': | ||
| 813 | case 'yuv2': | ||
| 814 | $info['fileformat'] = 'mp4'; | ||
| 815 | $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; | ||
| 816 | 										if ($this->QuicktimeVideoCodecLookup($info['video']['fourcc'])) { | ||
| 817 | $info['video']['fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($info['video']['fourcc']); | ||
| 818 | } | ||
| 819 | |||
| 820 | // https://www.getid3.org/phpBB3/viewtopic.php?t=1550 | ||
| 821 | 										//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 | ||
| 822 | 										if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) { | ||
| 823 | // assume that values stored here are more important than values stored in [tkhd] atom | ||
| 824 | $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; | ||
| 825 | $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; | ||
| 826 | $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; | ||
| 827 | $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; | ||
| 828 | } | ||
| 829 | break; | ||
| 830 | |||
| 831 | case 'qtvr': | ||
| 832 | $info['video']['dataformat'] = 'quicktimevr'; | ||
| 833 | break; | ||
| 834 | |||
| 835 | case 'mp4a': | ||
| 836 | default: | ||
| 837 | $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); | ||
| 838 | $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; | ||
| 839 | $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; | ||
| 840 | $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; | ||
| 841 | $info['audio']['codec'] = $info['quicktime']['audio']['codec']; | ||
| 842 | $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate']; | ||
| 843 | $info['audio']['channels'] = $info['quicktime']['audio']['channels']; | ||
| 844 | $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth']; | ||
| 845 | 										switch ($atom_structure['sample_description_table'][$i]['data_format']) { | ||
| 846 | case 'raw ': // PCM | ||
| 847 | case 'alac': // Apple Lossless Audio Codec | ||
| 848 | case 'sowt': // signed/two's complement (Little Endian) | ||
| 849 | case 'twos': // signed/two's complement (Big Endian) | ||
| 850 | case 'in24': // 24-bit Integer | ||
| 851 | case 'in32': // 32-bit Integer | ||
| 852 | case 'fl32': // 32-bit Floating Point | ||
| 853 | case 'fl64': // 64-bit Floating Point | ||
| 854 | $info['audio']['lossless'] = $info['quicktime']['audio']['lossless'] = true; | ||
| 855 | $info['audio']['bitrate'] = $info['quicktime']['audio']['bitrate'] = $info['audio']['channels'] * $info['audio']['bits_per_sample'] * $info['audio']['sample_rate']; | ||
| 856 | break; | ||
| 857 | default: | ||
| 858 | $info['audio']['lossless'] = false; | ||
| 859 | break; | ||
| 860 | } | ||
| 861 | break; | ||
| 862 | } | ||
| 863 | break; | ||
| 864 | |||
| 865 | default: | ||
| 866 | 								switch ($atom_structure['sample_description_table'][$i]['data_format']) { | ||
| 867 | case 'mp4s': | ||
| 868 | $info['fileformat'] = 'mp4'; | ||
| 869 | break; | ||
| 870 | |||
| 871 | default: | ||
| 872 | // video atom | ||
| 873 | $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); | ||
| 874 | $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); | ||
| 875 | $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); | ||
| 876 | $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); | ||
| 877 | $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); | ||
| 878 | $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); | ||
| 879 | $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); | ||
| 880 | $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); | ||
| 881 | $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); | ||
| 882 | $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']); | ||
| 883 | $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); | ||
| 884 | $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); | ||
| 885 | |||
| 886 | $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); | ||
| 887 | $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); | ||
| 888 | |||
| 889 | 										if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { | ||
| 890 | $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; | ||
| 891 | $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); | ||
| 892 | $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']); | ||
| 893 | $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; | ||
| 894 | $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; | ||
| 895 | |||
| 896 | $info['video']['codec'] = $info['quicktime']['video']['codec']; | ||
| 897 | $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth']; | ||
| 898 | } | ||
| 899 | $info['video']['lossless'] = false; | ||
| 900 | $info['video']['pixel_aspect_ratio'] = (float) 1; | ||
| 901 | break; | ||
| 902 | } | ||
| 903 | break; | ||
| 904 | } | ||
| 905 | 						switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { | ||
| 906 | case 'mp4a': | ||
| 907 | $info['audio']['dataformat'] = 'mp4'; | ||
| 908 | $info['quicktime']['audio']['codec'] = 'mp4'; | ||
| 909 | break; | ||
| 910 | |||
| 911 | case '3ivx': | ||
| 912 | case '3iv1': | ||
| 913 | case '3iv2': | ||
| 914 | $info['video']['dataformat'] = '3ivx'; | ||
| 915 | break; | ||
| 916 | |||
| 917 | case 'xvid': | ||
| 918 | $info['video']['dataformat'] = 'xvid'; | ||
| 919 | break; | ||
| 920 | |||
| 921 | case 'mp4v': | ||
| 922 | $info['video']['dataformat'] = 'mpeg4'; | ||
| 923 | break; | ||
| 924 | |||
| 925 | case 'divx': | ||
| 926 | case 'div1': | ||
| 927 | case 'div2': | ||
| 928 | case 'div3': | ||
| 929 | case 'div4': | ||
| 930 | case 'div5': | ||
| 931 | case 'div6': | ||
| 932 | $info['video']['dataformat'] = 'divx'; | ||
| 933 | break; | ||
| 934 | |||
| 935 | default: | ||
| 936 | // do nothing | ||
| 937 | break; | ||
| 938 | } | ||
| 939 | unset($atom_structure['sample_description_table'][$i]['data']); | ||
| 940 | } | ||
| 941 | break; | ||
| 942 | |||
| 943 | |||
| 944 | case 'stts': // Sample Table Time-to-Sample atom | ||
| 945 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 946 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 947 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 948 | $sttsEntriesDataOffset = 8; | ||
| 949 | //$FrameRateCalculatorArray = array(); | ||
| 950 | $frames_count = 0; | ||
| 951 | |||
| 952 | $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']); | ||
| 953 | 					if ($max_stts_entries_to_scan < $atom_structure['number_entries']) { | ||
| 954 | 						$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).'); | ||
| 955 | } | ||
| 956 | View Code Duplication | 					for ($i = 0; $i < $max_stts_entries_to_scan; $i++) { | |
| 957 | $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); | ||
| 958 | $sttsEntriesDataOffset += 4; | ||
| 959 | $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); | ||
| 960 | $sttsEntriesDataOffset += 4; | ||
| 961 | |||
| 962 | $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; | ||
| 963 | |||
| 964 | // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM | ||
| 965 | 						//if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { | ||
| 966 | // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; | ||
| 967 | 						//	if ($stts_new_framerate <= 60) { | ||
| 968 | // // some atoms have durations of "1" giving a very large framerate, which probably is not right | ||
| 969 | // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate); | ||
| 970 | // } | ||
| 971 | //} | ||
| 972 | // | ||
| 973 | //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; | ||
| 974 | } | ||
| 975 | $info['quicktime']['stts_framecount'][] = $frames_count; | ||
| 976 | //$sttsFramesTotal = 0; | ||
| 977 | //$sttsSecondsTotal = 0; | ||
| 978 | 					//foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { | ||
| 979 | 					//	if (($frames_per_second > 60) || ($frames_per_second < 1)) { | ||
| 980 | // // not video FPS information, probably audio information | ||
| 981 | // $sttsFramesTotal = 0; | ||
| 982 | // $sttsSecondsTotal = 0; | ||
| 983 | // break; | ||
| 984 | // } | ||
| 985 | // $sttsFramesTotal += $frame_count; | ||
| 986 | // $sttsSecondsTotal += $frame_count / $frames_per_second; | ||
| 987 | //} | ||
| 988 | 					//if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { | ||
| 989 | 					//	if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) { | ||
| 990 | // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; | ||
| 991 | // } | ||
| 992 | //} | ||
| 993 | break; | ||
| 994 | |||
| 995 | |||
| 996 | View Code Duplication | case 'stss': // Sample Table Sync Sample (key frames) atom | |
| 997 | 					if ($ParseAllPossibleAtoms) { | ||
| 998 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 999 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1000 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1001 | $stssEntriesDataOffset = 8; | ||
| 1002 | 						for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 1003 | $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); | ||
| 1004 | $stssEntriesDataOffset += 4; | ||
| 1005 | } | ||
| 1006 | } | ||
| 1007 | break; | ||
| 1008 | |||
| 1009 | |||
| 1010 | case 'stsc': // Sample Table Sample-to-Chunk atom | ||
| 1011 | 					if ($ParseAllPossibleAtoms) { | ||
| 1012 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1013 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1014 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1015 | $stscEntriesDataOffset = 8; | ||
| 1016 | View Code Duplication | 						for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | |
| 1017 | $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); | ||
| 1018 | $stscEntriesDataOffset += 4; | ||
| 1019 | $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); | ||
| 1020 | $stscEntriesDataOffset += 4; | ||
| 1021 | $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); | ||
| 1022 | $stscEntriesDataOffset += 4; | ||
| 1023 | } | ||
| 1024 | } | ||
| 1025 | break; | ||
| 1026 | |||
| 1027 | |||
| 1028 | case 'stsz': // Sample Table SiZe atom | ||
| 1029 | 					if ($ParseAllPossibleAtoms) { | ||
| 1030 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1031 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1032 | $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1033 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 1034 | $stszEntriesDataOffset = 12; | ||
| 1035 | 						if ($atom_structure['sample_size'] == 0) { | ||
| 1036 | 							for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 1037 | $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); | ||
| 1038 | $stszEntriesDataOffset += 4; | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | break; | ||
| 1043 | |||
| 1044 | |||
| 1045 | View Code Duplication | case 'stco': // Sample Table Chunk Offset atom | |
| 1046 | //					if (true) { | ||
| 1047 | 					if ($ParseAllPossibleAtoms) { | ||
| 1048 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1049 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1050 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1051 | $stcoEntriesDataOffset = 8; | ||
| 1052 | 						for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 1053 | $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); | ||
| 1054 | $stcoEntriesDataOffset += 4; | ||
| 1055 | } | ||
| 1056 | } | ||
| 1057 | break; | ||
| 1058 | |||
| 1059 | |||
| 1060 | View Code Duplication | case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) | |
| 1061 | 					if ($ParseAllPossibleAtoms) { | ||
| 1062 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1063 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1064 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1065 | $stcoEntriesDataOffset = 8; | ||
| 1066 | 						for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 1067 | $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); | ||
| 1068 | $stcoEntriesDataOffset += 8; | ||
| 1069 | } | ||
| 1070 | } | ||
| 1071 | break; | ||
| 1072 | |||
| 1073 | |||
| 1074 | case 'dref': // Data REFerence atom | ||
| 1075 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1076 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1077 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1078 | $drefDataOffset = 8; | ||
| 1079 | 					for ($i = 0; $i < $atom_structure['number_entries']; $i++) { | ||
| 1080 | $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); | ||
| 1081 | $drefDataOffset += 4; | ||
| 1082 | $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); | ||
| 1083 | $drefDataOffset += 4; | ||
| 1084 | $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); | ||
| 1085 | $drefDataOffset += 1; | ||
| 1086 | $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 | ||
| 1087 | $drefDataOffset += 3; | ||
| 1088 | $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); | ||
| 1089 | $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); | ||
| 1090 | |||
| 1091 | $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); | ||
| 1092 | } | ||
| 1093 | break; | ||
| 1094 | |||
| 1095 | |||
| 1096 | case 'gmin': // base Media INformation atom | ||
| 1097 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1098 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1099 | $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); | ||
| 1100 | $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); | ||
| 1101 | $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); | ||
| 1102 | $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); | ||
| 1103 | $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); | ||
| 1104 | $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); | ||
| 1105 | break; | ||
| 1106 | |||
| 1107 | |||
| 1108 | View Code Duplication | case 'smhd': // Sound Media information HeaDer atom | |
| 1109 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1110 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1111 | $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); | ||
| 1112 | $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); | ||
| 1113 | break; | ||
| 1114 | |||
| 1115 | |||
| 1116 | case 'vmhd': // Video Media information HeaDer atom | ||
| 1117 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1118 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1119 | $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); | ||
| 1120 | $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); | ||
| 1121 | $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); | ||
| 1122 | $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); | ||
| 1123 | |||
| 1124 | $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); | ||
| 1125 | break; | ||
| 1126 | |||
| 1127 | |||
| 1128 | case 'hdlr': // HanDLeR reference atom | ||
| 1129 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1130 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1131 | $atom_structure['component_type'] = substr($atom_data, 4, 4); | ||
| 1132 | $atom_structure['component_subtype'] = substr($atom_data, 8, 4); | ||
| 1133 | $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); | ||
| 1134 | $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); | ||
| 1135 | $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); | ||
| 1136 | $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24)); | ||
| 1137 | |||
| 1138 | 					if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { | ||
| 1139 | $info['video']['dataformat'] = 'quicktimevr'; | ||
| 1140 | } | ||
| 1141 | break; | ||
| 1142 | |||
| 1143 | |||
| 1144 | case 'mdhd': // MeDia HeaDer atom | ||
| 1145 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1146 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1147 | $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1148 | $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 1149 | $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); | ||
| 1150 | $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); | ||
| 1151 | $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); | ||
| 1152 | $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); | ||
| 1153 | |||
| 1154 | 					if ($atom_structure['time_scale'] == 0) { | ||
| 1155 | 						$this->error('Corrupt Quicktime file: mdhd.time_scale == zero'); | ||
| 1156 | return false; | ||
| 1157 | } | ||
| 1158 | $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); | ||
| 1159 | |||
| 1160 | $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); | ||
| 1161 | $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); | ||
| 1162 | $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; | ||
| 1163 | $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); | ||
| 1164 | View Code Duplication | 					if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { | |
| 1165 | $info['comments']['language'][] = $atom_structure['language']; | ||
| 1166 | } | ||
| 1167 | break; | ||
| 1168 | |||
| 1169 | |||
| 1170 | case 'pnot': // Preview atom | ||
| 1171 | $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" | ||
| 1172 | $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 | ||
| 1173 | $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' | ||
| 1174 | $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 | ||
| 1175 | |||
| 1176 | $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); | ||
| 1177 | break; | ||
| 1178 | |||
| 1179 | |||
| 1180 | View Code Duplication | case 'crgn': // Clipping ReGioN atom | |
| 1181 | $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, | ||
| 1182 | $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields | ||
| 1183 | $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. | ||
| 1184 | break; | ||
| 1185 | |||
| 1186 | |||
| 1187 | case 'load': // track LOAD settings atom | ||
| 1188 | $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); | ||
| 1189 | $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1190 | $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 1191 | $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); | ||
| 1192 | |||
| 1193 | $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); | ||
| 1194 | $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); | ||
| 1195 | break; | ||
| 1196 | |||
| 1197 | |||
| 1198 | case 'tmcd': // TiMe CoDe atom | ||
| 1199 | case 'chap': // CHAPter list atom | ||
| 1200 | case 'sync': // SYNChronization atom | ||
| 1201 | case 'scpt': // tranSCriPT atom | ||
| 1202 | View Code Duplication | case 'ssrc': // non-primary SouRCe atom | |
| 1203 | 					for ($i = 0; $i < strlen($atom_data); $i += 4) { | ||
| 1204 | @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); | ||
| 1205 | } | ||
| 1206 | break; | ||
| 1207 | |||
| 1208 | |||
| 1209 | case 'elst': // Edit LiST atom | ||
| 1210 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1211 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1212 | $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1213 | 					for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) { | ||
| 1214 | $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); | ||
| 1215 | $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); | ||
| 1216 | $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); | ||
| 1217 | } | ||
| 1218 | break; | ||
| 1219 | |||
| 1220 | |||
| 1221 | View Code Duplication | case 'kmat': // compressed MATte atom | |
| 1222 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1223 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 | ||
| 1224 | $atom_structure['matte_data_raw'] = substr($atom_data, 4); | ||
| 1225 | break; | ||
| 1226 | |||
| 1227 | |||
| 1228 | case 'ctab': // Color TABle atom | ||
| 1229 | $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 | ||
| 1230 | $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 | ||
| 1231 | $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; | ||
| 1232 | 					for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { | ||
| 1233 | $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); | ||
| 1234 | $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); | ||
| 1235 | $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); | ||
| 1236 | $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); | ||
| 1237 | } | ||
| 1238 | break; | ||
| 1239 | |||
| 1240 | |||
| 1241 | case 'mvhd': // MoVie HeaDer atom | ||
| 1242 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1243 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1244 | $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1245 | $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 1246 | $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); | ||
| 1247 | $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); | ||
| 1248 | $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); | ||
| 1249 | $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); | ||
| 1250 | $atom_structure['reserved'] = substr($atom_data, 26, 10); | ||
| 1251 | $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); | ||
| 1252 | $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); | ||
| 1253 | $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); | ||
| 1254 | $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); | ||
| 1255 | $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); | ||
| 1256 | $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); | ||
| 1257 | $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); | ||
| 1258 | $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); | ||
| 1259 | $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); | ||
| 1260 | $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); | ||
| 1261 | $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); | ||
| 1262 | $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); | ||
| 1263 | $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); | ||
| 1264 | $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); | ||
| 1265 | $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); | ||
| 1266 | $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); | ||
| 1267 | |||
| 1268 | 					if ($atom_structure['time_scale'] == 0) { | ||
| 1269 | 						$this->error('Corrupt Quicktime file: mvhd.time_scale == zero'); | ||
| 1270 | return false; | ||
| 1271 | } | ||
| 1272 | $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); | ||
| 1273 | $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); | ||
| 1274 | $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); | ||
| 1275 | $info['quicktime']['display_scale'] = $atom_structure['matrix_a']; | ||
| 1276 | $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; | ||
| 1277 | break; | ||
| 1278 | |||
| 1279 | |||
| 1280 | case 'tkhd': // TracK HeaDer atom | ||
| 1281 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1282 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1283 | $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1284 | $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); | ||
| 1285 | $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); | ||
| 1286 | $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); | ||
| 1287 | $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); | ||
| 1288 | $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); | ||
| 1289 | $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); | ||
| 1290 | $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); | ||
| 1291 | $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); | ||
| 1292 | $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); | ||
| 1293 | // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html | ||
| 1294 | // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737 | ||
| 1295 | $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); | ||
| 1296 | $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); | ||
| 1297 | $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4)); | ||
| 1298 | $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); | ||
| 1299 | $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); | ||
| 1300 | $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4)); | ||
| 1301 | $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); | ||
| 1302 | $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4)); | ||
| 1303 | $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); | ||
| 1304 | $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); | ||
| 1305 | $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); | ||
| 1306 | $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); | ||
| 1307 | $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); | ||
| 1308 | $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); | ||
| 1309 | $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); | ||
| 1310 | $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); | ||
| 1311 | $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); | ||
| 1312 | |||
| 1313 | // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 | ||
| 1314 | // attempt to compute rotation from matrix values | ||
| 1315 | // 2017-Dec-28: uncertain if 90/270 are correctly oriented; values returned by FixedPoint16_16 should perhaps be -1 instead of 65535(?) | ||
| 1316 | $matrixRotation = 0; | ||
| 1317 | 					switch ($atom_structure['matrix_a'].':'.$atom_structure['matrix_b'].':'.$atom_structure['matrix_c'].':'.$atom_structure['matrix_d']) { | ||
| 1318 | case '1:0:0:1': $matrixRotation = 0; break; | ||
| 1319 | case '0:1:65535:0': $matrixRotation = 90; break; | ||
| 1320 | case '65535:0:0:65535': $matrixRotation = 180; break; | ||
| 1321 | case '0:65535:1:0': $matrixRotation = 270; break; | ||
| 1322 | default: break; | ||
| 1323 | } | ||
| 1324 | |||
| 1325 | // https://www.getid3.org/phpBB3/viewtopic.php?t=2468 | ||
| 1326 | // The rotation matrix can appear in the Quicktime file multiple times, at least once for each track, | ||
| 1327 | // and it's possible that only the video track (or, in theory, one of the video tracks) is flagged as | ||
| 1328 | // rotated while the other tracks (e.g. audio) is tagged as rotation=0 (behavior noted on iPhone 8 Plus) | ||
| 1329 | // The correct solution would be to check if the TrackID associated with the rotation matrix is indeed | ||
| 1330 | // a video track (or the main video track) and only set the rotation then, but since information about | ||
| 1331 | // what track is what is not trivially there to be examined, the lazy solution is to set the rotation | ||
| 1332 | // if it is found to be nonzero, on the assumption that tracks that don't need it will have rotation set | ||
| 1333 | // to zero (and be effectively ignored) and the video track will have rotation set correctly, which will | ||
| 1334 | // either be zero and automatically correct, or nonzero and be set correctly. | ||
| 1335 | 					if (!isset($info['video']['rotate']) || (($info['video']['rotate'] == 0) && ($matrixRotation > 0))) { | ||
| 1336 | $info['quicktime']['video']['rotate'] = $info['video']['rotate'] = $matrixRotation; | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | 					if ($atom_structure['flags']['enabled'] == 1) { | ||
| 1340 | 						if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) { | ||
| 1341 | $info['video']['resolution_x'] = $atom_structure['width']; | ||
| 1342 | $info['video']['resolution_y'] = $atom_structure['height']; | ||
| 1343 | } | ||
| 1344 | $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']); | ||
| 1345 | $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']); | ||
| 1346 | $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; | ||
| 1347 | $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; | ||
| 1348 | 					} else { | ||
| 1349 | // see: https://www.getid3.org/phpBB3/viewtopic.php?t=1295 | ||
| 1350 | 						//if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); } | ||
| 1351 | 						//if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); } | ||
| 1352 | 						//if (isset($info['quicktime']['video']))    { unset($info['quicktime']['video']);    } | ||
| 1353 | } | ||
| 1354 | break; | ||
| 1355 | |||
| 1356 | |||
| 1357 | case 'iods': // Initial Object DeScriptor atom | ||
| 1358 | // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h | ||
| 1359 | // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html | ||
| 1360 | $offset = 0; | ||
| 1361 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1362 | $offset += 1; | ||
| 1363 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); | ||
| 1364 | $offset += 3; | ||
| 1365 | $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1366 | $offset += 1; | ||
| 1367 | $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); | ||
| 1368 | //$offset already adjusted by quicktime_read_mp4_descr_length() | ||
| 1369 | $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); | ||
| 1370 | $offset += 2; | ||
| 1371 | $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1372 | $offset += 1; | ||
| 1373 | $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1374 | $offset += 1; | ||
| 1375 | $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1376 | $offset += 1; | ||
| 1377 | $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1378 | $offset += 1; | ||
| 1379 | $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1380 | $offset += 1; | ||
| 1381 | |||
| 1382 | $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields | ||
| 1383 | View Code Duplication | 					for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { | |
| 1384 | $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); | ||
| 1385 | $offset += 1; | ||
| 1386 | $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); | ||
| 1387 | //$offset already adjusted by quicktime_read_mp4_descr_length() | ||
| 1388 | $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); | ||
| 1389 | $offset += 4; | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); | ||
| 1393 | $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); | ||
| 1394 | break; | ||
| 1395 | |||
| 1396 | View Code Duplication | case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) | |
| 1397 | $atom_structure['signature'] = substr($atom_data, 0, 4); | ||
| 1398 | $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1399 | $atom_structure['fourcc'] = substr($atom_data, 8, 4); | ||
| 1400 | break; | ||
| 1401 | |||
| 1402 | case 'mdat': // Media DATa atom | ||
| 1403 | // 'mdat' contains the actual data for the audio/video, possibly also subtitles | ||
| 1404 | |||
| 1405 | /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to [email protected] */ | ||
| 1406 | |||
| 1407 | // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?) | ||
| 1408 | $mdat_offset = 0; | ||
| 1409 | 					while (true) { | ||
| 1410 | 						if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') { | ||
| 1411 | $mdat_offset += 8; | ||
| 1412 | 						} elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') { | ||
| 1413 | $mdat_offset += 8; | ||
| 1414 | 						} else { | ||
| 1415 | break; | ||
| 1416 | } | ||
| 1417 | } | ||
| 1418 | 					if (substr($atom_data, $mdat_offset, 4) == 'GPRO') { | ||
| 1419 | $GOPRO_chunk_length = getid3_lib::LittleEndian2Int(substr($atom_data, $mdat_offset + 4, 4)); | ||
| 1420 | $GOPRO_offset = 8; | ||
| 1421 | $atom_structure['GPRO']['raw'] = substr($atom_data, $mdat_offset + 8, $GOPRO_chunk_length - 8); | ||
| 1422 | $atom_structure['GPRO']['firmware'] = substr($atom_structure['GPRO']['raw'], 0, 15); | ||
| 1423 | $atom_structure['GPRO']['unknown1'] = substr($atom_structure['GPRO']['raw'], 15, 16); | ||
| 1424 | $atom_structure['GPRO']['unknown2'] = substr($atom_structure['GPRO']['raw'], 31, 32); | ||
| 1425 | $atom_structure['GPRO']['unknown3'] = substr($atom_structure['GPRO']['raw'], 63, 16); | ||
| 1426 | $atom_structure['GPRO']['camera'] = substr($atom_structure['GPRO']['raw'], 79, 32); | ||
| 1427 | $info['quicktime']['camera']['model'] = rtrim($atom_structure['GPRO']['camera'], "\x00"); | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field | ||
| 1431 | while (($mdat_offset < (strlen($atom_data) - 8)) | ||
| 1432 | && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) | ||
| 1433 | && ($chapter_string_length < 1000) | ||
| 1434 | && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) | ||
| 1435 | 						&& preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { | ||
| 1436 | list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; | ||
| 1437 | $mdat_offset += (2 + $chapter_string_length); | ||
| 1438 | @$info['quicktime']['comments']['chapters'][] = $chapter_string; | ||
| 1439 | |||
| 1440 | // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) | ||
| 1441 | 							if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 | ||
| 1442 | $mdat_offset += 12; | ||
| 1443 | } | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | 					if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) { | ||
| 1447 | |||
| 1448 | $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8; | ||
| 1449 | $OldAVDataEnd = $info['avdataend']; | ||
| 1450 | $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size']; | ||
| 1451 | |||
| 1452 | $getid3_temp = new getID3(); | ||
| 1453 | $getid3_temp->openfile($this->getid3->filename); | ||
| 1454 | $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; | ||
| 1455 | $getid3_temp->info['avdataend'] = $info['avdataend']; | ||
| 1456 | $getid3_mp3 = new getid3_mp3($getid3_temp); | ||
| 1457 | 						if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) { | ||
| 1458 | $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); | ||
| 1459 | 							if (!empty($getid3_temp->info['warning'])) { | ||
| 1460 | 								foreach ($getid3_temp->info['warning'] as $value) { | ||
| 1461 | $this->warning($value); | ||
| 1462 | } | ||
| 1463 | } | ||
| 1464 | 							if (!empty($getid3_temp->info['mpeg'])) { | ||
| 1465 | $info['mpeg'] = $getid3_temp->info['mpeg']; | ||
| 1466 | 								if (isset($info['mpeg']['audio'])) { | ||
| 1467 | $info['audio']['dataformat'] = 'mp3'; | ||
| 1468 | $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3'))); | ||
| 1469 | $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; | ||
| 1470 | $info['audio']['channels'] = $info['mpeg']['audio']['channels']; | ||
| 1471 | $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; | ||
| 1472 | $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); | ||
| 1473 | $info['bitrate'] = $info['audio']['bitrate']; | ||
| 1474 | } | ||
| 1475 | } | ||
| 1476 | } | ||
| 1477 | unset($getid3_mp3, $getid3_temp); | ||
| 1478 | $info['avdataend'] = $OldAVDataEnd; | ||
| 1479 | unset($OldAVDataEnd); | ||
| 1480 | |||
| 1481 | } | ||
| 1482 | |||
| 1483 | unset($mdat_offset, $chapter_string_length, $chapter_matches); | ||
| 1484 | break; | ||
| 1485 | |||
| 1486 | case 'free': // FREE space atom | ||
| 1487 | case 'skip': // SKIP atom | ||
| 1488 | case 'wide': // 64-bit expansion placeholder atom | ||
| 1489 | // 'free', 'skip' and 'wide' are just padding, contains no useful data at all | ||
| 1490 | |||
| 1491 | // When writing QuickTime files, it is sometimes necessary to update an atom's size. | ||
| 1492 | // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom | ||
| 1493 | // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime | ||
| 1494 | // puts an 8-byte placeholder atom before any atoms it may have to update the size of. | ||
| 1495 | // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the | ||
| 1496 | // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. | ||
| 1497 | // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). | ||
| 1498 | break; | ||
| 1499 | |||
| 1500 | |||
| 1501 | case 'nsav': // NoSAVe atom | ||
| 1502 | // http://developer.apple.com/technotes/tn/tn2038.html | ||
| 1503 | $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); | ||
| 1504 | break; | ||
| 1505 | |||
| 1506 | case 'ctyp': // Controller TYPe atom (seen on QTVR) | ||
| 1507 | // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt | ||
| 1508 | // some controller names are: | ||
| 1509 | // 0x00 + 'std' for linear movie | ||
| 1510 | // 'none' for no controls | ||
| 1511 | $atom_structure['ctyp'] = substr($atom_data, 0, 4); | ||
| 1512 | $info['quicktime']['controller'] = $atom_structure['ctyp']; | ||
| 1513 | 					switch ($atom_structure['ctyp']) { | ||
| 1514 | case 'qtvr': | ||
| 1515 | $info['video']['dataformat'] = 'quicktimevr'; | ||
| 1516 | break; | ||
| 1517 | } | ||
| 1518 | break; | ||
| 1519 | |||
| 1520 | case 'pano': // PANOrama track (seen on QTVR) | ||
| 1521 | $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); | ||
| 1522 | break; | ||
| 1523 | |||
| 1524 | case 'hint': // HINT track | ||
| 1525 | case 'hinf': // | ||
| 1526 | case 'hinv': // | ||
| 1527 | case 'hnti': // | ||
| 1528 | $info['quicktime']['hinting'] = true; | ||
| 1529 | break; | ||
| 1530 | |||
| 1531 | case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) | ||
| 1532 | 					for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { | ||
| 1533 | $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); | ||
| 1534 | } | ||
| 1535 | break; | ||
| 1536 | |||
| 1537 | |||
| 1538 | // Observed-but-not-handled atom types are just listed here to prevent warnings being generated | ||
| 1539 | case 'FXTC': // Something to do with Adobe After Effects (?) | ||
| 1540 | case 'PrmA': | ||
| 1541 | case 'code': | ||
| 1542 | case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html | ||
| 1543 | case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html | ||
| 1544 | // tapt seems to be used to compute the video size [https://www.getid3.org/phpBB3/viewtopic.php?t=838] | ||
| 1545 | // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html | ||
| 1546 | // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html | ||
| 1547 | case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html | ||
| 1548 | case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html | ||
| 1549 | case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html | ||
| 1550 | case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html | ||
| 1551 | //$atom_structure['data'] = $atom_data; | ||
| 1552 | break; | ||
| 1553 | |||
| 1554 | case "\xA9".'xyz': // GPS latitude+longitude+altitude | ||
| 1555 | $atom_structure['data'] = $atom_data; | ||
| 1556 | 					if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) { | ||
| 1557 | @list($all, $latitude, $longitude, $altitude) = $matches; | ||
| 1558 | $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude); | ||
| 1559 | $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude); | ||
| 1560 | 						if (!empty($altitude)) { | ||
| 1561 | $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude); | ||
| 1562 | } | ||
| 1563 | 					} else { | ||
| 1564 | 						$this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.'); | ||
| 1565 | } | ||
| 1566 | break; | ||
| 1567 | |||
| 1568 | case 'NCDT': | ||
| 1569 | // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html | ||
| 1570 | // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 | ||
| 1571 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 1572 | break; | ||
| 1573 | case 'NCTH': // Nikon Camera THumbnail image | ||
| 1574 | case 'NCVW': // Nikon Camera preVieW image | ||
| 1575 | // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html | ||
| 1576 | 					if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) { | ||
| 1577 | $atom_structure['data'] = $atom_data; | ||
| 1578 | $atom_structure['image_mime'] = 'image/jpeg'; | ||
| 1579 | $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image')); | ||
| 1580 | 						$info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']); | ||
| 1581 | } | ||
| 1582 | break; | ||
| 1583 | case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG | ||
| 1584 | $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data); | ||
| 1585 | break; | ||
| 1586 | case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html | ||
| 1587 | case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html | ||
| 1588 | case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html | ||
| 1589 | $atom_structure['data'] = $atom_data; | ||
| 1590 | break; | ||
| 1591 | |||
| 1592 | View Code Duplication | case "\x00\x00\x00\x00": | |
| 1593 | // some kind of metacontainer, may contain a big data dump such as: | ||
| 1594 | // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4 | ||
| 1595 | // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt | ||
| 1596 | |||
| 1597 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1598 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1599 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 1600 | //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 1601 | break; | ||
| 1602 | |||
| 1603 | View Code Duplication | case 'meta': // METAdata atom | |
| 1604 | // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html | ||
| 1605 | |||
| 1606 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1607 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1608 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 1609 | break; | ||
| 1610 | |||
| 1611 | case 'data': // metaDATA atom | ||
| 1612 | static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other | ||
| 1613 | // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data | ||
| 1614 | $atom_structure['language'] = substr($atom_data, 4 + 0, 2); | ||
| 1615 | $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); | ||
| 1616 | $atom_structure['data'] = substr($atom_data, 4 + 4); | ||
| 1617 | $atom_structure['key_name'] = @$info['quicktime']['temp_meta_key_names'][$metaDATAkey++]; | ||
| 1618 | |||
| 1619 | 					if ($atom_structure['key_name'] && $atom_structure['data']) { | ||
| 1620 | 						@$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data']; | ||
| 1621 | } | ||
| 1622 | break; | ||
| 1623 | |||
| 1624 | case 'keys': // KEYS that may be present in the metadata atom. | ||
| 1625 | // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 | ||
| 1626 | // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. | ||
| 1627 | // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys". | ||
| 1628 | $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); | ||
| 1629 | $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); | ||
| 1630 | $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); | ||
| 1631 | $keys_atom_offset = 8; | ||
| 1632 | 					for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { | ||
| 1633 | $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); | ||
| 1634 | $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); | ||
| 1635 | $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); | ||
| 1636 | $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace | ||
| 1637 | |||
| 1638 | $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value']; | ||
| 1639 | } | ||
| 1640 | break; | ||
| 1641 | |||
| 1642 | case 'uuid': // Atom holding 360fly spatial data?? | ||
| 1643 | /* code in this block by Paul Lewis 2019-Oct-31 */ | ||
| 1644 | /* Sensor Timestamps need to be calculated using the recordings base time at ['quicktime']['moov']['subatoms'][0]['creation_time_unix']. */ | ||
| 1645 | $atom_structure['title'] = '360Fly Sensor Data'; | ||
| 1646 | |||
| 1647 | //Get the UUID ID in first 16 bytes | ||
| 1648 | 					$uuid_bytes_read = unpack('H8time_low/H4time_mid/H4time_hi/H4clock_seq_hi/H12clock_seq_low', substr($atom_data, 0, 16)); | ||
| 1649 | 					$atom_structure['uuid_field_id'] = print_r(implode('-', $uuid_bytes_read), true); | ||
| 1650 | |||
| 1651 | //Get the UUID HEADER data | ||
| 1652 | 					$uuid_bytes_read = unpack('Sheader_size/Sheader_version/Stimescale/Shardware_version/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/', substr($atom_data, 16, 32)); | ||
| 1653 | $atom_structure['uuid_header'] = json_encode($uuid_bytes_read, true); | ||
| 1654 | |||
| 1655 | $start_byte = 48; | ||
| 1656 | $atom_SENSOR_data = substr($atom_data, $start_byte); | ||
| 1657 | $atom_structure['sensor_data']['data_type'] = array( | ||
| 1658 | 'fusion_count' => 0, // ID 250 | ||
| 1659 | 'fusion_data' => array(), | ||
| 1660 | 'accel_count' => 0, // ID 1 | ||
| 1661 | 'accel_data' => array(), | ||
| 1662 | 'gyro_count' => 0, // ID 2 | ||
| 1663 | 'gyro_data' => array(), | ||
| 1664 | 'magno_count' => 0, // ID 3 | ||
| 1665 | 'magno_data' => array(), | ||
| 1666 | 'gps_count' => 0, // ID 5 | ||
| 1667 | 'gps_data' => array(), | ||
| 1668 | 'rotation_count' => 0, // ID 6 | ||
| 1669 | 'rotation_data' => array(), | ||
| 1670 | 'unknown_count' => 0, // ID ?? | ||
| 1671 | 'unknown_data' => array(), | ||
| 1672 | 'debug_list' => '', // Used to debug variables stored as comma delimited strings | ||
| 1673 | ); | ||
| 1674 | $debug_structure['debug_items'] = array(); | ||
| 1675 | // Can start loop here to decode all sensor data in 32 Byte chunks: | ||
| 1676 | 					foreach (str_split($atom_SENSOR_data, 32) as $sensor_key => $sensor_data) { | ||
| 1677 | // This gets me a data_type code to work out what data is in the next 31 bytes. | ||
| 1678 | $sensor_data_type = substr($sensor_data, 0, 1); | ||
| 1679 | $sensor_data_content = substr($sensor_data, 1); | ||
| 1680 | 						$uuid_bytes_read = unpack('C*', $sensor_data_type); | ||
| 1681 | $sensor_data_array = array(); | ||
| 1682 | 						switch ($uuid_bytes_read[1]) { | ||
| 1683 | View Code Duplication | case 250: | |
| 1684 | $atom_structure['sensor_data']['data_type']['fusion_count']++; | ||
| 1685 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); | ||
| 1686 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1687 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1688 | $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; | ||
| 1689 | $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; | ||
| 1690 | $sensor_data_array['roll'] = $uuid_bytes_read['roll']; | ||
| 1691 | array_push($atom_structure['sensor_data']['data_type']['fusion_data'], $sensor_data_array); | ||
| 1692 | break; | ||
| 1693 | View Code Duplication | case 1: | |
| 1694 | $atom_structure['sensor_data']['data_type']['accel_count']++; | ||
| 1695 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); | ||
| 1696 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1697 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1698 | $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; | ||
| 1699 | $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; | ||
| 1700 | $sensor_data_array['roll'] = $uuid_bytes_read['roll']; | ||
| 1701 | array_push($atom_structure['sensor_data']['data_type']['accel_data'], $sensor_data_array); | ||
| 1702 | break; | ||
| 1703 | View Code Duplication | case 2: | |
| 1704 | $atom_structure['sensor_data']['data_type']['gyro_count']++; | ||
| 1705 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); | ||
| 1706 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1707 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1708 | $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; | ||
| 1709 | $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; | ||
| 1710 | $sensor_data_array['roll'] = $uuid_bytes_read['roll']; | ||
| 1711 | array_push($atom_structure['sensor_data']['data_type']['gyro_data'], $sensor_data_array); | ||
| 1712 | break; | ||
| 1713 | View Code Duplication | case 3: | |
| 1714 | $atom_structure['sensor_data']['data_type']['magno_count']++; | ||
| 1715 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Gmagx/Gmagy/Gmagz/x*', $sensor_data_content); | ||
| 1716 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1717 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1718 | $sensor_data_array['magx'] = $uuid_bytes_read['magx']; | ||
| 1719 | $sensor_data_array['magy'] = $uuid_bytes_read['magy']; | ||
| 1720 | $sensor_data_array['magz'] = $uuid_bytes_read['magz']; | ||
| 1721 | array_push($atom_structure['sensor_data']['data_type']['magno_data'], $sensor_data_array); | ||
| 1722 | break; | ||
| 1723 | case 5: | ||
| 1724 | $atom_structure['sensor_data']['data_type']['gps_count']++; | ||
| 1725 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Glat/Glon/Galt/Gspeed/nbearing/nacc/x*', $sensor_data_content); | ||
| 1726 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1727 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1728 | $sensor_data_array['lat'] = $uuid_bytes_read['lat']; | ||
| 1729 | $sensor_data_array['lon'] = $uuid_bytes_read['lon']; | ||
| 1730 | $sensor_data_array['alt'] = $uuid_bytes_read['alt']; | ||
| 1731 | $sensor_data_array['speed'] = $uuid_bytes_read['speed']; | ||
| 1732 | $sensor_data_array['bearing'] = $uuid_bytes_read['bearing']; | ||
| 1733 | $sensor_data_array['acc'] = $uuid_bytes_read['acc']; | ||
| 1734 | //$sensor_data_array = print_r($uuid_bytes_read, true); | ||
| 1735 | array_push($atom_structure['sensor_data']['data_type']['gps_data'], $sensor_data_array); | ||
| 1736 | //array_push($debug_structure['debug_items'], $uuid_bytes_read['timestamp']); | ||
| 1737 | break; | ||
| 1738 | View Code Duplication | case 6: | |
| 1739 | $atom_structure['sensor_data']['data_type']['rotation_count']++; | ||
| 1740 | 								$uuid_bytes_read = unpack('cmode/Jtimestamp/Grotx/Groty/Grotz/x*', $sensor_data_content); | ||
| 1741 | $sensor_data_array['mode'] = $uuid_bytes_read['mode']; | ||
| 1742 | $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; | ||
| 1743 | $sensor_data_array['rotx'] = $uuid_bytes_read['rotx']; | ||
| 1744 | $sensor_data_array['roty'] = $uuid_bytes_read['roty']; | ||
| 1745 | $sensor_data_array['rotz'] = $uuid_bytes_read['rotz']; | ||
| 1746 | array_push($atom_structure['sensor_data']['data_type']['rotation_data'], $sensor_data_array); | ||
| 1747 | break; | ||
| 1748 | default: | ||
| 1749 | $atom_structure['sensor_data']['data_type']['unknown_count']++; | ||
| 1750 | break; | ||
| 1751 | } | ||
| 1752 | } | ||
| 1753 | //					if (isset($debug_structure['debug_items']) && count($debug_structure['debug_items']) > 0) { | ||
| 1754 | //						$atom_structure['sensor_data']['data_type']['debug_list'] = implode(',', $debug_structure['debug_items']); | ||
| 1755 | //					} else { | ||
| 1756 | $atom_structure['sensor_data']['data_type']['debug_list'] = 'No debug items in list!'; | ||
| 1757 | // } | ||
| 1758 | break; | ||
| 1759 | |||
| 1760 | case 'gps ': | ||
| 1761 | // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 | ||
| 1762 | // The 'gps ' contains simple look up table made up of 8byte rows, that point to the 'free' atoms that contains the actual GPS data. | ||
| 1763 | // The first row is version/metadata/notsure, I skip that. | ||
| 1764 | // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file. | ||
| 1765 | |||
| 1766 | $GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size | ||
| 1767 | 					if (strlen($atom_data) > 0) { | ||
| 1768 | 						if ((strlen($atom_data) % $GPS_rowsize) == 0) { | ||
| 1769 | $atom_structure['gps_toc'] = array(); | ||
| 1770 | 							foreach (str_split($atom_data, $GPS_rowsize) as $counter => $datapair) { | ||
| 1771 | 								$atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data, $counter * $GPS_rowsize, $GPS_rowsize)); | ||
| 1772 | } | ||
| 1773 | |||
| 1774 | $atom_structure['gps_entries'] = array(); | ||
| 1775 | $previous_offset = $this->ftell(); | ||
| 1776 | 							foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) { | ||
| 1777 | 								if ($key == 0) { | ||
| 1778 | // "The first row is version/metadata/notsure, I skip that." | ||
| 1779 | continue; | ||
| 1780 | } | ||
| 1781 | $this->fseek($gps_pointer['offset']); | ||
| 1782 | $GPS_free_data = $this->fread($gps_pointer['size']); | ||
| 1783 | |||
| 1784 | /* | ||
| 1785 | // 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 | ||
| 1786 | |||
| 1787 | // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 | ||
| 1788 | // The structure of the GPS data atom (the 'free' atoms mentioned above) is following: | ||
| 1789 | 								// hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from('<IIIIIIssssfff',data, 48) | ||
| 1790 | // For those unfamiliar with python struct: | ||
| 1791 | // I = int | ||
| 1792 | // s = is string (size 1, in this case) | ||
| 1793 | // f = float | ||
| 1794 | |||
| 1795 | 								//$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)); | ||
| 1796 | */ | ||
| 1797 | |||
| 1798 | // $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62 | ||
| 1799 | // $GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67 | ||
| 1800 | // $GPRMC,002454,A,3553.5295,N,13938.6570,E,0.0,43.1,180700,7.1,W,A*3F | ||
| 1801 | // $GPRMC,094347.000,A,5342.0061,N,00737.9908,W,0.01,156.75,140217,,,A*7D | ||
| 1802 | 								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)) { | ||
| 1803 | $GPS_this_GPRMC = array(); | ||
| 1804 | $GPS_this_GPRMC_raw = array(); | ||
| 1805 | list( | ||
| 1806 | $GPS_this_GPRMC_raw['gprmc'], | ||
| 1807 | $GPS_this_GPRMC_raw['timestamp'], | ||
| 1808 | $GPS_this_GPRMC_raw['status'], | ||
| 1809 | $GPS_this_GPRMC_raw['latitude'], | ||
| 1810 | $GPS_this_GPRMC_raw['latitude_direction'], | ||
| 1811 | $GPS_this_GPRMC_raw['longitude'], | ||
| 1812 | $GPS_this_GPRMC_raw['longitude_direction'], | ||
| 1813 | $GPS_this_GPRMC_raw['knots'], | ||
| 1814 | $GPS_this_GPRMC_raw['angle'], | ||
| 1815 | $GPS_this_GPRMC_raw['datestamp'], | ||
| 1816 | $GPS_this_GPRMC_raw['variation'], | ||
| 1817 | $GPS_this_GPRMC_raw['variation_direction'], | ||
| 1818 | $dummy, | ||
| 1819 | $GPS_this_GPRMC_raw['checksum'], | ||
| 1820 | ) = $matches; | ||
| 1821 | $GPS_this_GPRMC['raw'] = $GPS_this_GPRMC_raw; | ||
| 1822 | |||
| 1823 | $hour = substr($GPS_this_GPRMC['raw']['timestamp'], 0, 2); | ||
| 1824 | $minute = substr($GPS_this_GPRMC['raw']['timestamp'], 2, 2); | ||
| 1825 | $second = substr($GPS_this_GPRMC['raw']['timestamp'], 4, 2); | ||
| 1826 | $ms = substr($GPS_this_GPRMC['raw']['timestamp'], 6); // may contain decimal seconds | ||
| 1827 | $day = substr($GPS_this_GPRMC['raw']['datestamp'], 0, 2); | ||
| 1828 | $month = substr($GPS_this_GPRMC['raw']['datestamp'], 2, 2); | ||
| 1829 | $year = (int) substr($GPS_this_GPRMC['raw']['datestamp'], 4, 2); | ||
| 1830 | $year += (($year > 90) ? 1900 : 2000); // complete lack of foresight: datestamps are stored with 2-digit years, take best guess | ||
| 1831 | $GPS_this_GPRMC['timestamp'] = $year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second.$ms; | ||
| 1832 | |||
| 1833 | $GPS_this_GPRMC['active'] = ($GPS_this_GPRMC['raw']['status'] == 'A'); // A=Active,V=Void | ||
| 1834 | |||
| 1835 | 									foreach (array('latitude','longitude') as $latlon) { | ||
| 1836 | 										preg_match('#^([0-9]{1,3})([0-9]{2}\\.[0-9]+)$#', $GPS_this_GPRMC['raw'][$latlon], $matches); | ||
| 1837 | list($dummy, $deg, $min) = $matches; | ||
| 1838 | $GPS_this_GPRMC[$latlon] = $deg + ($min / 60); | ||
| 1839 | } | ||
| 1840 | $GPS_this_GPRMC['latitude'] *= (($GPS_this_GPRMC['raw']['latitude_direction'] == 'S') ? -1 : 1); | ||
| 1841 | $GPS_this_GPRMC['longitude'] *= (($GPS_this_GPRMC['raw']['longitude_direction'] == 'W') ? -1 : 1); | ||
| 1842 | |||
| 1843 | $GPS_this_GPRMC['heading'] = $GPS_this_GPRMC['raw']['angle']; | ||
| 1844 | $GPS_this_GPRMC['speed_knot'] = $GPS_this_GPRMC['raw']['knots']; | ||
| 1845 | $GPS_this_GPRMC['speed_kmh'] = $GPS_this_GPRMC['raw']['knots'] * 1.852; | ||
| 1846 | 									if ($GPS_this_GPRMC['raw']['variation']) { | ||
| 1847 | $GPS_this_GPRMC['variation'] = $GPS_this_GPRMC['raw']['variation']; | ||
| 1848 | $GPS_this_GPRMC['variation'] *= (($GPS_this_GPRMC['raw']['variation_direction'] == 'W') ? -1 : 1); | ||
| 1849 | } | ||
| 1850 | |||
| 1851 | $atom_structure['gps_entries'][$key] = $GPS_this_GPRMC; | ||
| 1852 | |||
| 1853 | @$info['quicktime']['gps_track'][$GPS_this_GPRMC['timestamp']] = array( | ||
| 1854 | 'latitude' => (float) $GPS_this_GPRMC['latitude'], | ||
| 1855 | 'longitude' => (float) $GPS_this_GPRMC['longitude'], | ||
| 1856 | 'speed_kmh' => (float) $GPS_this_GPRMC['speed_kmh'], | ||
| 1857 | 'heading' => (float) $GPS_this_GPRMC['heading'], | ||
| 1858 | ); | ||
| 1859 | |||
| 1860 | 								} else { | ||
| 1861 | 									$this->warning('Unhandled GPS format in "free" atom at offset '.$gps_pointer['offset']); | ||
| 1862 | } | ||
| 1863 | } | ||
| 1864 | $this->fseek($previous_offset); | ||
| 1865 | |||
| 1866 | 						} else { | ||
| 1867 | 							$this->warning('QuickTime atom "'.$atomname.'" is not mod-8 bytes long ('.$atomsize.' bytes) at offset '.$baseoffset); | ||
| 1868 | } | ||
| 1869 | 					} else { | ||
| 1870 | 						$this->warning('QuickTime atom "'.$atomname.'" is zero bytes long at offset '.$baseoffset); | ||
| 1871 | } | ||
| 1872 | break; | ||
| 1873 | |||
| 1874 | case 'loci':// 3GP location (El Loco) | ||
| 1875 | $loffset = 0; | ||
| 1876 | $info['quicktime']['comments']['gps_flags'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 0, 4))); | ||
| 1877 | $info['quicktime']['comments']['gps_lang'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 4, 2))); | ||
| 1878 | $info['quicktime']['comments']['gps_location'] = array( $this->LociString(substr($atom_data, 6), $loffset)); | ||
| 1879 | $loci_data = substr($atom_data, 6 + $loffset); | ||
| 1880 | $info['quicktime']['comments']['gps_role'] = array( getid3_lib::BigEndian2Int(substr($loci_data, 0, 1))); | ||
| 1881 | $info['quicktime']['comments']['gps_longitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 1, 4))); | ||
| 1882 | $info['quicktime']['comments']['gps_latitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 5, 4))); | ||
| 1883 | $info['quicktime']['comments']['gps_altitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 9, 4))); | ||
| 1884 | $info['quicktime']['comments']['gps_body'] = array( $this->LociString(substr($loci_data, 13 ), $loffset)); | ||
| 1885 | $info['quicktime']['comments']['gps_notes'] = array( $this->LociString(substr($loci_data, 13 + $loffset), $loffset)); | ||
| 1886 | break; | ||
| 1887 | |||
| 1888 | case 'chpl': // CHaPter List | ||
| 1889 | // https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf | ||
| 1890 | $chpl_version = getid3_lib::BigEndian2Int(substr($atom_data, 4, 1)); // Expected to be 0 | ||
| 1891 | $chpl_flags = getid3_lib::BigEndian2Int(substr($atom_data, 5, 3)); // Reserved, set to 0 | ||
| 1892 | $chpl_count = getid3_lib::BigEndian2Int(substr($atom_data, 8, 1)); | ||
| 1893 | $chpl_offset = 9; | ||
| 1894 | 					for ($i = 0; $i < $chpl_count; $i++) { | ||
| 1895 | 						if (($chpl_offset + 9) >= strlen($atom_data)) { | ||
| 1896 | 							$this->warning('QuickTime chapter '.$i.' extends beyond end of "chpl" atom'); | ||
| 1897 | break; | ||
| 1898 | } | ||
| 1899 | $info['quicktime']['chapters'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 8)) / 10000000; // timestamps are stored as 100-nanosecond units | ||
| 1900 | $chpl_offset += 8; | ||
| 1901 | $chpl_title_size = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 1)); | ||
| 1902 | $chpl_offset += 1; | ||
| 1903 | $info['quicktime']['chapters'][$i]['title'] = substr($atom_data, $chpl_offset, $chpl_title_size); | ||
| 1904 | $chpl_offset += $chpl_title_size; | ||
| 1905 | } | ||
| 1906 | break; | ||
| 1907 | |||
| 1908 | case 'FIRM': // FIRMware version(?), seen on GoPro Hero4 | ||
| 1909 | $info['quicktime']['camera']['firmware'] = $atom_data; | ||
| 1910 | break; | ||
| 1911 | |||
| 1912 | case 'CAME': // FIRMware version(?), seen on GoPro Hero4 | ||
| 1913 | 					$info['quicktime']['camera']['serial_hash'] = unpack('H*', $atom_data); | ||
| 1914 | break; | ||
| 1915 | |||
| 1916 | case 'dscp': | ||
| 1917 | case 'rcif': | ||
| 1918 | // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 | ||
| 1919 | 					if (substr($atom_data, 0, 7) == "\x00\x00\x00\x00\x55\xC4".'{') { | ||
| 1920 | 						if ($json_decoded = @json_decode(rtrim(substr($atom_data, 6), "\x00"), true)) { | ||
| 1921 | $info['quicktime']['camera'][$atomname] = $json_decoded; | ||
| 1922 | 							if (($atomname == 'rcif') && isset($info['quicktime']['camera']['rcif']['wxcamera']['rotate'])) { | ||
| 1923 | $info['video']['rotate'] = $info['quicktime']['video']['rotate'] = $info['quicktime']['camera']['rcif']['wxcamera']['rotate']; | ||
| 1924 | } | ||
| 1925 | 						} else { | ||
| 1926 | 							$this->warning('Failed to JSON decode atom "'.$atomname.'"'); | ||
| 1927 | $atom_structure['data'] = $atom_data; | ||
| 1928 | } | ||
| 1929 | unset($json_decoded); | ||
| 1930 | 					} else { | ||
| 1931 | 						$this->warning('Expecting 55 C4 7B at start of atom "'.$atomname.'", found '.getid3_lib::PrintHexBytes(substr($atom_data, 4, 3)).' instead'); | ||
| 1932 | $atom_structure['data'] = $atom_data; | ||
| 1933 | } | ||
| 1934 | break; | ||
| 1935 | |||
| 1936 | case 'frea': | ||
| 1937 | // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea | ||
| 1938 | // may contain "scra" (PreviewImage) and/or "thma" (ThumbnailImage) | ||
| 1939 | $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); | ||
| 1940 | break; | ||
| 1941 | case 'tima': // subatom to "frea" | ||
| 1942 | // no idea what this does, the one sample file I've seen has a value of 0x00000027 | ||
| 1943 | $atom_structure['data'] = $atom_data; | ||
| 1944 | break; | ||
| 1945 | case 'ver ': // subatom to "frea" | ||
| 1946 | // some kind of version number, the one sample file I've seen has a value of "3.00.073" | ||
| 1947 | $atom_structure['data'] = $atom_data; | ||
| 1948 | break; | ||
| 1949 | View Code Duplication | case 'thma': // subatom to "frea" -- "ThumbnailImage" | |
| 1950 | // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea | ||
| 1951 | 					if (strlen($atom_data) > 0) { | ||
| 1952 | 						$info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg'); | ||
| 1953 | } | ||
| 1954 | break; | ||
| 1955 | View Code Duplication | case 'scra': // subatom to "frea" -- "PreviewImage" | |
| 1956 | // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea | ||
| 1957 | // but the only sample file I've seen has no useful data here | ||
| 1958 | 					if (strlen($atom_data) > 0) { | ||
| 1959 | 						$info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg'); | ||
| 1960 | } | ||
| 1961 | break; | ||
| 1962 | |||
| 1963 | |||
| 1964 | View Code Duplication | default: | |
| 1965 | 					$this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).'), '.$atomsize.' bytes at offset '.$baseoffset); | ||
| 1966 | $atom_structure['data'] = $atom_data; | ||
| 1967 | break; | ||
| 1968 | } | ||
| 1969 | } | ||
| 1970 | array_pop($atomHierarchy); | ||
| 1971 | return $atom_structure; | ||
| 1972 | } | ||
| 1973 | |||
| 3030 |