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


Generated : Thu Apr 25 08:20:02 2024 Cross-referenced by PHPXref