home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / ID3 / module.audio-video.quicktime.php < prev    next >
Encoding:
PHP Script  |  2017-07-31  |  137.5 KB  |  2,667 lines

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