module.audio-video.quicktime.php 106 KB

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