[ Index ]

PHP Cross Reference of WordPress

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


Generated: Mon Jan 24 01:00:08 2022 Cross-referenced by PHPXref 0.7.1