private function QuicktimeParseAtom($atom_name, $atom_size, $atom_data, $base_offset, &$atom_hierarchy)
 {
     // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
     $getid3 = $this->getid3;
     $info =& $getid3->info;
     $info_quicktime =& $info['quicktime'];
     array_push($atom_hierarchy, $atom_name);
     $atom_structure['hierarchy'] = implode(' ', $atom_hierarchy);
     $atom_structure['name'] = $atom_name;
     $atom_structure['size'] = $atom_size;
     $atom_structure['offset'] = $base_offset;
     switch ($atom_name) {
         case 'moov':
             // MOVie container atom
         // MOVie container atom
         case 'trak':
             // TRAcK container atom
         // TRAcK container atom
         case 'clip':
             // CLIPping container atom
         // CLIPping container atom
         case 'matt':
             // track MATTe container atom
         // track MATTe container atom
         case 'edts':
             // EDiTS container atom
         // EDiTS container atom
         case 'tref':
             // Track REFerence container atom
         // Track REFerence container atom
         case 'mdia':
             // MeDIA container atom
         // MeDIA container atom
         case 'minf':
             // Media INFormation container atom
         // Media INFormation container atom
         case 'dinf':
             // Data INFormation container atom
         // Data INFormation container atom
         case 'udta':
             // User DaTA container atom
         // User DaTA container atom
         case 'stbl':
             // Sample TaBLe container atom
         // Sample TaBLe container atom
         case 'cmov':
             // Compressed MOVie container atom
         // Compressed MOVie container atom
         case 'rmra':
             // Reference Movie Record Atom
         // Reference Movie Record Atom
         case 'rmda':
             // Reference Movie Descriptor Atom
         // Reference Movie Descriptor Atom
         case 'gmhd':
             // Generic Media info HeaDer atom (seen on QTVR)
             $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $base_offset + 8, $atom_hierarchy);
             break;
         case '©cpy':
         case '©day':
         case '©dir':
         case '©ed1':
         case '©ed2':
         case '©ed3':
         case '©ed4':
         case '©ed5':
         case '©ed6':
         case '©ed7':
         case '©ed8':
         case '©ed9':
         case '©fmt':
         case '©inf':
         case '©prd':
         case '©prf':
         case '©req':
         case '©src':
         case '©wrt':
         case '©nam':
         case '©cmt':
         case '©wrn':
         case '©hst':
         case '©mak':
         case '©mod':
         case '©PRD':
         case '©swr':
         case '©aut':
         case '©ART':
         case '©trk':
         case '©alb':
         case '©com':
         case '©gen':
         case '©ope':
         case '©url':
         case '©enc':
             $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
             $atom_structure['data'] = substr($atom_data, 4);
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             $this->CopyToAppropriateCommentsSection($atom_name, $atom_structure['data']);
             break;
         case 'play':
             // auto-PLAY atom
             $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
             $info_quicktime['autoplay'] = $atom_structure['autoplay'];
             break;
         case 'WLOC':
             // Window LOCation atom
             $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
             break;
         case 'LOOP':
             // LOOPing atom
         // LOOPing atom
         case 'SelO':
             // play SELection Only atom
         // play SELection Only atom
         case 'AllF':
             // play ALL Frames atom
             $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
             break;
         case 'name':
             //
         //
         case 'MCPS':
             // Media Cleaner PRo
         // Media Cleaner PRo
         case '@PRM':
             // adobe PReMiere version
         // adobe PReMiere version
         case '@PRQ':
             // adobe PRemiere Quicktime version
             $atom_structure['data'] = $atom_data;
             break;
         case 'cmvd':
             // Compressed MooV Data atom
             // Code by ubergeekØubergeek*tv based on information from
             // http://developer.apple.com/quicktime/icefloe/dispatch012.html
             $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             $compressed_file_data = substr($atom_data, 4);
             if (!function_exists('gzuncompress')) {
                 $getid3->warning('PHP does not have zlib support - cannot decompress MOV atom at offset ' . $atom_structure['offset']);
             } elseif ($uncompressed_header = @gzuncompress($compressed_file_data)) {
                 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($uncompressed_header, 0, $atom_hierarchy);
             } else {
                 $getid3->warning('Error decompressing compressed MOV atom at offset ' . $atom_structure['offset']);
             }
             break;
         case 'dcom':
             // Data COMpression atom
             $atom_structure['compression_id'] = $atom_data;
             $atom_structure['compression_text'] = getid3_quicktime::QuicktimeDCOMLookup($atom_data);
             break;
         case 'rdrf':
             // Reference movie Data ReFerence atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'reference_type_name' => -4, 'reference_length' => 4));
             $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             switch ($atom_structure['reference_type_name']) {
                 case 'url ':
                     $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
                     break;
                 case 'alis':
                     $atom_structure['file_alias'] = substr($atom_data, 12);
                     break;
                 case 'rsrc':
                     $atom_structure['resource_alias'] = substr($atom_data, 12);
                     break;
                 default:
                     $atom_structure['data'] = substr($atom_data, 12);
                     break;
             }
             break;
         case 'rmqu':
             // Reference Movie QUality atom
             $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
             break;
         case 'rmcs':
             // Reference Movie Cpu Speed atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'cpu_speed_rating' => 2));
             break;
         case 'rmvc':
             // Reference Movie Version Check atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'gestalt_selector' => -4, 'gestalt_value_mask' => 4, 'gestalt_value' => 4, 'gestalt_check_type' => 2));
             break;
         case 'rmcd':
             // Reference Movie Component check atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'component_type' => -4, 'component_subtype' => -4, 'component_manufacturer' => -4, 'component_flags_raw' => 4, 'component_flags_mask' => 4, 'component_min_version' => 4));
             break;
         case 'rmdr':
             // Reference Movie Data Rate atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'data_rate' => 4));
             $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
             break;
         case 'rmla':
             // Reference Movie Language Atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'language_id' => 2));
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             break;
         case 'rmla':
             // Reference Movie Language Atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'track_id' => 2));
             break;
         case 'ptv ':
             // Print To Video - defines a movie's full screen mode
             // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('display_size_raw' => 2, 'reserved_1' => 2, 'reserved_2' => 2, 'slide_show_flag' => 1, 'play_on_open_flag' => 1));
             $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
             $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
             $ptv_lookup[0] = 'normal';
             $ptv_lookup[1] = 'double';
             $ptv_lookup[2] = 'half';
             $ptv_lookup[3] = 'full';
             $ptv_lookup[4] = 'current';
             if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
                 $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
             } else {
                 $getid3->warning('unknown "ptv " display constant (' . $atom_structure['display_size_raw'] . ')');
             }
             break;
         case 'stsd':
             // Sample Table Sample Description atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $stsd_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_data, $stsd_entries_data_offset, array('size' => 4, 'data_format' => -4, 'reserved' => 6, 'reference_index' => 2));
                 $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, 16 + $stsd_entries_data_offset, $atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
                 $stsd_entries_data_offset += 16 + ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 0, array('encoder_version' => 2, 'encoder_revision' => 2, 'encoder_vendor' => -4));
                 switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
                     case "":
                         // audio atom
                         getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 8, array('audio_channels' => 2, 'audio_bit_depth' => 2, 'audio_compression_id' => 2, 'audio_packet_size' => 2));
                         $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
                         switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                             case 'mp4v':
                                 $info['fileformat'] = 'mp4';
                                 throw new getid3_exception('This version of getID3() does not fully support MPEG-4 audio/video streams');
                             case 'qtvr':
                                 $info['video']['dataformat'] = 'quicktimevr';
                                 break;
                             case 'mp4a':
                             default:
                                 $info_quicktime['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
                                 $info_quicktime['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
                                 $info_quicktime['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
                                 $info_quicktime['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
                                 $info['audio']['codec'] = $info_quicktime['audio']['codec'];
                                 $info['audio']['sample_rate'] = $info_quicktime['audio']['sample_rate'];
                                 $info['audio']['channels'] = $info_quicktime['audio']['channels'];
                                 $info['audio']['bits_per_sample'] = $info_quicktime['audio']['bit_depth'];
                                 switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                                     case 'raw ':
                                         // PCM
                                     // PCM
                                     case 'alac':
                                         // Apple Lossless Audio Codec
                                         $info['audio']['lossless'] = true;
                                         break;
                                     default:
                                         $info['audio']['lossless'] = false;
                                         break;
                                 }
                                 break;
                         }
                         break;
                     default:
                         switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                             case 'mp4s':
                                 $info['fileformat'] = 'mp4';
                                 break;
                             default:
                                 // video atom
                                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 8, array('video_temporal_quality' => 4, 'video_spatial_quality' => 4, 'video_frame_width' => 2, 'video_frame_height' => 2));
                                 $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
                                 $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
                                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 28, array('video_data_size' => 4, 'video_frame_count' => 2, 'video_encoder_name_len' => 1));
                                 $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']);
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
                                 $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32 ? 'grayscale' : 'color';
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
                                 if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
                                     $info_quicktime['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
                                     $info_quicktime['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
                                     $info_quicktime['video']['codec'] = $atom_structure['sample_description_table'][$i]['video_encoder_name'];
                                     $info_quicktime['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
                                     $info_quicktime['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
                                     $info['video']['codec'] = $info_quicktime['video']['codec'];
                                     $info['video']['bits_per_sample'] = $info_quicktime['video']['color_depth'];
                                 }
                                 $info['video']['lossless'] = false;
                                 $info['video']['pixel_aspect_ratio'] = (double) 1;
                                 break;
                         }
                         break;
                 }
                 switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
                     case 'mp4a':
                         $info['audio']['dataformat'] = $info_quicktime['audio']['codec'] = 'mp4';
                         break;
                     case '3ivx':
                     case '3iv1':
                     case '3iv2':
                         $info['video']['dataformat'] = '3ivx';
                         break;
                     case 'xvid':
                         $info['video']['dataformat'] = 'xvid';
                         break;
                     case 'mp4v':
                         $info['video']['dataformat'] = 'mpeg4';
                         break;
                     case 'divx':
                     case 'div1':
                     case 'div2':
                     case 'div3':
                     case 'div4':
                     case 'div5':
                     case 'div6':
                         //$TDIVXileInfo['video']['dataformat'] = 'divx';
                         break;
                     default:
                         // do nothing
                         break;
                 }
                 unset($atom_structure['sample_description_table'][$i]['data']);
             }
             break;
         case 'stts':
             // Sample Table Time-to-Sample atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $stts_entries_data_offset = 8;
             $frame_rate_calculator_array = array();
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $stts_entries_data_offset, 4));
                 $stts_entries_data_offset += 4;
                 $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $stts_entries_data_offset, 4));
                 $stts_entries_data_offset += 4;
                 if (!empty($info_quicktime['time_scale']) && @$atoms_structure['time_to_sample_table'][$i]['sample_duration'] > 0) {
                     $stts_new_framerate = $info_quicktime['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
                     if ($stts_new_framerate <= 60) {
                         // some atoms have durations of "1" giving a very large framerate, which probably is not right
                         $info['video']['frame_rate'] = max(@$info['video']['frame_rate'], $stts_new_framerate);
                     }
                 }
                 //@$frame_rate_calculator_array[($info_quicktime['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
             }
             /*
             $stts_frames_total  = 0;
             $stts_seconds_total = 0;
             foreach ($frame_rate_calculator_array as $frames_per_second => $frame_count) {
                 if (($frames_per_second > 60) || ($frames_per_second < 1)) {
                     // not video FPS information, probably audio information
                     $stts_frames_total  = 0;
                     $stts_seconds_total = 0;
                     break;
                 }
                 $stts_frames_total  += $frame_count;
                 $stts_seconds_total += $frame_count / $frames_per_second;
             }
             if (($stts_frames_total > 0) && ($stts_seconds_total > 0)) {
                 if (($stts_frames_total / $stts_seconds_total) > @$info['video']['frame_rate']) {
                     $info['video']['frame_rate'] = $stts_frames_total / $stts_seconds_total;
                 }
             }
             */
             break;
         case 'stss':
             // Sample Table Sync Sample (key frames) atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stss_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stss_entries_data_offset, 4));
                 $stss_entries_data_offset += 4;
             }
             */
             break;
         case 'stsc':
             // Sample Table Sample-to-Chunk atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stsc_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['sample_to_chunk_table'][$i]['first_chunk']        = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
                 $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk']  = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
                 $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
             }
             */
             break;
         case 'stsz':
             // Sample Table SiZe atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['sample_size']    = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
             $stsz_entries_data_offset = 12;
             if ($atom_structure['sample_size'] == 0) {
                 for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                     $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stsz_entries_data_offset, 4));
                     $stsz_entries_data_offset += 4;
                 }
             }
             */
             break;
         case 'stco':
             // Sample Table Chunk Offset atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stco_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stco_entries_data_offset, 4));
                 $stco_entries_data_offset += 4;
             }
             */
             break;
         case 'dref':
             // Data REFerence atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $dref_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['data_references'][$i], $atom_data, $dref_data_offset, array('size' => 4, 'type' => -4, 'version' => 1, 'flags_raw' => 3));
                 $dref_data_offset += 12;
                 $atom_structure['data_references'][$i]['data'] = substr($atom_data, $dref_data_offset, $atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
                 $dref_data_offset += $atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3;
                 $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x1);
             }
             break;
         case 'gmin':
             // base Media INformation atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'graphics_mode' => 2, 'opcolor_red' => 2, 'opcolor_green' => 2, 'opcolor_blue' => 2, 'balance' => 2, 'reserved' => 2));
             break;
         case 'smhd':
             // Sound Media information HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'balance' => 2, 'reserved' => 2));
             break;
         case 'vmhd':
             // Video Media information HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'graphics_mode' => 2, 'opcolor_red' => 2, 'opcolor_green' => 2, 'opcolor_blue' => 2));
             $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             break;
         case 'hdlr':
             // HanDLeR reference atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'component_type' => -4, 'component_subtype' => -4, 'component_manufacturer' => -4, 'component_flags_raw' => 4, 'component_flags_mask' => 4));
             $atom_structure['component_name'] = substr(substr($atom_data, 24), 1);
             /// Pascal2String
             if ($atom_structure['component_subtype'] == 'STpn' && $atom_structure['component_manufacturer'] == 'zzzz') {
                 $info['video']['dataformat'] = 'quicktimevr';
             }
             break;
         case 'mdhd':
             // MeDia HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'time_scale' => 4, 'duration' => 4, 'language_id' => 2, 'quality' => 2));
             if ($atom_structure['time_scale'] == 0) {
                 throw new getid3_exception('Corrupt Quicktime file: mdhd.time_scale == zero');
             }
             $info_quicktime['time_scale'] = max(@$info['quicktime']['time_scale'], $atom_structure['time_scale']);
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             break;
         case 'pnot':
             // Preview atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('modification_date' => 4, 'version_number' => 2, 'atom_type' => -4, 'atom_index' => 2));
             $atom_structure['modification_date_unix'] = (int) ($atom_structure['modification_date'] - 2082844800);
             // DateMac2Unix()
             break;
         case 'crgn':
             // Clipping ReGioN atom
             $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             // The Region size, Region boundary box,
             $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8));
             // and Clipping region data fields
             $atom_structure['clipping_data'] = substr($atom_data, 10);
             // constitute a QuickDraw region.
             break;
         case 'load':
             // track LOAD settings atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('preload_start_time' => 4, 'preload_duration' => 4, 'preload_flags_raw' => 4, 'default_hints_raw' => 4));
             $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x20);
             $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x100);
             break;
         case 'tmcd':
             // TiMe CoDe atom
         // TiMe CoDe atom
         case 'chap':
             // CHAPter list atom
         // CHAPter list atom
         case 'sync':
             // SYNChronization atom
         // SYNChronization atom
         case 'scpt':
             // tranSCriPT atom
         // tranSCriPT atom
         case 'ssrc':
             // non-primary SouRCe atom
             for ($i = 0; $i < strlen($atom_data) % 4; $i++) {
                 $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4));
             }
             break;
         case 'elst':
             // Edit LiST atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $i * 12 + 0, 4));
                 $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $i * 12 + 4, 4));
                 $atom_structure['edit_list'][$i]['media_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 8 + $i * 12 + 8, 4));
             }
             break;
         case 'kmat':
             // compressed MATte atom
             $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
             $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
             // hardcoded: 0x0000
             $atom_structure['matte_data_raw'] = substr($atom_data, 4);
             break;
         case 'ctab':
             // Color TABle atom
             $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             // hardcoded: 0x00000000
             $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
             // hardcoded: 0x8000
             $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
             for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
                 $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 0, 2));
                 $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 2, 2));
                 $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 4, 2));
                 $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 6, 2));
             }
             break;
         case 'mvhd':
             // MoVie HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'time_scale' => 4, 'duration' => 4));
             $atom_structure['preferred_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 20, 4));
             $atom_structure['preferred_volume'] = getid3_quicktime::FixedPoint8_8(substr($atom_data, 24, 2));
             $atom_structure['reserved'] = substr($atom_data, 26, 10);
             $atom_structure['matrix_a'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 36, 4));
             $atom_structure['matrix_b'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 40, 4));
             $atom_structure['matrix_u'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 44, 4));
             $atom_structure['matrix_c'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 48, 4));
             $atom_structure['matrix_d'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 52, 4));
             $atom_structure['matrix_v'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 56, 4));
             $atom_structure['matrix_x'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 60, 4));
             $atom_structure['matrix_y'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 64, 4));
             $atom_structure['matrix_w'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 68, 4));
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 72, array('preview_time' => 4, 'preview_duration' => 4, 'poster_time' => 4, 'selection_time' => 4, 'selection_duration' => 4, 'current_time' => 4, 'next_track_id' => 4));
             if ($atom_structure['time_scale'] == 0) {
                 throw new getid3_exception('Corrupt Quicktime file: mvhd.time_scale == zero');
             }
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             $info_quicktime['time_scale'] = max(@$info['quicktime']['time_scale'], $atom_structure['time_scale']);
             $info_quicktime['display_scale'] = $atom_structure['matrix_a'];
             $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
             break;
         case 'tkhd':
             // TracK HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'trackid' => 4, 'reserved1' => 4, 'duration' => 4, 'reserved2' => 8, 'layer' => 2, 'alternate_group' => 2));
             $atom_structure['volume'] = getid3_quicktime::FixedPoint8_8(substr($atom_data, 36, 2));
             $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
             $atom_structure['matrix_a'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 40, 4));
             $atom_structure['matrix_b'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 44, 4));
             $atom_structure['matrix_u'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 48, 4));
             $atom_structure['matrix_c'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 52, 4));
             $atom_structure['matrix_v'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 56, 4));
             $atom_structure['matrix_d'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 60, 4));
             $atom_structure['matrix_x'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 64, 4));
             $atom_structure['matrix_y'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 68, 4));
             $atom_structure['matrix_w'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 72, 4));
             $atom_structure['width'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 76, 4));
             $atom_structure['height'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 80, 4));
             $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x2);
             $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x4);
             $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x8);
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
                 $info['video']['resolution_x'] = $atom_structure['width'];
                 $info['video']['resolution_y'] = $atom_structure['height'];
             }
             if ($atom_structure['flags']['enabled'] == 1) {
                 $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
                 $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
             }
             if (!empty($info['video']['resolution_x']) && !empty($info['video']['resolution_y'])) {
                 $info_quicktime['video']['resolution_x'] = $info['video']['resolution_x'];
                 $info_quicktime['video']['resolution_y'] = $info['video']['resolution_y'];
             } else {
                 unset($info['video']['resolution_x']);
                 unset($info['video']['resolution_y']);
                 unset($info_quicktime['video']);
             }
             break;
         case 'meta':
             // METAdata atom
             // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
             $next_tag_position = strpos($atom_data, '©');
             while ($next_tag_position < strlen($atom_data)) {
                 $meta_item_size = getid3_lib::BigEndian2Int(substr($atom_data, $next_tag_position - 4, 4)) - 4;
                 if ($meta_item_size == -4) {
                     break;
                 }
                 $meta_item_raw = substr($atom_data, $next_tag_position, $meta_item_size);
                 $meta_item_key = substr($meta_item_raw, 0, 4);
                 $meta_item_data = substr($meta_item_raw, 20);
                 $next_tag_position += $meta_item_size + 4;
                 $this->CopyToAppropriateCommentsSection($meta_item_key, $meta_item_data);
             }
             break;
         case 'ftyp':
             // FileTYPe (?) atom (for MP4 it seems)
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('signature' => -4, 'unknown_1' => 4, 'fourcc' => -4));
             break;
         case 'mdat':
             // Media DATa atom
         // Media DATa atom
         case 'free':
             // FREE space atom
         // FREE space atom
         case 'skip':
             // SKIP atom
         // SKIP atom
         case 'wide':
             // 64-bit expansion placeholder atom
             // 'mdat' data is too big to deal with, contains no useful metadata
             // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
             // When writing QuickTime files, it is sometimes necessary to update an atom's size.
             // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
             // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
             // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
             // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
             // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
             // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
             break;
         case 'nsav':
             // NoSAVe atom
             // http://developer.apple.com/technotes/tn/tn2038.html
             $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             break;
         case 'ctyp':
             // Controller TYPe atom (seen on QTVR)
             // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
             // some controller names are:
             //   0x00 + 'std' for linear movie
             //   'none' for no controls
             $atom_structure['ctyp'] = substr($atom_data, 0, 4);
             switch ($atom_structure['ctyp']) {
                 case 'qtvr':
                     $info['video']['dataformat'] = 'quicktimevr';
                     break;
             }
             break;
         case 'pano':
             // PANOrama track (seen on QTVR)
             $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             break;
         case 'hint':
             // HINT track
         // HINT track
         case 'hinf':
             //
         //
         case 'hinv':
             //
         //
         case 'hnti':
             //
             $info['quicktime']['hinting'] = true;
             break;
         case 'imgt':
             // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
             for ($i = 0; $i < $atom_structure['size'] - 8; $i += 4) {
                 $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
             }
             break;
         case 'FXTC':
             // Something to do with Adobe After Effects (?)
         // Something to do with Adobe After Effects (?)
         case 'PrmA':
         case 'code':
         case 'FIEL':
             // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
             // Observed-but-not-handled atom types are just listed here
             // to prevent warnings being generated
             $atom_structure['data'] = $atom_data;
             break;
         default:
             $getid3->warning('Unknown QuickTime atom type: "' . $atom_name . '" at offset ' . $base_offset);
             $atom_structure['data'] = $atom_data;
             break;
     }
     array_pop($atom_hierarchy);
     return $atom_structure;
 }
 function process_notification($notification)
 {
     do_action('waz_before_process_notification', $notification);
     $ids = $this->get_site_and_post_id_from_job_id($notification->job->id);
     $post_id = $ids['post'];
     $site_id = $ids['site'];
     $switched = false;
     if (0 != $site_id) {
         switch_to_blog($site_id);
         $switched = true;
     }
     // If you're encoding to multiple outputs and only care when all of the outputs are finished
     // you can check if the entire job is finished.
     if (0 !== $ids['post'] && $notification->job->state == "finished") {
         $output = $notification->job->outputs['web'];
         // Get the Attachment
         $meta = $_meta = wp_get_attachment_metadata($post_id);
         require_once ABSPATH . '/wp-includes/ID3/getid3.lib.php';
         require_once ABSPATH . '/wp-includes/ID3/getid3.php';
         require_once ABSPATH . '/wp-includes/ID3/module.audio-video.quicktime.php';
         // Let's start modifying the metadata
         // TODO figure out a viable way to use built in WP ID3
         $meta['filesize'] = $output->file_size_in_bytes;
         $meta['mime_type'] = 'video/mp4';
         $meta['length'] = ceil($output->duration_in_ms * 0.001);
         $meta['length_formatted'] = getid3_lib::PlaytimeString($meta['length']);
         $meta['width'] = $output->width;
         $meta['height'] = $output->height;
         $meta['fileformat'] = 'mp4';
         $meta['dataformat'] = $output->format;
         $meta['codec'] = $output->video_codec;
         // TODO this needs to take into consideration other file formats
         // other than quicktime
         $id3 = new getID3();
         $qt = new getid3_quicktime($id3);
         $meta['audio'] = array('dataformat' => $output->audio_codec, 'codec' => $qt->QuicktimeAudioCodecLookup($output->audio_codec), 'sample_rate' => $output->audio_sample_rate, 'channels' => $output->channels, 'lossless' => false, 'channelmode' => 'stereo');
         // Update the Metadata
         wp_update_attachment_metadata($post_id, $meta);
         // Video has been encoded, here's the meta data
         do_action('waz_video_encoded', $post_id, $meta);
         // Let's update the S3 information
         $s3info = $_s3info = get_post_meta($post_id, 'amazonS3_info', true);
         $parsed = parse_url($output->url);
         $host = explode('.', $parsed['host']);
         $key = ltrim($parsed['path'], '/');
         $s3info['bucket'] = $host[0];
         $s3info['key'] = $key;
         // Update S3 to point to new file
         update_post_meta($post_id, 'amazonS3_info', $s3info);
         // Save original file for later
         update_post_meta($post_id, 'waz_original', $_s3info);
         // And we're done!
         update_post_meta($post_id, 'waz_encode_status', 'finished');
         // Clean up after ourselves
         delete_site_option('waz_job_' . $notification->job->id . '_blog_id');
         // Delete the original file
         $this->delete_attachment($post_id);
         foreach ($ids as $key => $id) {
             echo ucfirst($key) . ': ' . $id . "\n";
         }
     } else {
         update_post_meta($post_id, 'waz_encode_status', 'failed');
         update_post_meta($post_id, 'waz_notification_response', $notification);
     }
     echo 'Received!';
     if ($switched) {
         restore_current_blog();
     }
     do_action('waz_after_process_notification', $notification);
     die(0);
 }