"Fossies" - the Fresh Open Source Software Archive

Member "wordpress/wp-includes/ID3/module.audio-video.quicktime.php" (2 Jul 2020, 164611 Bytes) of package /linux/www/wordpress-5.7-RC1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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