PageRenderTime 681ms CodeModel.GetById 62ms app.highlight 558ms RepoModel.GetById 40ms app.codeStats 2ms

/Vendor/getid3/module.audio-video.quicktime.php

https://bitbucket.org/nova-atlantis/simple-server-media-player
PHP | 2246 lines | 1853 code | 222 blank | 171 comment | 182 complexity | 272dfd6e4c391f20611a11d921e66eeb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1<?php
  2/////////////////////////////////////////////////////////////////
  3/// getID3() by James Heinrich <info@getid3.org>               //
  4//  available at http://getid3.sourceforge.net                 //
  5//            or http://www.getid3.org                         //
  6//          also https://github.com/JamesHeinrich/getID3       //
  7/////////////////////////////////////////////////////////////////
  8// See readme.txt for more details                             //
  9/////////////////////////////////////////////////////////////////
 10//                                                             //
 11// module.audio-video.quicktime.php                            //
 12// module for analyzing Quicktime and MP3-in-MP4 files         //
 13// dependencies: module.audio.mp3.php                          //
 14// dependencies: module.tag.id3v2.php                          //
 15//                                                            ///
 16/////////////////////////////////////////////////////////////////
 17
 18getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
 19getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup
 20
 21class getid3_quicktime extends getid3_handler
 22{
 23
 24	public $ReturnAtomData        = true;
 25	public $ParseAllPossibleAtoms = false;
 26
 27	public function Analyze() {
 28		$info = &$this->getid3->info;
 29
 30		$info['fileformat'] = 'quicktime';
 31		$info['quicktime']['hinting']    = false;
 32		$info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
 33
 34		$this->fseek($info['avdataoffset']);
 35
 36		$offset      = 0;
 37		$atomcounter = 0;
 38		$atom_data_read_buffer_size = ($info['php_memory_limit'] ? round($info['php_memory_limit'] / 2) : $this->getid3->option_fread_buffer_size * 1024); // allow [default: 32MB] if PHP configured with no memory_limit
 39		while ($offset < $info['avdataend']) {
 40			if (!getid3_lib::intValueSupported($offset)) {
 41				$info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
 42				break;
 43			}
 44			$this->fseek($offset);
 45			$AtomHeader = $this->fread(8);
 46
 47			$atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
 48			$atomname = substr($AtomHeader, 4, 4);
 49
 50			// 64-bit MOV patch by jlegateØktnc*com
 51			if ($atomsize == 1) {
 52				$atomsize = getid3_lib::BigEndian2Int($this->fread(8));
 53			}
 54
 55			$info['quicktime'][$atomname]['name']   = $atomname;
 56			$info['quicktime'][$atomname]['size']   = $atomsize;
 57			$info['quicktime'][$atomname]['offset'] = $offset;
 58
 59			if (($offset + $atomsize) > $info['avdataend']) {
 60				$info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
 61				return false;
 62			}
 63
 64			if ($atomsize == 0) {
 65				// Furthermore, for historical reasons the list of atoms is optionally
 66				// terminated by a 32-bit integer set to 0. If you are writing a program
 67				// to read user data atoms, you should allow for the terminating 0.
 68				break;
 69			}
 70			$atomHierarchy = array();
 71			$info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
 72
 73			$offset += $atomsize;
 74			$atomcounter++;
 75		}
 76
 77		if (!empty($info['avdataend_tmp'])) {
 78			// this value is assigned to a temp value and then erased because
 79			// otherwise any atoms beyond the 'mdat' atom would not get parsed
 80			$info['avdataend'] = $info['avdataend_tmp'];
 81			unset($info['avdataend_tmp']);
 82		}
 83
 84		if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
 85			$info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
 86		}
 87		if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
 88			$info['audio']['bitrate'] = $info['bitrate'];
 89		}
 90		if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
 91			foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
 92				$samples_per_second = $samples_count / $info['playtime_seconds'];
 93				if ($samples_per_second > 240) {
 94					// has to be audio samples
 95				} else {
 96					$info['video']['frame_rate'] = $samples_per_second;
 97					break;
 98				}
 99			}
100		}
101		if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
102			$info['fileformat'] = 'mp4';
103			$info['mime_type']  = 'audio/mp4';
104			unset($info['video']['dataformat']);
105		}
106
107		if (!$this->ReturnAtomData) {
108			unset($info['quicktime']['moov']);
109		}
110
111		if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
112			$info['audio']['dataformat'] = 'quicktime';
113		}
114		if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
115			$info['video']['dataformat'] = 'quicktime';
116		}
117
118		return true;
119	}
120
121	public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
122		// http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
123
124		$info = &$this->getid3->info;
125
126		$atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717
127		array_push($atomHierarchy, $atomname);
128		$atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
129		$atom_structure['name']      = $atomname;
130		$atom_structure['size']      = $atomsize;
131		$atom_structure['offset']    = $baseoffset;
132		switch ($atomname) {
133			case 'moov': // MOVie container atom
134			case 'trak': // TRAcK container atom
135			case 'clip': // CLIPping container atom
136			case 'matt': // track MATTe container atom
137			case 'edts': // EDiTS container atom
138			case 'tref': // Track REFerence container atom
139			case 'mdia': // MeDIA container atom
140			case 'minf': // Media INFormation container atom
141			case 'dinf': // Data INFormation container atom
142			case 'udta': // User DaTA container atom
143			case 'cmov': // Compressed MOVie container atom
144			case 'rmra': // Reference Movie Record Atom
145			case 'rmda': // Reference Movie Descriptor Atom
146			case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
147				$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
148				break;
149
150			case 'ilst': // Item LiST container atom
151				if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) {
152					// some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
153					$allnumericnames = true;
154					foreach ($atom_structure['subatoms'] as $subatomarray) {
155						if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
156							$allnumericnames = false;
157							break;
158						}
159					}
160					if ($allnumericnames) {
161						$newData = array();
162						foreach ($atom_structure['subatoms'] as $subatomarray) {
163							foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
164								unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
165								$newData[$subatomarray['name']] = $newData_subatomarray;
166								break;
167							}
168						}
169						$atom_structure['data'] = $newData;
170						unset($atom_structure['subatoms']);
171					}
172				}
173				break;
174
175			case "\x00\x00\x00\x01":
176			case "\x00\x00\x00\x02":
177			case "\x00\x00\x00\x03":
178			case "\x00\x00\x00\x04":
179			case "\x00\x00\x00\x05":
180				$atomname = getid3_lib::BigEndian2Int($atomname);
181				$atom_structure['name'] = $atomname;
182				$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
183				break;
184
185			case 'stbl': // Sample TaBLe container atom
186				$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
187				$isVideo = false;
188				$framerate  = 0;
189				$framecount = 0;
190				foreach ($atom_structure['subatoms'] as $key => $value_array) {
191					if (isset($value_array['sample_description_table'])) {
192						foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
193							if (isset($value_array2['data_format'])) {
194								switch ($value_array2['data_format']) {
195									case 'avc1':
196									case 'mp4v':
197										// video data
198										$isVideo = true;
199										break;
200									case 'mp4a':
201										// audio data
202										break;
203								}
204							}
205						}
206					} elseif (isset($value_array['time_to_sample_table'])) {
207						foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
208							if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
209								$framerate  = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
210								$framecount = $value_array2['sample_count'];
211							}
212						}
213					}
214				}
215				if ($isVideo && $framerate) {
216					$info['quicktime']['video']['frame_rate'] = $framerate;
217					$info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
218				}
219				if ($isVideo && $framecount) {
220					$info['quicktime']['video']['frame_count'] = $framecount;
221				}
222				break;
223
224
225			case 'aART': // Album ARTist
226			case 'catg': // CaTeGory
227			case 'covr': // COVeR artwork
228			case 'cpil': // ComPILation
229			case 'cprt': // CoPyRighT
230			case 'desc': // DESCription
231			case 'disk': // DISK number
232			case 'egid': // Episode Global ID
233			case 'gnre': // GeNRE
234			case 'keyw': // KEYWord
235			case 'ldes':
236			case 'pcst': // PodCaST
237			case 'pgap': // GAPless Playback
238			case 'purd': // PURchase Date
239			case 'purl': // Podcast URL
240			case 'rati':
241			case 'rndu':
242			case 'rpdu':
243			case 'rtng': // RaTiNG
244			case 'stik':
245			case 'tmpo': // TeMPO (BPM)
246			case 'trkn': // TRacK Number
247			case 'tves': // TV EpiSode
248			case 'tvnn': // TV Network Name
249			case 'tvsh': // TV SHow Name
250			case 'tvsn': // TV SeasoN
251			case 'akID': // iTunes store account type
252			case 'apID':
253			case 'atID':
254			case 'cmID':
255			case 'cnID':
256			case 'geID':
257			case 'plID':
258			case 'sfID': // iTunes store country
259			case "\xA9".'alb': // ALBum
260			case "\xA9".'art': // ARTist
261			case "\xA9".'ART':
262			case "\xA9".'aut':
263			case "\xA9".'cmt': // CoMmenT
264			case "\xA9".'com': // COMposer
265			case "\xA9".'cpy':
266			case "\xA9".'day': // content created year
267			case "\xA9".'dir':
268			case "\xA9".'ed1':
269			case "\xA9".'ed2':
270			case "\xA9".'ed3':
271			case "\xA9".'ed4':
272			case "\xA9".'ed5':
273			case "\xA9".'ed6':
274			case "\xA9".'ed7':
275			case "\xA9".'ed8':
276			case "\xA9".'ed9':
277			case "\xA9".'enc':
278			case "\xA9".'fmt':
279			case "\xA9".'gen': // GENre
280			case "\xA9".'grp': // GRouPing
281			case "\xA9".'hst':
282			case "\xA9".'inf':
283			case "\xA9".'lyr': // LYRics
284			case "\xA9".'mak':
285			case "\xA9".'mod':
286			case "\xA9".'nam': // full NAMe
287			case "\xA9".'ope':
288			case "\xA9".'PRD':
289			case "\xA9".'prd':
290			case "\xA9".'prf':
291			case "\xA9".'req':
292			case "\xA9".'src':
293			case "\xA9".'swr':
294			case "\xA9".'too': // encoder
295			case "\xA9".'trk': // TRacK
296			case "\xA9".'url':
297			case "\xA9".'wrn':
298			case "\xA9".'wrt': // WRiTer
299			case '----': // itunes specific
300				if ($atom_parent == 'udta') {
301					// User data atom handler
302					$atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
303					$atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
304					$atom_structure['data']        =                           substr($atom_data, 4);
305
306					$atom_structure['language']    = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
307					if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
308						$info['comments']['language'][] = $atom_structure['language'];
309					}
310				} else {
311					// Apple item list box atom handler
312					$atomoffset = 0;
313					if (substr($atom_data, 2, 2) == "\x10\xB5") {
314						// not sure what it means, but observed on iPhone4 data.
315						// Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
316						while ($atomoffset < strlen($atom_data)) {
317							$boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset,     2));
318							$boxsmalltype =                           substr($atom_data, $atomoffset + 2, 2);
319							$boxsmalldata =                           substr($atom_data, $atomoffset + 4, $boxsmallsize);
320							if ($boxsmallsize <= 1) {
321								$info['warning'][] = 'Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
322								$atom_structure['data'] = null;
323								$atomoffset = strlen($atom_data);
324								break;
325							}
326							switch ($boxsmalltype) {
327								case "\x10\xB5":
328									$atom_structure['data'] = $boxsmalldata;
329									break;
330								default:
331									$info['warning'][] = 'Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset;
332									$atom_structure['data'] = $atom_data;
333									break;
334							}
335							$atomoffset += (4 + $boxsmallsize);
336						}
337					} else {
338						while ($atomoffset < strlen($atom_data)) {
339							$boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
340							$boxtype =                           substr($atom_data, $atomoffset + 4, 4);
341							$boxdata =                           substr($atom_data, $atomoffset + 8, $boxsize - 8);
342							if ($boxsize <= 1) {
343								$info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
344								$atom_structure['data'] = null;
345								$atomoffset = strlen($atom_data);
346								break;
347							}
348							$atomoffset += $boxsize;
349
350							switch ($boxtype) {
351								case 'mean':
352								case 'name':
353									$atom_structure[$boxtype] = substr($boxdata, 4);
354									break;
355
356								case 'data':
357									$atom_structure['version']   = getid3_lib::BigEndian2Int(substr($boxdata,  0, 1));
358									$atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata,  1, 3));
359									switch ($atom_structure['flags_raw']) {
360										case  0: // data flag
361										case 21: // tmpo/cpil flag
362											switch ($atomname) {
363												case 'cpil':
364												case 'pcst':
365												case 'pgap':
366													$atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
367													break;
368
369												case 'tmpo':
370													$atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
371													break;
372
373												case 'disk':
374												case 'trkn':
375													$num       = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
376													$num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
377													$atom_structure['data']  = empty($num) ? '' : $num;
378													$atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
379													break;
380
381												case 'gnre':
382													$GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
383													$atom_structure['data']    = getid3_id3v1::LookupGenreName($GenreID - 1);
384													break;
385
386												case 'rtng':
387													$atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
388													$atom_structure['data']    = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
389													break;
390
391												case 'stik':
392													$atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
393													$atom_structure['data']    = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
394													break;
395
396												case 'sfID':
397													$atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
398													$atom_structure['data']    = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
399													break;
400
401												case 'egid':
402												case 'purl':
403													$atom_structure['data'] = substr($boxdata, 8);
404													break;
405
406												default:
407													$atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
408											}
409											break;
410
411										case  1: // text flag
412										case 13: // image flag
413										default:
414											$atom_structure['data'] = substr($boxdata, 8);
415											if ($atomname == 'covr') {
416												// not a foolproof check, but better than nothing
417												if (preg_match('#^\xFF\xD8\xFF#', $atom_structure['data'])) {
418													$atom_structure['image_mime'] = 'image/jpeg';
419												} elseif (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $atom_structure['data'])) {
420													$atom_structure['image_mime'] = 'image/png';
421												} elseif (preg_match('#^GIF#', $atom_structure['data'])) {
422													$atom_structure['image_mime'] = 'image/gif';
423												}
424											}
425											break;
426
427									}
428									break;
429
430								default:
431									$info['warning'][] = 'Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset;
432									$atom_structure['data'] = $atom_data;
433
434							}
435						}
436					}
437				}
438				$this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
439				break;
440
441
442			case 'play': // auto-PLAY atom
443				$atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
444
445				$info['quicktime']['autoplay'] = $atom_structure['autoplay'];
446				break;
447
448
449			case 'WLOC': // Window LOCation atom
450				$atom_structure['location_x']  = getid3_lib::BigEndian2Int(substr($atom_data,  0, 2));
451				$atom_structure['location_y']  = getid3_lib::BigEndian2Int(substr($atom_data,  2, 2));
452				break;
453
454
455			case 'LOOP': // LOOPing atom
456			case 'SelO': // play SELection Only atom
457			case 'AllF': // play ALL Frames atom
458				$atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
459				break;
460
461
462			case 'name': //
463			case 'MCPS': // Media Cleaner PRo
464			case '@PRM': // adobe PReMiere version
465			case '@PRQ': // adobe PRemiere Quicktime version
466				$atom_structure['data'] = $atom_data;
467				break;
468
469
470			case 'cmvd': // Compressed MooV Data atom
471				// Code by ubergeekØubergeek*tv based on information from
472				// http://developer.apple.com/quicktime/icefloe/dispatch012.html
473				$atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
474
475				$CompressedFileData = substr($atom_data, 4);
476				if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
477					$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
478				} else {
479					$info['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset'];
480				}
481				break;
482
483
484			case 'dcom': // Data COMpression atom
485				$atom_structure['compression_id']   = $atom_data;
486				$atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
487				break;
488
489
490			case 'rdrf': // Reference movie Data ReFerence atom
491				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
492				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
493				$atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
494
495				$atom_structure['reference_type_name']    =                           substr($atom_data,  4, 4);
496				$atom_structure['reference_length']       = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
497				switch ($atom_structure['reference_type_name']) {
498					case 'url ':
499						$atom_structure['url']            =       $this->NoNullString(substr($atom_data, 12));
500						break;
501
502					case 'alis':
503						$atom_structure['file_alias']     =                           substr($atom_data, 12);
504						break;
505
506					case 'rsrc':
507						$atom_structure['resource_alias'] =                           substr($atom_data, 12);
508						break;
509
510					default:
511						$atom_structure['data']           =                           substr($atom_data, 12);
512						break;
513				}
514				break;
515
516
517			case 'rmqu': // Reference Movie QUality atom
518				$atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
519				break;
520
521
522			case 'rmcs': // Reference Movie Cpu Speed atom
523				$atom_structure['version']          = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
524				$atom_structure['flags_raw']        = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
525				$atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
526				break;
527
528
529			case 'rmvc': // Reference Movie Version Check atom
530				$atom_structure['version']            = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
531				$atom_structure['flags_raw']          = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
532				$atom_structure['gestalt_selector']   =                           substr($atom_data,  4, 4);
533				$atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
534				$atom_structure['gestalt_value']      = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
535				$atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
536				break;
537
538
539			case 'rmcd': // Reference Movie Component check atom
540				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
541				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
542				$atom_structure['component_type']         =                           substr($atom_data,  4, 4);
543				$atom_structure['component_subtype']      =                           substr($atom_data,  8, 4);
544				$atom_structure['component_manufacturer'] =                           substr($atom_data, 12, 4);
545				$atom_structure['component_flags_raw']    = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
546				$atom_structure['component_flags_mask']   = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
547				$atom_structure['component_min_version']  = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
548				break;
549
550
551			case 'rmdr': // Reference Movie Data Rate atom
552				$atom_structure['version']       = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
553				$atom_structure['flags_raw']     = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
554				$atom_structure['data_rate']     = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
555
556				$atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
557				break;
558
559
560			case 'rmla': // Reference Movie Language Atom
561				$atom_structure['version']     = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
562				$atom_structure['flags_raw']   = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
563				$atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
564
565				$atom_structure['language']    = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
566				if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
567					$info['comments']['language'][] = $atom_structure['language'];
568				}
569				break;
570
571
572			case 'rmla': // Reference Movie Language Atom
573				$atom_structure['version']   = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
574				$atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
575				$atom_structure['track_id']  = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
576				break;
577
578
579			case 'ptv ': // Print To Video - defines a movie's full screen mode
580				// http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
581				$atom_structure['display_size_raw']  = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
582				$atom_structure['reserved_1']        = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
583				$atom_structure['reserved_2']        = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
584				$atom_structure['slide_show_flag']   = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
585				$atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
586
587				$atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
588				$atom_structure['flags']['slide_show']   = (bool) $atom_structure['slide_show_flag'];
589
590				$ptv_lookup[0] = 'normal';
591				$ptv_lookup[1] = 'double';
592				$ptv_lookup[2] = 'half';
593				$ptv_lookup[3] = 'full';
594				$ptv_lookup[4] = 'current';
595				if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
596					$atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
597				} else {
598					$info['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')';
599				}
600				break;
601
602
603			case 'stsd': // Sample Table Sample Description atom
604				$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
605				$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
606				$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
607				$stsdEntriesDataOffset = 8;
608				for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
609					$atom_structure['sample_description_table'][$i]['size']             = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
610					$stsdEntriesDataOffset += 4;
611					$atom_structure['sample_description_table'][$i]['data_format']      =                           substr($atom_data, $stsdEntriesDataOffset, 4);
612					$stsdEntriesDataOffset += 4;
613					$atom_structure['sample_description_table'][$i]['reserved']         = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
614					$stsdEntriesDataOffset += 6;
615					$atom_structure['sample_description_table'][$i]['reference_index']  = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
616					$stsdEntriesDataOffset += 2;
617					$atom_structure['sample_description_table'][$i]['data']             =                           substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
618					$stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
619
620					$atom_structure['sample_description_table'][$i]['encoder_version']  = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  0, 2));
621					$atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  2, 2));
622					$atom_structure['sample_description_table'][$i]['encoder_vendor']   =                           substr($atom_structure['sample_description_table'][$i]['data'],  4, 4);
623
624					switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
625
626						case "\x00\x00\x00\x00":
627							// audio tracks
628							$atom_structure['sample_description_table'][$i]['audio_channels']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  8,  2));
629							$atom_structure['sample_description_table'][$i]['audio_bit_depth']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10,  2));
630							$atom_structure['sample_description_table'][$i]['audio_compression_id'] =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12,  2));
631							$atom_structure['sample_description_table'][$i]['audio_packet_size']    =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14,  2));
632							$atom_structure['sample_description_table'][$i]['audio_sample_rate']    = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16,  4));
633
634							// video tracks
635							// http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
636							$atom_structure['sample_description_table'][$i]['temporal_quality'] =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  8,  4));
637							$atom_structure['sample_description_table'][$i]['spatial_quality']  =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12,  4));
638							$atom_structure['sample_description_table'][$i]['width']            =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16,  2));
639							$atom_structure['sample_description_table'][$i]['height']           =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18,  2));
640							$atom_structure['sample_description_table'][$i]['resolution_x']     = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24,  4));
641							$atom_structure['sample_description_table'][$i]['resolution_y']     = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28,  4));
642							$atom_structure['sample_description_table'][$i]['data_size']        =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32,  4));
643							$atom_structure['sample_description_table'][$i]['frame_count']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36,  2));
644							$atom_structure['sample_description_table'][$i]['compressor_name']  =                             substr($atom_structure['sample_description_table'][$i]['data'], 38,  4);
645							$atom_structure['sample_description_table'][$i]['pixel_depth']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42,  2));
646							$atom_structure['sample_description_table'][$i]['color_table_id']   =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44,  2));
647
648							switch ($atom_structure['sample_description_table'][$i]['data_format']) {
649								case '2vuY':
650								case 'avc1':
651								case 'cvid':
652								case 'dvc ':
653								case 'dvcp':
654								case 'gif ':
655								case 'h263':
656								case 'jpeg':
657								case 'kpcd':
658								case 'mjpa':
659								case 'mjpb':
660								case 'mp4v':
661								case 'png ':
662								case 'raw ':
663								case 'rle ':
664								case 'rpza':
665								case 'smc ':
666								case 'SVQ1':
667								case 'SVQ3':
668								case 'tiff':
669								case 'v210':
670								case 'v216':
671								case 'v308':
672								case 'v408':
673								case 'v410':
674								case 'yuv2':
675									$info['fileformat'] = 'mp4';
676									$info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
677// http://www.getid3.org/phpBB3/viewtopic.php?t=1550
678//if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers
679if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) {
680	// assume that values stored here are more important than values stored in [tkhd] atom
681	$info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width'];
682	$info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height'];
683	$info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
684	$info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
685}
686									break;
687
688								case 'qtvr':
689									$info['video']['dataformat'] = 'quicktimevr';
690									break;
691
692								case 'mp4a':
693								default:
694									$info['quicktime']['audio']['codec']       = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
695									$info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
696									$info['quicktime']['audio']['channels']    = $atom_structure['sample_description_table'][$i]['audio_channels'];
697									$info['quicktime']['audio']['bit_depth']   = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
698									$info['audio']['codec']                    = $info['quicktime']['audio']['codec'];
699									$info['audio']['sample_rate']              = $info['quicktime']['audio']['sample_rate'];
700									$info['audio']['channels']                 = $info['quicktime']['audio']['channels'];
701									$info['audio']['bits_per_sample']          = $info['quicktime']['audio']['bit_depth'];
702									switch ($atom_structure['sample_description_table'][$i]['data_format']) {
703										case 'raw ': // PCM
704										case 'alac': // Apple Lossless Audio Codec
705											$info['audio']['lossless'] = true;
706											break;
707										default:
708											$info['audio']['lossless'] = false;
709											break;
710									}
711									break;
712							}
713							break;
714
715						default:
716							switch ($atom_structure['sample_description_table'][$i]['data_format']) {
717								case 'mp4s':
718									$info['fileformat'] = 'mp4';
719									break;
720
721								default:
722									// video atom
723									$atom_structure['sample_description_table'][$i]['video_temporal_quality']  =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'],  8,  4));
724									$atom_structure['sample_description_table'][$i]['video_spatial_quality']   =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12,  4));
725									$atom_structure['sample_description_table'][$i]['video_frame_width']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16,  2));
726									$atom_structure['sample_description_table'][$i]['video_frame_height']      =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18,  2));
727									$atom_structure['sample_description_table'][$i]['video_resolution_x']      = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20,  4));
728									$atom_structure['sample_description_table'][$i]['video_resolution_y']      = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24,  4));
729									$atom_structure['sample_description_table'][$i]['video_data_size']         =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28,  4));
730									$atom_structure['sample_description_table'][$i]['video_frame_count']       =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32,  2));
731									$atom_structure['sample_description_table'][$i]['video_encoder_name_len']  =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34,  1));
732									$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']);
733									$atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66,  2));
734									$atom_structure['sample_description_table'][$i]['video_color_table_id']    =   getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68,  2));
735
736									$atom_structure['sample_description_table'][$i]['video_pixel_color_type']  = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
737									$atom_structure['sample_description_table'][$i]['video_pixel_color_name']  = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
738
739									if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
740										$info['quicktime']['video']['codec_fourcc']        = $atom_structure['sample_description_table'][$i]['data_format'];
741										$info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
742										$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']);
743										$info['quicktime']['video']['color_depth']         = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
744										$info['quicktime']['video']['color_depth_name']    = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
745
746										$info['video']['codec']           = $info['quicktime']['video']['codec'];
747										$info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
748									}
749									$info['video']['lossless']           = false;
750									$info['video']['pixel_aspect_ratio'] = (float) 1;
751									break;
752							}
753							break;
754					}
755					switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
756						case 'mp4a':
757							$info['audio']['dataformat']         = 'mp4';
758							$info['quicktime']['audio']['codec'] = 'mp4';
759							break;
760
761						case '3ivx':
762						case '3iv1':
763						case '3iv2':
764							$info['video']['dataformat'] = '3ivx';
765							break;
766
767						case 'xvid':
768							$info['video']['dataformat'] = 'xvid';
769							break;
770
771						case 'mp4v':
772							$info['video']['dataformat'] = 'mpeg4';
773							break;
774
775						case 'divx':
776						case 'div1':
777						case 'div2':
778						case 'div3':
779						case 'div4':
780						case 'div5':
781						case 'div6':
782							$info['video']['dataformat'] = 'divx';
783							break;
784
785						default:
786							// do nothing
787							break;
788					}
789					unset($atom_structure['sample_description_table'][$i]['data']);
790				}
791				break;
792
793
794			case 'stts': // Sample Table Time-to-Sample atom
795				$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
796				$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
797				$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
798				$sttsEntriesDataOffset = 8;
799				//$FrameRateCalculatorArray = array();
800				$frames_count = 0;
801
802				$max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']);
803				if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
804					$info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($atom_structure['number_entries'] / 1048576).'MB).';
805				}
806				for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
807					$atom_structure['time_to_sample_table'][$i]['sample_count']    = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
808					$sttsEntriesDataOffset += 4;
809					$atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
810					$sttsEntriesDataOffset += 4;
811
812					$frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
813
814					// THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
815					//if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
816					//	$stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
817					//	if ($stts_new_framerate <= 60) {
818					//		// some atoms have durations of "1" giving a very large framerate, which probably is not right
819					//		$info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
820					//	}
821					//}
822					//
823					//$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
824				}
825				$info['quicktime']['stts_framecount'][] = $frames_count;
826				//$sttsFramesTotal  = 0;
827				//$sttsSecondsTotal = 0;
828				//foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
829				//	if (($frames_per_second > 60) || ($frames_per_second < 1)) {
830				//		// not video FPS information, probably audio information
831				//		$sttsFramesTotal  = 0;
832				//		$sttsSecondsTotal = 0;
833				//		break;
834				//	}
835				//	$sttsFramesTotal  += $frame_count;
836				//	$sttsSecondsTotal += $frame_count / $frames_per_second;
837				//}
838				//if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
839				//	if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
840				//		$info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
841				//	}
842				//}
843				break;
844
845
846			case 'stss': // Sample Table Sync Sample (key frames) atom
847				if ($ParseAllPossibleAtoms) {
848					$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
849					$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
850					$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
851					$stssEntriesDataOffset = 8;
852					for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
853						$atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
854						$stssEntriesDataOffset += 4;
855					}
856				}
857				break;
858
859
860			case 'stsc': // Sample Table Sample-to-Chunk atom
861				if ($ParseAllPossibleAtoms) {
862					$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
863					$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
864					$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
865					$stscEntriesDataOffset = 8;
866					for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
867						$atom_structure['sample_to_chunk_table'][$i]['first_chunk']        = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
868						$stscEntriesDataOffset += 4;
869						$atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk']  = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
870						$stscEntriesDataOffset += 4;
871						$atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
872						$stscEntriesDataOffset += 4;
873					}
874				}
875				break;
876
877
878			case 'stsz': // Sample Table SiZe atom
879				if ($ParseAllPossibleAtoms) {
880					$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
881					$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
882					$atom_structure['sample_size']    = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
883					$atom_structure['number_entries'] = getid3_lib::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] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
888							$stszEntriesDataOffset += 4;
889						}
890					}
891				}
892				break;
893
894
895			case 'stco': // Sample Table Chunk Offset atom
896				if ($ParseAllPossibleAtoms) {
897					$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
898					$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
899					$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
900					$stcoEntriesDataOffset = 8;
901					for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
902						$atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
903						$stcoEntriesDataOffset += 4;
904					}
905				}
906				break;
907
908
909			case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
910				if ($ParseAllPossibleAtoms) {
911					$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
912					$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
913					$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
914					$stcoEntriesDataOffset = 8;
915					for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
916						$atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
917						$stcoEntriesDataOffset += 8;
918					}
919				}
920				break;
921
922
923			case 'dref': // Data REFerence atom
924				$atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
925				$atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
926				$atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
927				$drefDataOffset = 8;
928				for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
929					$atom_structure['data_references'][$i]['size']                    = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
930					$drefDataOffset += 4;
931					$atom_structure['data_references'][$i]['type']                    =               substr($atom_data, $drefDataOffset, 4);
932					$drefDataOffset += 4;
933					$atom_structure['data_references'][$i]['version']                 = getid3_lib::BigEndian2Int(substr($atom_data,  $drefDataOffset, 1));
934					$drefDataOffset += 1;
935					$atom_structure['data_references'][$i]['flags_raw']               = getid3_lib::BigEndian2Int(substr($atom_data,  $drefDataOffset, 3)); // hardcoded: 0x0000
936					$drefDataOffset += 3;
937					$atom_structure['data_references'][$i]['data']                    =               substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
938					$drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
939
940					$atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
941				}
942				break;
943
944
945			case 'gmin': // base Media INformation atom
946				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
947				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
948				$atom_structure['graphics_mode']          = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
949				$atom_structure['opcolor_red']            = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
950				$atom_structure['opcolor_green']          = getid3_lib::BigEndian2Int(substr($atom_data,  8, 2));
951				$atom_structure['opcolor_blue']           = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
952				$atom_structure['balance']                = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
953				$atom_structure['reserved']               = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
954				break;
955
956
957			case 'smhd': // Sound Media information HeaDer atom
958				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
959				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
960				$atom_structure['balance']                = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
961				$atom_structure['reserved']               = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
962				break;
963
964
965			case 'vmhd': // Video Media information HeaDer atom
966				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
967				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3));
968				$atom_structure['graphics_mode']          = getid3_lib::BigEndian2Int(substr($atom_data,  4, 2));
969				$atom_structure['opcolor_red']            = getid3_lib::BigEndian2Int(substr($atom_data,  6, 2));
970				$atom_structure['opcolor_green']          = getid3_lib::BigEndian2Int(substr($atom_data,  8, 2));
971				$atom_structure['opcolor_blue']           = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
972
973				$atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
974				break;
975
976
977			case 'hdlr': // HanDLeR reference atom
978				$atom_structure['version']                = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
979				$atom_structure['flags_raw']              = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
980				$atom_structure['component_type']         =                           substr($atom_data,  4, 4);
981				$atom_structure['component_subtype']      =        

Large files files are truncated, but you can click here to view the full file