[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ID3/ -> module.audio-video.quicktime.php (source)

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


Generated : Mon Nov 23 08:20:01 2026 Cross-referenced by PHPXref