module.audio-video.quicktime.php 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio-video.quicktime.php //
  11. // module for analyzing Quicktime and MP3-in-MP4 files //
  12. // dependencies: module.audio.mp3.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  16. class getid3_quicktime
  17. {
  18. function getid3_quicktime(&$fd, &$ThisFileInfo, $ReturnAtomData=true, $ParseAllPossibleAtoms=false) {
  19. $ThisFileInfo['fileformat'] = 'quicktime';
  20. $ThisFileInfo['quicktime']['hinting'] = false;
  21. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  22. $offset = 0;
  23. $atomcounter = 0;
  24. while ($offset < $ThisFileInfo['avdataend']) {
  25. if ($offset >= pow(2, 31)) {
  26. $ThisFileInfo['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond 2GB limit of PHP filesystem functions';
  27. break;
  28. }
  29. fseek($fd, $offset, SEEK_SET);
  30. $AtomHeader = fread($fd, 8);
  31. $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
  32. $atomname = substr($AtomHeader, 4, 4);
  33. // 64-bit MOV patch by jlegateØktnc*com
  34. if ($atomsize == 1) {
  35. $atomsize = getid3_lib::BigEndian2Int(fread($fd, 8));
  36. }
  37. $ThisFileInfo['quicktime'][$atomname]['name'] = $atomname;
  38. $ThisFileInfo['quicktime'][$atomname]['size'] = $atomsize;
  39. $ThisFileInfo['quicktime'][$atomname]['offset'] = $offset;
  40. if (($offset + $atomsize) > $ThisFileInfo['avdataend']) {
  41. $ThisFileInfo['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
  42. return false;
  43. }
  44. if ($atomsize == 0) {
  45. // Furthermore, for historical reasons the list of atoms is optionally
  46. // terminated by a 32-bit integer set to 0. If you are writing a program
  47. // to read user data atoms, you should allow for the terminating 0.
  48. break;
  49. }
  50. switch ($atomname) {
  51. case 'mdat': // Media DATa atom
  52. // 'mdat' contains the actual data for the audio/video
  53. if (($atomsize > 8) && (!isset($ThisFileInfo['avdataend_tmp']) || ($ThisFileInfo['quicktime'][$atomname]['size'] > ($ThisFileInfo['avdataend_tmp'] - $ThisFileInfo['avdataoffset'])))) {
  54. $ThisFileInfo['avdataoffset'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + 8;
  55. $OldAVDataEnd = $ThisFileInfo['avdataend'];
  56. $ThisFileInfo['avdataend'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + $ThisFileInfo['quicktime'][$atomname]['size'];
  57. if (getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode(fread($fd, 4)))) {
  58. getid3_mp3::getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'], false);
  59. if (isset($ThisFileInfo['mpeg']['audio'])) {
  60. $ThisFileInfo['audio']['dataformat'] = 'mp3';
  61. $ThisFileInfo['audio']['codec'] = (!empty($ThisFileInfo['mpeg']['audio']['encoder']) ? $ThisFileInfo['mpeg']['audio']['encoder'] : (!empty($ThisFileInfo['mpeg']['audio']['codec']) ? $ThisFileInfo['mpeg']['audio']['codec'] : (!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
  62. $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
  63. $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
  64. $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'];
  65. $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
  66. $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate'];
  67. }
  68. }
  69. $ThisFileInfo['avdataend'] = $OldAVDataEnd;
  70. unset($OldAVDataEnd);
  71. }
  72. break;
  73. case 'free': // FREE space atom
  74. case 'skip': // SKIP atom
  75. case 'wide': // 64-bit expansion placeholder atom
  76. // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
  77. break;
  78. default:
  79. $atomHierarchy = array();
  80. $ThisFileInfo['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($fd, $atomsize), $ThisFileInfo, $offset, $atomHierarchy, $ParseAllPossibleAtoms);
  81. break;
  82. }
  83. $offset += $atomsize;
  84. $atomcounter++;
  85. }
  86. if (!empty($ThisFileInfo['avdataend_tmp'])) {
  87. // this value is assigned to a temp value and then erased because
  88. // otherwise any atoms beyond the 'mdat' atom would not get parsed
  89. $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataend_tmp'];
  90. unset($ThisFileInfo['avdataend_tmp']);
  91. }
  92. if (!isset($ThisFileInfo['bitrate']) && isset($ThisFileInfo['playtime_seconds'])) {
  93. $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
  94. }
  95. if (isset($ThisFileInfo['bitrate']) && !isset($ThisFileInfo['audio']['bitrate']) && !isset($ThisFileInfo['quicktime']['video'])) {
  96. $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['bitrate'];
  97. }
  98. if (@$ThisFileInfo['playtime_seconds'] && !isset($ThisFileInfo['video']['frame_rate']) && !empty($ThisFileInfo['quicktime']['stts_framecount'])) {
  99. foreach ($ThisFileInfo['quicktime']['stts_framecount'] as $key => $samples_count) {
  100. $samples_per_second = $samples_count / $ThisFileInfo['playtime_seconds'];
  101. if ($samples_per_second > 240) {
  102. // has to be audio samples
  103. } else {
  104. $ThisFileInfo['video']['frame_rate'] = $samples_per_second;
  105. break;
  106. }
  107. }
  108. }
  109. if (($ThisFileInfo['audio']['dataformat'] == 'mp4') && empty($ThisFileInfo['video']['resolution_x'])) {
  110. $ThisFileInfo['fileformat'] = 'mp4';
  111. $ThisFileInfo['mime_type'] = 'audio/mp4';
  112. unset($ThisFileInfo['video']['dataformat']);
  113. }
  114. if (!$ReturnAtomData) {
  115. unset($ThisFileInfo['quicktime']['moov']);
  116. }
  117. if (empty($ThisFileInfo['audio']['dataformat']) && !empty($ThisFileInfo['quicktime']['audio'])) {
  118. $ThisFileInfo['audio']['dataformat'] = 'quicktime';
  119. }
  120. if (empty($ThisFileInfo['video']['dataformat']) && !empty($ThisFileInfo['quicktime']['video'])) {
  121. $ThisFileInfo['video']['dataformat'] = 'quicktime';
  122. }
  123. return true;
  124. }
  125. function QuicktimeParseAtom($atomname, $atomsize, $atomdata, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  126. // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
  127. array_push($atomHierarchy, $atomname);
  128. $atomstructure['hierarchy'] = implode(' ', $atomHierarchy);
  129. $atomstructure['name'] = $atomname;
  130. $atomstructure['size'] = $atomsize;
  131. $atomstructure['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. $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($atomdata, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  148. break;
  149. case 'stbl': // Sample TaBLe container atom
  150. $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($atomdata, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  151. $isVideo = false;
  152. $framerate = 0;
  153. $framecount = 0;
  154. foreach ($atomstructure['subatoms'] as $key => $value_array) {
  155. if (isset($value_array['sample_description_table'])) {
  156. foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
  157. if (isset($value_array2['data_format'])) {
  158. switch ($value_array2['data_format']) {
  159. case 'avc1':
  160. case 'mp4v':
  161. // video data
  162. $isVideo = true;
  163. break;
  164. case 'mp4a':
  165. // audio data
  166. break;
  167. }
  168. }
  169. }
  170. } elseif (isset($value_array['time_to_sample_table'])) {
  171. foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
  172. if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration'])) {
  173. $framerate = round($ThisFileInfo['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
  174. $framecount = $value_array2['sample_count'];
  175. }
  176. }
  177. }
  178. }
  179. if ($isVideo && $framerate) {
  180. $ThisFileInfo['quicktime']['video']['frame_rate'] = $framerate;
  181. $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['quicktime']['video']['frame_rate'];
  182. }
  183. if ($isVideo && $framecount) {
  184. $ThisFileInfo['quicktime']['video']['frame_count'] = $framecount;
  185. }
  186. break;
  187. case '©cpy':
  188. case '©day':
  189. case '©dir':
  190. case '©ed1':
  191. case '©ed2':
  192. case '©ed3':
  193. case '©ed4':
  194. case '©ed5':
  195. case '©ed6':
  196. case '©ed7':
  197. case '©ed8':
  198. case '©ed9':
  199. case '©fmt':
  200. case '©inf':
  201. case '©prd':
  202. case '©prf':
  203. case '©req':
  204. case '©src':
  205. case '©wrt':
  206. case '©nam':
  207. case '©cmt':
  208. case '©wrn':
  209. case '©hst':
  210. case '©mak':
  211. case '©mod':
  212. case '©PRD':
  213. case '©swr':
  214. case '©aut':
  215. case '©ART':
  216. case '©trk':
  217. case '©alb':
  218. case '©com':
  219. case '©gen':
  220. case '©ope':
  221. case '©url':
  222. case '©enc':
  223. $atomstructure['data_length'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
  224. $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2));
  225. $atomstructure['data'] = substr($atomdata, 4);
  226. $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
  227. if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
  228. $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
  229. }
  230. $this->CopyToAppropriateCommentsSection($atomname, $atomstructure['data'], $ThisFileInfo);
  231. break;
  232. case 'play': // auto-PLAY atom
  233. $atomstructure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  234. $ThisFileInfo['quicktime']['autoplay'] = $atomstructure['autoplay'];
  235. break;
  236. case 'WLOC': // Window LOCation atom
  237. $atomstructure['location_x'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
  238. $atomstructure['location_y'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2));
  239. break;
  240. case 'LOOP': // LOOPing atom
  241. case 'SelO': // play SELection Only atom
  242. case 'AllF': // play ALL Frames atom
  243. $atomstructure['data'] = getid3_lib::BigEndian2Int($atomdata);
  244. break;
  245. case 'name': //
  246. case 'MCPS': // Media Cleaner PRo
  247. case '@PRM': // adobe PReMiere version
  248. case '@PRQ': // adobe PRemiere Quicktime version
  249. $atomstructure['data'] = $atomdata;
  250. break;
  251. case 'cmvd': // Compressed MooV Data atom
  252. // Code by ubergeekØubergeek*tv based on information from
  253. // http://developer.apple.com/quicktime/icefloe/dispatch012.html
  254. $atomstructure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
  255. $CompressedFileData = substr($atomdata, 4);
  256. if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
  257. $atomstructure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, $ThisFileInfo, 0, $atomHierarchy, $ParseAllPossibleAtoms);
  258. } else {
  259. $ThisFileInfo['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atomstructure['offset'];
  260. }
  261. break;
  262. case 'dcom': // Data COMpression atom
  263. $atomstructure['compression_id'] = $atomdata;
  264. $atomstructure['compression_text'] = $this->QuicktimeDCOMLookup($atomdata);
  265. break;
  266. case 'rdrf': // Reference movie Data ReFerence atom
  267. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  268. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
  269. $atomstructure['flags']['internal_data'] = (bool) ($atomstructure['flags_raw'] & 0x000001);
  270. $atomstructure['reference_type_name'] = substr($atomdata, 4, 4);
  271. $atomstructure['reference_length'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  272. switch ($atomstructure['reference_type_name']) {
  273. case 'url ':
  274. $atomstructure['url'] = $this->NoNullString(substr($atomdata, 12));
  275. break;
  276. case 'alis':
  277. $atomstructure['file_alias'] = substr($atomdata, 12);
  278. break;
  279. case 'rsrc':
  280. $atomstructure['resource_alias'] = substr($atomdata, 12);
  281. break;
  282. default:
  283. $atomstructure['data'] = substr($atomdata, 12);
  284. break;
  285. }
  286. break;
  287. case 'rmqu': // Reference Movie QUality atom
  288. $atomstructure['movie_quality'] = getid3_lib::BigEndian2Int($atomdata);
  289. break;
  290. case 'rmcs': // Reference Movie Cpu Speed atom
  291. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  292. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  293. $atomstructure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  294. break;
  295. case 'rmvc': // Reference Movie Version Check atom
  296. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  297. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  298. $atomstructure['gestalt_selector'] = substr($atomdata, 4, 4);
  299. $atomstructure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  300. $atomstructure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
  301. $atomstructure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atomdata, 14, 2));
  302. break;
  303. case 'rmcd': // Reference Movie Component check atom
  304. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  305. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  306. $atomstructure['component_type'] = substr($atomdata, 4, 4);
  307. $atomstructure['component_subtype'] = substr($atomdata, 8, 4);
  308. $atomstructure['component_manufacturer'] = substr($atomdata, 12, 4);
  309. $atomstructure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
  310. $atomstructure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
  311. $atomstructure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atomdata, 24, 4));
  312. break;
  313. case 'rmdr': // Reference Movie Data Rate atom
  314. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  315. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  316. $atomstructure['data_rate'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  317. $atomstructure['data_rate_bps'] = $atomstructure['data_rate'] * 10;
  318. break;
  319. case 'rmla': // Reference Movie Language Atom
  320. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  321. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  322. $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  323. $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
  324. if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
  325. $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
  326. }
  327. break;
  328. case 'rmla': // Reference Movie Language Atom
  329. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  330. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  331. $atomstructure['track_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  332. break;
  333. case 'ptv ': // Print To Video - defines a movie's full screen mode
  334. // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
  335. $atomstructure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2));
  336. $atomstructure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 2)); // hardcoded: 0x0000
  337. $atomstructure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x0000
  338. $atomstructure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 1));
  339. $atomstructure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atomdata, 7, 1));
  340. $atomstructure['flags']['play_on_open'] = (bool) $atomstructure['play_on_open_flag'];
  341. $atomstructure['flags']['slide_show'] = (bool) $atomstructure['slide_show_flag'];
  342. $ptv_lookup[0] = 'normal';
  343. $ptv_lookup[1] = 'double';
  344. $ptv_lookup[2] = 'half';
  345. $ptv_lookup[3] = 'full';
  346. $ptv_lookup[4] = 'current';
  347. if (isset($ptv_lookup[$atomstructure['display_size_raw']])) {
  348. $atomstructure['display_size'] = $ptv_lookup[$atomstructure['display_size_raw']];
  349. } else {
  350. $ThisFileInfo['warning'][] = 'unknown "ptv " display constant ('.$atomstructure['display_size_raw'].')';
  351. }
  352. break;
  353. case 'stsd': // Sample Table Sample Description atom
  354. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  355. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  356. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  357. $stsdEntriesDataOffset = 8;
  358. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  359. $atomstructure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 4));
  360. $stsdEntriesDataOffset += 4;
  361. $atomstructure['sample_description_table'][$i]['data_format'] = substr($atomdata, $stsdEntriesDataOffset, 4);
  362. $stsdEntriesDataOffset += 4;
  363. $atomstructure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 6));
  364. $stsdEntriesDataOffset += 6;
  365. $atomstructure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atomdata, $stsdEntriesDataOffset, 2));
  366. $stsdEntriesDataOffset += 2;
  367. $atomstructure['sample_description_table'][$i]['data'] = substr($atomdata, $stsdEntriesDataOffset, ($atomstructure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
  368. $stsdEntriesDataOffset += ($atomstructure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
  369. $atomstructure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 0, 2));
  370. $atomstructure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 2, 2));
  371. $atomstructure['sample_description_table'][$i]['encoder_vendor'] = substr($atomstructure['sample_description_table'][$i]['data'], 4, 4);
  372. switch ($atomstructure['sample_description_table'][$i]['encoder_vendor']) {
  373. case "\x00\x00\x00\x00":
  374. // audio atom
  375. $atomstructure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 8, 2));
  376. $atomstructure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 10, 2));
  377. $atomstructure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 12, 2));
  378. $atomstructure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 14, 2));
  379. $atomstructure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 16, 4));
  380. switch ($atomstructure['sample_description_table'][$i]['data_format']) {
  381. case 'avc1':
  382. case 'mp4v':
  383. $ThisFileInfo['fileformat'] = 'mp4';
  384. $ThisFileInfo['video']['fourcc'] = $atomstructure['sample_description_table'][$i]['data_format'];
  385. $ThisFileInfo['warning'][] = 'This version ('.GETID3_VERSION.') of getID3() does not fully support MPEG-4 audio/video streams';
  386. break;
  387. case 'qtvr':
  388. $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
  389. break;
  390. case 'mp4a':
  391. default:
  392. $ThisFileInfo['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atomstructure['sample_description_table'][$i]['data_format']);
  393. $ThisFileInfo['quicktime']['audio']['sample_rate'] = $atomstructure['sample_description_table'][$i]['audio_sample_rate'];
  394. $ThisFileInfo['quicktime']['audio']['channels'] = $atomstructure['sample_description_table'][$i]['audio_channels'];
  395. $ThisFileInfo['quicktime']['audio']['bit_depth'] = $atomstructure['sample_description_table'][$i]['audio_bit_depth'];
  396. $ThisFileInfo['audio']['codec'] = $ThisFileInfo['quicktime']['audio']['codec'];
  397. $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['quicktime']['audio']['sample_rate'];
  398. $ThisFileInfo['audio']['channels'] = $ThisFileInfo['quicktime']['audio']['channels'];
  399. $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['quicktime']['audio']['bit_depth'];
  400. switch ($atomstructure['sample_description_table'][$i]['data_format']) {
  401. case 'raw ': // PCM
  402. case 'alac': // Apple Lossless Audio Codec
  403. $ThisFileInfo['audio']['lossless'] = true;
  404. break;
  405. default:
  406. $ThisFileInfo['audio']['lossless'] = false;
  407. break;
  408. }
  409. break;
  410. }
  411. break;
  412. default:
  413. switch ($atomstructure['sample_description_table'][$i]['data_format']) {
  414. case 'mp4s':
  415. $ThisFileInfo['fileformat'] = 'mp4';
  416. break;
  417. default:
  418. // video atom
  419. $atomstructure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 8, 4));
  420. $atomstructure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 12, 4));
  421. $atomstructure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 16, 2));
  422. $atomstructure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 18, 2));
  423. $atomstructure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 20, 4));
  424. $atomstructure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atomstructure['sample_description_table'][$i]['data'], 24, 4));
  425. $atomstructure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 28, 4));
  426. $atomstructure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 32, 2));
  427. $atomstructure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 34, 1));
  428. $atomstructure['sample_description_table'][$i]['video_encoder_name'] = substr($atomstructure['sample_description_table'][$i]['data'], 35, $atomstructure['sample_description_table'][$i]['video_encoder_name_len']);
  429. $atomstructure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 66, 2));
  430. $atomstructure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atomstructure['sample_description_table'][$i]['data'], 68, 2));
  431. $atomstructure['sample_description_table'][$i]['video_pixel_color_type'] = (($atomstructure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
  432. $atomstructure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atomstructure['sample_description_table'][$i]['video_pixel_color_depth']);
  433. if ($atomstructure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
  434. $ThisFileInfo['quicktime']['video']['codec_fourcc'] = $atomstructure['sample_description_table'][$i]['data_format'];
  435. $ThisFileInfo['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atomstructure['sample_description_table'][$i]['data_format']);
  436. $ThisFileInfo['quicktime']['video']['codec'] = $atomstructure['sample_description_table'][$i]['video_encoder_name'];
  437. $ThisFileInfo['quicktime']['video']['color_depth'] = $atomstructure['sample_description_table'][$i]['video_pixel_color_depth'];
  438. $ThisFileInfo['quicktime']['video']['color_depth_name'] = $atomstructure['sample_description_table'][$i]['video_pixel_color_name'];
  439. $ThisFileInfo['video']['codec'] = $ThisFileInfo['quicktime']['video']['codec'];
  440. $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['quicktime']['video']['color_depth'];
  441. }
  442. $ThisFileInfo['video']['lossless'] = false;
  443. $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
  444. break;
  445. }
  446. break;
  447. }
  448. switch (strtolower($atomstructure['sample_description_table'][$i]['data_format'])) {
  449. case 'mp4a':
  450. $ThisFileInfo['audio']['dataformat'] = 'mp4';
  451. $ThisFileInfo['quicktime']['audio']['codec'] = 'mp4';
  452. break;
  453. case '3ivx':
  454. case '3iv1':
  455. case '3iv2':
  456. $ThisFileInfo['video']['dataformat'] = '3ivx';
  457. break;
  458. case 'xvid':
  459. $ThisFileInfo['video']['dataformat'] = 'xvid';
  460. break;
  461. case 'mp4v':
  462. $ThisFileInfo['video']['dataformat'] = 'mpeg4';
  463. break;
  464. case 'divx':
  465. case 'div1':
  466. case 'div2':
  467. case 'div3':
  468. case 'div4':
  469. case 'div5':
  470. case 'div6':
  471. $TDIVXileInfo['video']['dataformat'] = 'divx';
  472. break;
  473. default:
  474. // do nothing
  475. break;
  476. }
  477. unset($atomstructure['sample_description_table'][$i]['data']);
  478. }
  479. break;
  480. case 'stts': // Sample Table Time-to-Sample atom
  481. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  482. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  483. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  484. $sttsEntriesDataOffset = 8;
  485. //$FrameRateCalculatorArray = array();
  486. $frames_count = 0;
  487. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  488. $atomstructure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atomdata, $sttsEntriesDataOffset, 4));
  489. $sttsEntriesDataOffset += 4;
  490. $atomstructure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, $sttsEntriesDataOffset, 4));
  491. $sttsEntriesDataOffset += 4;
  492. $frames_count += $atomstructure['time_to_sample_table'][$i]['sample_count'];
  493. // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
  494. //if (!empty($ThisFileInfo['quicktime']['time_scale']) && (@$atomstructure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
  495. // $stts_new_framerate = $ThisFileInfo['quicktime']['time_scale'] / $atomstructure['time_to_sample_table'][$i]['sample_duration'];
  496. // if ($stts_new_framerate <= 60) {
  497. // // some atoms have durations of "1" giving a very large framerate, which probably is not right
  498. // $ThisFileInfo['video']['frame_rate'] = max(@$ThisFileInfo['video']['frame_rate'], $stts_new_framerate);
  499. // }
  500. //}
  501. //
  502. //@$FrameRateCalculatorArray[($ThisFileInfo['quicktime']['time_scale'] / $atomstructure['time_to_sample_table'][$i]['sample_duration'])] += $atomstructure['time_to_sample_table'][$i]['sample_count'];
  503. }
  504. $ThisFileInfo['quicktime']['stts_framecount'][] = $frames_count;
  505. //$sttsFramesTotal = 0;
  506. //$sttsSecondsTotal = 0;
  507. //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
  508. // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
  509. // // not video FPS information, probably audio information
  510. // $sttsFramesTotal = 0;
  511. // $sttsSecondsTotal = 0;
  512. // break;
  513. // }
  514. // $sttsFramesTotal += $frame_count;
  515. // $sttsSecondsTotal += $frame_count / $frames_per_second;
  516. //}
  517. //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
  518. // if (($sttsFramesTotal / $sttsSecondsTotal) > @$ThisFileInfo['video']['frame_rate']) {
  519. // $ThisFileInfo['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
  520. // }
  521. //}
  522. break;
  523. case 'stss': // Sample Table Sync Sample (key frames) atom
  524. if ($ParseAllPossibleAtoms) {
  525. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  526. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  527. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  528. $stssEntriesDataOffset = 8;
  529. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  530. $atomstructure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stssEntriesDataOffset, 4));
  531. $stssEntriesDataOffset += 4;
  532. }
  533. }
  534. break;
  535. case 'stsc': // Sample Table Sample-to-Chunk atom
  536. if ($ParseAllPossibleAtoms) {
  537. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  538. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  539. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  540. $stscEntriesDataOffset = 8;
  541. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  542. $atomstructure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
  543. $stscEntriesDataOffset += 4;
  544. $atomstructure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
  545. $stscEntriesDataOffset += 4;
  546. $atomstructure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atomdata, $stscEntriesDataOffset, 4));
  547. $stscEntriesDataOffset += 4;
  548. }
  549. }
  550. break;
  551. case 'stsz': // Sample Table SiZe atom
  552. if ($ParseAllPossibleAtoms) {
  553. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  554. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  555. $atomstructure['sample_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  556. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  557. $stszEntriesDataOffset = 12;
  558. if ($atomstructure['sample_size'] == 0) {
  559. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  560. $atomstructure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stszEntriesDataOffset, 4));
  561. $stszEntriesDataOffset += 4;
  562. }
  563. }
  564. }
  565. break;
  566. case 'stco': // Sample Table Chunk Offset atom
  567. if ($ParseAllPossibleAtoms) {
  568. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  569. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  570. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  571. $stcoEntriesDataOffset = 8;
  572. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  573. $atomstructure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stcoEntriesDataOffset, 4));
  574. $stcoEntriesDataOffset += 4;
  575. }
  576. }
  577. break;
  578. case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
  579. if ($ParseAllPossibleAtoms) {
  580. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  581. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  582. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  583. $stcoEntriesDataOffset = 8;
  584. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  585. $atomstructure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $stcoEntriesDataOffset, 8));
  586. $stcoEntriesDataOffset += 8;
  587. }
  588. }
  589. break;
  590. case 'dref': // Data REFerence atom
  591. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  592. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  593. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  594. $drefDataOffset = 8;
  595. for ($i = 0; $i < $atomstructure['number_entries']; $i++) {
  596. $atomstructure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 4));
  597. $drefDataOffset += 4;
  598. $atomstructure['data_references'][$i]['type'] = substr($atomdata, $drefDataOffset, 4);
  599. $drefDataOffset += 4;
  600. $atomstructure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 1));
  601. $drefDataOffset += 1;
  602. $atomstructure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, $drefDataOffset, 3)); // hardcoded: 0x0000
  603. $drefDataOffset += 3;
  604. $atomstructure['data_references'][$i]['data'] = substr($atomdata, $drefDataOffset, ($atomstructure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
  605. $drefDataOffset += ($atomstructure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
  606. $atomstructure['data_references'][$i]['flags']['self_reference'] = (bool) ($atomstructure['data_references'][$i]['flags_raw'] & 0x001);
  607. }
  608. break;
  609. case 'gmin': // base Media INformation atom
  610. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  611. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  612. $atomstructure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  613. $atomstructure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
  614. $atomstructure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 2));
  615. $atomstructure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2));
  616. $atomstructure['balance'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 2));
  617. $atomstructure['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, 14, 2));
  618. break;
  619. case 'smhd': // Sound Media information HeaDer atom
  620. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  621. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  622. $atomstructure['balance'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  623. $atomstructure['reserved'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
  624. break;
  625. case 'vmhd': // Video Media information HeaDer atom
  626. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  627. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
  628. $atomstructure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2));
  629. $atomstructure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2));
  630. $atomstructure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 2));
  631. $atomstructure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2));
  632. $atomstructure['flags']['no_lean_ahead'] = (bool) ($atomstructure['flags_raw'] & 0x001);
  633. break;
  634. case 'hdlr': // HanDLeR reference atom
  635. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  636. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  637. $atomstructure['component_type'] = substr($atomdata, 4, 4);
  638. $atomstructure['component_subtype'] = substr($atomdata, 8, 4);
  639. $atomstructure['component_manufacturer'] = substr($atomdata, 12, 4);
  640. $atomstructure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
  641. $atomstructure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
  642. $atomstructure['component_name'] = $this->Pascal2String(substr($atomdata, 24));
  643. if (($atomstructure['component_subtype'] == 'STpn') && ($atomstructure['component_manufacturer'] == 'zzzz')) {
  644. $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
  645. }
  646. break;
  647. case 'mdhd': // MeDia HeaDer atom
  648. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  649. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  650. $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  651. $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  652. $atomstructure['time_scale'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
  653. $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
  654. $atomstructure['language_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 2));
  655. $atomstructure['quality'] = getid3_lib::BigEndian2Int(substr($atomdata, 22, 2));
  656. if ($atomstructure['time_scale'] == 0) {
  657. $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
  658. return false;
  659. }
  660. $ThisFileInfo['quicktime']['time_scale'] = max(@$ThisFileInfo['quicktime']['time_scale'], $atomstructure['time_scale']);
  661. $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
  662. $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
  663. $atomstructure['playtime_seconds'] = $atomstructure['duration'] / $atomstructure['time_scale'];
  664. $atomstructure['language'] = $this->QuicktimeLanguageLookup($atomstructure['language_id']);
  665. if (empty($ThisFileInfo['comments']['language']) || (!in_array($atomstructure['language'], $ThisFileInfo['comments']['language']))) {
  666. $ThisFileInfo['comments']['language'][] = $atomstructure['language'];
  667. }
  668. break;
  669. case 'pnot': // Preview atom
  670. $atomstructure['modification_date'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4)); // "standard Macintosh format"
  671. $atomstructure['version_number'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x00
  672. $atomstructure['atom_type'] = substr($atomdata, 6, 4); // usually: 'PICT'
  673. $atomstructure['atom_index'] = getid3_lib::BigEndian2Int(substr($atomdata, 10, 2)); // usually: 0x01
  674. $atomstructure['modification_date_unix'] = getid3_lib::DateMac2Unix($atomstructure['modification_date']);
  675. break;
  676. case 'crgn': // Clipping ReGioN atom
  677. $atomstructure['region_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 2)); // The Region size, Region boundary box,
  678. $atomstructure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atomdata, 2, 8)); // and Clipping region data fields
  679. $atomstructure['clipping_data'] = substr($atomdata, 10); // constitute a QuickDraw region.
  680. break;
  681. case 'load': // track LOAD settings atom
  682. $atomstructure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
  683. $atomstructure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  684. $atomstructure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  685. $atomstructure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
  686. $atomstructure['default_hints']['double_buffer'] = (bool) ($atomstructure['default_hints_raw'] & 0x0020);
  687. $atomstructure['default_hints']['high_quality'] = (bool) ($atomstructure['default_hints_raw'] & 0x0100);
  688. break;
  689. case 'tmcd': // TiMe CoDe atom
  690. case 'chap': // CHAPter list atom
  691. case 'sync': // SYNChronization atom
  692. case 'scpt': // tranSCriPT atom
  693. case 'ssrc': // non-primary SouRCe atom
  694. for ($i = 0; $i < (strlen($atomdata) % 4); $i++) {
  695. $atomstructure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atomdata, $i * 4, 4));
  696. }
  697. break;
  698. case 'elst': // Edit LiST atom
  699. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  700. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  701. $atomstructure['number_entries'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  702. for ($i = 0; $i < $atomstructure['number_entries']; $i++ ) {
  703. $atomstructure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($i * 12) + 0, 4));
  704. $atomstructure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($i * 12) + 4, 4));
  705. $atomstructure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atomdata, 8 + ($i * 12) + 8, 4));
  706. }
  707. break;
  708. case 'kmat': // compressed MATte atom
  709. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  710. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3)); // hardcoded: 0x0000
  711. $atomstructure['matte_data_raw'] = substr($atomdata, 4);
  712. break;
  713. case 'ctab': // Color TABle atom
  714. $atomstructure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4)); // hardcoded: 0x00000000
  715. $atomstructure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 2)); // hardcoded: 0x8000
  716. $atomstructure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atomdata, 6, 2)) + 1;
  717. for ($colortableentry = 0; $colortableentry < $atomstructure['color_table_size']; $colortableentry++) {
  718. $atomstructure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 0, 2));
  719. $atomstructure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 2, 2));
  720. $atomstructure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 4, 2));
  721. $atomstructure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atomdata, 8 + ($colortableentry * 8) + 6, 2));
  722. }
  723. break;
  724. case 'mvhd': // MoVie HeaDer atom
  725. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  726. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
  727. $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  728. $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  729. $atomstructure['time_scale'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
  730. $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
  731. $atomstructure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atomdata, 20, 4));
  732. $atomstructure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atomdata, 24, 2));
  733. $atomstructure['reserved'] = substr($atomdata, 26, 10);
  734. $atomstructure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atomdata, 36, 4));
  735. $atomstructure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atomdata, 40, 4));
  736. $atomstructure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atomdata, 44, 4));
  737. $atomstructure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atomdata, 48, 4));
  738. $atomstructure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atomdata, 52, 4));
  739. $atomstructure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atomdata, 56, 4));
  740. $atomstructure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atomdata, 60, 4));
  741. $atomstructure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atomdata, 64, 4));
  742. $atomstructure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atomdata, 68, 4));
  743. $atomstructure['preview_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 72, 4));
  744. $atomstructure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 76, 4));
  745. $atomstructure['poster_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 80, 4));
  746. $atomstructure['selection_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 84, 4));
  747. $atomstructure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 88, 4));
  748. $atomstructure['current_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 92, 4));
  749. $atomstructure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atomdata, 96, 4));
  750. if ($atomstructure['time_scale'] == 0) {
  751. $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
  752. return false;
  753. }
  754. $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
  755. $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
  756. $ThisFileInfo['quicktime']['time_scale'] = max(@$ThisFileInfo['quicktime']['time_scale'], $atomstructure['time_scale']);
  757. $ThisFileInfo['quicktime']['display_scale'] = $atomstructure['matrix_a'];
  758. $ThisFileInfo['playtime_seconds'] = $atomstructure['duration'] / $atomstructure['time_scale'];
  759. break;
  760. case 'tkhd': // TracK HeaDer atom
  761. $atomstructure['version'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 1));
  762. $atomstructure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atomdata, 1, 3));
  763. $atomstructure['creation_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  764. $atomstructure['modify_time'] = getid3_lib::BigEndian2Int(substr($atomdata, 8, 4));
  765. $atomstructure['trackid'] = getid3_lib::BigEndian2Int(substr($atomdata, 12, 4));
  766. $atomstructure['reserved1'] = getid3_lib::BigEndian2Int(substr($atomdata, 16, 4));
  767. $atomstructure['duration'] = getid3_lib::BigEndian2Int(substr($atomdata, 20, 4));
  768. $atomstructure['reserved2'] = getid3_lib::BigEndian2Int(substr($atomdata, 24, 8));
  769. $atomstructure['layer'] = getid3_lib::BigEndian2Int(substr($atomdata, 32, 2));
  770. $atomstructure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atomdata, 34, 2));
  771. $atomstructure['volume'] = getid3_lib::FixedPoint8_8(substr($atomdata, 36, 2));
  772. $atomstructure['reserved3'] = getid3_lib::BigEndian2Int(substr($atomdata, 38, 2));
  773. $atomstructure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atomdata, 40, 4));
  774. $atomstructure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atomdata, 44, 4));
  775. $atomstructure['matrix_u'] = getid3_lib::FixedPoint16_16(substr($atomdata, 48, 4));
  776. $atomstructure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atomdata, 52, 4));
  777. $atomstructure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atomdata, 56, 4));
  778. $atomstructure['matrix_v'] = getid3_lib::FixedPoint16_16(substr($atomdata, 60, 4));
  779. $atomstructure['matrix_x'] = getid3_lib::FixedPoint2_30(substr($atomdata, 64, 4));
  780. $atomstructure['matrix_y'] = getid3_lib::FixedPoint2_30(substr($atomdata, 68, 4));
  781. $atomstructure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atomdata, 72, 4));
  782. $atomstructure['width'] = getid3_lib::FixedPoint16_16(substr($atomdata, 76, 4));
  783. $atomstructure['height'] = getid3_lib::FixedPoint16_16(substr($atomdata, 80, 4));
  784. $atomstructure['flags']['enabled'] = (bool) ($atomstructure['flags_raw'] & 0x0001);
  785. $atomstructure['flags']['in_movie'] = (bool) ($atomstructure['flags_raw'] & 0x0002);
  786. $atomstructure['flags']['in_preview'] = (bool) ($atomstructure['flags_raw'] & 0x0004);
  787. $atomstructure['flags']['in_poster'] = (bool) ($atomstructure['flags_raw'] & 0x0008);
  788. $atomstructure['creation_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['creation_time']);
  789. $atomstructure['modify_time_unix'] = getid3_lib::DateMac2Unix($atomstructure['modify_time']);
  790. if (!isset($ThisFileInfo['video']['resolution_x']) || !isset($ThisFileInfo['video']['resolution_y'])) {
  791. $ThisFileInfo['video']['resolution_x'] = $atomstructure['width'];
  792. $ThisFileInfo['video']['resolution_y'] = $atomstructure['height'];
  793. }
  794. if ($atomstructure['flags']['enabled'] == 1) {
  795. $ThisFileInfo['video']['resolution_x'] = max($ThisFileInfo['video']['resolution_x'], $atomstructure['width']);
  796. $ThisFileInfo['video']['resolution_y'] = max($ThisFileInfo['video']['resolution_y'], $atomstructure['height']);
  797. }
  798. if (!empty($ThisFileInfo['video']['resolution_x']) && !empty($ThisFileInfo['video']['resolution_y'])) {
  799. $ThisFileInfo['quicktime']['video']['resolution_x'] = $ThisFileInfo['video']['resolution_x'];
  800. $ThisFileInfo['quicktime']['video']['resolution_y'] = $ThisFileInfo['video']['resolution_y'];
  801. } else {
  802. unset($ThisFileInfo['video']['resolution_x']);
  803. unset($ThisFileInfo['video']['resolution_y']);
  804. unset($ThisFileInfo['quicktime']['video']);
  805. }
  806. break;
  807. case 'meta': // METAdata atom
  808. // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
  809. $NextTagPosition = strpos($atomdata, '©');
  810. while ($NextTagPosition < strlen($atomdata)) {
  811. $metaItemSize = getid3_lib::BigEndian2Int(substr($atomdata, $NextTagPosition - 4, 4)) - 4;
  812. if ($metaItemSize == -4) {
  813. break;
  814. }
  815. $metaItemRaw = substr($atomdata, $NextTagPosition, $metaItemSize);
  816. $metaItemKey = substr($metaItemRaw, 0, 4);
  817. $metaItemData = substr($metaItemRaw, 20);
  818. $NextTagPosition += $metaItemSize + 4;
  819. $this->CopyToAppropriateCommentsSection($metaItemKey, $metaItemData, $ThisFileInfo);
  820. }
  821. break;
  822. case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
  823. $atomstructure['signature'] = substr($atomdata, 0, 4);
  824. $atomstructure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atomdata, 4, 4));
  825. $atomstructure['fourcc'] = substr($atomdata, 8, 4);
  826. break;
  827. case 'mdat': // Media DATa atom
  828. case 'free': // FREE space atom
  829. case 'skip': // SKIP atom
  830. case 'wide': // 64-bit expansion placeholder atom
  831. // 'mdat' data is too big to deal with, contains no useful metadata
  832. // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
  833. // When writing QuickTime files, it is sometimes necessary to update an atom's size.
  834. // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
  835. // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
  836. // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
  837. // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
  838. // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
  839. // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
  840. break;
  841. case 'nsav': // NoSAVe atom
  842. // http://developer.apple.com/technotes/tn/tn2038.html
  843. $atomstructure['data'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
  844. break;
  845. case 'ctyp': // Controller TYPe atom (seen on QTVR)
  846. // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
  847. // some controller names are:
  848. // 0x00 + 'std' for linear movie
  849. // 'none' for no controls
  850. $atomstructure['ctyp'] = substr($atomdata, 0, 4);
  851. switch ($atomstructure['ctyp']) {
  852. case 'qtvr':
  853. $ThisFileInfo['video']['dataformat'] = 'quicktimevr';
  854. break;
  855. }
  856. break;
  857. case 'pano': // PANOrama track (seen on QTVR)
  858. $atomstructure['pano'] = getid3_lib::BigEndian2Int(substr($atomdata, 0, 4));
  859. break;
  860. case 'hint': // HINT track
  861. case 'hinf': //
  862. case 'hinv': //
  863. case 'hnti': //
  864. $ThisFileInfo['quicktime']['hinting'] = true;
  865. break;
  866. case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
  867. for ($i = 0; $i < ($atomstructure['size'] - 8); $i += 4) {
  868. $atomstructure['imgt'][] = getid3_lib::BigEndian2Int(substr($atomdata, $i, 4));
  869. }
  870. break;
  871. case 'FXTC': // Something to do with Adobe After Effects (?)
  872. case 'PrmA':
  873. case 'code':
  874. case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
  875. // Observed-but-not-handled atom types are just listed here
  876. // to prevent warnings being generated
  877. $atomstructure['data'] = $atomdata;
  878. break;
  879. default:
  880. $ThisFileInfo['warning'][] = 'Unknown QuickTime atom type: "'.$atomname.'" at offset '.$baseoffset;
  881. $atomstructure['data'] = $atomdata;
  882. break;
  883. }
  884. array_pop($atomHierarchy);
  885. return $atomstructure;
  886. }
  887. function QuicktimeParseContainerAtom($atomdata, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  888. $atomstructure = false;
  889. $subatomoffset = 0;
  890. $subatomcounter = 0;
  891. if ((strlen($atomdata) == 4) && (getid3_lib::BigEndian2Int($atomdata) == 0x00000000)) {
  892. return false;
  893. }
  894. while ($subatomoffset < strlen($atomdata)) {
  895. $subatomsize = getid3_lib::BigEndian2Int(substr($atomdata, $subatomoffset + 0, 4));
  896. $subatomname = substr($atomdata, $subatomoffset + 4, 4);
  897. $subatomdata = substr($atomdata, $subatomoffset + 8, $subatomsize - 8);
  898. if ($subatomsize == 0) {
  899. // Furthermore, for historical reasons the list of atoms is optionally
  900. // terminated by a 32-bit integer set to 0. If you are writing a program
  901. // to read user data atoms, you should allow for the terminating 0.
  902. return $atomstructure;
  903. }
  904. $atomstructure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $ThisFileInfo, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
  905. $subatomoffset += $subatomsize;
  906. $subatomcounter++;
  907. }
  908. return $atomstructure;
  909. }
  910. function QuicktimeLanguageLookup($languageid) {
  911. static $QuicktimeLanguageLookup = array();
  912. if (empty($QuicktimeLanguageLookup)) {
  913. $QuicktimeLanguageLookup[0] = 'English';
  914. $QuicktimeLanguageLookup[1] = 'French';
  915. $QuicktimeLanguageLookup[2] = 'German';
  916. $QuicktimeLanguageLookup[3] = 'Italian';
  917. $QuicktimeLanguageLookup[4] = 'Dutch';
  918. $QuicktimeLanguageLookup[5] = 'Swedish';
  919. $QuicktimeLanguageLookup[6] = 'Spanish';
  920. $QuicktimeLanguageLookup[7] = 'Danish';
  921. $QuicktimeLanguageLookup[8] = 'Portuguese';
  922. $QuicktimeLanguageLookup[9] = 'Norwegian';
  923. $QuicktimeLanguageLookup[10] = 'Hebrew';
  924. $QuicktimeLanguageLookup[11] = 'Japanese';
  925. $QuicktimeLanguageLookup[12] = 'Arabic';
  926. $QuicktimeLanguageLookup[13] = 'Finnish';
  927. $QuicktimeLanguageLookup[14] = 'Greek';
  928. $QuicktimeLanguageLookup[15] = 'Icelandic';
  929. $QuicktimeLanguageLookup[16] = 'Maltese';
  930. $QuicktimeLanguageLookup[17] = 'Turkish';
  931. $QuicktimeLanguageLookup[18] = 'Croatian';
  932. $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
  933. $QuicktimeLanguageLookup[20] = 'Urdu';
  934. $QuicktimeLanguageLookup[21] = 'Hindi';
  935. $QuicktimeLanguageLookup[22] = 'Thai';
  936. $QuicktimeLanguageLookup[23] = 'Korean';
  937. $QuicktimeLanguageLookup[24] = 'Lithuanian';
  938. $QuicktimeLanguageLookup[25] = 'Polish';
  939. $QuicktimeLanguageLookup[26] = 'Hungarian';
  940. $QuicktimeLanguageLookup[27] = 'Estonian';
  941. $QuicktimeLanguageLookup[28] = 'Lettish';
  942. $QuicktimeLanguageLookup[28] = 'Latvian';
  943. $QuicktimeLanguageLookup[29] = 'Saamisk';
  944. $QuicktimeLanguageLookup[29] = 'Lappish';
  945. $QuicktimeLanguageLookup[30] = 'Faeroese';
  946. $QuicktimeLanguageLookup[31] = 'Farsi';
  947. $QuicktimeLanguageLookup[31] = 'Persian';
  948. $QuicktimeLanguageLookup[32] = 'Russian';
  949. $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
  950. $QuicktimeLanguageLookup[34] = 'Flemish';
  951. $QuicktimeLanguageLookup[35] = 'Irish';
  952. $QuicktimeLanguageLookup[36] = 'Albanian';
  953. $QuicktimeLanguageLookup[37] = 'Romanian';
  954. $QuicktimeLanguageLookup[38] = 'Czech';
  955. $QuicktimeLanguageLookup[39] = 'Slovak';
  956. $QuicktimeLanguageLookup[40] = 'Slovenian';
  957. $QuicktimeLanguageLookup[41] = 'Yiddish';
  958. $QuicktimeLanguageLookup[42] = 'Serbian';
  959. $QuicktimeLanguageLookup[43] = 'Macedonian';
  960. $QuicktimeLanguageLookup[44] = 'Bulgarian';
  961. $QuicktimeLanguageLookup[45] = 'Ukrainian';
  962. $QuicktimeLanguageLookup[46] = 'Byelorussian';
  963. $QuicktimeLanguageLookup[47] = 'Uzbek';
  964. $QuicktimeLanguageLookup[48] = 'Kazakh';
  965. $QuicktimeLanguageLookup[49] = 'Azerbaijani';
  966. $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
  967. $QuicktimeLanguageLookup[51] = 'Armenian';
  968. $QuicktimeLanguageLookup[52] = 'Georgian';
  969. $QuicktimeLanguageLookup[53] = 'Moldavian';
  970. $QuicktimeLanguageLookup[54] = 'Kirghiz';
  971. $QuicktimeLanguageLookup[55] = 'Tajiki';
  972. $QuicktimeLanguageLookup[56] = 'Turkmen';
  973. $QuicktimeLanguageLookup[57] = 'Mongolian';
  974. $QuicktimeLanguageLookup[58] = 'MongolianCyr';
  975. $QuicktimeLanguageLookup[59] = 'Pashto';
  976. $QuicktimeLanguageLookup[60] = 'Kurdish';
  977. $QuicktimeLanguageLookup[61] = 'Kashmiri';
  978. $QuicktimeLanguageLookup[62] = 'Sindhi';
  979. $QuicktimeLanguageLookup[63] = 'Tibetan';
  980. $QuicktimeLanguageLookup[64] = 'Nepali';
  981. $QuicktimeLanguageLookup[65] = 'Sanskrit';
  982. $QuicktimeLanguageLookup[66] = 'Marathi';
  983. $QuicktimeLanguageLookup[67] = 'Bengali';
  984. $QuicktimeLanguageLookup[68] = 'Assamese';
  985. $QuicktimeLanguageLookup[69] = 'Gujarati';
  986. $QuicktimeLanguageLookup[70] = 'Punjabi';
  987. $QuicktimeLanguageLookup[71] = 'Oriya';
  988. $QuicktimeLanguageLookup[72] = 'Malayalam';
  989. $QuicktimeLanguageLookup[73] = 'Kannada';
  990. $QuicktimeLanguageLookup[74] = 'Tamil';
  991. $QuicktimeLanguageLookup[75] = 'Telugu';
  992. $QuicktimeLanguageLookup[76] = 'Sinhalese';
  993. $QuicktimeLanguageLookup[77] = 'Burmese';
  994. $QuicktimeLanguageLookup[78] = 'Khmer';
  995. $QuicktimeLanguageLookup[79] = 'Lao';
  996. $QuicktimeLanguageLookup[80] = 'Vietnamese';
  997. $QuicktimeLanguageLookup[81] = 'Indonesian';
  998. $QuicktimeLanguageLookup[82] = 'Tagalog';
  999. $QuicktimeLanguageLookup[83] = 'MalayRoman';
  1000. $QuicktimeLanguageLookup[84] = 'MalayArabic';
  1001. $QuicktimeLanguageLookup[85] = 'Amharic';
  1002. $QuicktimeLanguageLookup[86] = 'Tigrinya';
  1003. $QuicktimeLanguageLookup[87] = 'Galla';
  1004. $QuicktimeLanguageLookup[87] = 'Oromo';
  1005. $QuicktimeLanguageLookup[88] = 'Somali';
  1006. $QuicktimeLanguageLookup[89] = 'Swahili';
  1007. $QuicktimeLanguageLookup[90] = 'Ruanda';
  1008. $QuicktimeLanguageLookup[91] = 'Rundi';
  1009. $QuicktimeLanguageLookup[92] = 'Chewa';
  1010. $QuicktimeLanguageLookup[93] = 'Malagasy';
  1011. $QuicktimeLanguageLookup[94] = 'Esperanto';
  1012. $QuicktimeLanguageLookup[128] = 'Welsh';
  1013. $QuicktimeLanguageLookup[129] = 'Basque';
  1014. $QuicktimeLanguageLookup[130] = 'Catalan';
  1015. $QuicktimeLanguageLookup[131] = 'Latin';
  1016. $QuicktimeLanguageLookup[132] = 'Quechua';
  1017. $QuicktimeLanguageLookup[133] = 'Guarani';
  1018. $QuicktimeLanguageLookup[134] = 'Aymara';
  1019. $QuicktimeLanguageLookup[135] = 'Tatar';
  1020. $QuicktimeLanguageLookup[136] = 'Uighur';
  1021. $QuicktimeLanguageLookup[137] = 'Dzongkha';
  1022. $QuicktimeLanguageLookup[138] = 'JavaneseRom';
  1023. }
  1024. return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
  1025. }
  1026. function QuicktimeVideoCodecLookup($codecid) {
  1027. static $QuicktimeVideoCodecLookup = array();
  1028. if (empty($QuicktimeVideoCodecLookup)) {
  1029. $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
  1030. $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
  1031. $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
  1032. $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
  1033. $QuicktimeVideoCodecLookup['base'] = 'Base';
  1034. $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
  1035. $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
  1036. $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
  1037. $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
  1038. $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
  1039. $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
  1040. $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
  1041. $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
  1042. $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
  1043. $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
  1044. $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
  1045. $QuicktimeVideoCodecLookup['fire'] = 'Fire';
  1046. $QuicktimeVideoCodecLookup['flic'] = 'FLC';
  1047. $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
  1048. $QuicktimeVideoCodecLookup['gif '] = 'GIF';
  1049. $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
  1050. $QuicktimeVideoCodecLookup['h261'] = 'H261';
  1051. $QuicktimeVideoCodecLookup['h263'] = 'H263';
  1052. $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
  1053. $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
  1054. $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
  1055. $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
  1056. $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
  1057. $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
  1058. $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
  1059. $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
  1060. $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
  1061. $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
  1062. $QuicktimeVideoCodecLookup['png '] = 'PNG';
  1063. $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
  1064. $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
  1065. $QuicktimeVideoCodecLookup['raw '] = 'RAW';
  1066. $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
  1067. $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
  1068. $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
  1069. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
  1070. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
  1071. $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
  1072. $QuicktimeVideoCodecLookup['tga '] = 'Targa';
  1073. $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
  1074. $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
  1075. $QuicktimeVideoCodecLookup['path'] = 'Vector';
  1076. $QuicktimeVideoCodecLookup['rpza'] = 'Video';
  1077. $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
  1078. $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
  1079. $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
  1080. }
  1081. return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
  1082. }
  1083. function QuicktimeAudioCodecLookup($codecid) {
  1084. static $QuicktimeAudioCodecLookup = array();
  1085. if (empty($QuicktimeAudioCodecLookup)) {
  1086. $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
  1087. $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
  1088. $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
  1089. $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
  1090. $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
  1091. $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
  1092. $QuicktimeAudioCodecLookup['dvca'] = 'DV';
  1093. $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
  1094. $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
  1095. $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
  1096. $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
  1097. $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
  1098. $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
  1099. $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
  1100. $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
  1101. $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
  1102. $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
  1103. $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
  1104. $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
  1105. $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
  1106. $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
  1107. $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
  1108. $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
  1109. $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
  1110. $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
  1111. $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
  1112. $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
  1113. $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
  1114. $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
  1115. $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
  1116. $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
  1117. $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
  1118. $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
  1119. $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
  1120. $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
  1121. $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
  1122. $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
  1123. $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
  1124. }
  1125. return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
  1126. }
  1127. function QuicktimeDCOMLookup($compressionid) {
  1128. static $QuicktimeDCOMLookup = array();
  1129. if (empty($QuicktimeDCOMLookup)) {
  1130. $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
  1131. $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
  1132. }
  1133. return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
  1134. }
  1135. function QuicktimeColorNameLookup($colordepthid) {
  1136. static $QuicktimeColorNameLookup = array();
  1137. if (empty($QuicktimeColorNameLookup)) {
  1138. $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
  1139. $QuicktimeColorNameLookup[2] = '4-color';
  1140. $QuicktimeColorNameLookup[4] = '16-color';
  1141. $QuicktimeColorNameLookup[8] = '256-color';
  1142. $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
  1143. $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
  1144. $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
  1145. $QuicktimeColorNameLookup[33] = 'black & white';
  1146. $QuicktimeColorNameLookup[34] = '4-gray';
  1147. $QuicktimeColorNameLookup[36] = '16-gray';
  1148. $QuicktimeColorNameLookup[40] = '256-gray';
  1149. }
  1150. return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
  1151. }
  1152. function CopyToAppropriateCommentsSection($keyname, $data, &$ThisFileInfo) {
  1153. static $handyatomtranslatorarray = array();
  1154. if (empty($handyatomtranslatorarray)) {
  1155. $handyatomtranslatorarray['©cpy'] = 'copyright';
  1156. $handyatomtranslatorarray['©day'] = 'creation_date';
  1157. $handyatomtranslatorarray['©dir'] = 'director';
  1158. $handyatomtranslatorarray['©ed1'] = 'edit1';
  1159. $handyatomtranslatorarray['©ed2'] = 'edit2';
  1160. $handyatomtranslatorarray['©ed3'] = 'edit3';
  1161. $handyatomtranslatorarray['©ed4'] = 'edit4';
  1162. $handyatomtranslatorarray['©ed5'] = 'edit5';
  1163. $handyatomtranslatorarray['©ed6'] = 'edit6';
  1164. $handyatomtranslatorarray['©ed7'] = 'edit7';
  1165. $handyatomtranslatorarray['©ed8'] = 'edit8';
  1166. $handyatomtranslatorarray['©ed9'] = 'edit9';
  1167. $handyatomtranslatorarray['©fmt'] = 'format';
  1168. $handyatomtranslatorarray['©inf'] = 'information';
  1169. $handyatomtranslatorarray['©prd'] = 'producer';
  1170. $handyatomtranslatorarray['©prf'] = 'performers';
  1171. $handyatomtranslatorarray['©req'] = 'system_requirements';
  1172. $handyatomtranslatorarray['©src'] = 'source_credit';
  1173. $handyatomtranslatorarray['©wrt'] = 'writer';
  1174. // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
  1175. $handyatomtranslatorarray['©nam'] = 'title';
  1176. $handyatomtranslatorarray['©cmt'] = 'comment';
  1177. $handyatomtranslatorarray['©wrn'] = 'warning';
  1178. $handyatomtranslatorarray['©hst'] = 'host_computer';
  1179. $handyatomtranslatorarray['©mak'] = 'make';
  1180. $handyatomtranslatorarray['©mod'] = 'model';
  1181. $handyatomtranslatorarray['©PRD'] = 'product';
  1182. $handyatomtranslatorarray['©swr'] = 'software';
  1183. $handyatomtranslatorarray['©aut'] = 'author';
  1184. $handyatomtranslatorarray['©ART'] = 'artist';
  1185. $handyatomtranslatorarray['©trk'] = 'track';
  1186. $handyatomtranslatorarray['©alb'] = 'album';
  1187. $handyatomtranslatorarray['©com'] = 'comment';
  1188. $handyatomtranslatorarray['©gen'] = 'genre';
  1189. $handyatomtranslatorarray['©ope'] = 'composer';
  1190. $handyatomtranslatorarray['©url'] = 'url';
  1191. $handyatomtranslatorarray['©enc'] = 'encoder';
  1192. }
  1193. if (isset($handyatomtranslatorarray[$keyname])) {
  1194. $ThisFileInfo['quicktime']['comments'][$handyatomtranslatorarray[$keyname]][] = $data;
  1195. }
  1196. return true;
  1197. }
  1198. function NoNullString($nullterminatedstring) {
  1199. // remove the single null terminator on null terminated strings
  1200. if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
  1201. return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
  1202. }
  1203. return $nullterminatedstring;
  1204. }
  1205. function Pascal2String($pascalstring) {
  1206. // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
  1207. return substr($pascalstring, 1);
  1208. }
  1209. }
  1210. ?>