source: extensions/piwigo_videojs/include/getid3/module.audio-video.quicktime.php @ 31945

Last change on this file since 31945 was 24676, checked in by ddtddt, 11 years ago

[extensions] - piwigo_videojs - add file for translate

File size: 107.1 KB
Line 
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/////////////////////////////////////////////////////////////////
7// See readme.txt for more details                             //
8/////////////////////////////////////////////////////////////////
9//                                                             //
10// module.audio-video.quicktime.php                            //
11// module for analyzing Quicktime and MP3-in-MP4 files         //
12// dependencies: module.audio.mp3.php                          //
13//                                                            ///
14/////////////////////////////////////////////////////////////////
15
16getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
17
18class getid3_quicktime extends getid3_handler
19{
20
21        public $ReturnAtomData        = true;
22        public $ParseAllPossibleAtoms = false;
23
24        public function Analyze() {
25                $info = &$this->getid3->info;
26
27                $info['fileformat'] = 'quicktime';
28                $info['quicktime']['hinting']    = false;
29                $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
30
31                fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
32
33                $offset      = 0;
34                $atomcounter = 0;
35
36                while ($offset < $info['avdataend']) {
37                        if (!getid3_lib::intValueSupported($offset)) {
38                                $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
39                                break;
40                        }
41                        fseek($this->getid3->fp, $offset, SEEK_SET);
42                        $AtomHeader = fread($this->getid3->fp, 8);
43
44                        $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
45                        $atomname = substr($AtomHeader, 4, 4);
46
47                        // 64-bit MOV patch by jlegateØktnc*com
48                        if ($atomsize == 1) {
49                                $atomsize = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 8));
50                        }
51
52                        $info['quicktime'][$atomname]['name']   = $atomname;
53                        $info['quicktime'][$atomname]['size']   = $atomsize;
54                        $info['quicktime'][$atomname]['offset'] = $offset;
55
56                        if (($offset + $atomsize) > $info['avdataend']) {
57                                $info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
58                                return false;
59                        }
60
61                        if ($atomsize == 0) {
62                                // Furthermore, for historical reasons the list of atoms is optionally
63                                // terminated by a 32-bit integer set to 0. If you are writing a program
64                                // to read user data atoms, you should allow for the terminating 0.
65                                break;
66                        }
67                        switch ($atomname) {
68                                case 'mdat': // Media DATa atom
69                                        // 'mdat' contains the actual data for the audio/video
70                                        if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
71
72                                                $info['avdataoffset'] = $info['quicktime'][$atomname]['offset'] + 8;
73                                                $OldAVDataEnd         = $info['avdataend'];
74                                                $info['avdataend']    = $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
75
76                                                $getid3_temp = new getID3();
77                                                $getid3_temp->openfile($this->getid3->filename);
78                                                $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
79                                                $getid3_temp->info['avdataend']    = $info['avdataend'];
80                                                $getid3_mp3 = new getid3_mp3($getid3_temp);
81                                                if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode(fread($this->getid3->fp, 4)))) {
82                                                        $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
83                                                        if (!empty($getid3_temp->info['warning'])) {
84                                                                foreach ($getid3_temp->info['warning'] as $value) {
85                                                                        $info['warning'][] = $value;
86                                                                }
87                                                        }
88                                                        if (!empty($getid3_temp->info['mpeg'])) {
89                                                                $info['mpeg'] = $getid3_temp->info['mpeg'];
90                                                                if (isset($info['mpeg']['audio'])) {
91                                                                        $info['audio']['dataformat']   = 'mp3';
92                                                                        $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')));
93                                                                        $info['audio']['sample_rate']  = $info['mpeg']['audio']['sample_rate'];
94                                                                        $info['audio']['channels']     = $info['mpeg']['audio']['channels'];
95                                                                        $info['audio']['bitrate']      = $info['mpeg']['audio']['bitrate'];
96                                                                        $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
97                                                                        $info['bitrate']               = $info['audio']['bitrate'];
98                                                                }
99                                                        }
100                                                }
101                                                unset($getid3_mp3, $getid3_temp);
102                                                $info['avdataend'] = $OldAVDataEnd;
103                                                unset($OldAVDataEnd);
104
105                                        }
106                                        break;
107
108                                case 'free': // FREE space atom
109                                case 'skip': // SKIP atom
110                                case 'wide': // 64-bit expansion placeholder atom
111                                        // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
112                                        break;
113
114                                default:
115                                        $atomHierarchy = array();
116                                        $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($this->getid3->fp, $atomsize), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
117                                        break;
118                        }
119
120                        $offset += $atomsize;
121                        $atomcounter++;
122                }
123
124                if (!empty($info['avdataend_tmp'])) {
125                        // this value is assigned to a temp value and then erased because
126                        // otherwise any atoms beyond the 'mdat' atom would not get parsed
127                        $info['avdataend'] = $info['avdataend_tmp'];
128                        unset($info['avdataend_tmp']);
129                }
130
131                if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
132                        $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
133                }
134                if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
135                        $info['audio']['bitrate'] = $info['bitrate'];
136                }
137                if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
138                        foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
139                                $samples_per_second = $samples_count / $info['playtime_seconds'];
140                                if ($samples_per_second > 240) {
141                                        // has to be audio samples
142                                } else {
143                                        $info['video']['frame_rate'] = $samples_per_second;
144                                        break;
145                                }
146                        }
147                }
148                if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
149                        $info['fileformat'] = 'mp4';
150                        $info['mime_type']  = 'audio/mp4';
151                        unset($info['video']['dataformat']);
152                }
153
154                if (!$this->ReturnAtomData) {
155                        unset($info['quicktime']['moov']);
156                }
157
158                if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
159                        $info['audio']['dataformat'] = 'quicktime';
160                }
161                if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
162                        $info['video']['dataformat'] = 'quicktime';
163                }
164
165                return true;
166        }
167
168        public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
169                // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
170
171                $info = &$this->getid3->info;
172
173                $atom_parent = array_pop($atomHierarchy);
174                array_push($atomHierarchy, $atomname);
175                $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
176                $atom_structure['name']      = $atomname;
177                $atom_structure['size']      = $atomsize;
178                $atom_structure['offset']    = $baseoffset;
179//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8)).'<br>';
180//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8), false).'<br><br>';
181                switch ($atomname) {
182                        case 'moov': // MOVie container atom
183                        case 'trak': // TRAcK container atom
184                        case 'clip': // CLIPping container atom
185                        case 'matt': // track MATTe container atom
186                        case 'edts': // EDiTS container atom
187                        case 'tref': // Track REFerence container atom
188                        case 'mdia': // MeDIA container atom
189                        case 'minf': // Media INFormation container atom
190                        case 'dinf': // Data INFormation container atom
191                        case 'udta': // User DaTA container atom
192                        case 'cmov': // Compressed MOVie container atom
193                        case 'rmra': // Reference Movie Record Atom
194                        case 'rmda': // Reference Movie Descriptor Atom
195                        case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
196                                $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
197                                break;
198
199                        case 'ilst': // Item LiST container atom
200                                $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
201
202                                // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
203                                $allnumericnames = true;
204                                foreach ($atom_structure['subatoms'] as $subatomarray) {
205                                        if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
206                                                $allnumericnames = false;
207                                                break;
208                                        }
209                                }
210                                if ($allnumericnames) {
211                                        $newData = array();
212                                        foreach ($atom_structure['subatoms'] as $subatomarray) {
213                                                foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
214                                                        unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
215                                                        $newData[$subatomarray['name']] = $newData_subatomarray;
216                                                        break;
217                                                }
218                                        }
219                                        $atom_structure['data'] = $newData;
220                                        unset($atom_structure['subatoms']);
221                                }
222                                break;
223
224                        case "\x00\x00\x00\x01":
225                        case "\x00\x00\x00\x02":
226                        case "\x00\x00\x00\x03":
227                        case "\x00\x00\x00\x04":
228                        case "\x00\x00\x00\x05":
229                                $atomname = getid3_lib::BigEndian2Int($atomname);
230                                $atom_structure['name'] = $atomname;
231                                $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
232                                break;
233
234                        case 'stbl': // Sample TaBLe container atom
235                                $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
236                                $isVideo = false;
237                                $framerate  = 0;
238                                $framecount = 0;
239                                foreach ($atom_structure['subatoms'] as $key => $value_array) {
240                                        if (isset($value_array['sample_description_table'])) {
241                                                foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
242                                                        if (isset($value_array2['data_format'])) {
243                                                                switch ($value_array2['data_format']) {
244                                                                        case 'avc1':
245                                                                        case 'mp4v':
246                                                                                // video data
247                                                                                $isVideo = true;
248                                                                                break;
249                                                                        case 'mp4a':
250                                                                                // audio data
251                                                                                break;
252                                                                }
253                                                        }
254                                                }
255                                        } elseif (isset($value_array['time_to_sample_table'])) {
256                                                foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
257                                                        if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
258                                                                $framerate  = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
259                                                                $framecount = $value_array2['sample_count'];
260                                                        }
261                                                }
262                                        }
263                                }
264                                if ($isVideo && $framerate) {
265                                        $info['quicktime']['video']['frame_rate'] = $framerate;
266                                        $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
267                                }
268                                if ($isVideo && $framecount) {
269                                        $info['quicktime']['video']['frame_count'] = $framecount;
270                                }
271                                break;
272
273
274                        case 'aART': // Album ARTist
275                        case 'catg': // CaTeGory
276                        case 'covr': // COVeR artwork
277                        case 'cpil': // ComPILation
278                        case 'cprt': // CoPyRighT
279                        case 'desc': // DESCription
280                        case 'disk': // DISK number
281                        case 'egid': // Episode Global ID
282                        case 'gnre': // GeNRE
283                        case 'keyw': // KEYWord
284                        case 'ldes':
285                        case 'pcst': // PodCaST
286                        case 'pgap': // GAPless Playback
287                        case 'purd': // PURchase Date
288                        case 'purl': // Podcast URL
289                        case 'rati':
290                        case 'rndu':
291                        case 'rpdu':
292                        case 'rtng': // RaTiNG
293                        case 'stik':
294                        case 'tmpo': // TeMPO (BPM)
295                        case 'trkn': // TRacK Number
296                        case 'tves': // TV EpiSode
297                        case 'tvnn': // TV Network Name
298                        case 'tvsh': // TV SHow Name
299                        case 'tvsn': // TV SeasoN
300                        case 'akID': // iTunes store account type
301                        case 'apID':
302                        case 'atID':
303                        case 'cmID':
304                        case 'cnID':
305                        case 'geID':
306                        case 'plID':
307                        case 'sfID': // iTunes store country
308                        case '©alb': // ALBum
309                        case '©art': // ARTist
310                        case '©ART':
311                        case '©aut':
312                        case '©cmt': // CoMmenT
313                        case '©com': // COMposer
314                        case '©cpy':
315                        case '©day': // content created year
316                        case '©dir':
317                        case '©ed1':
318                        case '©ed2':
319                        case '©ed3':
320                        case '©ed4':
321                        case '©ed5':
322                        case '©ed6':
323                        case '©ed7':
324                        case '©ed8':
325                        case '©ed9':
326                        case '©enc':
327                        case '©fmt':
328                        case '©gen': // GENre
329                        case '©grp': // GRouPing
330                        case '©hst':
331                        case '©inf':
332                        case '©lyr': // LYRics
333                        case '©mak':
334                        case '©mod':
335                        case '©nam': // full NAMe
336                        case '©ope':
337                        case '©PRD':
338                        case '©prd':
339                        case '©prf':
340                        case '©req':
341                        case '©src':
342                        case '©swr':
343                        case '©too': // encoder
344                        case '©trk': // TRacK
345                        case '©url':
346                        case '©wrn':
347                        case '©wrt': // WRiTer
348                        case '----': // itunes specific
349                                if ($atom_parent == 'udta') {
350                                        // User data atom handler
351                                        $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
352                                        $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
353                                        $atom_structure['data']        =                           substr($atom_data, 4);
354
355                                        $atom_structure['language']    = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
356                                        if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
357                                                $info['comments']['language'][] = $atom_structure['language'];
358                                        }
359                                } else {
360                                        // Apple item list box atom handler
361                                        $atomoffset = 0;
362                                        if (substr($atom_data, 2, 2) == "\x10\xB5") {
363                                                // not sure what it means, but observed on iPhone4 data.
364                                                // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
365                                                while ($atomoffset < strlen($atom_data)) {
366                                                        $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset,     2));
367                                                        $boxsmalltype =                           substr($atom_data, $atomoffset + 2, 2);
368                                                        $boxsmalldata =                           substr($atom_data, $atomoffset + 4, $boxsmallsize);
369                                                        switch ($boxsmalltype) {
370                                                                case "\x10\xB5":
371                                                                        $atom_structure['data'] = $boxsmalldata;
372                                                                        break;
373                                                                default:
374                                                                        $info['warning'][] = 'Unknown QuickTime smallbox type: "'.getid3_lib::PrintHexBytes($boxsmalltype).'" at offset '.$baseoffset;
375                                                                        $atom_structure['data'] = $atom_data;
376                                                                        break;
377                                                        }
378                                                        $atomoffset += (4 + $boxsmallsize);
379                                                }
380                                        } else {
381                                                while ($atomoffset < strlen($atom_data)) {
382                                                        $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
383                                                        $boxtype =                           substr($atom_data, $atomoffset + 4, 4);
384                                                        $boxdata =                           substr($atom_data, $atomoffset + 8, $boxsize - 8);
385                                                        if ($boxsize <= 1) {
386                                                                $info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.$atomname.'" at offset: '.($atom_structure['offset'] + $atomoffset);
387                                                                $atom_structure['data'] = null;
388                                                                $atomoffset = strlen($atom_data);
389                                                                break;
390                                                        }
391                                                        $atomoffset += $boxsize;
392
393                                                        switch ($boxtype) {
394                                                                case 'mean':
395                                                                case 'name':
396                                                                        $atom_structure[$boxtype] = substr($boxdata, 4);
397                                                                        break;
398
399                                                                case 'data':
400                                                                        $atom_structure['version']   = getid3_lib::BigEndian2Int(substr($boxdata,  0, 1));
401                                                                        $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata,  1, 3));
402                                                                        switch ($atom_structure['flags_raw']) {
403                                                                                case 0:  // data flag
404                                                                                case 21: // tmpo/cpil flag
405                                                                                        switch ($atomname) {
406                                                                                                case 'cpil':
407                                                                                                case 'pcst':
408                                                                                                case 'pgap':
409                                                                                                        $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
410                                                                                                        break;
411
412                                                                                                case 'tmpo':
413                                                                                                        $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
414                                                                                                        break;
415
416                                                                                                case 'disk':
417                                                                                                case 'trkn':
418                                                                                                        $num       = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
419                                                                                                        $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
420                                                                                                        $atom_structure['data']  = empty($num) ? '' : $num;
421                                                                                                        $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
422                                                                                                        break;
423
424                                                                                                case 'gnre':
425                                                                                                        $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
426                                                                                                        $atom_structure['data']    = getid3_id3v1::LookupGenreName($GenreID - 1);
427                                                                                                        break;
428
429                                                                                                case 'rtng':
430                                                                                                        $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
431                                                                                                        $atom_structure['data']    = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
432                                                                                                        break;
433
434                                                                                                case 'stik':
435                                                                                                        $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
436                                                                                                        $atom_structure['data']    = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
437                                                                                                        break;
438
439                                                                                                case 'sfID':
440                                                                                                        $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
441                                                                                                        $atom_structure['data']    = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
442                                                                                                        break;
443
444                                                                                                case 'egid':
445                                                                                                case 'purl':
446                                                                                                        $atom_structure['data'] = substr($boxdata, 8);
447                                                                                                        break;
448
449                                                                                                default:
450                                                                                                        $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
451                                                                                        }
452                                                                                        break;
453
454                                                                                case 1:  // text flag
455                                                                                case 13: // image flag
456                                                                                default:
457                                                                                        $atom_structure['data'] = substr($boxdata, 8);
458                                                                                        break;
459
460                                                                        }
461                                                                        break;
462
463                                                                default:
464                                                                        $info['warning'][] = 'Unknown QuickTime box type: "'.getid3_lib::PrintHexBytes($boxtype).'" at offset '.$baseoffset;
465                                                                        $atom_structure['data'] = $atom_data;
466
467                                                        }
468                                                }
469                                        }
470                                }
471                                $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
472                                break;
473
474
475                        case 'play': // auto-PLAY atom
476                                $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
477
478                                $info['quicktime']['autoplay'] = $atom_structure['autoplay'];
479                                break;
480
481
482                        case 'WLOC': // Window LOCation atom
483                                $atom_structure['location_x']  = getid3_lib::BigEndian2Int(substr($atom_data,  0, 2));
484                                $atom_structure['location_y']  = getid3_lib::BigEndian2Int(substr($atom_data,  2, 2));
485                                break;
486
487
488                        case 'LOOP': // LOOPing atom
489                        case 'SelO': // play SELection Only atom
490                        case 'AllF': // play ALL Frames atom
491                                $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
492                                break;
493
494
495                        case 'name': //
496                        case 'MCPS': // Media Cleaner PRo
497                        case '@PRM': // adobe PReMiere version
498                        case '@PRQ': // adobe PRemiere Quicktime version
499                                $atom_structure['data'] = $atom_data;
500                                break;
501
502
503                        case 'cmvd': // Compressed MooV Data atom
504                                // Code by ubergeekØubergeek*tv based on information from
505                                // http://developer.apple.com/quicktime/icefloe/dispatch012.html
506                                $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
507
508                                $CompressedFileData = substr($atom_data, 4);
509                                if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
510                                        $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
511                                } else {
512                                        $info['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset'];
513                                }
514                                break;
515
516
517                        case 'dcom': // Data COMpression atom
518                                $atom_structure['compression_id']   = $atom_data;
519                                $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
520                                break;
521
522
523                        case 'rdrf': // Reference movie Data ReFerence atom
524                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
525                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
526                                $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
527
528                                $atom_structure['reference_type_name']    =                           substr($atom_data,  4, 4);
529                                $atom_structure['reference_length']       = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
530                                switch ($atom_structure['reference_type_name']) {
531                                        case 'url ':
532                                                $atom_structure['url']            =       $this->NoNullString(substr($atom_data, 12));
533                                                break;
534
535                                        case 'alis':
536                                                $atom_structure['file_alias']     =                           substr($atom_data, 12);
537                                                break;
538
539                                        case 'rsrc':
540                                                $atom_structure['resource_alias'] =                           substr($atom_data, 12);
541                                                break;
542
543                                        default:
544                                                $atom_structure['data']           =                           substr($atom_data, 12);
545                                                break;
546                                }
547                                break;
548
549
550                        case 'rmqu': // Reference Movie QUality atom
551                                $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
552                                break;
553
554
555                        case 'rmcs': // Reference Movie Cpu Speed atom
556                                $atom_structure['version']          = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
557                                $atom_structure['flags_raw']        = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
558                                $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
559                                break;
560
561
562                        case 'rmvc': // Reference Movie Version Check atom
563                                $atom_structure['version']            = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
564                                $atom_structure['flags_raw']          = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
565                                $atom_structure['gestalt_selector']   =                           substr($atom_data,  4, 4);
566                                $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
567                                $atom_structure['gestalt_value']      = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
568                                $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
569                                break;
570
571
572                        case 'rmcd': // Reference Movie Component check atom
573                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
574                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
575                                $atom_structure['component_type']         =                           substr($atom_data,  4, 4);
576                                $atom_structure['component_subtype']      =                           substr($atom_data,  8, 4);
577                                $atom_structure['component_manufacturer'] =                           substr($atom_data, 12, 4);
578                                $atom_structure['component_flags_raw']    = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
579                                $atom_structure['component_flags_mask']   = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
580                                $atom_structure['component_min_version']  = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
581                                break;
582
583
584                        case 'rmdr': // Reference Movie Data Rate atom
585                                $atom_structure['version']       = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
586                                $atom_structure['flags_raw']     = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
587                                $atom_structure['data_rate']     = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
588
589                                $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
590                                break;
591
592
593                        case 'rmla': // Reference Movie Language Atom
594                                $atom_structure['version']     = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
595                                $atom_structure['flags_raw']   = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
596                                $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
597
598                                $atom_structure['language']    = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
599                                if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
600                                        $info['comments']['language'][] = $atom_structure['language'];
601                                }
602                                break;
603
604
605                        case 'rmla': // Reference Movie Language Atom
606                                $atom_structure['version']   = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
607                                $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
608                                $atom_structure['track_id']  = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
609                                break;
610
611
612                        case 'ptv ': // Print To Video - defines a movie's full screen mode
613                                // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
614                                $atom_structure['display_size_raw']  = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
615                                $atom_structure['reserved_1']        = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
616                                $atom_structure['reserved_2']        = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
617                                $atom_structure['slide_show_flag']   = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
618                                $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
619
620                                $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
621                                $atom_structure['flags']['slide_show']   = (bool) $atom_structure['slide_show_flag'];
622
623                                $ptv_lookup[0] = 'normal';
624                                $ptv_lookup[1] = 'double';
625                                $ptv_lookup[2] = 'half';
626                                $ptv_lookup[3] = 'full';
627                                $ptv_lookup[4] = 'current';
628                                if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
629                                        $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
630                                } else {
631                                        $info['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')';
632                                }
633                                break;
634
635
636                        case 'stsd': // Sample Table Sample Description atom
637                                $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
638                                $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
639                                $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
640                                $stsdEntriesDataOffset = 8;
641                                for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
642                                        $atom_structure['sample_description_table'][$i]['size']             = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
643                                        $stsdEntriesDataOffset += 4;
644                                        $atom_structure['sample_description_table'][$i]['data_format']      =                           substr($atom_data, $stsdEntriesDataOffset, 4);
645                                        $stsdEntriesDataOffset += 4;
646                                        $atom_structure['sample_description_table'][$i]['reserved']         = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
647                                        $stsdEntriesDataOffset += 6;
648                                        $atom_structure['sample_description_table'][$i]['reference_index']  = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
649                                        $stsdEntriesDataOffset += 2;
650                                        $atom_structure['sample_description_table'][$i]['data']             =                           substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
651                                        $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
652
653                                        $atom_structure['sample_description_table'][$i]['encoder_version']  = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  0, 2));
654                                        $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  2, 2));
655                                        $atom_structure['sample_description_table'][$i]['encoder_vendor']   =                           substr($atom_structure['sample_description_table'][$i]['data'],  4, 4);
656
657                                        switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
658
659                                                case "\x00\x00\x00\x00":
660                                                        // audio atom
661                                                        $atom_structure['sample_description_table'][$i]['audio_channels']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  8,  2));
662                                                        $atom_structure['sample_description_table'][$i]['audio_bit_depth']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10,  2));
663                                                        $atom_structure['sample_description_table'][$i]['audio_compression_id'] =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12,  2));
664                                                        $atom_structure['sample_description_table'][$i]['audio_packet_size']    =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14,  2));
665                                                        $atom_structure['sample_description_table'][$i]['audio_sample_rate']    = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16,  4));
666
667                                                        switch ($atom_structure['sample_description_table'][$i]['data_format']) {
668                                                                case 'avc1':
669                                                                case 'mp4v':
670                                                                        $info['fileformat'] = 'mp4';
671                                                                        $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
672                                                                        //$info['warning'][] = 'This version of getID3() ['.$this->getid3->version().'] does not fully support MPEG-4 audio/video streams'; // 2011-02-18: why am I warning about this again? What's not supported?
673                                                                        break;
674
675                                                                case 'qtvr':
676                                                                        $info['video']['dataformat'] = 'quicktimevr';
677                                                                        break;
678
679                                                                case 'mp4a':
680                                                                default:
681                                                                        $info['quicktime']['audio']['codec']       = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
682                                                                        $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
683                                                                        $info['quicktime']['audio']['channels']    = $atom_structure['sample_description_table'][$i]['audio_channels'];
684                                                                        $info['quicktime']['audio']['bit_depth']   = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
685                                                                        $info['audio']['codec']                    = $info['quicktime']['audio']['codec'];
686                                                                        $info['audio']['sample_rate']              = $info['quicktime']['audio']['sample_rate'];
687                                                                        $info['audio']['channels']                 = $info['quicktime']['audio']['channels'];
688                                                                        $info['audio']['bits_per_sample']          = $info['quicktime']['audio']['bit_depth'];
689                                                                        switch ($atom_structure['sample_description_table'][$i]['data_format']) {
690                                                                                case 'raw ': // PCM
691                                                                                case 'alac': // Apple Lossless Audio Codec
692                                                                                        $info['audio']['lossless'] = true;
693                                                                                        break;
694                                                                                default:
695                                                                                        $info['audio']['lossless'] = false;
696                                                                                        break;
697                                                                        }
698                                                                        break;
699                                                        }
700                                                        break;
701
702                                                default:
703                                                        switch ($atom_structure['sample_description_table'][$i]['data_format']) {
704                                                                case 'mp4s':
705                                                                        $info['fileformat'] = 'mp4';
706                                                                        break;
707
708                                                                default:
709                                                                        // video atom
710                                                                        $atom_structure['sample_description_table'][$i]['video_temporal_quality']  =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  8,  4));
711                                                                        $atom_structure['sample_description_table'][$i]['video_spatial_quality']   =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12,  4));
712                                                                        $atom_structure['sample_description_table'][$i]['video_frame_width']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16,  2));
713                                                                        $atom_structure['sample_description_table'][$i]['video_frame_height']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18,  2));
714                                                                        $atom_structure['sample_description_table'][$i]['video_resolution_x']      = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20,  4));
715                                                                        $atom_structure['sample_description_table'][$i]['video_resolution_y']      = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24,  4));
716                                                                        $atom_structure['sample_description_table'][$i]['video_data_size']         =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28,  4));
717                                                                        $atom_structure['sample_description_table'][$i]['video_frame_count']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32,  2));
718                                                                        $atom_structure['sample_description_table'][$i]['video_encoder_name_len']  =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34,  1));
719                                                                        $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']);
720                                                                        $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66,  2));
721                                                                        $atom_structure['sample_description_table'][$i]['video_color_table_id']    =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68,  2));
722
723                                                                        $atom_structure['sample_description_table'][$i]['video_pixel_color_type']  = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
724                                                                        $atom_structure['sample_description_table'][$i]['video_pixel_color_name']  = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
725
726                                                                        if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
727                                                                                $info['quicktime']['video']['codec_fourcc']        = $atom_structure['sample_description_table'][$i]['data_format'];
728                                                                                $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
729                                                                                $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']);
730                                                                                $info['quicktime']['video']['color_depth']         = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
731                                                                                $info['quicktime']['video']['color_depth_name']    = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
732
733                                                                                $info['video']['codec']           = $info['quicktime']['video']['codec'];
734                                                                                $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
735                                                                        }
736                                                                        $info['video']['lossless']           = false;
737                                                                        $info['video']['pixel_aspect_ratio'] = (float) 1;
738                                                                        break;
739                                                        }
740                                                        break;
741                                        }
742                                        switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
743                                                case 'mp4a':
744                                                        $info['audio']['dataformat']         = 'mp4';
745                                                        $info['quicktime']['audio']['codec'] = 'mp4';
746                                                        break;
747
748                                                case '3ivx':
749                                                case '3iv1':
750                                                case '3iv2':
751                                                        $info['video']['dataformat'] = '3ivx';
752                                                        break;
753
754                                                case 'xvid':
755                                                        $info['video']['dataformat'] = 'xvid';
756                                                        break;
757
758                                                case 'mp4v':
759                                                        $info['video']['dataformat'] = 'mpeg4';
760                                                        break;
761
762                                                case 'divx':
763                                                case 'div1':
764                                                case 'div2':
765                                                case 'div3':
766                                                case 'div4':
767                                                case 'div5':
768                                                case 'div6':
769                                                        $info['video']['dataformat'] = 'divx';
770                                                        break;
771
772                                                default:
773                                                        // do nothing
774                                                        break;
775                                        }
776                                        unset($atom_structure['sample_description_table'][$i]['data']);
777                                }
778                                break;
779
780
781                        case 'stts': // Sample Table Time-to-Sample atom
782                                $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
783                                $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
784                                $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
785                                $sttsEntriesDataOffset = 8;
786                                //$FrameRateCalculatorArray = array();
787                                $frames_count = 0;
788                                for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
789                                        $atom_structure['time_to_sample_table'][$i]['sample_count']    = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
790                                        $sttsEntriesDataOffset += 4;
791                                        $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
792                                        $sttsEntriesDataOffset += 4;
793
794                                        $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
795
796                                        // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
797                                        //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
798                                        //      $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
799                                        //      if ($stts_new_framerate <= 60) {
800                                        //              // some atoms have durations of "1" giving a very large framerate, which probably is not right
801                                        //              $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
802                                        //      }
803                                        //}
804                                        //
805                                        //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
806                                }
807                                $info['quicktime']['stts_framecount'][] = $frames_count;
808                                //$sttsFramesTotal  = 0;
809                                //$sttsSecondsTotal = 0;
810                                //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
811                                //      if (($frames_per_second > 60) || ($frames_per_second < 1)) {
812                                //              // not video FPS information, probably audio information
813                                //              $sttsFramesTotal  = 0;
814                                //              $sttsSecondsTotal = 0;
815                                //              break;
816                                //      }
817                                //      $sttsFramesTotal  += $frame_count;
818                                //      $sttsSecondsTotal += $frame_count / $frames_per_second;
819                                //}
820                                //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
821                                //      if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
822                                //              $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
823                                //      }
824                                //}
825                                break;
826
827
828                        case 'stss': // Sample Table Sync Sample (key frames) atom
829                                if ($ParseAllPossibleAtoms) {
830                                        $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
831                                        $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
832                                        $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
833                                        $stssEntriesDataOffset = 8;
834                                        for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
835                                                $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
836                                                $stssEntriesDataOffset += 4;
837                                        }
838                                }
839                                break;
840
841
842                        case 'stsc': // Sample Table Sample-to-Chunk atom
843                                if ($ParseAllPossibleAtoms) {
844                                        $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
845                                        $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
846                                        $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
847                                        $stscEntriesDataOffset = 8;
848                                        for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
849                                                $atom_structure['sample_to_chunk_table'][$i]['first_chunk']        = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
850                                                $stscEntriesDataOffset += 4;
851                                                $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk']  = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
852                                                $stscEntriesDataOffset += 4;
853                                                $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
854                                                $stscEntriesDataOffset += 4;
855                                        }
856                                }
857                                break;
858
859
860                        case 'stsz': // Sample Table SiZe atom
861                                if ($ParseAllPossibleAtoms) {
862                                        $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
863                                        $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
864                                        $atom_structure['sample_size']    = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
865                                        $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
866                                        $stszEntriesDataOffset = 12;
867                                        if ($atom_structure['sample_size'] == 0) {
868                                                for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
869                                                        $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
870                                                        $stszEntriesDataOffset += 4;
871                                                }
872                                        }
873                                }
874                                break;
875
876
877                        case 'stco': // Sample Table Chunk Offset atom
878                                if ($ParseAllPossibleAtoms) {
879                                        $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
880                                        $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
881                                        $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
882                                        $stcoEntriesDataOffset = 8;
883                                        for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
884                                                $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
885                                                $stcoEntriesDataOffset += 4;
886                                        }
887                                }
888                                break;
889
890
891                        case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
892                                if ($ParseAllPossibleAtoms) {
893                                        $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
894                                        $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
895                                        $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
896                                        $stcoEntriesDataOffset = 8;
897                                        for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
898                                                $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
899                                                $stcoEntriesDataOffset += 8;
900                                        }
901                                }
902                                break;
903
904
905                        case 'dref': // Data REFerence atom
906                                $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
907                                $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
908                                $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
909                                $drefDataOffset = 8;
910                                for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
911                                        $atom_structure['data_references'][$i]['size']                    = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
912                                        $drefDataOffset += 4;
913                                        $atom_structure['data_references'][$i]['type']                    =               substr($atom_data, $drefDataOffset, 4);
914                                        $drefDataOffset += 4;
915                                        $atom_structure['data_references'][$i]['version']                 = getid3_lib::BigEndian2Int(substr($atom_data,  $drefDataOffset, 1));
916                                        $drefDataOffset += 1;
917                                        $atom_structure['data_references'][$i]['flags_raw']               = getid3_lib::BigEndian2Int(substr($atom_data,  $drefDataOffset, 3)); // hardcoded: 0x0000
918                                        $drefDataOffset += 3;
919                                        $atom_structure['data_references'][$i]['data']                    =               substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
920                                        $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
921
922                                        $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
923                                }
924                                break;
925
926
927                        case 'gmin': // base Media INformation atom
928                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
929                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
930                                $atom_structure['graphics_mode']          = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
931                                $atom_structure['opcolor_red']            = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
932                                $atom_structure['opcolor_green']          = getid3_lib::BigEndian2Int(substr($atom_data,  8, 2));
933                                $atom_structure['opcolor_blue']           = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
934                                $atom_structure['balance']                = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
935                                $atom_structure['reserved']               = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
936                                break;
937
938
939                        case 'smhd': // Sound Media information HeaDer atom
940                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
941                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
942                                $atom_structure['balance']                = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
943                                $atom_structure['reserved']               = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
944                                break;
945
946
947                        case 'vmhd': // Video Media information HeaDer atom
948                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
949                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
950                                $atom_structure['graphics_mode']          = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
951                                $atom_structure['opcolor_red']            = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
952                                $atom_structure['opcolor_green']          = getid3_lib::BigEndian2Int(substr($atom_data,  8, 2));
953                                $atom_structure['opcolor_blue']           = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
954
955                                $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
956                                break;
957
958
959                        case 'hdlr': // HanDLeR reference atom
960                                $atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
961                                $atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
962                                $atom_structure['component_type']         =                           substr($atom_data,  4, 4);
963                                $atom_structure['component_subtype']      =                           substr($atom_data,  8, 4);
964                                $atom_structure['component_manufacturer'] =                           substr($atom_data, 12, 4);
965                                $atom_structure['component_flags_raw']    = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
966                                $atom_structure['component_flags_mask']   = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
967                                $atom_structure['component_name']         =      $this->Pascal2String(substr($atom_data, 24));
968
969                                if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) {
970                                        $info['video']['dataformat'] = 'quicktimevr';
971                                }
972                                break;
973
974
975                        case 'mdhd': // MeDia HeaDer atom
976                                $atom_structure['version']               = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
977                                $atom_structure['flags_raw']             = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
978                                $atom_structure['creation_time']         = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
979                                $atom_structure['modify_time']           = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
980                                $atom_structure['time_scale']            = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
981                                $atom_structure['duration']              = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
982                                $atom_structure['language_id']           = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2));
983                                $atom_structure['quality']               = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2));
984
985                                if ($atom_structure['time_scale'] == 0) {
986                                        $info['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
987                                        return false;
988                                }
989                                $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
990
991                                $atom_structure['creation_time_unix']    = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
992                                $atom_structure['modify_time_unix']      = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
993                                $atom_structure['playtime_seconds']      = $atom_structure['duration'] / $atom_structure['time_scale'];
994                                $atom_structure['language']              = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
995                                if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
996                                        $info['comments']['language'][] = $atom_structure['language'];
997                                }
998                                break;
999
1000
1001                        case 'pnot': // Preview atom
1002                                $atom_structure['modification_date']      = getid3_lib::BigEndian2Int(substr($atom_data,  0, 4)); // "standard Macintosh format"
1003                                $atom_structure['version_number']         = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2)); // hardcoded: 0x00
1004                                $atom_structure['atom_type']              =               substr($atom_data,  6, 4);        // usually: 'PICT'
1005                                $atom_structure['atom_index']             = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01
1006
1007                                $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']);
1008                                break;
1009
1010
1011                        case 'crgn': // Clipping ReGioN atom
1012                                $atom_structure['region_size']   = getid3_lib::BigEndian2Int(substr($atom_data,  0, 2)); // The Region size, Region boundary box,
1013                                $atom_structure['boundary_box']  = getid3_lib::BigEndian2Int(substr($atom_data,  2, 8)); // and Clipping region data fields
1014                                $atom_structure['clipping_data'] =               substr($atom_data, 10);           // constitute a QuickDraw region.
1015                                break;
1016
1017
1018                        case 'load': // track LOAD settings atom
1019                                $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data,  0, 4));
1020                                $atom_structure['preload_duration']   = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
1021                                $atom_structure['preload_flags_raw']  = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
1022                                $atom_structure['default_hints_raw']  = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1023
1024                                $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020);
1025                                $atom_structure['default_hints']['high_quality']  = (bool) ($atom_structure['default_hints_raw'] & 0x0100);
1026                                break;
1027
1028
1029                        case 'tmcd': // TiMe CoDe atom
1030                        case 'chap': // CHAPter list atom
1031                        case 'sync': // SYNChronization atom
1032                        case 'scpt': // tranSCriPT atom
1033                        case 'ssrc': // non-primary SouRCe atom
1034                                for ($i = 0; $i < (strlen($atom_data) % 4); $i++) {
1035                                        $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4));
1036                                }
1037                                break;
1038
1039
1040                        case 'elst': // Edit LiST atom
1041                                $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
1042                                $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
1043                                $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
1044                                for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) {
1045                                        $atom_structure['edit_list'][$i]['track_duration'] =   getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4));
1046                                        $atom_structure['edit_list'][$i]['media_time']     =   getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4));
1047                                        $atom_structure['edit_list'][$i]['media_rate']     = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4));
1048                                }
1049                                break;
1050
1051
1052                        case 'kmat': // compressed MATte atom
1053                                $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
1054                                $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
1055                                $atom_structure['matte_data_raw'] =               substr($atom_data,  4);
1056                                break;
1057
1058
1059                        case 'ctab': // Color TABle atom
1060                                $atom_structure['color_table_seed']   = getid3_lib::BigEndian2Int(substr($atom_data,  0, 4)); // hardcoded: 0x00000000
1061                                $atom_structure['color_table_flags']  = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2)); // hardcoded: 0x8000
1062                                $atom_structure['color_table_size']   = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2)) + 1;
1063                                for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
1064                                        $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2));
1065                                        $atom_structure['color_table'][$colortableentry]['red']   = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2));
1066                                        $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2));
1067                                        $atom_structure['color_table'][$colortableentry]['blue']  = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2));
1068                                }
1069                                break;
1070
1071
1072                        case 'mvhd': // MoVie HeaDer atom
1073                                $atom_structure['version']            =   getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
1074                                $atom_structure['flags_raw']          =   getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
1075                                $atom_structure['creation_time']      =   getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
1076                                $atom_structure['modify_time']        =   getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
1077                                $atom_structure['time_scale']         =   getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1078                                $atom_structure['duration']           =   getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1079                                $atom_structure['preferred_rate']     = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4));
1080                                $atom_structure['preferred_volume']   =   getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2));
1081                                $atom_structure['reserved']           =                             substr($atom_data, 26, 10);
1082                                $atom_structure['matrix_a']           = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4));
1083                                $atom_structure['matrix_b']           = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1084                                $atom_structure['matrix_u']           =  getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4));
1085                                $atom_structure['matrix_c']           = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
1086                                $atom_structure['matrix_d']           = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1087                                $atom_structure['matrix_v']           =  getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4));
1088                                $atom_structure['matrix_x']           = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
1089                                $atom_structure['matrix_y']           = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
1090                                $atom_structure['matrix_w']           =  getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
1091                                $atom_structure['preview_time']       =   getid3_lib::BigEndian2Int(substr($atom_data, 72, 4));
1092                                $atom_structure['preview_duration']   =   getid3_lib::BigEndian2Int(substr($atom_data, 76, 4));
1093                                $atom_structure['poster_time']        =   getid3_lib::BigEndian2Int(substr($atom_data, 80, 4));
1094                                $atom_structure['selection_time']     =   getid3_lib::BigEndian2Int(substr($atom_data, 84, 4));
1095                                $atom_structure['selection_duration'] =   getid3_lib::BigEndian2Int(substr($atom_data, 88, 4));
1096                                $atom_structure['current_time']       =   getid3_lib::BigEndian2Int(substr($atom_data, 92, 4));
1097                                $atom_structure['next_track_id']      =   getid3_lib::BigEndian2Int(substr($atom_data, 96, 4));
1098
1099                                if ($atom_structure['time_scale'] == 0) {
1100                                        $info['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
1101                                        return false;
1102                                }
1103                                $atom_structure['creation_time_unix']        = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1104                                $atom_structure['modify_time_unix']          = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1105                                $info['quicktime']['time_scale']    = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
1106                                $info['quicktime']['display_scale'] = $atom_structure['matrix_a'];
1107                                $info['playtime_seconds']           = $atom_structure['duration'] / $atom_structure['time_scale'];
1108                                break;
1109
1110
1111                        case 'tkhd': // TracK HeaDer atom
1112                                $atom_structure['version']             =   getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
1113                                $atom_structure['flags_raw']           =   getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
1114                                $atom_structure['creation_time']       =   getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
1115                                $atom_structure['modify_time']         =   getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
1116                                $atom_structure['trackid']             =   getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1117                                $atom_structure['reserved1']           =   getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1118                                $atom_structure['duration']            =   getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
1119                                $atom_structure['reserved2']           =   getid3_lib::BigEndian2Int(substr($atom_data, 24, 8));
1120                                $atom_structure['layer']               =   getid3_lib::BigEndian2Int(substr($atom_data, 32, 2));
1121                                $atom_structure['alternate_group']     =   getid3_lib::BigEndian2Int(substr($atom_data, 34, 2));
1122                                $atom_structure['volume']              =   getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2));
1123                                $atom_structure['reserved3']           =   getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
1124                                $atom_structure['matrix_a']            = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1125                                $atom_structure['matrix_b']            = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4));
1126                                $atom_structure['matrix_u']            = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
1127                                $atom_structure['matrix_c']            = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1128                                $atom_structure['matrix_d']            = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4));
1129                                $atom_structure['matrix_v']            = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
1130                                $atom_structure['matrix_x']            =  getid3_lib::FixedPoint2_30(substr($atom_data, 64, 4));
1131                                $atom_structure['matrix_y']            =  getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
1132                                $atom_structure['matrix_w']            =  getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4));
1133                                $atom_structure['width']               = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4));
1134                                $atom_structure['height']              = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4));
1135
1136                                $atom_structure['flags']['enabled']    = (bool) ($atom_structure['flags_raw'] & 0x0001);
1137                                $atom_structure['flags']['in_movie']   = (bool) ($atom_structure['flags_raw'] & 0x0002);
1138                                $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004);
1139                                $atom_structure['flags']['in_poster']  = (bool) ($atom_structure['flags_raw'] & 0x0008);
1140                                $atom_structure['creation_time_unix']  = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1141                                $atom_structure['modify_time_unix']    = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1142
1143                                if ($atom_structure['flags']['enabled'] == 1) {
1144                                        if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
1145                                                $info['video']['resolution_x'] = $atom_structure['width'];
1146                                                $info['video']['resolution_y'] = $atom_structure['height'];
1147                                        }
1148                                        $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
1149                                        $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
1150                                        $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
1151                                        $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
1152                                } else {
1153                                        // see: http://www.getid3.org/phpBB3/viewtopic.php?t=1295
1154                                        //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); }
1155                                        //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); }
1156                                        //if (isset($info['quicktime']['video']))    { unset($info['quicktime']['video']);    }
1157                                }
1158                                break;
1159
1160
1161                        case 'iods': // Initial Object DeScriptor atom
1162                                // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h
1163                                // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html
1164                                $offset = 0;
1165                                $atom_structure['version']                =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1166                                $offset += 1;
1167                                $atom_structure['flags_raw']              =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3));
1168                                $offset += 3;
1169                                $atom_structure['mp4_iod_tag']            =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1170                                $offset += 1;
1171                                $atom_structure['length']                 = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1172                                //$offset already adjusted by quicktime_read_mp4_descr_length()
1173                                $atom_structure['object_descriptor_id']   =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));
1174                                $offset += 2;
1175                                $atom_structure['od_profile_level']       =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1176                                $offset += 1;
1177                                $atom_structure['scene_profile_level']    =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1178                                $offset += 1;
1179                                $atom_structure['audio_profile_id']       =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1180                                $offset += 1;
1181                                $atom_structure['video_profile_id']       =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1182                                $offset += 1;
1183                                $atom_structure['graphics_profile_level'] =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1184                                $offset += 1;
1185
1186                                $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields
1187                                for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) {
1188                                        $atom_structure['track'][$i]['ES_ID_IncTag'] =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1189                                        $offset += 1;
1190                                        $atom_structure['track'][$i]['length']       = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1191                                        //$offset already adjusted by quicktime_read_mp4_descr_length()
1192                                        $atom_structure['track'][$i]['track_id']     =       getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));
1193                                        $offset += 4;
1194                                }
1195
1196                                $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']);
1197                                $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']);
1198                                break;
1199
1200                        case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
1201                                $atom_structure['signature'] =                           substr($atom_data,  0, 4);
1202                                $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
1203                                $atom_structure['fourcc']    =                           substr($atom_data,  8, 4);
1204                                break;
1205
1206                        case 'mdat': // Media DATa atom
1207                        case 'free': // FREE space atom
1208                        case 'skip': // SKIP atom
1209                        case 'wide': // 64-bit expansion placeholder atom
1210                                // 'mdat' data is too big to deal with, contains no useful metadata
1211                                // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
1212
1213                                // When writing QuickTime files, it is sometimes necessary to update an atom's size.
1214                                // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
1215                                // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
1216                                // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
1217                                // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
1218                                // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
1219                                // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
1220                                break;
1221
1222
1223                        case 'nsav': // NoSAVe atom
1224                                // http://developer.apple.com/technotes/tn/tn2038.html
1225                                $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data,  0, 4));
1226                                break;
1227
1228                        case 'ctyp': // Controller TYPe atom (seen on QTVR)
1229                                // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
1230                                // some controller names are:
1231                                //   0x00 + 'std' for linear movie
1232                                //   'none' for no controls
1233                                $atom_structure['ctyp'] = substr($atom_data, 0, 4);
1234                                $info['quicktime']['controller'] = $atom_structure['ctyp'];
1235                                switch ($atom_structure['ctyp']) {
1236                                        case 'qtvr':
1237                                                $info['video']['dataformat'] = 'quicktimevr';
1238                                                break;
1239                                }
1240                                break;
1241
1242                        case 'pano': // PANOrama track (seen on QTVR)
1243                                $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data,  0, 4));
1244                                break;
1245
1246                        case 'hint': // HINT track
1247                        case 'hinf': //
1248                        case 'hinv': //
1249                        case 'hnti': //
1250                                $info['quicktime']['hinting'] = true;
1251                                break;
1252
1253                        case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
1254                                for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) {
1255                                        $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
1256                                }
1257                                break;
1258
1259
1260                        // Observed-but-not-handled atom types are just listed here to prevent warnings being generated
1261                        case 'FXTC': // Something to do with Adobe After Effects (?)
1262                        case 'PrmA':
1263                        case 'code':
1264                        case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
1265                        case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html
1266                                                // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838]
1267                                                // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html
1268                                                // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html
1269                        case 'ctts'://  STCompositionOffsetAID             - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1270                        case 'cslg'://  STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1271                        case 'sdtp'://  STSampleDependencyAID              - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1272                        case 'stps'://  STPartialSyncSampleAID             - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1273                                //$atom_structure['data'] = $atom_data;
1274                                break;
1275
1276                        case '©xyz':  // GPS latitude+longitude+altitude
1277                                $atom_structure['data'] = $atom_data;
1278                                if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
1279                                        @list($all, $latitude, $longitude, $altitude) = $matches;
1280                                        $info['quicktime']['comments']['gps_latitude'][]  = floatval($latitude);
1281                                        $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude);
1282                                        if (!empty($altitude)) {
1283                                                $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude);
1284                                        }
1285                                } else {
1286                                        $info['warning'][] = 'QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.';
1287                                }
1288                                break;
1289
1290                        case 'NCDT':
1291                                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1292                                // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1293                                $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
1294                                break;
1295                        case 'NCTH': // Nikon Camera THumbnail image
1296                        case 'NCVW': // Nikon Camera preVieW image
1297                                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1298                                if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) {
1299                                        $atom_structure['data'] = $atom_data;
1300                                        $atom_structure['image_mime'] = 'image/jpeg';
1301                                        $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image'));
1302                                        $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']);
1303                                }
1304                                break;
1305                        case 'NCHD': // MakerNoteVersion
1306                                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1307                                $atom_structure['data'] = $atom_data;
1308                                break;
1309                        case 'NCTG': // NikonTags
1310                                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1311                                $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
1312                                break;
1313                        case 'NCDB': // NikonTags
1314                                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1315                                $atom_structure['data'] = $atom_data;
1316                                break;
1317
1318                        case "\x00\x00\x00\x00":
1319                        case 'meta': // METAdata atom
1320                                // some kind of metacontainer, may contain a big data dump such as:
1321                                // mdta keys mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst data DEApple 0 (data DE2011-05-11T17:54:04+0200 2 *data DE+52.4936+013.3897+040.247/ data DE4.3.1 data DEiPhone 4
1322                                // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
1323
1324                    $atom_structure['version']   =          getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1325                    $atom_structure['flags_raw'] =          getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1326                    $atom_structure['subatoms']  = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1327                                //$atom_structure['subatoms']  = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1328                                break;
1329
1330                        case 'data': // metaDATA atom
1331                                // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data
1332                                $atom_structure['language'] =                           substr($atom_data, 4 + 0, 2);
1333                                $atom_structure['unknown']  = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2));
1334                                $atom_structure['data']     =                           substr($atom_data, 4 + 4);
1335                                break;
1336
1337                        default:
1338                                $info['warning'][] = 'Unknown QuickTime atom type: "'.$atomname.'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset;
1339                                $atom_structure['data'] = $atom_data;
1340                                break;
1341                }
1342                array_pop($atomHierarchy);
1343                return $atom_structure;
1344        }
1345
1346        public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
1347//echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'<br><br>';
1348                $atom_structure  = false;
1349                $subatomoffset  = 0;
1350                $subatomcounter = 0;
1351                if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) {
1352                        return false;
1353                }
1354                while ($subatomoffset < strlen($atom_data)) {
1355                        $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4));
1356                        $subatomname =                           substr($atom_data, $subatomoffset + 4, 4);
1357                        $subatomdata =                           substr($atom_data, $subatomoffset + 8, $subatomsize - 8);
1358                        if ($subatomsize == 0) {
1359                                // Furthermore, for historical reasons the list of atoms is optionally
1360                                // terminated by a 32-bit integer set to 0. If you are writing a program
1361                                // to read user data atoms, you should allow for the terminating 0.
1362                                return $atom_structure;
1363                        }
1364
1365                        $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
1366
1367                        $subatomoffset += $subatomsize;
1368                        $subatomcounter++;
1369                }
1370                return $atom_structure;
1371        }
1372
1373
1374        public function quicktime_read_mp4_descr_length($data, &$offset) {
1375                // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html
1376                $num_bytes = 0;
1377                $length    = 0;
1378                do {
1379                        $b = ord(substr($data, $offset++, 1));
1380                        $length = ($length << 7) | ($b & 0x7F);
1381                } while (($b & 0x80) && ($num_bytes++ < 4));
1382                return $length;
1383        }
1384
1385
1386        public function QuicktimeLanguageLookup($languageid) {
1387                static $QuicktimeLanguageLookup = array();
1388                if (empty($QuicktimeLanguageLookup)) {
1389                        $QuicktimeLanguageLookup[0]   = 'English';
1390                        $QuicktimeLanguageLookup[1]   = 'French';
1391                        $QuicktimeLanguageLookup[2]   = 'German';
1392                        $QuicktimeLanguageLookup[3]   = 'Italian';
1393                        $QuicktimeLanguageLookup[4]   = 'Dutch';
1394                        $QuicktimeLanguageLookup[5]   = 'Swedish';
1395                        $QuicktimeLanguageLookup[6]   = 'Spanish';
1396                        $QuicktimeLanguageLookup[7]   = 'Danish';
1397                        $QuicktimeLanguageLookup[8]   = 'Portuguese';
1398                        $QuicktimeLanguageLookup[9]   = 'Norwegian';
1399                        $QuicktimeLanguageLookup[10]  = 'Hebrew';
1400                        $QuicktimeLanguageLookup[11]  = 'Japanese';
1401                        $QuicktimeLanguageLookup[12]  = 'Arabic';
1402                        $QuicktimeLanguageLookup[13]  = 'Finnish';
1403                        $QuicktimeLanguageLookup[14]  = 'Greek';
1404                        $QuicktimeLanguageLookup[15]  = 'Icelandic';
1405                        $QuicktimeLanguageLookup[16]  = 'Maltese';
1406                        $QuicktimeLanguageLookup[17]  = 'Turkish';
1407                        $QuicktimeLanguageLookup[18]  = 'Croatian';
1408                        $QuicktimeLanguageLookup[19]  = 'Chinese (Traditional)';
1409                        $QuicktimeLanguageLookup[20]  = 'Urdu';
1410                        $QuicktimeLanguageLookup[21]  = 'Hindi';
1411                        $QuicktimeLanguageLookup[22]  = 'Thai';
1412                        $QuicktimeLanguageLookup[23]  = 'Korean';
1413                        $QuicktimeLanguageLookup[24]  = 'Lithuanian';
1414                        $QuicktimeLanguageLookup[25]  = 'Polish';
1415                        $QuicktimeLanguageLookup[26]  = 'Hungarian';
1416                        $QuicktimeLanguageLookup[27]  = 'Estonian';
1417                        $QuicktimeLanguageLookup[28]  = 'Lettish';
1418                        $QuicktimeLanguageLookup[28]  = 'Latvian';
1419                        $QuicktimeLanguageLookup[29]  = 'Saamisk';
1420                        $QuicktimeLanguageLookup[29]  = 'Lappish';
1421                        $QuicktimeLanguageLookup[30]  = 'Faeroese';
1422                        $QuicktimeLanguageLookup[31]  = 'Farsi';
1423                        $QuicktimeLanguageLookup[31]  = 'Persian';
1424                        $QuicktimeLanguageLookup[32]  = 'Russian';
1425                        $QuicktimeLanguageLookup[33]  = 'Chinese (Simplified)';
1426                        $QuicktimeLanguageLookup[34]  = 'Flemish';
1427                        $QuicktimeLanguageLookup[35]  = 'Irish';
1428                        $QuicktimeLanguageLookup[36]  = 'Albanian';
1429                        $QuicktimeLanguageLookup[37]  = 'Romanian';
1430                        $QuicktimeLanguageLookup[38]  = 'Czech';
1431                        $QuicktimeLanguageLookup[39]  = 'Slovak';
1432                        $QuicktimeLanguageLookup[40]  = 'Slovenian';
1433                        $QuicktimeLanguageLookup[41]  = 'Yiddish';
1434                        $QuicktimeLanguageLookup[42]  = 'Serbian';
1435                        $QuicktimeLanguageLookup[43]  = 'Macedonian';
1436                        $QuicktimeLanguageLookup[44]  = 'Bulgarian';
1437                        $QuicktimeLanguageLookup[45]  = 'Ukrainian';
1438                        $QuicktimeLanguageLookup[46]  = 'Byelorussian';
1439                        $QuicktimeLanguageLookup[47]  = 'Uzbek';
1440                        $QuicktimeLanguageLookup[48]  = 'Kazakh';
1441                        $QuicktimeLanguageLookup[49]  = 'Azerbaijani';
1442                        $QuicktimeLanguageLookup[50]  = 'AzerbaijanAr';
1443                        $QuicktimeLanguageLookup[51]  = 'Armenian';
1444                        $QuicktimeLanguageLookup[52]  = 'Georgian';
1445                        $QuicktimeLanguageLookup[53]  = 'Moldavian';
1446                        $QuicktimeLanguageLookup[54]  = 'Kirghiz';
1447                        $QuicktimeLanguageLookup[55]  = 'Tajiki';
1448                        $QuicktimeLanguageLookup[56]  = 'Turkmen';
1449                        $QuicktimeLanguageLookup[57]  = 'Mongolian';
1450                        $QuicktimeLanguageLookup[58]  = 'MongolianCyr';
1451                        $QuicktimeLanguageLookup[59]  = 'Pashto';
1452                        $QuicktimeLanguageLookup[60]  = 'Kurdish';
1453                        $QuicktimeLanguageLookup[61]  = 'Kashmiri';
1454                        $QuicktimeLanguageLookup[62]  = 'Sindhi';
1455                        $QuicktimeLanguageLookup[63]  = 'Tibetan';
1456                        $QuicktimeLanguageLookup[64]  = 'Nepali';
1457                        $QuicktimeLanguageLookup[65]  = 'Sanskrit';
1458                        $QuicktimeLanguageLookup[66]  = 'Marathi';
1459                        $QuicktimeLanguageLookup[67]  = 'Bengali';
1460                        $QuicktimeLanguageLookup[68]  = 'Assamese';
1461                        $QuicktimeLanguageLookup[69]  = 'Gujarati';
1462                        $QuicktimeLanguageLookup[70]  = 'Punjabi';
1463                        $QuicktimeLanguageLookup[71]  = 'Oriya';
1464                        $QuicktimeLanguageLookup[72]  = 'Malayalam';
1465                        $QuicktimeLanguageLookup[73]  = 'Kannada';
1466                        $QuicktimeLanguageLookup[74]  = 'Tamil';
1467                        $QuicktimeLanguageLookup[75]  = 'Telugu';
1468                        $QuicktimeLanguageLookup[76]  = 'Sinhalese';
1469                        $QuicktimeLanguageLookup[77]  = 'Burmese';
1470                        $QuicktimeLanguageLookup[78]  = 'Khmer';
1471                        $QuicktimeLanguageLookup[79]  = 'Lao';
1472                        $QuicktimeLanguageLookup[80]  = 'Vietnamese';
1473                        $QuicktimeLanguageLookup[81]  = 'Indonesian';
1474                        $QuicktimeLanguageLookup[82]  = 'Tagalog';
1475                        $QuicktimeLanguageLookup[83]  = 'MalayRoman';
1476                        $QuicktimeLanguageLookup[84]  = 'MalayArabic';
1477                        $QuicktimeLanguageLookup[85]  = 'Amharic';
1478                        $QuicktimeLanguageLookup[86]  = 'Tigrinya';
1479                        $QuicktimeLanguageLookup[87]  = 'Galla';
1480                        $QuicktimeLanguageLookup[87]  = 'Oromo';
1481                        $QuicktimeLanguageLookup[88]  = 'Somali';
1482                        $QuicktimeLanguageLookup[89]  = 'Swahili';
1483                        $QuicktimeLanguageLookup[90]  = 'Ruanda';
1484                        $QuicktimeLanguageLookup[91]  = 'Rundi';
1485                        $QuicktimeLanguageLookup[92]  = 'Chewa';
1486                        $QuicktimeLanguageLookup[93]  = 'Malagasy';
1487                        $QuicktimeLanguageLookup[94]  = 'Esperanto';
1488                        $QuicktimeLanguageLookup[128] = 'Welsh';
1489                        $QuicktimeLanguageLookup[129] = 'Basque';
1490                        $QuicktimeLanguageLookup[130] = 'Catalan';
1491                        $QuicktimeLanguageLookup[131] = 'Latin';
1492                        $QuicktimeLanguageLookup[132] = 'Quechua';
1493                        $QuicktimeLanguageLookup[133] = 'Guarani';
1494                        $QuicktimeLanguageLookup[134] = 'Aymara';
1495                        $QuicktimeLanguageLookup[135] = 'Tatar';
1496                        $QuicktimeLanguageLookup[136] = 'Uighur';
1497                        $QuicktimeLanguageLookup[137] = 'Dzongkha';
1498                        $QuicktimeLanguageLookup[138] = 'JavaneseRom';
1499                }
1500                return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
1501        }
1502
1503        public function QuicktimeVideoCodecLookup($codecid) {
1504                static $QuicktimeVideoCodecLookup = array();
1505                if (empty($QuicktimeVideoCodecLookup)) {
1506                        $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
1507                        $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
1508                        $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
1509                        $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
1510                        $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
1511                        $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC';
1512                        $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
1513                        $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
1514                        $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
1515                        $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
1516                        $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
1517                        $QuicktimeVideoCodecLookup['base'] = 'Base';
1518                        $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
1519                        $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
1520                        $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
1521                        $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
1522                        $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
1523                        $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
1524                        $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
1525                        $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
1526                        $QuicktimeVideoCodecLookup['fire'] = 'Fire';
1527                        $QuicktimeVideoCodecLookup['flic'] = 'FLC';
1528                        $QuicktimeVideoCodecLookup['gif '] = 'GIF';
1529                        $QuicktimeVideoCodecLookup['h261'] = 'H261';
1530                        $QuicktimeVideoCodecLookup['h263'] = 'H263';
1531                        $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
1532                        $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
1533                        $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
1534                        $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
1535                        $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
1536                        $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
1537                        $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
1538                        $QuicktimeVideoCodecLookup['path'] = 'Vector';
1539                        $QuicktimeVideoCodecLookup['png '] = 'PNG';
1540                        $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
1541                        $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
1542                        $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
1543                        $QuicktimeVideoCodecLookup['raw '] = 'RAW';
1544                        $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
1545                        $QuicktimeVideoCodecLookup['rpza'] = 'Video';
1546                        $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
1547                        $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
1548                        $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
1549                        $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
1550                        $QuicktimeVideoCodecLookup['tga '] = 'Targa';
1551                        $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
1552                        $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
1553                        $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
1554                        $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
1555                        $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
1556                        $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
1557                        $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
1558                }
1559                return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
1560        }
1561
1562        public function QuicktimeAudioCodecLookup($codecid) {
1563                static $QuicktimeAudioCodecLookup = array();
1564                if (empty($QuicktimeAudioCodecLookup)) {
1565                        $QuicktimeAudioCodecLookup['.mp3']          = 'Fraunhofer MPEG Layer-III alias';
1566                        $QuicktimeAudioCodecLookup['aac ']          = 'ISO/IEC 14496-3 AAC';
1567                        $QuicktimeAudioCodecLookup['agsm']          = 'Apple GSM 10:1';
1568                        $QuicktimeAudioCodecLookup['alac']          = 'Apple Lossless Audio Codec';
1569                        $QuicktimeAudioCodecLookup['alaw']          = 'A-law 2:1';
1570                        $QuicktimeAudioCodecLookup['conv']          = 'Sample Format';
1571                        $QuicktimeAudioCodecLookup['dvca']          = 'DV';
1572                        $QuicktimeAudioCodecLookup['dvi ']          = 'DV 4:1';
1573                        $QuicktimeAudioCodecLookup['eqal']          = 'Frequency Equalizer';
1574                        $QuicktimeAudioCodecLookup['fl32']          = '32-bit Floating Point';
1575                        $QuicktimeAudioCodecLookup['fl64']          = '64-bit Floating Point';
1576                        $QuicktimeAudioCodecLookup['ima4']          = 'Interactive Multimedia Association 4:1';
1577                        $QuicktimeAudioCodecLookup['in24']          = '24-bit Integer';
1578                        $QuicktimeAudioCodecLookup['in32']          = '32-bit Integer';
1579                        $QuicktimeAudioCodecLookup['lpc ']          = 'LPC 23:1';
1580                        $QuicktimeAudioCodecLookup['MAC3']          = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
1581                        $QuicktimeAudioCodecLookup['MAC6']          = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
1582                        $QuicktimeAudioCodecLookup['mixb']          = '8-bit Mixer';
1583                        $QuicktimeAudioCodecLookup['mixw']          = '16-bit Mixer';
1584                        $QuicktimeAudioCodecLookup['mp4a']          = 'ISO/IEC 14496-3 AAC';
1585                        $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
1586                        $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
1587                        $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
1588                        $QuicktimeAudioCodecLookup['NONE']          = 'No Encoding';
1589                        $QuicktimeAudioCodecLookup['Qclp']          = 'Qualcomm PureVoice';
1590                        $QuicktimeAudioCodecLookup['QDM2']          = 'QDesign Music 2';
1591                        $QuicktimeAudioCodecLookup['QDMC']          = 'QDesign Music 1';
1592                        $QuicktimeAudioCodecLookup['ratb']          = '8-bit Rate';
1593                        $QuicktimeAudioCodecLookup['ratw']          = '16-bit Rate';
1594                        $QuicktimeAudioCodecLookup['raw ']          = 'raw PCM';
1595                        $QuicktimeAudioCodecLookup['sour']          = 'Sound Source';
1596                        $QuicktimeAudioCodecLookup['sowt']          = 'signed/two\'s complement (Little Endian)';
1597                        $QuicktimeAudioCodecLookup['str1']          = 'Iomega MPEG layer II';
1598                        $QuicktimeAudioCodecLookup['str2']          = 'Iomega MPEG *layer II';
1599                        $QuicktimeAudioCodecLookup['str3']          = 'Iomega MPEG **layer II';
1600                        $QuicktimeAudioCodecLookup['str4']          = 'Iomega MPEG ***layer II';
1601                        $QuicktimeAudioCodecLookup['twos']          = 'signed/two\'s complement (Big Endian)';
1602                        $QuicktimeAudioCodecLookup['ulaw']          = 'mu-law 2:1';
1603                }
1604                return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
1605        }
1606
1607        public function QuicktimeDCOMLookup($compressionid) {
1608                static $QuicktimeDCOMLookup = array();
1609                if (empty($QuicktimeDCOMLookup)) {
1610                        $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
1611                        $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
1612                }
1613                return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
1614        }
1615
1616        public function QuicktimeColorNameLookup($colordepthid) {
1617                static $QuicktimeColorNameLookup = array();
1618                if (empty($QuicktimeColorNameLookup)) {
1619                        $QuicktimeColorNameLookup[1]  = '2-color (monochrome)';
1620                        $QuicktimeColorNameLookup[2]  = '4-color';
1621                        $QuicktimeColorNameLookup[4]  = '16-color';
1622                        $QuicktimeColorNameLookup[8]  = '256-color';
1623                        $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
1624                        $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
1625                        $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
1626                        $QuicktimeColorNameLookup[33] = 'black & white';
1627                        $QuicktimeColorNameLookup[34] = '4-gray';
1628                        $QuicktimeColorNameLookup[36] = '16-gray';
1629                        $QuicktimeColorNameLookup[40] = '256-gray';
1630                }
1631                return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
1632        }
1633
1634        public function QuicktimeSTIKLookup($stik) {
1635                static $QuicktimeSTIKLookup = array();
1636                if (empty($QuicktimeSTIKLookup)) {
1637                        $QuicktimeSTIKLookup[0]  = 'Movie';
1638                        $QuicktimeSTIKLookup[1]  = 'Normal';
1639                        $QuicktimeSTIKLookup[2]  = 'Audiobook';
1640                        $QuicktimeSTIKLookup[5]  = 'Whacked Bookmark';
1641                        $QuicktimeSTIKLookup[6]  = 'Music Video';
1642                        $QuicktimeSTIKLookup[9]  = 'Short Film';
1643                        $QuicktimeSTIKLookup[10] = 'TV Show';
1644                        $QuicktimeSTIKLookup[11] = 'Booklet';
1645                        $QuicktimeSTIKLookup[14] = 'Ringtone';
1646                        $QuicktimeSTIKLookup[21] = 'Podcast';
1647                }
1648                return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid');
1649        }
1650
1651        public function QuicktimeIODSaudioProfileName($audio_profile_id) {
1652                static $QuicktimeIODSaudioProfileNameLookup = array();
1653                if (empty($QuicktimeIODSaudioProfileNameLookup)) {
1654                        $QuicktimeIODSaudioProfileNameLookup = array(
1655                            0x00 => 'ISO Reserved (0x00)',
1656                            0x01 => 'Main Audio Profile @ Level 1',
1657                            0x02 => 'Main Audio Profile @ Level 2',
1658                            0x03 => 'Main Audio Profile @ Level 3',
1659                            0x04 => 'Main Audio Profile @ Level 4',
1660                            0x05 => 'Scalable Audio Profile @ Level 1',
1661                            0x06 => 'Scalable Audio Profile @ Level 2',
1662                            0x07 => 'Scalable Audio Profile @ Level 3',
1663                            0x08 => 'Scalable Audio Profile @ Level 4',
1664                            0x09 => 'Speech Audio Profile @ Level 1',
1665                            0x0A => 'Speech Audio Profile @ Level 2',
1666                            0x0B => 'Synthetic Audio Profile @ Level 1',
1667                            0x0C => 'Synthetic Audio Profile @ Level 2',
1668                            0x0D => 'Synthetic Audio Profile @ Level 3',
1669                            0x0E => 'High Quality Audio Profile @ Level 1',
1670                            0x0F => 'High Quality Audio Profile @ Level 2',
1671                            0x10 => 'High Quality Audio Profile @ Level 3',
1672                            0x11 => 'High Quality Audio Profile @ Level 4',
1673                            0x12 => 'High Quality Audio Profile @ Level 5',
1674                            0x13 => 'High Quality Audio Profile @ Level 6',
1675                            0x14 => 'High Quality Audio Profile @ Level 7',
1676                            0x15 => 'High Quality Audio Profile @ Level 8',
1677                            0x16 => 'Low Delay Audio Profile @ Level 1',
1678                            0x17 => 'Low Delay Audio Profile @ Level 2',
1679                            0x18 => 'Low Delay Audio Profile @ Level 3',
1680                            0x19 => 'Low Delay Audio Profile @ Level 4',
1681                            0x1A => 'Low Delay Audio Profile @ Level 5',
1682                            0x1B => 'Low Delay Audio Profile @ Level 6',
1683                            0x1C => 'Low Delay Audio Profile @ Level 7',
1684                            0x1D => 'Low Delay Audio Profile @ Level 8',
1685                            0x1E => 'Natural Audio Profile @ Level 1',
1686                            0x1F => 'Natural Audio Profile @ Level 2',
1687                            0x20 => 'Natural Audio Profile @ Level 3',
1688                            0x21 => 'Natural Audio Profile @ Level 4',
1689                            0x22 => 'Mobile Audio Internetworking Profile @ Level 1',
1690                            0x23 => 'Mobile Audio Internetworking Profile @ Level 2',
1691                            0x24 => 'Mobile Audio Internetworking Profile @ Level 3',
1692                            0x25 => 'Mobile Audio Internetworking Profile @ Level 4',
1693                            0x26 => 'Mobile Audio Internetworking Profile @ Level 5',
1694                            0x27 => 'Mobile Audio Internetworking Profile @ Level 6',
1695                            0x28 => 'AAC Profile @ Level 1',
1696                            0x29 => 'AAC Profile @ Level 2',
1697                            0x2A => 'AAC Profile @ Level 4',
1698                            0x2B => 'AAC Profile @ Level 5',
1699                            0x2C => 'High Efficiency AAC Profile @ Level 2',
1700                            0x2D => 'High Efficiency AAC Profile @ Level 3',
1701                            0x2E => 'High Efficiency AAC Profile @ Level 4',
1702                            0x2F => 'High Efficiency AAC Profile @ Level 5',
1703                            0xFE => 'Not part of MPEG-4 audio profiles',
1704                            0xFF => 'No audio capability required',
1705                        );
1706                }
1707                return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private');
1708        }
1709
1710
1711        public function QuicktimeIODSvideoProfileName($video_profile_id) {
1712                static $QuicktimeIODSvideoProfileNameLookup = array();
1713                if (empty($QuicktimeIODSvideoProfileNameLookup)) {
1714                        $QuicktimeIODSvideoProfileNameLookup = array(
1715                                0x00 => 'Reserved (0x00) Profile',
1716                                0x01 => 'Simple Profile @ Level 1',
1717                                0x02 => 'Simple Profile @ Level 2',
1718                                0x03 => 'Simple Profile @ Level 3',
1719                                0x08 => 'Simple Profile @ Level 0',
1720                                0x10 => 'Simple Scalable Profile @ Level 0',
1721                                0x11 => 'Simple Scalable Profile @ Level 1',
1722                                0x12 => 'Simple Scalable Profile @ Level 2',
1723                                0x15 => 'AVC/H264 Profile',
1724                                0x21 => 'Core Profile @ Level 1',
1725                                0x22 => 'Core Profile @ Level 2',
1726                                0x32 => 'Main Profile @ Level 2',
1727                                0x33 => 'Main Profile @ Level 3',
1728                                0x34 => 'Main Profile @ Level 4',
1729                                0x42 => 'N-bit Profile @ Level 2',
1730                                0x51 => 'Scalable Texture Profile @ Level 1',
1731                                0x61 => 'Simple Face Animation Profile @ Level 1',
1732                                0x62 => 'Simple Face Animation Profile @ Level 2',
1733                                0x63 => 'Simple FBA Profile @ Level 1',
1734                                0x64 => 'Simple FBA Profile @ Level 2',
1735                                0x71 => 'Basic Animated Texture Profile @ Level 1',
1736                                0x72 => 'Basic Animated Texture Profile @ Level 2',
1737                                0x81 => 'Hybrid Profile @ Level 1',
1738                                0x82 => 'Hybrid Profile @ Level 2',
1739                                0x91 => 'Advanced Real Time Simple Profile @ Level 1',
1740                                0x92 => 'Advanced Real Time Simple Profile @ Level 2',
1741                                0x93 => 'Advanced Real Time Simple Profile @ Level 3',
1742                                0x94 => 'Advanced Real Time Simple Profile @ Level 4',
1743                                0xA1 => 'Core Scalable Profile @ Level1',
1744                                0xA2 => 'Core Scalable Profile @ Level2',
1745                                0xA3 => 'Core Scalable Profile @ Level3',
1746                                0xB1 => 'Advanced Coding Efficiency Profile @ Level 1',
1747                                0xB2 => 'Advanced Coding Efficiency Profile @ Level 2',
1748                                0xB3 => 'Advanced Coding Efficiency Profile @ Level 3',
1749                                0xB4 => 'Advanced Coding Efficiency Profile @ Level 4',
1750                                0xC1 => 'Advanced Core Profile @ Level 1',
1751                                0xC2 => 'Advanced Core Profile @ Level 2',
1752                                0xD1 => 'Advanced Scalable Texture @ Level1',
1753                                0xD2 => 'Advanced Scalable Texture @ Level2',
1754                                0xE1 => 'Simple Studio Profile @ Level 1',
1755                                0xE2 => 'Simple Studio Profile @ Level 2',
1756                                0xE3 => 'Simple Studio Profile @ Level 3',
1757                                0xE4 => 'Simple Studio Profile @ Level 4',
1758                                0xE5 => 'Core Studio Profile @ Level 1',
1759                                0xE6 => 'Core Studio Profile @ Level 2',
1760                                0xE7 => 'Core Studio Profile @ Level 3',
1761                                0xE8 => 'Core Studio Profile @ Level 4',
1762                                0xF0 => 'Advanced Simple Profile @ Level 0',
1763                                0xF1 => 'Advanced Simple Profile @ Level 1',
1764                                0xF2 => 'Advanced Simple Profile @ Level 2',
1765                                0xF3 => 'Advanced Simple Profile @ Level 3',
1766                                0xF4 => 'Advanced Simple Profile @ Level 4',
1767                                0xF5 => 'Advanced Simple Profile @ Level 5',
1768                                0xF7 => 'Advanced Simple Profile @ Level 3b',
1769                                0xF8 => 'Fine Granularity Scalable Profile @ Level 0',
1770                                0xF9 => 'Fine Granularity Scalable Profile @ Level 1',
1771                                0xFA => 'Fine Granularity Scalable Profile @ Level 2',
1772                                0xFB => 'Fine Granularity Scalable Profile @ Level 3',
1773                                0xFC => 'Fine Granularity Scalable Profile @ Level 4',
1774                                0xFD => 'Fine Granularity Scalable Profile @ Level 5',
1775                                0xFE => 'Not part of MPEG-4 Visual profiles',
1776                                0xFF => 'No visual capability required',
1777                        );
1778                }
1779                return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile');
1780        }
1781
1782
1783        public function QuicktimeContentRatingLookup($rtng) {
1784                static $QuicktimeContentRatingLookup = array();
1785                if (empty($QuicktimeContentRatingLookup)) {
1786                        $QuicktimeContentRatingLookup[0]  = 'None';
1787                        $QuicktimeContentRatingLookup[2]  = 'Clean';
1788                        $QuicktimeContentRatingLookup[4]  = 'Explicit';
1789                }
1790                return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid');
1791        }
1792
1793        public function QuicktimeStoreAccountTypeLookup($akid) {
1794                static $QuicktimeStoreAccountTypeLookup = array();
1795                if (empty($QuicktimeStoreAccountTypeLookup)) {
1796                        $QuicktimeStoreAccountTypeLookup[0] = 'iTunes';
1797                        $QuicktimeStoreAccountTypeLookup[1] = 'AOL';
1798                }
1799                return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid');
1800        }
1801
1802        public function QuicktimeStoreFrontCodeLookup($sfid) {
1803                static $QuicktimeStoreFrontCodeLookup = array();
1804                if (empty($QuicktimeStoreFrontCodeLookup)) {
1805                        $QuicktimeStoreFrontCodeLookup[143460] = 'Australia';
1806                        $QuicktimeStoreFrontCodeLookup[143445] = 'Austria';
1807                        $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium';
1808                        $QuicktimeStoreFrontCodeLookup[143455] = 'Canada';
1809                        $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark';
1810                        $QuicktimeStoreFrontCodeLookup[143447] = 'Finland';
1811                        $QuicktimeStoreFrontCodeLookup[143442] = 'France';
1812                        $QuicktimeStoreFrontCodeLookup[143443] = 'Germany';
1813                        $QuicktimeStoreFrontCodeLookup[143448] = 'Greece';
1814                        $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland';
1815                        $QuicktimeStoreFrontCodeLookup[143450] = 'Italy';
1816                        $QuicktimeStoreFrontCodeLookup[143462] = 'Japan';
1817                        $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg';
1818                        $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands';
1819                        $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand';
1820                        $QuicktimeStoreFrontCodeLookup[143457] = 'Norway';
1821                        $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal';
1822                        $QuicktimeStoreFrontCodeLookup[143454] = 'Spain';
1823                        $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden';
1824                        $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland';
1825                        $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom';
1826                        $QuicktimeStoreFrontCodeLookup[143441] = 'United States';
1827                }
1828                return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid');
1829        }
1830
1831        public function QuicktimeParseNikonNCTG($atom_data) {
1832                // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1833                // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1834                // Data is stored as records of:
1835                // * 4 bytes record type
1836                // * 2 bytes size of data field type:
1837                //     0x0001 = flag   (size field *= 1-byte)
1838                //     0x0002 = char   (size field *= 1-byte)
1839                //     0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1840                //     0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
1841                //     0x0005 = float  (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
1842                //     0x0007 = bytes  (size field *= 1-byte), values are stored as ??????
1843                //     0x0008 = ?????  (size field *= 2-byte), values are stored as ??????
1844                // * 2 bytes data size field
1845                // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15")
1846                // all integers are stored BigEndian
1847
1848                $NCTGtagName = array(
1849                        0x00000001 => 'Make',
1850                        0x00000002 => 'Model',
1851                        0x00000003 => 'Software',
1852                        0x00000011 => 'CreateDate',
1853                        0x00000012 => 'DateTimeOriginal',
1854                        0x00000013 => 'FrameCount',
1855                        0x00000016 => 'FrameRate',
1856                        0x00000022 => 'FrameWidth',
1857                        0x00000023 => 'FrameHeight',
1858                        0x00000032 => 'AudioChannels',
1859                        0x00000033 => 'AudioBitsPerSample',
1860                        0x00000034 => 'AudioSampleRate',
1861                        0x02000001 => 'MakerNoteVersion',
1862                        0x02000005 => 'WhiteBalance',
1863                        0x0200000b => 'WhiteBalanceFineTune',
1864                        0x0200001e => 'ColorSpace',
1865                        0x02000023 => 'PictureControlData',
1866                        0x02000024 => 'WorldTime',
1867                        0x02000032 => 'UnknownInfo',
1868                        0x02000083 => 'LensType',
1869                        0x02000084 => 'Lens',
1870                );
1871
1872                $offset = 0;
1873                $datalength = strlen($atom_data);
1874                $parsed = array();
1875                while ($offset < $datalength) {
1876//echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'<br>';
1877                        $record_type       = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));  $offset += 4;
1878                        $data_size_type    = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));  $offset += 2;
1879                        $data_size         = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));  $offset += 2;
1880                        switch ($data_size_type) {
1881                                case 0x0001: // 0x0001 = flag   (size field *= 1-byte)
1882                                        $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1));
1883                                        $offset += ($data_size * 1);
1884                                        break;
1885                                case 0x0002: // 0x0002 = char   (size field *= 1-byte)
1886                                        $data = substr($atom_data, $offset, $data_size * 1);
1887                                        $offset += ($data_size * 1);
1888                                        $data = rtrim($data, "\x00");
1889                                        break;
1890                                case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1891                                        $data = '';
1892                                        for ($i = $data_size - 1; $i >= 0; $i--) {
1893                                                $data .= substr($atom_data, $offset + ($i * 2), 2);
1894                                        }
1895                                        $data = getid3_lib::BigEndian2Int($data);
1896                                        $offset += ($data_size * 2);
1897                                        break;
1898                                case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
1899                                        $data = '';
1900                                        for ($i = $data_size - 1; $i >= 0; $i--) {
1901                                                $data .= substr($atom_data, $offset + ($i * 4), 4);
1902                                        }
1903                                        $data = getid3_lib::BigEndian2Int($data);
1904                                        $offset += ($data_size * 4);
1905                                        break;
1906                                case 0x0005: // 0x0005 = float  (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
1907                                        $data = array();
1908                                        for ($i = 0; $i < $data_size; $i++) {
1909                                                $numerator    = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4));
1910                                                $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4));
1911                                                if ($denomninator == 0) {
1912                                                        $data[$i] = false;
1913                                                } else {
1914                                                        $data[$i] = (double) $numerator / $denomninator;
1915                                                }
1916                                        }
1917                                        $offset += (8 * $data_size);
1918                                        if (count($data) == 1) {
1919                                                $data = $data[0];
1920                                        }
1921                                        break;
1922                                case 0x0007: // 0x0007 = bytes  (size field *= 1-byte), values are stored as ??????
1923                                        $data = substr($atom_data, $offset, $data_size * 1);
1924                                        $offset += ($data_size * 1);
1925                                        break;
1926                                case 0x0008: // 0x0008 = ?????  (size field *= 2-byte), values are stored as ??????
1927                                        $data = substr($atom_data, $offset, $data_size * 2);
1928                                        $offset += ($data_size * 2);
1929                                        break;
1930                                default:
1931echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>';
1932                                        break 2;
1933                        }
1934
1935                        switch ($record_type) {
1936                                case 0x00000011: // CreateDate
1937                                case 0x00000012: // DateTimeOriginal
1938                                        $data = strtotime($data);
1939                                        break;
1940                                case 0x0200001e: // ColorSpace
1941                                        switch ($data) {
1942                                                case 1:
1943                                                        $data = 'sRGB';
1944                                                        break;
1945                                                case 2:
1946                                                        $data = 'Adobe RGB';
1947                                                        break;
1948                                        }
1949                                        break;
1950                                case 0x02000023: // PictureControlData
1951                                        $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full');
1952                                        $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange',    0x83=>'red', 0x84=>'green',  0xff=>'n/a');
1953                                        $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');
1954                                        $data = array(
1955                                                'PictureControlVersion'     =>                           substr($data,  0,  4),
1956                                                'PictureControlName'        =>                     rtrim(substr($data,  4, 20), "\x00"),
1957                                                'PictureControlBase'        =>                     rtrim(substr($data, 24, 20), "\x00"),
1958                                                //'?'                       =>                           substr($data, 44,  4),
1959                                                'PictureControlAdjust'      => $PictureControlAdjust[ord(substr($data, 48,  1))],
1960                                                'PictureControlQuickAdjust' =>                       ord(substr($data, 49,  1)),
1961                                                'Sharpness'                 =>                       ord(substr($data, 50,  1)),
1962                                                'Contrast'                  =>                       ord(substr($data, 51,  1)),
1963                                                'Brightness'                =>                       ord(substr($data, 52,  1)),
1964                                                'Saturation'                =>                       ord(substr($data, 53,  1)),
1965                                                'HueAdjustment'             =>                       ord(substr($data, 54,  1)),
1966                                                'FilterEffect'              =>         $FilterEffect[ord(substr($data, 55,  1))],
1967                                                'ToningEffect'              =>         $ToningEffect[ord(substr($data, 56,  1))],
1968                                                'ToningSaturation'          =>                       ord(substr($data, 57,  1)),
1969                                        );
1970                                        break;
1971                                case 0x02000024: // WorldTime
1972                                        // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime
1973                                        // timezone is stored as offset from GMT in minutes
1974                                        $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2));
1975                                        if ($timezone & 0x8000) {
1976                                                $timezone = 0 - (0x10000 - $timezone);
1977                                        }
1978                                        $timezone /= 60;
1979
1980                                        $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1));
1981                                        switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) {
1982                                                case 2:
1983                                                        $datedisplayformat = 'D/M/Y'; break;
1984                                                case 1:
1985                                                        $datedisplayformat = 'M/D/Y'; break;
1986                                                case 0:
1987                                                default:
1988                                                        $datedisplayformat = 'Y/M/D'; break;
1989                                        }
1990
1991                                        $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat);
1992                                        break;
1993                                case 0x02000083: // LensType
1994                                        $data = array(
1995                                                //'_'  => $data,
1996                                                'mf' => (bool) ($data & 0x01),
1997                                                'd'  => (bool) ($data & 0x02),
1998                                                'g'  => (bool) ($data & 0x04),
1999                                                'vr' => (bool) ($data & 0x08),
2000                                        );
2001                                        break;
2002                        }
2003                        $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT));
2004                        $parsed[$tag_name] = $data;
2005                }
2006                return $parsed;
2007        }
2008
2009
2010        public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') {
2011                static $handyatomtranslatorarray = array();
2012                if (empty($handyatomtranslatorarray)) {
2013                        $handyatomtranslatorarray['©cpy'] = 'copyright';
2014                        $handyatomtranslatorarray['©day'] = 'creation_date';    // iTunes 4.0
2015                        $handyatomtranslatorarray['©dir'] = 'director';
2016                        $handyatomtranslatorarray['©ed1'] = 'edit1';
2017                        $handyatomtranslatorarray['©ed2'] = 'edit2';
2018                        $handyatomtranslatorarray['©ed3'] = 'edit3';
2019                        $handyatomtranslatorarray['©ed4'] = 'edit4';
2020                        $handyatomtranslatorarray['©ed5'] = 'edit5';
2021                        $handyatomtranslatorarray['©ed6'] = 'edit6';
2022                        $handyatomtranslatorarray['©ed7'] = 'edit7';
2023                        $handyatomtranslatorarray['©ed8'] = 'edit8';
2024                        $handyatomtranslatorarray['©ed9'] = 'edit9';
2025                        $handyatomtranslatorarray['©fmt'] = 'format';
2026                        $handyatomtranslatorarray['©inf'] = 'information';
2027                        $handyatomtranslatorarray['©prd'] = 'producer';
2028                        $handyatomtranslatorarray['©prf'] = 'performers';
2029                        $handyatomtranslatorarray['©req'] = 'system_requirements';
2030                        $handyatomtranslatorarray['©src'] = 'source_credit';
2031                        $handyatomtranslatorarray['©wrt'] = 'writer';
2032
2033                        // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
2034                        $handyatomtranslatorarray['©nam'] = 'title';           // iTunes 4.0
2035                        $handyatomtranslatorarray['©cmt'] = 'comment';         // iTunes 4.0
2036                        $handyatomtranslatorarray['©wrn'] = 'warning';
2037                        $handyatomtranslatorarray['©hst'] = 'host_computer';
2038                        $handyatomtranslatorarray['©mak'] = 'make';
2039                        $handyatomtranslatorarray['©mod'] = 'model';
2040                        $handyatomtranslatorarray['©PRD'] = 'product';
2041                        $handyatomtranslatorarray['©swr'] = 'software';
2042                        $handyatomtranslatorarray['©aut'] = 'author';
2043                        $handyatomtranslatorarray['©ART'] = 'artist';
2044                        $handyatomtranslatorarray['©trk'] = 'track';
2045                        $handyatomtranslatorarray['©alb'] = 'album';           // iTunes 4.0
2046                        $handyatomtranslatorarray['©com'] = 'comment';
2047                        $handyatomtranslatorarray['©gen'] = 'genre';           // iTunes 4.0
2048                        $handyatomtranslatorarray['©ope'] = 'composer';
2049                        $handyatomtranslatorarray['©url'] = 'url';
2050                        $handyatomtranslatorarray['©enc'] = 'encoder';
2051
2052                        // http://atomicparsley.sourceforge.net/mpeg-4files.html
2053                        $handyatomtranslatorarray['©art'] = 'artist';           // iTunes 4.0
2054                        $handyatomtranslatorarray['aART'] = 'album_artist';
2055                        $handyatomtranslatorarray['trkn'] = 'track_number';     // iTunes 4.0
2056                        $handyatomtranslatorarray['disk'] = 'disc_number';      // iTunes 4.0
2057                        $handyatomtranslatorarray['gnre'] = 'genre';            // iTunes 4.0
2058                        $handyatomtranslatorarray['©too'] = 'encoder';          // iTunes 4.0
2059                        $handyatomtranslatorarray['tmpo'] = 'bpm';              // iTunes 4.0
2060                        $handyatomtranslatorarray['cprt'] = 'copyright';        // iTunes 4.0?
2061                        $handyatomtranslatorarray['cpil'] = 'compilation';      // iTunes 4.0
2062                        $handyatomtranslatorarray['covr'] = 'picture';          // iTunes 4.0
2063                        $handyatomtranslatorarray['rtng'] = 'rating';           // iTunes 4.0
2064                        $handyatomtranslatorarray['©grp'] = 'grouping';         // iTunes 4.2
2065                        $handyatomtranslatorarray['stik'] = 'stik';             // iTunes 4.9
2066                        $handyatomtranslatorarray['pcst'] = 'podcast';          // iTunes 4.9
2067                        $handyatomtranslatorarray['catg'] = 'category';         // iTunes 4.9
2068                        $handyatomtranslatorarray['keyw'] = 'keyword';          // iTunes 4.9
2069                        $handyatomtranslatorarray['purl'] = 'podcast_url';      // iTunes 4.9
2070                        $handyatomtranslatorarray['egid'] = 'episode_guid';     // iTunes 4.9
2071                        $handyatomtranslatorarray['desc'] = 'description';      // iTunes 5.0
2072                        $handyatomtranslatorarray['©lyr'] = 'lyrics';           // iTunes 5.0
2073                        $handyatomtranslatorarray['tvnn'] = 'tv_network_name';  // iTunes 6.0
2074                        $handyatomtranslatorarray['tvsh'] = 'tv_show_name';     // iTunes 6.0
2075                        $handyatomtranslatorarray['tvsn'] = 'tv_season';        // iTunes 6.0
2076                        $handyatomtranslatorarray['tves'] = 'tv_episode';       // iTunes 6.0
2077                        $handyatomtranslatorarray['purd'] = 'purchase_date';    // iTunes 6.0.2
2078                        $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0
2079
2080                        // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt
2081
2082
2083
2084                        // boxnames:
2085                        /*
2086                        $handyatomtranslatorarray['iTunSMPB']                    = 'iTunSMPB';
2087                        $handyatomtranslatorarray['iTunNORM']                    = 'iTunNORM';
2088                        $handyatomtranslatorarray['Encoding Params']             = 'Encoding Params';
2089                        $handyatomtranslatorarray['replaygain_track_gain']       = 'replaygain_track_gain';
2090                        $handyatomtranslatorarray['replaygain_track_peak']       = 'replaygain_track_peak';
2091                        $handyatomtranslatorarray['replaygain_track_minmax']     = 'replaygain_track_minmax';
2092                        $handyatomtranslatorarray['MusicIP PUID']                = 'MusicIP PUID';
2093                        $handyatomtranslatorarray['MusicBrainz Artist Id']       = 'MusicBrainz Artist Id';
2094                        $handyatomtranslatorarray['MusicBrainz Album Id']        = 'MusicBrainz Album Id';
2095                        $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id';
2096                        $handyatomtranslatorarray['MusicBrainz Track Id']        = 'MusicBrainz Track Id';
2097                        $handyatomtranslatorarray['MusicBrainz Disc Id']         = 'MusicBrainz Disc Id';
2098
2099                        // http://age.hobba.nl/audio/tag_frame_reference.html
2100                        $handyatomtranslatorarray['PLAY_COUNTER']                = 'play_counter'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
2101                        $handyatomtranslatorarray['MEDIATYPE']                   = 'mediatype';    // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
2102                        */
2103                }
2104                $info = &$this->getid3->info;
2105                $comment_key = '';
2106                if ($boxname && ($boxname != $keyname)) {
2107                        $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname);
2108                } elseif (isset($handyatomtranslatorarray[$keyname])) {
2109                        $comment_key = $handyatomtranslatorarray[$keyname];
2110                }
2111                if ($comment_key) {
2112                        if ($comment_key == 'picture') {
2113                                if (!is_array($data)) {
2114                                        $image_mime = '';
2115                                        if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) {
2116                                                $image_mime = 'image/png';
2117                                        } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) {
2118                                                $image_mime = 'image/jpeg';
2119                                        } elseif (preg_match('#^GIF#', $data)) {
2120                                                $image_mime = 'image/gif';
2121                                        } elseif (preg_match('#^BM#', $data)) {
2122                                                $image_mime = 'image/bmp';
2123                                        }
2124                                        $data = array('data'=>$data, 'image_mime'=>$image_mime);
2125                                }
2126                        }
2127                        $info['quicktime']['comments'][$comment_key][] = $data;
2128                }
2129                return true;
2130        }
2131
2132        public function NoNullString($nullterminatedstring) {
2133                // remove the single null terminator on null terminated strings
2134                if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
2135                        return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
2136                }
2137                return $nullterminatedstring;
2138        }
2139
2140        public function Pascal2String($pascalstring) {
2141                // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
2142                return substr($pascalstring, 1);
2143        }
2144
2145}
Note: See TracBrowser for help on using the repository browser.