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