///////////////////////////////////////////////////////////////// /// getID3() by James Heinrich <info@getid3.org> // // available at https://github.com/JamesHeinrich/getID3 // // or https://www.getid3.org // // or http://getid3.sourceforge.net // // see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio-video.quicktime.php // // module for analyzing Quicktime and MP3-in-MP4 files // // dependencies: module.audio.mp3.php // // dependencies: module.tag.id3v2.php // // /// /////////////////////////////////////////////////////////////////
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers exit; } getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup
class getid3_quicktime extends getid3_handler {
/** audio-video.quicktime * return all parsed data from all atoms if true, otherwise just returned parsed metadata * * @var bool */ public $ReturnAtomData = false;
/** audio-video.quicktime * return all parsed data from all atoms if true, otherwise just returned parsed metadata * * @var bool */ public $ParseAllPossibleAtoms = false;
/** * @return bool */ public function Analyze() { $info = &$this->getid3->info;
$info['fileformat'] = 'quicktime'; $info['quicktime']['hinting'] = false; $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
$this->fseek($info['avdataoffset']);
$offset = 0; $atomcounter = 0; $atom_data_read_buffer_size = $info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : $this->getid3->option_fread_buffer_size * 1024; // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB] while ($offset < $info['avdataend']) { if (!getid3_lib::intValueSupported($offset)) { $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'); break; } $this->fseek($offset); $AtomHeader = $this->fread(8);
// https://github.com/JamesHeinrich/getID3/issues/382 // Atom sizes are stored as 32-bit number in most cases, but sometimes (notably for "mdat") // a 64-bit value is required, in which case the normal 32-bit size field is set to 0x00000001 // and the 64-bit "real" size value is the next 8 bytes. $atom_size_extended_bytes = 0; $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); $atomname = substr($AtomHeader, 4, 4); if ($atomsize == 1) { $atom_size_extended_bytes = 8; $atomsize = getid3_lib::BigEndian2Int($this->fread($atom_size_extended_bytes)); }
if (($offset + $atomsize) > $info['avdataend']) { $info['quicktime'][$atomname]['name'] = $atomname; $info['quicktime'][$atomname]['size'] = $atomsize; $info['quicktime'][$atomname]['offset'] = $offset; $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'); return false; } if ($atomsize == 0) { // Furthermore, for historical reasons the list of atoms is optionally // terminated by a 32-bit integer set to 0. If you are writing a program // to read user data atoms, you should allow for the terminating 0. $info['quicktime'][$atomname]['name'] = $atomname; $info['quicktime'][$atomname]['size'] = $atomsize; $info['quicktime'][$atomname]['offset'] = $offset; break; } $atomHierarchy = array(); $parsedAtomData = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize - $atom_size_extended_bytes, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms); $parsedAtomData['name'] = $atomname; $parsedAtomData['size'] = $atomsize; $parsedAtomData['offset'] = $offset; if ($atom_size_extended_bytes) { $parsedAtomData['xsize_bytes'] = $atom_size_extended_bytes; } if (in_array($atomname, array('uuid'))) { @$info['quicktime'][$atomname][] = $parsedAtomData; } else { $info['quicktime'][$atomname] = $parsedAtomData; }
$offset += $atomsize; $atomcounter++; }
if (!empty($info['avdataend_tmp'])) { // this value is assigned to a temp value and then erased because // otherwise any atoms beyond the 'mdat' atom would not get parsed $info['avdataend'] = $info['avdataend_tmp']; unset($info['avdataend_tmp']); }
$atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see https://www.getid3.org/phpBB3/viewtopic.php?t=1717 array_push($atomHierarchy, $atomname); $atom_structure = array(); $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); $atom_structure['name'] = $atomname; $atom_structure['size'] = $atomsize; $atom_structure['offset'] = $baseoffset; if (substr($atomname, 0, 3) == "\x00\x00\x00") { // https://github.com/JamesHeinrich/getID3/issues/139 $atomname = getid3_lib::BigEndian2Int($atomname); $atom_structure['name'] = $atomname; $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); } else { switch ($atomname) { case 'moov': // MOVie container atom case 'moof': // MOvie Fragment box case 'trak': // TRAcK container atom case 'traf': // TRAck Fragment box case 'clip': // CLIPping container atom case 'matt': // track MATTe container atom case 'edts': // EDiTS container atom case 'tref': // Track REFerence container atom case 'mdia': // MeDIA container atom case 'minf': // Media INFormation container atom case 'dinf': // Data INFormation container atom case 'nmhd': // Null Media HeaDer container atom case 'udta': // User DaTA container atom case 'cmov': // Compressed MOVie container atom case 'rmra': // Reference Movie Record Atom case 'rmda': // Reference Movie Descriptor Atom case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); break;
case 'ilst': // Item LiST container atom if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted $allnumericnames = true; foreach ($atom_structure['subatoms'] as $subatomarray) { if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { $allnumericnames = false; break; } } if ($allnumericnames) { $newData = array(); foreach ($atom_structure['subatoms'] as $subatomarray) { foreach ($subatomarray['subatoms'] as $newData_subatomarray) { unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); $newData[$subatomarray['name']] = $newData_subatomarray; break; } } $atom_structure['data'] = $newData; unset($atom_structure['subatoms']); } } break;
case 'stbl': // Sample TaBLe container atom $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); $isVideo = false; $framerate = 0; $framecount = 0; foreach ($atom_structure['subatoms'] as $key => $value_array) { if (isset($value_array['sample_description_table'])) { foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { if (isset($value_array2['data_format'])) { switch ($value_array2['data_format']) { case 'avc1': case 'mp4v': // video data $isVideo = true; break; case 'mp4a': // audio data break; } } } } elseif (isset($value_array['time_to_sample_table'])) { foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0) && !empty($info['quicktime']['time_scale'])) { $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); $framecount = $value_array2['sample_count']; } } } } if ($isVideo && $framerate) { $info['quicktime']['video']['frame_rate'] = $framerate; $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; } if ($isVideo && $framecount) { $info['quicktime']['video']['frame_count'] = $framecount; } break;
case "\xA9".'alb': // ALBum case "\xA9".'ART': // case "\xA9".'art': // ARTist case "\xA9".'aut': // case "\xA9".'cmt': // CoMmenT case "\xA9".'com': // COMposer case "\xA9".'cpy': // case "\xA9".'day': // content created year case "\xA9".'dir': // case "\xA9".'ed1': // case "\xA9".'ed2': // case "\xA9".'ed3': // case "\xA9".'ed4': // case "\xA9".'ed5': // case "\xA9".'ed6': // case "\xA9".'ed7': // case "\xA9".'ed8': // case "\xA9".'ed9': // case "\xA9".'enc': // case "\xA9".'fmt': // case "\xA9".'gen': // GENre case "\xA9".'grp': // GRouPing case "\xA9".'hst': // case "\xA9".'inf': // case "\xA9".'lyr': // LYRics case "\xA9".'mak': // case "\xA9".'mod': // case "\xA9".'nam': // full NAMe case "\xA9".'ope': // case "\xA9".'PRD': // case "\xA9".'prf': // case "\xA9".'req': // case "\xA9".'src': // case "\xA9".'swr': // case "\xA9".'too': // encoder case "\xA9".'trk': // TRacK case "\xA9".'url': // case "\xA9".'wrn': // case "\xA9".'wrt': // WRiTer case '----': // itunes specific case 'aART': // Album ARTist case 'akID': // iTunes store account type case 'apID': // Purchase Account case 'atID': // case 'catg': // CaTeGory case 'cmID': // case 'cnID': // case 'covr': // COVeR artwork case 'cpil': // ComPILation case 'cprt': // CoPyRighT case 'desc': // DESCription case 'disk': // DISK number case 'egid': // Episode Global ID case 'geID': // case 'gnre': // GeNRE case 'hdvd': // HD ViDeo case 'keyw': // KEYWord case 'ldes': // Long DEScription case 'pcst': // PodCaST case 'pgap': // GAPless Playback case 'plID': // case 'purd': // PURchase Date case 'purl': // Podcast URL case 'rati': // case 'rndu': // case 'rpdu': // case 'rtng': // RaTiNG case 'sfID': // iTunes store country case 'soaa': // SOrt Album Artist case 'soal': // SOrt ALbum case 'soar': // SOrt ARtist case 'soco': // SOrt COmposer case 'sonm': // SOrt NaMe case 'sosn': // SOrt Show Name case 'stik': // case 'tmpo': // TeMPO (BPM) case 'trkn': // TRacK Number case 'tven': // tvEpisodeID case 'tves': // TV EpiSode case 'tvnn': // TV Network Name case 'tvsh': // TV SHow Name case 'tvsn': // TV SeasoN if ($atom_parent == 'udta') { // User data atom handler $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); $atom_structure['data'] = substr($atom_data, 4);
$atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { $info['comments']['language'][] = $atom_structure['language']; } } else { // Apple item list box atom handler $atomoffset = 0; if (substr($atom_data, 2, 2) == "\x10\xB5") { // not sure what it means, but observed on iPhone4 data. // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data while ($atomoffset < strlen($atom_data)) { $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); if ($boxsmallsize <= 1) { $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); $atom_structure['data'] = null; $atomoffset = strlen($atom_data); break; } switch ($boxsmalltype) { case "\x10\xB5": $atom_structure['data'] = $boxsmalldata; break; default: $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); $atom_structure['data'] = $atom_data; break; } $atomoffset += (4 + $boxsmallsize); } } else { while ($atomoffset < strlen($atom_data)) { $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); $boxtype = substr($atom_data, $atomoffset + 4, 4); $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); if ($boxsize <= 1) { $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); $atom_structure['data'] = null; $atomoffset = strlen($atom_data); break; } $atomoffset += $boxsize;
switch ($boxtype) { case 'mean': case 'name': $atom_structure[$boxtype] = substr($boxdata, 4); break;
case 'data': $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); switch ($atom_structure['flags_raw']) { case 0: // data flag case 21: // tmpo/cpil flag switch ($atomname) { case 'cpil': case 'hdvd': case 'pcst': case 'pgap': // 8-bit integer (boolean) $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); break;
case 'covr': $atom_structure['data'] = substr($boxdata, 8); // not a foolproof check, but better than nothing if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { $atom_structure['image_mime'] = 'image/jpeg'; } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { $atom_structure['image_mime'] = 'image/png'; } elseif (preg_match('#^GIF#', $atom_structure['data'])) { $atom_structure['image_mime'] = 'image/gif'; } $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_structure['data'], 'description'=>'cover'); break;
case 'atID': case 'cnID': case 'geID': case 'tves': case 'tvsn': default: // 32-bit integer $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); } break;
case 1: // text flag case 13: // image flag default: $atom_structure['data'] = substr($boxdata, 8); if ($atomname == 'covr') { if (!empty($atom_structure['data'])) { $atom_structure['image_mime'] = 'image/unknown'; // provide default MIME type to ensure array keys exist if (function_exists('getimagesizefromstring') && ($getimagesize = getimagesizefromstring($atom_structure['data'])) && !empty($getimagesize['mime'])) { $atom_structure['image_mime'] = $getimagesize['mime']; } else { // if getimagesizefromstring is not available, or fails for some reason, fall back to simple detection of common image formats $ImageFormatSignatures = array( 'image/jpeg' => "\xFF\xD8\xFF", 'image/png' => "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 'image/gif' => 'GIF', ); foreach ($ImageFormatSignatures as $mime => $image_format_signature) { if (substr($atom_structure['data'], 0, strlen($image_format_signature)) == $image_format_signature) { $atom_structure['image_mime'] = $mime; break; } } } $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_structure['data'], 'description'=>'cover'); } else { $this->warning('Unknown empty "covr" image at offset '.$baseoffset); } } break;
case 'WLOC': // Window LOCation atom $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); break;
case 'LOOP': // LOOPing atom case 'SelO': // play SELection Only atom case 'AllF': // play ALL Frames atom $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); break;
case 'name': // case 'MCPS': // Media Cleaner PRo case '@PRM': // adobe PReMiere version case '@PRQ': // adobe PRemiere Quicktime version $atom_structure['data'] = $atom_data; break;
case 'cmvd': // Compressed MooV Data atom // Code by ubergeekØubergeek*tv based on information from // http://developer.apple.com/quicktime/icefloe/dispatch012.html $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
$CompressedFileData = substr($atom_data, 4); if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); } else { $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); } break;
case 'dcom': // Data COMpression atom $atom_structure['compression_id'] = $atom_data; $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); break;
case 'rdrf': // Reference movie Data ReFerence atom $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
// see: https://github.com/JamesHeinrich/getID3/issues/111 // Some corrupt files have been known to have high bits set in the number_entries field // This field shouldn't really need to be 32-bits, values stores are likely in the range 1-100000 // Workaround: mask off the upper byte and throw a warning if it's nonzero if ($atom_structure['number_entries'] > 0x000FFFFF) { if ($atom_structure['number_entries'] > 0x00FFFFFF) { $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)); $atom_structure['number_entries'] = ($atom_structure['number_entries'] & 0x00FFFFFF); } else { $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Please report this to info@getid3.org referencing bug report #111'); } }
$stsdEntriesDataOffset = 8; for ($i = 0; $i < $atom_structure['number_entries']; $i++) { $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); $stsdEntriesDataOffset += 4; $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); $stsdEntriesDataOffset += 4; $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); $stsdEntriesDataOffset += 6; $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); $stsdEntriesDataOffset += 2; $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); if (substr($atom_structure['sample_description_table'][$i]['data'], 1, 54) == 'application/octet-stream;type=com.parrot.videometadata') { // special handling for apparently-malformed (TextMetaDataSampleEntry?) data for some version of Parrot drones $atom_structure['sample_description_table'][$i]['parrot_frame_metadata']['mime_type'] = substr($atom_structure['sample_description_table'][$i]['data'], 1, 55); $atom_structure['sample_description_table'][$i]['parrot_frame_metadata']['metadata_version'] = (int) substr($atom_structure['sample_description_table'][$i]['data'], 55, 1); unset($atom_structure['sample_description_table'][$i]['data']); $this->warning('incomplete/incorrect handling of "stsd" with Parrot metadata in this version of getID3() ['.$this->getid3->version().']'); continue; }
switch ($atom_structure['sample_description_table'][$i]['data_format']) { case '2vuY': case 'avc1': case 'cvid': case 'dvc ': case 'dvcp': case 'gif ': case 'h263': case 'hvc1': case 'jpeg': case 'kpcd': case 'mjpa': case 'mjpb': case 'mp4v': case 'png ': case 'raw ': case 'rle ': case 'rpza': case 'smc ': case 'SVQ1': case 'SVQ3': case 'tiff': case 'v210': case 'v216': case 'v308': case 'v408': case 'v410': case 'yuv2': $info['fileformat'] = 'mp4'; $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; if ($this->QuicktimeVideoCodecLookup($info['video']['fourcc'])) { $info['video']['fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($info['video']['fourcc']); }
// https://www.getid3.org/phpBB3/viewtopic.php?t=1550 //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 if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) { // assume that values stored here are more important than values stored in [tkhd] atom $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; } break;
case 'qtvr': $info['video']['dataformat'] = 'quicktimevr'; break;
case 'crgn': // Clipping ReGioN atom $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. break;
case 'tmcd': // TiMe CoDe atom case 'chap': // CHAPter list atom case 'sync': // SYNChronization atom case 'scpt': // tranSCriPT atom case 'ssrc': // non-primary SouRCe atom for ($i = 0; $i < strlen($atom_data); $i += 4) { @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); } break;
// https://www.getid3.org/phpBB3/viewtopic.php?t=1908 // attempt to compute rotation from matrix values // 2017-Dec-28: uncertain if 90/270 are correctly oriented; values returned by FixedPoint16_16 should perhaps be -1 instead of 65535(?) $matrixRotation = 0; switch ($atom_structure['matrix_a'].':'.$atom_structure['matrix_b'].':'.$atom_structure['matrix_c'].':'.$atom_structure['matrix_d']) { case '1:0:0:1': $matrixRotation = 0; break; case '0:1:65535:0': $matrixRotation = 90; break; case '65535:0:0:65535': $matrixRotation = 180; break; case '0:65535:1:0': $matrixRotation = 270; break; default: break; }
// https://www.getid3.org/phpBB3/viewtopic.php?t=2468 // The rotation matrix can appear in the Quicktime file multiple times, at least once for each track, // and it's possible that only the video track (or, in theory, one of the video tracks) is flagged as // rotated while the other tracks (e.g. audio) is tagged as rotation=0 (behavior noted on iPhone 8 Plus) // The correct solution would be to check if the TrackID associated with the rotation matrix is indeed // a video track (or the main video track) and only set the rotation then, but since information about // what track is what is not trivially there to be examined, the lazy solution is to set the rotation // if it is found to be nonzero, on the assumption that tracks that don't need it will have rotation set // to zero (and be effectively ignored) and the video track will have rotation set correctly, which will // either be zero and automatically correct, or nonzero and be set correctly. if (!isset($info['video']['rotate']) || (($info['video']['rotate'] == 0) && ($matrixRotation > 0))) { $info['quicktime']['video']['rotate'] = $info['video']['rotate'] = $matrixRotation; }
case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) $atom_structure['signature'] = substr($atom_data, 0, 4); $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); $atom_structure['fourcc'] = substr($atom_data, 8, 4); break;
case 'mdat': // Media DATa atom // 'mdat' contains the actual data for the audio/video, possibly also subtitles
/* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */
// check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field while (($mdat_offset < (strlen($atom_data) - 8)) && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) && ($chapter_string_length < 1000) && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; $mdat_offset += (2 + $chapter_string_length); @$info['quicktime']['comments']['chapters'][] = $chapter_string;
// "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 $mdat_offset += 12; } }
case 'ID32': // ID3v2 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
$getid3_temp = new getID3(); $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); $getid3_id3v2 = new getid3_id3v2($getid3_temp); $getid3_id3v2->StartingOffset = $atom_structure['offset'] + 14; // framelength(4)+framename(4)+flags(4)+??(2) if ($atom_structure['valid'] = $getid3_id3v2->Analyze()) { $atom_structure['id3v2'] = $getid3_temp->info['id3v2']; } else { $this->warning('ID32 frame at offset '.$atom_structure['offset'].' did not parse'); } unset($getid3_temp, $getid3_id3v2); break;
case 'free': // FREE space atom case 'skip': // SKIP atom case 'wide': // 64-bit expansion placeholder atom // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
// When writing QuickTime files, it is sometimes necessary to update an atom's size. // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime // puts an 8-byte placeholder atom before any atoms it may have to update the size of. // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). break;
case 'nsav': // NoSAVe atom // http://developer.apple.com/technotes/tn/tn2038.html $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); break;
case 'ctyp': // Controller TYPe atom (seen on QTVR) // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt // some controller names are: // 0x00 + 'std' for linear movie // 'none' for no controls $atom_structure['ctyp'] = substr($atom_data, 0, 4); $info['quicktime']['controller'] = $atom_structure['ctyp']; switch ($atom_structure['ctyp']) { case 'qtvr': $info['video']['dataformat'] = 'quicktimevr'; break; } break;
case 'pano': // PANOrama track (seen on QTVR) $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); break;
case 'hint': // HINT track case 'hinf': // case 'hinv': // case 'hnti': // $info['quicktime']['hinting'] = true; break;
case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); } break;
// Observed-but-not-handled atom types are just listed here to prevent warnings being generated case 'FXTC': // Something to do with Adobe After Effects (?) case 'PrmA': case 'code': case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html // tapt seems to be used to compute the video size [https://www.getid3.org/phpBB3/viewtopic.php?t=838] // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html //$atom_structure['data'] = $atom_data; break;
case 'data': // metaDATA atom 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 // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data $atom_structure['language'] = substr($atom_data, 4 + 0, 2); $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); $atom_structure['data'] = substr($atom_data, 4 + 4); $atom_structure['key_name'] = (isset($info['quicktime']['temp_meta_key_names'][$metaDATAkey]) ? $info['quicktime']['temp_meta_key_names'][$metaDATAkey] : ''); $metaDATAkey++;
case 'keys': // KEYS that may be present in the metadata atom. // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. // 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". $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); $keys_atom_offset = 8; for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace
case 'uuid': // user-defined atom often seen containing XML data, also used for potentially many other purposes, only a few specifically handled by getID3 (e.g. 360fly spatial data) //Get the UUID ID in first 16 bytes $uuid_bytes_read = unpack('H8time_low/H4time_mid/H4time_hi/H4clock_seq_hi/H12clock_seq_low', substr($atom_data, 0, 16)); $atom_structure['uuid_field_id'] = implode('-', $uuid_bytes_read);
case '0537cdab-9d0c-4431-a72a-fa561f2a113e': // Exif - http://fileformats.archiveteam.org/wiki/Exif case '2c4c0100-8504-40b9-a03e-562148d6dfeb': // Photoshop Image Resources - http://fileformats.archiveteam.org/wiki/Photoshop_Image_Resources case '33c7a4d2-b81d-4723-a0ba-f1a3e097ad38': // IPTC-IIM - http://fileformats.archiveteam.org/wiki/IPTC-IIM case '8974dbce-7be7-4c51-84f9-7148f9882554': // PIFF Track Encryption Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format case '96a9f1f1-dc98-402d-a7ae-d68e34451809': // GeoJP2 World File Box - http://fileformats.archiveteam.org/wiki/GeoJP2 case 'a2394f52-5a9b-4f14-a244-6c427c648df4': // PIFF Sample Encryption Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format case 'b14bf8bd-083d-4b43-a5ae-8cd7d5a6ce03': // GeoJP2 GeoTIFF Box - http://fileformats.archiveteam.org/wiki/GeoJP2 case 'd08a4f18-10f3-4a82-b6c8-32d8aba183d3': // PIFF Protection System Specific Header Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format $this->warning('Unhandled (but recognized) "uuid" atom identified by "'.$atom_structure['uuid_field_id'].'" at offset '.$atom_structure['offset'].' ('.strlen($atom_data).' bytes)'); break;
case 'be7acfcb-97a9-42e8-9c71-999491e3afac': // XMP data (in XML format) $atom_structure['xml'] = substr($atom_data, 16, strlen($atom_data) - 16 - 8); // 16 bytes for UUID, 8 bytes header(?) break;
case 'efe1589a-bb77-49ef-8095-27759eb1dc6f': // 360fly data /* 360fly code in this block by Paul Lewis 2019-Oct-31 */ /* Sensor Timestamps need to be calculated using the recordings base time at ['quicktime']['moov']['subatoms'][0]['creation_time_unix']. */ $atom_structure['title'] = '360Fly Sensor Data';
//Get the UUID HEADER data $uuid_bytes_read = unpack('vheader_size/vheader_version/vtimescale/vhardware_version/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/', substr($atom_data, 16, 32)); $atom_structure['uuid_header'] = $uuid_bytes_read;
$start_byte = 48; $atom_SENSOR_data = substr($atom_data, $start_byte); $atom_structure['sensor_data']['data_type'] = array( 'fusion_count' => 0, // ID 250 'fusion_data' => array(), 'accel_count' => 0, // ID 1 'accel_data' => array(), 'gyro_count' => 0, // ID 2 'gyro_data' => array(), 'magno_count' => 0, // ID 3 'magno_data' => array(), 'gps_count' => 0, // ID 5 'gps_data' => array(), 'rotation_count' => 0, // ID 6 'rotation_data' => array(), 'unknown_count' => 0, // ID ?? 'unknown_data' => array(), 'debug_list' => '', // Used to debug variables stored as comma delimited strings ); $debug_structure = array(); $debug_structure['debug_items'] = array(); // Can start loop here to decode all sensor data in 32 Byte chunks: foreach (str_split($atom_SENSOR_data, 32) as $sensor_key => $sensor_data) { // This gets me a data_type code to work out what data is in the next 31 bytes. $sensor_data_type = substr($sensor_data, 0, 1); $sensor_data_content = substr($sensor_data, 1); $uuid_bytes_read = unpack('C*', $sensor_data_type); $sensor_data_array = array(); switch ($uuid_bytes_read[1]) { case 250: $atom_structure['sensor_data']['data_type']['fusion_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; $sensor_data_array['roll'] = $uuid_bytes_read['roll']; array_push($atom_structure['sensor_data']['data_type']['fusion_data'], $sensor_data_array); break; case 1: $atom_structure['sensor_data']['data_type']['accel_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; $sensor_data_array['roll'] = $uuid_bytes_read['roll']; array_push($atom_structure['sensor_data']['data_type']['accel_data'], $sensor_data_array); break; case 2: $atom_structure['sensor_data']['data_type']['gyro_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; $sensor_data_array['roll'] = $uuid_bytes_read['roll']; array_push($atom_structure['sensor_data']['data_type']['gyro_data'], $sensor_data_array); break; case 3: $atom_structure['sensor_data']['data_type']['magno_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Gmagx/Gmagy/Gmagz/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['magx'] = $uuid_bytes_read['magx']; $sensor_data_array['magy'] = $uuid_bytes_read['magy']; $sensor_data_array['magz'] = $uuid_bytes_read['magz']; array_push($atom_structure['sensor_data']['data_type']['magno_data'], $sensor_data_array); break; case 5: $atom_structure['sensor_data']['data_type']['gps_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Glat/Glon/Galt/Gspeed/nbearing/nacc/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['lat'] = $uuid_bytes_read['lat']; $sensor_data_array['lon'] = $uuid_bytes_read['lon']; $sensor_data_array['alt'] = $uuid_bytes_read['alt']; $sensor_data_array['speed'] = $uuid_bytes_read['speed']; $sensor_data_array['bearing'] = $uuid_bytes_read['bearing']; $sensor_data_array['acc'] = $uuid_bytes_read['acc']; array_push($atom_structure['sensor_data']['data_type']['gps_data'], $sensor_data_array); //array_push($debug_structure['debug_items'], $uuid_bytes_read['timestamp']); break; case 6: $atom_structure['sensor_data']['data_type']['rotation_count']++; $uuid_bytes_read = unpack('cmode/Jtimestamp/Grotx/Groty/Grotz/x*', $sensor_data_content); $sensor_data_array['mode'] = $uuid_bytes_read['mode']; $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; $sensor_data_array['rotx'] = $uuid_bytes_read['rotx']; $sensor_data_array['roty'] = $uuid_bytes_read['roty']; $sensor_data_array['rotz'] = $uuid_bytes_read['rotz']; array_push($atom_structure['sensor_data']['data_type']['rotation_data'], $sensor_data_array); break; default: $atom_structure['sensor_data']['data_type']['unknown_count']++; break; } } //if (isset($debug_structure['debug_items']) && count($debug_structure['debug_items']) > 0) { // $atom_structure['sensor_data']['data_type']['debug_list'] = implode(',', $debug_structure['debug_items']); //} else { $atom_structure['sensor_data']['data_type']['debug_list'] = 'No debug items in list!'; //} break;
default: $this->warning('Unhandled "uuid" atom identified by "'.$atom_structure['uuid_field_id'].'" at offset '.$atom_structure['offset'].' ('.strlen($atom_data).' bytes)'); } break;
case 'gps ': // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 // The 'gps ' contains simple look up table made up of 8byte rows, that point to the 'free' atoms that contains the actual GPS data. // The first row is version/metadata/notsure, I skip that. // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file.
$GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size if (strlen($atom_data) > 0) { if ((strlen($atom_data) % $GPS_rowsize) == 0) { $atom_structure['gps_toc'] = array(); foreach (str_split($atom_data, $GPS_rowsize) as $counter => $datapair) { $atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data, $counter * $GPS_rowsize, $GPS_rowsize)); }
$atom_structure['gps_entries'] = array(); $previous_offset = $this->ftell(); foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) { if ($key == 0) { // "The first row is version/metadata/notsure, I skip that." continue; } $this->fseek($gps_pointer['offset']); $GPS_free_data = $this->fread($gps_pointer['size']);
/* // 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
// https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 // The structure of the GPS data atom (the 'free' atoms mentioned above) is following: // hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from('<IIIIIIssssfff',data, 48) // For those unfamiliar with python struct: // I = int // s = is string (size 1, in this case) // f = float
} else { $this->warning('Unhandled GPS format in "free" atom at offset '.$gps_pointer['offset']); } } $this->fseek($previous_offset);
} else { $this->warning('QuickTime atom "'.$atomname.'" is not mod-8 bytes long ('.$atomsize.' bytes) at offset '.$baseoffset); } } else { $this->warning('QuickTime atom "'.$atomname.'" is zero bytes long at offset '.$baseoffset); } break;
case 'chpl': // CHaPter List // https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf $chpl_version = getid3_lib::BigEndian2Int(substr($atom_data, 4, 1)); // Expected to be 0 $chpl_flags = getid3_lib::BigEndian2Int(substr($atom_data, 5, 3)); // Reserved, set to 0 $chpl_count = getid3_lib::BigEndian2Int(substr($atom_data, 8, 1)); $chpl_offset = 9; for ($i = 0; $i < $chpl_count; $i++) { if (($chpl_offset + 9) >= strlen($atom_data)) { $this->warning('QuickTime chapter '.$i.' extends beyond end of "chpl" atom'); break; } $info['quicktime']['chapters'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 8)) / 10000000; // timestamps are stored as 100-nanosecond units $chpl_offset += 8; $chpl_title_size = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 1)); $chpl_offset += 1; $info['quicktime']['chapters'][$i]['title'] = substr($atom_data, $chpl_offset, $chpl_title_size); $chpl_offset += $chpl_title_size; } break;
case 'FIRM': // FIRMware version(?), seen on GoPro Hero4 $info['quicktime']['camera']['firmware'] = $atom_data; break;
case 'CAME': // FIRMware version(?), seen on GoPro Hero4 $info['quicktime']['camera']['serial_hash'] = unpack('H*', $atom_data); break;
case 'dscp': case 'rcif': // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 if (substr($atom_data, 0, 7) == "\x00\x00\x00\x00\x55\xC4".'{') { if ($json_decoded = @json_decode(rtrim(substr($atom_data, 6), "\x00"), true)) { $info['quicktime']['camera'][$atomname] = $json_decoded; if (($atomname == 'rcif') && isset($info['quicktime']['camera']['rcif']['wxcamera']['rotate'])) { $info['video']['rotate'] = $info['quicktime']['video']['rotate'] = $info['quicktime']['camera']['rcif']['wxcamera']['rotate']; } } else { $this->warning('Failed to JSON decode atom "'.$atomname.'"'); $atom_structure['data'] = $atom_data; } unset($json_decoded); } else { $this->warning('Expecting 55 C4 7B at start of atom "'.$atomname.'", found '.getid3_lib::PrintHexBytes(substr($atom_data, 4, 3)).' instead'); $atom_structure['data'] = $atom_data; } break;
case 'frea': // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea // may contain "scra" (PreviewImage) and/or "thma" (ThumbnailImage) $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); break; case 'tima': // subatom to "frea" // no idea what this does, the one sample file I've seen has a value of 0x00000027 $atom_structure['data'] = $atom_data; break; case 'ver ': // subatom to "frea" // some kind of version number, the one sample file I've seen has a value of "3.00.073" $atom_structure['data'] = $atom_data; break; case 'thma': // subatom to "frea" -- "ThumbnailImage" // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea if (strlen($atom_data) > 0) { $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg', 'description'=>'ThumbnailImage'); } break; case 'scra': // subatom to "frea" -- "PreviewImage" // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea // but the only sample file I've seen has no useful data here if (strlen($atom_data) > 0) { $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg', 'description'=>'PreviewImage'); } break;
case 'cdsc': // timed metadata reference // A QuickTime movie can contain none, one, or several timed metadata tracks. Timed metadata tracks can refer to multiple tracks. // Metadata tracks are linked to the tracks they describe using a track-reference of type 'cdsc'. The metadata track holds the 'cdsc' track reference. $atom_structure['track_number'] = getid3_lib::BigEndian2Int($atom_data); break;
// AVIF-related - https://docs.rs/avif-parse/0.13.2/src/avif_parse/boxes.rs.html case 'pitm': // Primary ITeM case 'iloc': // Item LOCation case 'iinf': // Item INFo case 'iref': // Image REFerence case 'iprp': // Image PRoPerties $this->error('AVIF files not currently supported'); $atom_structure['data'] = $atom_data; break;
case 'tfdt': // Track Fragment base media Decode Time box case 'tfhd': // Track Fragment HeaDer box case 'mfhd': // Movie Fragment HeaDer box case 'trun': // Track fragment RUN box $this->error('fragmented mp4 files not currently supported'); $atom_structure['data'] = $atom_data; break;
case 'mvex': // MoVie EXtends box case 'pssh': // Protection System Specific Header box case 'sidx': // Segment InDeX box default: $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).'), '.$atomsize.' bytes at offset '.$baseoffset); $atom_structure['data'] = $atom_data; break; } } array_pop($atomHierarchy); return $atom_structure; }
/** * @param string $atom_data * @param int $baseoffset * @param array $atomHierarchy * @param bool $ParseAllPossibleAtoms * * @return array|false */ public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { $atom_structure = array(); $subatomoffset = 0; $subatomcounter = 0; if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { return false; } while ($subatomoffset < strlen($atom_data)) { $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); $subatomname = substr($atom_data, $subatomoffset + 4, 4); $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); if ($subatomsize == 0) { // Furthermore, for historical reasons the list of atoms is optionally // terminated by a 32-bit integer set to 0. If you are writing a program // to read user data atoms, you should allow for the terminating 0. if (strlen($atom_data) > 12) { $subatomoffset += 4; continue; } break; } if (strlen($subatomdata) < ($subatomsize - 8)) { // we don't have enough data to decode the subatom. // this may be because we are refusing to parse large subatoms, or it may be because this atom had its size set too large // so we passed in the start of a following atom incorrectly? break; } $atom_structure[$subatomcounter++] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); $subatomoffset += $subatomsize; }
if (empty($atom_structure)) { return false; }
return $atom_structure; }
/** * @param string $data * @param int $offset * * @return int */ public function quicktime_read_mp4_descr_length($data, &$offset) { // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html $num_bytes = 0; $length = 0; do { $b = ord(substr($data, $offset++, 1)); $length = ($length << 7) | ($b & 0x7F); } while (($b & 0x80) && ($num_bytes++ < 4)); return $length; }
/** * @param int $languageid * * @return string */ public function QuicktimeLanguageLookup($languageid) { // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353 static $QuicktimeLanguageLookup = array(); if (empty($QuicktimeLanguageLookup)) { $QuicktimeLanguageLookup[0] = 'English'; $QuicktimeLanguageLookup[1] = 'French'; $QuicktimeLanguageLookup[2] = 'German'; $QuicktimeLanguageLookup[3] = 'Italian'; $QuicktimeLanguageLookup[4] = 'Dutch'; $QuicktimeLanguageLookup[5] = 'Swedish'; $QuicktimeLanguageLookup[6] = 'Spanish'; $QuicktimeLanguageLookup[7] = 'Danish'; $QuicktimeLanguageLookup[8] = 'Portuguese'; $QuicktimeLanguageLookup[9] = 'Norwegian'; $QuicktimeLanguageLookup[10] = 'Hebrew'; $QuicktimeLanguageLookup[11] = 'Japanese'; $QuicktimeLanguageLookup[12] = 'Arabic'; $QuicktimeLanguageLookup[13] = 'Finnish'; $QuicktimeLanguageLookup[14] = 'Greek'; $QuicktimeLanguageLookup[15] = 'Icelandic'; $QuicktimeLanguageLookup[16] = 'Maltese'; $QuicktimeLanguageLookup[17] = 'Turkish'; $QuicktimeLanguageLookup[18] = 'Croatian'; $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; $QuicktimeLanguageLookup[20] = 'Urdu'; $QuicktimeLanguageLookup[21] = 'Hindi'; $QuicktimeLanguageLookup[22] = 'Thai'; $QuicktimeLanguageLookup[23] = 'Korean'; $QuicktimeLanguageLookup[24] = 'Lithuanian'; $QuicktimeLanguageLookup[25] = 'Polish'; $QuicktimeLanguageLookup[26] = 'Hungarian'; $QuicktimeLanguageLookup[27] = 'Estonian'; $QuicktimeLanguageLookup[28] = 'Lettish'; $QuicktimeLanguageLookup[28] = 'Latvian'; $QuicktimeLanguageLookup[29] = 'Saamisk'; $QuicktimeLanguageLookup[29] = 'Lappish'; $QuicktimeLanguageLookup[30] = 'Faeroese'; $QuicktimeLanguageLookup[31] = 'Farsi'; $QuicktimeLanguageLookup[31] = 'Persian'; $QuicktimeLanguageLookup[32] = 'Russian'; $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; $QuicktimeLanguageLookup[34] = 'Flemish'; $QuicktimeLanguageLookup[35] = 'Irish'; $QuicktimeLanguageLookup[36] = 'Albanian'; $QuicktimeLanguageLookup[37] = 'Romanian'; $QuicktimeLanguageLookup[38] = 'Czech'; $QuicktimeLanguageLookup[39] = 'Slovak'; $QuicktimeLanguageLookup[40] = 'Slovenian'; $QuicktimeLanguageLookup[41] = 'Yiddish'; $QuicktimeLanguageLookup[42] = 'Serbian'; $QuicktimeLanguageLookup[43] = 'Macedonian'; $QuicktimeLanguageLookup[44] = 'Bulgarian'; $QuicktimeLanguageLookup[45] = 'Ukrainian'; $QuicktimeLanguageLookup[46] = 'Byelorussian'; $QuicktimeLanguageLookup[47] = 'Uzbek'; $QuicktimeLanguageLookup[48] = 'Kazakh'; $QuicktimeLanguageLookup[49] = 'Azerbaijani'; $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; $QuicktimeLanguageLookup[51] = 'Armenian'; $QuicktimeLanguageLookup[52] = 'Georgian'; $QuicktimeLanguageLookup[53] = 'Moldavian'; $QuicktimeLanguageLookup[54] = 'Kirghiz'; $QuicktimeLanguageLookup[55] = 'Tajiki'; $QuicktimeLanguageLookup[56] = 'Turkmen'; $QuicktimeLanguageLookup[57] = 'Mongolian'; $QuicktimeLanguageLookup[58] = 'MongolianCyr'; $QuicktimeLanguageLookup[59] = 'Pashto'; $QuicktimeLanguageLookup[60] = 'Kurdish'; $QuicktimeLanguageLookup[61] = 'Kashmiri'; $QuicktimeLanguageLookup[62] = 'Sindhi'; $QuicktimeLanguageLookup[63] = 'Tibetan'; $QuicktimeLanguageLookup[64] = 'Nepali'; $QuicktimeLanguageLookup[65] = 'Sanskrit'; $QuicktimeLanguageLookup[66] = 'Marathi'; $QuicktimeLanguageLookup[67] = 'Bengali'; $QuicktimeLanguageLookup[68] = 'Assamese'; $QuicktimeLanguageLookup[69] = 'Gujarati'; $QuicktimeLanguageLookup[70] = 'Punjabi'; $QuicktimeLanguageLookup[71] = 'Oriya'; $QuicktimeLanguageLookup[72] = 'Malayalam'; $QuicktimeLanguageLookup[73] = 'Kannada'; $QuicktimeLanguageLookup[74] = 'Tamil'; $QuicktimeLanguageLookup[75] = 'Telugu'; $QuicktimeLanguageLookup[76] = 'Sinhalese'; $QuicktimeLanguageLookup[77] = 'Burmese'; $QuicktimeLanguageLookup[78] = 'Khmer'; $QuicktimeLanguageLookup[79] = 'Lao'; $QuicktimeLanguageLookup[80] = 'Vietnamese'; $QuicktimeLanguageLookup[81] = 'Indonesian'; $QuicktimeLanguageLookup[82] = 'Tagalog'; $QuicktimeLanguageLookup[83] = 'MalayRoman'; $QuicktimeLanguageLookup[84] = 'MalayArabic'; $QuicktimeLanguageLookup[85] = 'Amharic'; $QuicktimeLanguageLookup[86] = 'Tigrinya'; $QuicktimeLanguageLookup[87] = 'Galla'; $QuicktimeLanguageLookup[87] = 'Oromo'; $QuicktimeLanguageLookup[88] = 'Somali'; $QuicktimeLanguageLookup[89] = 'Swahili'; $QuicktimeLanguageLookup[90] = 'Ruanda'; $QuicktimeLanguageLookup[91] = 'Rundi'; $QuicktimeLanguageLookup[92] = 'Chewa'; $QuicktimeLanguageLookup[93] = 'Malagasy'; $QuicktimeLanguageLookup[94] = 'Esperanto'; $QuicktimeLanguageLookup[128] = 'Welsh'; $QuicktimeLanguageLookup[129] = 'Basque'; $QuicktimeLanguageLookup[130] = 'Catalan'; $QuicktimeLanguageLookup[131] = 'Latin'; $QuicktimeLanguageLookup[132] = 'Quechua'; $QuicktimeLanguageLookup[133] = 'Guarani'; $QuicktimeLanguageLookup[134] = 'Aymara'; $QuicktimeLanguageLookup[135] = 'Tatar'; $QuicktimeLanguageLookup[136] = 'Uighur'; $QuicktimeLanguageLookup[137] = 'Dzongkha'; $QuicktimeLanguageLookup[138] = 'JavaneseRom'; $QuicktimeLanguageLookup[32767] = 'Unspecified'; } if (($languageid > 138) && ($languageid < 32767)) { /* ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field. The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero.
One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character, and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least significant bits and the most significant bit set to zero. */ $iso_language_id = ''; $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60); $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60); $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60); $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id); } return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'); }
// boxnames: /* $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id';
// http://age.hobba.nl/audio/tag_frame_reference.html $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 */ } $info = &$this->getid3->info; $comment_key = ''; if ($boxname && ($boxname != $keyname)) { $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname); } elseif (isset($handyatomtranslatorarray[$keyname])) { $comment_key = $handyatomtranslatorarray[$keyname]; } if ($comment_key) { if ($comment_key == 'picture') { // already copied directly into [comments][picture] elsewhere, do not re-copy here return true; } $gooddata = array($data); if ($comment_key == 'genre') { // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" $gooddata = explode(';', $data); } foreach ($gooddata as $data) { if (!empty($info['quicktime']['comments'][$comment_key]) && in_array($data, $info['quicktime']['comments'][$comment_key], true)) { // avoid duplicate copies of identical data continue; } $info['quicktime']['comments'][$comment_key][] = $data; } } return true; }
/** * @param string $lstring * @param int $count * * @return string */ public function LociString($lstring, &$count) { // Loci strings are UTF-8 or UTF-16 and null (x00/x0000) terminated. UTF-16 has a BOM // Also need to return the number of bytes the string occupied so additional fields can be extracted $len = strlen($lstring); if ($len == 0) { $count = 0; return ''; } if ($lstring[0] == "\x00") { $count = 1; return ''; } // check for BOM if (($len > 2) && ((($lstring[0] == "\xFE") && ($lstring[1] == "\xFF")) || (($lstring[0] == "\xFF") && ($lstring[1] == "\xFE")))) { // UTF-16 if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { $count = strlen($lmatches[1]) * 2 + 2; //account for 2 byte characters and trailing \x0000 return getid3_lib::iconv_fallback_utf16_utf8($lmatches[1]); } else { return ''; } } // UTF-8 if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { $count = strlen($lmatches[1]) + 1; //account for trailing \x00 return $lmatches[1]; } return ''; }
/** * @param string $nullterminatedstring * * @return string */ public function NoNullString($nullterminatedstring) { // remove the single null terminator on null terminated strings if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); } return $nullterminatedstring; }
/** * @param string $pascalstring * * @return string */ public function Pascal2String($pascalstring) { // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string return substr($pascalstring, 1); }
/** * @param string $pascalstring * * @return string */ public function MaybePascal2String($pascalstring) { // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string // Check if string actually is in this format or written incorrectly, straight string, or null-terminated string if (ord(substr($pascalstring, 0, 1)) == (strlen($pascalstring) - 1)) { return substr($pascalstring, 1); } elseif (substr($pascalstring, -1, 1) == "\x00") { // appears to be null-terminated instead of Pascal-style return substr($pascalstring, 0, -1); } return $pascalstring; }