module.audio-video.quicktime.php 147 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  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. // dependencies: module.tag.id3v2.php //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  17. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup
  18. class getid3_quicktime extends getid3_handler
  19. {
  20. public $ReturnAtomData = true;
  21. public $ParseAllPossibleAtoms = false;
  22. /**
  23. * @return bool
  24. */
  25. public function Analyze() {
  26. $info = &$this->getid3->info;
  27. $info['fileformat'] = 'quicktime';
  28. $info['quicktime']['hinting'] = false;
  29. $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
  30. $this->fseek($info['avdataoffset']);
  31. $offset = 0;
  32. $atomcounter = 0;
  33. $atom_data_read_buffer_size = $info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : $this->getid3->option_fread_buffer_size * 1024; // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB]
  34. while ($offset < $info['avdataend']) {
  35. if (!getid3_lib::intValueSupported($offset)) {
  36. $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions');
  37. break;
  38. }
  39. $this->fseek($offset);
  40. $AtomHeader = $this->fread(8);
  41. $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
  42. $atomname = substr($AtomHeader, 4, 4);
  43. // 64-bit MOV patch by jlegateØktnc*com
  44. if ($atomsize == 1) {
  45. $atomsize = getid3_lib::BigEndian2Int($this->fread(8));
  46. }
  47. $info['quicktime'][$atomname]['name'] = $atomname;
  48. $info['quicktime'][$atomname]['size'] = $atomsize;
  49. $info['quicktime'][$atomname]['offset'] = $offset;
  50. if (($offset + $atomsize) > $info['avdataend']) {
  51. $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)');
  52. return false;
  53. }
  54. if ($atomsize == 0) {
  55. // Furthermore, for historical reasons the list of atoms is optionally
  56. // terminated by a 32-bit integer set to 0. If you are writing a program
  57. // to read user data atoms, you should allow for the terminating 0.
  58. break;
  59. }
  60. $atomHierarchy = array();
  61. $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
  62. $offset += $atomsize;
  63. $atomcounter++;
  64. }
  65. if (!empty($info['avdataend_tmp'])) {
  66. // this value is assigned to a temp value and then erased because
  67. // otherwise any atoms beyond the 'mdat' atom would not get parsed
  68. $info['avdataend'] = $info['avdataend_tmp'];
  69. unset($info['avdataend_tmp']);
  70. }
  71. if (!empty($info['quicktime']['comments']['chapters']) && is_array($info['quicktime']['comments']['chapters']) && (count($info['quicktime']['comments']['chapters']) > 0)) {
  72. $durations = $this->quicktime_time_to_sample_table($info);
  73. for ($i = 0; $i < count($info['quicktime']['comments']['chapters']); $i++) {
  74. $bookmark = array();
  75. $bookmark['title'] = $info['quicktime']['comments']['chapters'][$i];
  76. if (isset($durations[$i])) {
  77. $bookmark['duration_sample'] = $durations[$i]['sample_duration'];
  78. if ($i > 0) {
  79. $bookmark['start_sample'] = $info['quicktime']['bookmarks'][($i - 1)]['start_sample'] + $info['quicktime']['bookmarks'][($i - 1)]['duration_sample'];
  80. } else {
  81. $bookmark['start_sample'] = 0;
  82. }
  83. if ($time_scale = $this->quicktime_bookmark_time_scale($info)) {
  84. $bookmark['duration_seconds'] = $bookmark['duration_sample'] / $time_scale;
  85. $bookmark['start_seconds'] = $bookmark['start_sample'] / $time_scale;
  86. }
  87. }
  88. $info['quicktime']['bookmarks'][] = $bookmark;
  89. }
  90. }
  91. if (isset($info['quicktime']['temp_meta_key_names'])) {
  92. unset($info['quicktime']['temp_meta_key_names']);
  93. }
  94. if (!empty($info['quicktime']['comments']['location.ISO6709'])) {
  95. // https://en.wikipedia.org/wiki/ISO_6709
  96. foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) {
  97. $latitude = false;
  98. $longitude = false;
  99. $altitude = false;
  100. if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) {
  101. @list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches;
  102. if (strlen($lat_deg) == 2) { // [+-]DD.D
  103. $latitude = floatval(ltrim($lat_deg, '0').$lat_deg_dec);
  104. } elseif (strlen($lat_deg) == 4) { // [+-]DDMM.M
  105. $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0').$lat_deg_dec / 60);
  106. } elseif (strlen($lat_deg) == 6) { // [+-]DDMMSS.S
  107. $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lat_deg, 4, 2), '0').$lat_deg_dec / 3600);
  108. }
  109. if (strlen($lon_deg) == 3) { // [+-]DDD.D
  110. $longitude = floatval(ltrim($lon_deg, '0').$lon_deg_dec);
  111. } elseif (strlen($lon_deg) == 5) { // [+-]DDDMM.M
  112. $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0').$lon_deg_dec / 60);
  113. } elseif (strlen($lon_deg) == 7) { // [+-]DDDMMSS.S
  114. $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lon_deg, 4, 2), '0').$lon_deg_dec / 3600);
  115. }
  116. if (strlen($alt_deg) == 3) { // [+-]DDD.D
  117. $altitude = floatval(ltrim($alt_deg, '0').$alt_deg_dec);
  118. } elseif (strlen($alt_deg) == 5) { // [+-]DDDMM.M
  119. $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0').$alt_deg_dec / 60);
  120. } elseif (strlen($alt_deg) == 7) { // [+-]DDDMMSS.S
  121. $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($alt_deg, 4, 2), '0').$alt_deg_dec / 3600);
  122. }
  123. if ($latitude !== false) {
  124. $info['quicktime']['comments']['gps_latitude'][] = (($lat_sign == '-') ? -1 : 1) * floatval($latitude);
  125. }
  126. if ($longitude !== false) {
  127. $info['quicktime']['comments']['gps_longitude'][] = (($lon_sign == '-') ? -1 : 1) * floatval($longitude);
  128. }
  129. if ($altitude !== false) {
  130. $info['quicktime']['comments']['gps_altitude'][] = (($alt_sign == '-') ? -1 : 1) * floatval($altitude);
  131. }
  132. }
  133. if ($latitude === false) {
  134. $this->warning('location.ISO6709 string not parsed correctly: "'.$ISO6709string.'", please submit as a bug');
  135. }
  136. break;
  137. }
  138. }
  139. if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
  140. $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  141. }
  142. if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
  143. $info['audio']['bitrate'] = $info['bitrate'];
  144. }
  145. if (!empty($info['bitrate']) && !empty($info['audio']['bitrate']) && empty($info['video']['bitrate']) && !empty($info['video']['frame_rate']) && !empty($info['video']['resolution_x']) && ($info['bitrate'] > $info['audio']['bitrate'])) {
  146. $info['video']['bitrate'] = $info['bitrate'] - $info['audio']['bitrate'];
  147. }
  148. if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
  149. foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
  150. $samples_per_second = $samples_count / $info['playtime_seconds'];
  151. if ($samples_per_second > 240) {
  152. // has to be audio samples
  153. } else {
  154. $info['video']['frame_rate'] = $samples_per_second;
  155. break;
  156. }
  157. }
  158. }
  159. if ($info['audio']['dataformat'] == 'mp4') {
  160. $info['fileformat'] = 'mp4';
  161. if (empty($info['video']['resolution_x'])) {
  162. $info['mime_type'] = 'audio/mp4';
  163. unset($info['video']['dataformat']);
  164. } else {
  165. $info['mime_type'] = 'video/mp4';
  166. }
  167. }
  168. if (!$this->ReturnAtomData) {
  169. unset($info['quicktime']['moov']);
  170. }
  171. if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
  172. $info['audio']['dataformat'] = 'quicktime';
  173. }
  174. if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
  175. $info['video']['dataformat'] = 'quicktime';
  176. }
  177. if (isset($info['video']) && ($info['mime_type'] == 'audio/mp4') && empty($info['video']['resolution_x']) && empty($info['video']['resolution_y'])) {
  178. unset($info['video']);
  179. }
  180. return true;
  181. }
  182. /**
  183. * @param string $atomname
  184. * @param int $atomsize
  185. * @param string $atom_data
  186. * @param int $baseoffset
  187. * @param array $atomHierarchy
  188. * @param bool $ParseAllPossibleAtoms
  189. *
  190. * @return array|false
  191. */
  192. public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  193. // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
  194. // https://code.google.com/p/mp4v2/wiki/iTunesMetadata
  195. $info = &$this->getid3->info;
  196. $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see https://www.getid3.org/phpBB3/viewtopic.php?t=1717
  197. array_push($atomHierarchy, $atomname);
  198. $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
  199. $atom_structure['name'] = $atomname;
  200. $atom_structure['size'] = $atomsize;
  201. $atom_structure['offset'] = $baseoffset;
  202. if (substr($atomname, 0, 3) == "\x00\x00\x00") {
  203. // https://github.com/JamesHeinrich/getID3/issues/139
  204. $atomname = getid3_lib::BigEndian2Int($atomname);
  205. $atom_structure['name'] = $atomname;
  206. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  207. } else {
  208. switch ($atomname) {
  209. case 'moov': // MOVie container atom
  210. case 'trak': // TRAcK container atom
  211. case 'clip': // CLIPping container atom
  212. case 'matt': // track MATTe container atom
  213. case 'edts': // EDiTS container atom
  214. case 'tref': // Track REFerence container atom
  215. case 'mdia': // MeDIA container atom
  216. case 'minf': // Media INFormation container atom
  217. case 'dinf': // Data INFormation container atom
  218. case 'udta': // User DaTA container atom
  219. case 'cmov': // Compressed MOVie container atom
  220. case 'rmra': // Reference Movie Record Atom
  221. case 'rmda': // Reference Movie Descriptor Atom
  222. case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
  223. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  224. break;
  225. case 'ilst': // Item LiST container atom
  226. if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) {
  227. // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
  228. $allnumericnames = true;
  229. foreach ($atom_structure['subatoms'] as $subatomarray) {
  230. if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
  231. $allnumericnames = false;
  232. break;
  233. }
  234. }
  235. if ($allnumericnames) {
  236. $newData = array();
  237. foreach ($atom_structure['subatoms'] as $subatomarray) {
  238. foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
  239. unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
  240. $newData[$subatomarray['name']] = $newData_subatomarray;
  241. break;
  242. }
  243. }
  244. $atom_structure['data'] = $newData;
  245. unset($atom_structure['subatoms']);
  246. }
  247. }
  248. break;
  249. case 'stbl': // Sample TaBLe container atom
  250. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  251. $isVideo = false;
  252. $framerate = 0;
  253. $framecount = 0;
  254. foreach ($atom_structure['subatoms'] as $key => $value_array) {
  255. if (isset($value_array['sample_description_table'])) {
  256. foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
  257. if (isset($value_array2['data_format'])) {
  258. switch ($value_array2['data_format']) {
  259. case 'avc1':
  260. case 'mp4v':
  261. // video data
  262. $isVideo = true;
  263. break;
  264. case 'mp4a':
  265. // audio data
  266. break;
  267. }
  268. }
  269. }
  270. } elseif (isset($value_array['time_to_sample_table'])) {
  271. foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
  272. if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
  273. $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
  274. $framecount = $value_array2['sample_count'];
  275. }
  276. }
  277. }
  278. }
  279. if ($isVideo && $framerate) {
  280. $info['quicktime']['video']['frame_rate'] = $framerate;
  281. $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
  282. }
  283. if ($isVideo && $framecount) {
  284. $info['quicktime']['video']['frame_count'] = $framecount;
  285. }
  286. break;
  287. case "\xA9".'alb': // ALBum
  288. case "\xA9".'ART': //
  289. case "\xA9".'art': // ARTist
  290. case "\xA9".'aut': //
  291. case "\xA9".'cmt': // CoMmenT
  292. case "\xA9".'com': // COMposer
  293. case "\xA9".'cpy': //
  294. case "\xA9".'day': // content created year
  295. case "\xA9".'dir': //
  296. case "\xA9".'ed1': //
  297. case "\xA9".'ed2': //
  298. case "\xA9".'ed3': //
  299. case "\xA9".'ed4': //
  300. case "\xA9".'ed5': //
  301. case "\xA9".'ed6': //
  302. case "\xA9".'ed7': //
  303. case "\xA9".'ed8': //
  304. case "\xA9".'ed9': //
  305. case "\xA9".'enc': //
  306. case "\xA9".'fmt': //
  307. case "\xA9".'gen': // GENre
  308. case "\xA9".'grp': // GRouPing
  309. case "\xA9".'hst': //
  310. case "\xA9".'inf': //
  311. case "\xA9".'lyr': // LYRics
  312. case "\xA9".'mak': //
  313. case "\xA9".'mod': //
  314. case "\xA9".'nam': // full NAMe
  315. case "\xA9".'ope': //
  316. case "\xA9".'PRD': //
  317. case "\xA9".'prf': //
  318. case "\xA9".'req': //
  319. case "\xA9".'src': //
  320. case "\xA9".'swr': //
  321. case "\xA9".'too': // encoder
  322. case "\xA9".'trk': // TRacK
  323. case "\xA9".'url': //
  324. case "\xA9".'wrn': //
  325. case "\xA9".'wrt': // WRiTer
  326. case '----': // itunes specific
  327. case 'aART': // Album ARTist
  328. case 'akID': // iTunes store account type
  329. case 'apID': // Purchase Account
  330. case 'atID': //
  331. case 'catg': // CaTeGory
  332. case 'cmID': //
  333. case 'cnID': //
  334. case 'covr': // COVeR artwork
  335. case 'cpil': // ComPILation
  336. case 'cprt': // CoPyRighT
  337. case 'desc': // DESCription
  338. case 'disk': // DISK number
  339. case 'egid': // Episode Global ID
  340. case 'geID': //
  341. case 'gnre': // GeNRE
  342. case 'hdvd': // HD ViDeo
  343. case 'keyw': // KEYWord
  344. case 'ldes': // Long DEScription
  345. case 'pcst': // PodCaST
  346. case 'pgap': // GAPless Playback
  347. case 'plID': //
  348. case 'purd': // PURchase Date
  349. case 'purl': // Podcast URL
  350. case 'rati': //
  351. case 'rndu': //
  352. case 'rpdu': //
  353. case 'rtng': // RaTiNG
  354. case 'sfID': // iTunes store country
  355. case 'soaa': // SOrt Album Artist
  356. case 'soal': // SOrt ALbum
  357. case 'soar': // SOrt ARtist
  358. case 'soco': // SOrt COmposer
  359. case 'sonm': // SOrt NaMe
  360. case 'sosn': // SOrt Show Name
  361. case 'stik': //
  362. case 'tmpo': // TeMPO (BPM)
  363. case 'trkn': // TRacK Number
  364. case 'tven': // tvEpisodeID
  365. case 'tves': // TV EpiSode
  366. case 'tvnn': // TV Network Name
  367. case 'tvsh': // TV SHow Name
  368. case 'tvsn': // TV SeasoN
  369. if ($atom_parent == 'udta') {
  370. // User data atom handler
  371. $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  372. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
  373. $atom_structure['data'] = substr($atom_data, 4);
  374. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  375. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  376. $info['comments']['language'][] = $atom_structure['language'];
  377. }
  378. } else {
  379. // Apple item list box atom handler
  380. $atomoffset = 0;
  381. if (substr($atom_data, 2, 2) == "\x10\xB5") {
  382. // not sure what it means, but observed on iPhone4 data.
  383. // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
  384. while ($atomoffset < strlen($atom_data)) {
  385. $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2));
  386. $boxsmalltype = substr($atom_data, $atomoffset + 2, 2);
  387. $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize);
  388. if ($boxsmallsize <= 1) {
  389. $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset));
  390. $atom_structure['data'] = null;
  391. $atomoffset = strlen($atom_data);
  392. break;
  393. }
  394. switch ($boxsmalltype) {
  395. case "\x10\xB5":
  396. $atom_structure['data'] = $boxsmalldata;
  397. break;
  398. default:
  399. $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset);
  400. $atom_structure['data'] = $atom_data;
  401. break;
  402. }
  403. $atomoffset += (4 + $boxsmallsize);
  404. }
  405. } else {
  406. while ($atomoffset < strlen($atom_data)) {
  407. $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
  408. $boxtype = substr($atom_data, $atomoffset + 4, 4);
  409. $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8);
  410. if ($boxsize <= 1) {
  411. $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset));
  412. $atom_structure['data'] = null;
  413. $atomoffset = strlen($atom_data);
  414. break;
  415. }
  416. $atomoffset += $boxsize;
  417. switch ($boxtype) {
  418. case 'mean':
  419. case 'name':
  420. $atom_structure[$boxtype] = substr($boxdata, 4);
  421. break;
  422. case 'data':
  423. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1));
  424. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3));
  425. switch ($atom_structure['flags_raw']) {
  426. case 0: // data flag
  427. case 21: // tmpo/cpil flag
  428. switch ($atomname) {
  429. case 'cpil':
  430. case 'hdvd':
  431. case 'pcst':
  432. case 'pgap':
  433. // 8-bit integer (boolean)
  434. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  435. break;
  436. case 'tmpo':
  437. // 16-bit integer
  438. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
  439. break;
  440. case 'disk':
  441. case 'trkn':
  442. // binary
  443. $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
  444. $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
  445. $atom_structure['data'] = empty($num) ? '' : $num;
  446. $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
  447. break;
  448. case 'gnre':
  449. // enum
  450. $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  451. $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1);
  452. break;
  453. case 'rtng':
  454. // 8-bit integer
  455. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  456. $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
  457. break;
  458. case 'stik':
  459. // 8-bit integer (enum)
  460. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
  461. $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
  462. break;
  463. case 'sfID':
  464. // 32-bit integer
  465. $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  466. $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
  467. break;
  468. case 'egid':
  469. case 'purl':
  470. $atom_structure['data'] = substr($boxdata, 8);
  471. break;
  472. case 'plID':
  473. // 64-bit integer
  474. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8));
  475. break;
  476. case 'covr':
  477. $atom_structure['data'] = substr($boxdata, 8);
  478. // not a foolproof check, but better than nothing
  479. if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) {
  480. $atom_structure['image_mime'] = 'image/jpeg';
  481. } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) {
  482. $atom_structure['image_mime'] = 'image/png';
  483. } elseif (preg_match('#^GIF#', $atom_structure['data'])) {
  484. $atom_structure['image_mime'] = 'image/gif';
  485. }
  486. break;
  487. case 'atID':
  488. case 'cnID':
  489. case 'geID':
  490. case 'tves':
  491. case 'tvsn':
  492. default:
  493. // 32-bit integer
  494. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
  495. }
  496. break;
  497. case 1: // text flag
  498. case 13: // image flag
  499. default:
  500. $atom_structure['data'] = substr($boxdata, 8);
  501. if ($atomname == 'covr') {
  502. // not a foolproof check, but better than nothing
  503. if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) {
  504. $atom_structure['image_mime'] = 'image/jpeg';
  505. } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) {
  506. $atom_structure['image_mime'] = 'image/png';
  507. } elseif (preg_match('#^GIF#', $atom_structure['data'])) {
  508. $atom_structure['image_mime'] = 'image/gif';
  509. }
  510. }
  511. break;
  512. }
  513. break;
  514. default:
  515. $this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset);
  516. $atom_structure['data'] = $atom_data;
  517. }
  518. }
  519. }
  520. }
  521. $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
  522. break;
  523. case 'play': // auto-PLAY atom
  524. $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  525. $info['quicktime']['autoplay'] = $atom_structure['autoplay'];
  526. break;
  527. case 'WLOC': // Window LOCation atom
  528. $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  529. $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
  530. break;
  531. case 'LOOP': // LOOPing atom
  532. case 'SelO': // play SELection Only atom
  533. case 'AllF': // play ALL Frames atom
  534. $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
  535. break;
  536. case 'name': //
  537. case 'MCPS': // Media Cleaner PRo
  538. case '@PRM': // adobe PReMiere version
  539. case '@PRQ': // adobe PRemiere Quicktime version
  540. $atom_structure['data'] = $atom_data;
  541. break;
  542. case 'cmvd': // Compressed MooV Data atom
  543. // Code by ubergeekØubergeek*tv based on information from
  544. // http://developer.apple.com/quicktime/icefloe/dispatch012.html
  545. $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  546. $CompressedFileData = substr($atom_data, 4);
  547. if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
  548. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
  549. } else {
  550. $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']);
  551. }
  552. break;
  553. case 'dcom': // Data COMpression atom
  554. $atom_structure['compression_id'] = $atom_data;
  555. $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
  556. break;
  557. case 'rdrf': // Reference movie Data ReFerence atom
  558. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  559. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  560. $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
  561. $atom_structure['reference_type_name'] = substr($atom_data, 4, 4);
  562. $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  563. switch ($atom_structure['reference_type_name']) {
  564. case 'url ':
  565. $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
  566. break;
  567. case 'alis':
  568. $atom_structure['file_alias'] = substr($atom_data, 12);
  569. break;
  570. case 'rsrc':
  571. $atom_structure['resource_alias'] = substr($atom_data, 12);
  572. break;
  573. default:
  574. $atom_structure['data'] = substr($atom_data, 12);
  575. break;
  576. }
  577. break;
  578. case 'rmqu': // Reference Movie QUality atom
  579. $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
  580. break;
  581. case 'rmcs': // Reference Movie Cpu Speed atom
  582. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  583. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  584. $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  585. break;
  586. case 'rmvc': // Reference Movie Version Check atom
  587. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  588. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  589. $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4);
  590. $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  591. $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  592. $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
  593. break;
  594. case 'rmcd': // Reference Movie Component check atom
  595. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  596. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  597. $atom_structure['component_type'] = substr($atom_data, 4, 4);
  598. $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
  599. $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
  600. $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  601. $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  602. $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
  603. break;
  604. case 'rmdr': // Reference Movie Data Rate atom
  605. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  606. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  607. $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  608. $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
  609. break;
  610. case 'rmla': // Reference Movie Language Atom
  611. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  612. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  613. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  614. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  615. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  616. $info['comments']['language'][] = $atom_structure['language'];
  617. }
  618. break;
  619. case 'ptv ': // Print To Video - defines a movie's full screen mode
  620. // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
  621. $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
  622. $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
  623. $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
  624. $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
  625. $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
  626. $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
  627. $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
  628. $ptv_lookup[0] = 'normal';
  629. $ptv_lookup[1] = 'double';
  630. $ptv_lookup[2] = 'half';
  631. $ptv_lookup[3] = 'full';
  632. $ptv_lookup[4] = 'current';
  633. if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
  634. $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
  635. } else {
  636. $this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')');
  637. }
  638. break;
  639. case 'stsd': // Sample Table Sample Description atom
  640. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  641. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  642. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  643. // see: https://github.com/JamesHeinrich/getID3/issues/111
  644. // Some corrupt files have been known to have high bits set in the number_entries field
  645. // This field shouldn't really need to be 32-bits, values stores are likely in the range 1-100000
  646. // Workaround: mask off the upper byte and throw a warning if it's nonzero
  647. if ($atom_structure['number_entries'] > 0x000FFFFF) {
  648. if ($atom_structure['number_entries'] > 0x00FFFFFF) {
  649. $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Ignoring upper byte and interpreting this as 0x'.getid3_lib::PrintHexBytes(substr($atom_data, 5, 3), true, false).' = '.($atom_structure['number_entries'] & 0x00FFFFFF));
  650. $atom_structure['number_entries'] = ($atom_structure['number_entries'] & 0x00FFFFFF);
  651. } else {
  652. $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Please report this to info@getid3.org referencing bug report #111');
  653. }
  654. }
  655. $stsdEntriesDataOffset = 8;
  656. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  657. $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
  658. $stsdEntriesDataOffset += 4;
  659. $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4);
  660. $stsdEntriesDataOffset += 4;
  661. $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
  662. $stsdEntriesDataOffset += 6;
  663. $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
  664. $stsdEntriesDataOffset += 2;
  665. $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
  666. $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
  667. $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2));
  668. $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2));
  669. $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4);
  670. switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
  671. case "\x00\x00\x00\x00":
  672. // audio tracks
  673. $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2));
  674. $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2));
  675. $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2));
  676. $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2));
  677. $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
  678. // video tracks
  679. // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
  680. $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
  681. $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
  682. $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
  683. $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
  684. $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
  685. $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
  686. $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4));
  687. $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2));
  688. $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4);
  689. $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2));
  690. $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2));
  691. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  692. case '2vuY':
  693. case 'avc1':
  694. case 'cvid':
  695. case 'dvc ':
  696. case 'dvcp':
  697. case 'gif ':
  698. case 'h263':
  699. case 'jpeg':
  700. case 'kpcd':
  701. case 'mjpa':
  702. case 'mjpb':
  703. case 'mp4v':
  704. case 'png ':
  705. case 'raw ':
  706. case 'rle ':
  707. case 'rpza':
  708. case 'smc ':
  709. case 'SVQ1':
  710. case 'SVQ3':
  711. case 'tiff':
  712. case 'v210':
  713. case 'v216':
  714. case 'v308':
  715. case 'v408':
  716. case 'v410':
  717. case 'yuv2':
  718. $info['fileformat'] = 'mp4';
  719. $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
  720. if ($this->QuicktimeVideoCodecLookup($info['video']['fourcc'])) {
  721. $info['video']['fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($info['video']['fourcc']);
  722. }
  723. // https://www.getid3.org/phpBB3/viewtopic.php?t=1550
  724. //if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers
  725. if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) {
  726. // assume that values stored here are more important than values stored in [tkhd] atom
  727. $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width'];
  728. $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height'];
  729. $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
  730. $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
  731. }
  732. break;
  733. case 'qtvr':
  734. $info['video']['dataformat'] = 'quicktimevr';
  735. break;
  736. case 'mp4a':
  737. default:
  738. $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
  739. $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
  740. $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
  741. $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
  742. $info['audio']['codec'] = $info['quicktime']['audio']['codec'];
  743. $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate'];
  744. $info['audio']['channels'] = $info['quicktime']['audio']['channels'];
  745. $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth'];
  746. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  747. case 'raw ': // PCM
  748. case 'alac': // Apple Lossless Audio Codec
  749. case 'sowt': // signed/two's complement (Little Endian)
  750. case 'twos': // signed/two's complement (Big Endian)
  751. case 'in24': // 24-bit Integer
  752. case 'in32': // 32-bit Integer
  753. case 'fl32': // 32-bit Floating Point
  754. case 'fl64': // 64-bit Floating Point
  755. $info['audio']['lossless'] = $info['quicktime']['audio']['lossless'] = true;
  756. $info['audio']['bitrate'] = $info['quicktime']['audio']['bitrate'] = $info['audio']['channels'] * $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'];
  757. break;
  758. default:
  759. $info['audio']['lossless'] = false;
  760. break;
  761. }
  762. break;
  763. }
  764. break;
  765. default:
  766. switch ($atom_structure['sample_description_table'][$i]['data_format']) {
  767. case 'mp4s':
  768. $info['fileformat'] = 'mp4';
  769. break;
  770. default:
  771. // video atom
  772. $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
  773. $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
  774. $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
  775. $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
  776. $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
  777. $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
  778. $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
  779. $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2));
  780. $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1));
  781. $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']);
  782. $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
  783. $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
  784. $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
  785. $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
  786. if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
  787. $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
  788. $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
  789. $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']);
  790. $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
  791. $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
  792. $info['video']['codec'] = $info['quicktime']['video']['codec'];
  793. $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
  794. }
  795. $info['video']['lossless'] = false;
  796. $info['video']['pixel_aspect_ratio'] = (float) 1;
  797. break;
  798. }
  799. break;
  800. }
  801. switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
  802. case 'mp4a':
  803. $info['audio']['dataformat'] = 'mp4';
  804. $info['quicktime']['audio']['codec'] = 'mp4';
  805. break;
  806. case '3ivx':
  807. case '3iv1':
  808. case '3iv2':
  809. $info['video']['dataformat'] = '3ivx';
  810. break;
  811. case 'xvid':
  812. $info['video']['dataformat'] = 'xvid';
  813. break;
  814. case 'mp4v':
  815. $info['video']['dataformat'] = 'mpeg4';
  816. break;
  817. case 'divx':
  818. case 'div1':
  819. case 'div2':
  820. case 'div3':
  821. case 'div4':
  822. case 'div5':
  823. case 'div6':
  824. $info['video']['dataformat'] = 'divx';
  825. break;
  826. default:
  827. // do nothing
  828. break;
  829. }
  830. unset($atom_structure['sample_description_table'][$i]['data']);
  831. }
  832. break;
  833. case 'stts': // Sample Table Time-to-Sample atom
  834. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  835. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  836. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  837. $sttsEntriesDataOffset = 8;
  838. //$FrameRateCalculatorArray = array();
  839. $frames_count = 0;
  840. $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']);
  841. if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
  842. $this->warning('QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($this->getid3->memory_limit / 1048576).'MB).');
  843. }
  844. for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
  845. $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
  846. $sttsEntriesDataOffset += 4;
  847. $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
  848. $sttsEntriesDataOffset += 4;
  849. $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
  850. // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
  851. //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
  852. // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
  853. // if ($stts_new_framerate <= 60) {
  854. // // some atoms have durations of "1" giving a very large framerate, which probably is not right
  855. // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
  856. // }
  857. //}
  858. //
  859. //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
  860. }
  861. $info['quicktime']['stts_framecount'][] = $frames_count;
  862. //$sttsFramesTotal = 0;
  863. //$sttsSecondsTotal = 0;
  864. //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
  865. // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
  866. // // not video FPS information, probably audio information
  867. // $sttsFramesTotal = 0;
  868. // $sttsSecondsTotal = 0;
  869. // break;
  870. // }
  871. // $sttsFramesTotal += $frame_count;
  872. // $sttsSecondsTotal += $frame_count / $frames_per_second;
  873. //}
  874. //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
  875. // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
  876. // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
  877. // }
  878. //}
  879. break;
  880. case 'stss': // Sample Table Sync Sample (key frames) atom
  881. if ($ParseAllPossibleAtoms) {
  882. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  883. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  884. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  885. $stssEntriesDataOffset = 8;
  886. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  887. $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
  888. $stssEntriesDataOffset += 4;
  889. }
  890. }
  891. break;
  892. case 'stsc': // Sample Table Sample-to-Chunk atom
  893. if ($ParseAllPossibleAtoms) {
  894. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  895. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  896. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  897. $stscEntriesDataOffset = 8;
  898. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  899. $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  900. $stscEntriesDataOffset += 4;
  901. $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  902. $stscEntriesDataOffset += 4;
  903. $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
  904. $stscEntriesDataOffset += 4;
  905. }
  906. }
  907. break;
  908. case 'stsz': // Sample Table SiZe atom
  909. if ($ParseAllPossibleAtoms) {
  910. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  911. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  912. $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  913. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  914. $stszEntriesDataOffset = 12;
  915. if ($atom_structure['sample_size'] == 0) {
  916. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  917. $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
  918. $stszEntriesDataOffset += 4;
  919. }
  920. }
  921. }
  922. break;
  923. case 'stco': // Sample Table Chunk Offset atom
  924. if ($ParseAllPossibleAtoms) {
  925. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  926. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  927. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  928. $stcoEntriesDataOffset = 8;
  929. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  930. $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
  931. $stcoEntriesDataOffset += 4;
  932. }
  933. }
  934. break;
  935. case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
  936. if ($ParseAllPossibleAtoms) {
  937. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  938. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  939. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  940. $stcoEntriesDataOffset = 8;
  941. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  942. $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
  943. $stcoEntriesDataOffset += 8;
  944. }
  945. }
  946. break;
  947. case 'dref': // Data REFerence 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)); // hardcoded: 0x0000
  950. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  951. $drefDataOffset = 8;
  952. for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
  953. $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
  954. $drefDataOffset += 4;
  955. $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4);
  956. $drefDataOffset += 4;
  957. $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1));
  958. $drefDataOffset += 1;
  959. $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000
  960. $drefDataOffset += 3;
  961. $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
  962. $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
  963. $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
  964. }
  965. break;
  966. case 'gmin': // base Media INformation atom
  967. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  968. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  969. $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  970. $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  971. $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
  972. $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
  973. $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
  974. $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
  975. break;
  976. case 'smhd': // Sound Media information HeaDer atom
  977. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  978. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  979. $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  980. $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  981. break;
  982. case 'vmhd': // Video Media information HeaDer atom
  983. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  984. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  985. $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
  986. $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
  987. $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
  988. $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
  989. $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
  990. break;
  991. case 'hdlr': // HanDLeR reference atom
  992. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  993. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  994. $atom_structure['component_type'] = substr($atom_data, 4, 4);
  995. $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
  996. $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
  997. $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  998. $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  999. $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24));
  1000. if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) {
  1001. $info['video']['dataformat'] = 'quicktimevr';
  1002. }
  1003. break;
  1004. case 'mdhd': // MeDia HeaDer atom
  1005. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1006. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  1007. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1008. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  1009. $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  1010. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  1011. $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2));
  1012. $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2));
  1013. if ($atom_structure['time_scale'] == 0) {
  1014. $this->error('Corrupt Quicktime file: mdhd.time_scale == zero');
  1015. return false;
  1016. }
  1017. $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
  1018. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  1019. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  1020. $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
  1021. $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
  1022. if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
  1023. $info['comments']['language'][] = $atom_structure['language'];
  1024. }
  1025. break;
  1026. case 'pnot': // Preview atom
  1027. $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format"
  1028. $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00
  1029. $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT'
  1030. $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01
  1031. $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']);
  1032. break;
  1033. case 'crgn': // Clipping ReGioN atom
  1034. $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box,
  1035. $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields
  1036. $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region.
  1037. break;
  1038. case 'load': // track LOAD settings atom
  1039. $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  1040. $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1041. $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  1042. $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  1043. $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020);
  1044. $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100);
  1045. break;
  1046. case 'tmcd': // TiMe CoDe atom
  1047. case 'chap': // CHAPter list atom
  1048. case 'sync': // SYNChronization atom
  1049. case 'scpt': // tranSCriPT atom
  1050. case 'ssrc': // non-primary SouRCe atom
  1051. for ($i = 0; $i < strlen($atom_data); $i += 4) {
  1052. @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
  1053. }
  1054. break;
  1055. case 'elst': // Edit LiST atom
  1056. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1057. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  1058. $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1059. for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) {
  1060. $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4));
  1061. $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4));
  1062. $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4));
  1063. }
  1064. break;
  1065. case 'kmat': // compressed MATte atom
  1066. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1067. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
  1068. $atom_structure['matte_data_raw'] = substr($atom_data, 4);
  1069. break;
  1070. case 'ctab': // Color TABle atom
  1071. $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000
  1072. $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000
  1073. $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
  1074. for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
  1075. $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2));
  1076. $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2));
  1077. $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2));
  1078. $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2));
  1079. }
  1080. break;
  1081. case 'mvhd': // MoVie HeaDer atom
  1082. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1083. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1084. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1085. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  1086. $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  1087. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  1088. $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4));
  1089. $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2));
  1090. $atom_structure['reserved'] = substr($atom_data, 26, 10);
  1091. $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4));
  1092. $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
  1093. $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4));
  1094. $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
  1095. $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
  1096. $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4));
  1097. $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
  1098. $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
  1099. $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
  1100. $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4));
  1101. $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4));
  1102. $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4));
  1103. $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4));
  1104. $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4));
  1105. $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4));
  1106. $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4));
  1107. if ($atom_structure['time_scale'] == 0) {
  1108. $this->error('Corrupt Quicktime file: mvhd.time_scale == zero');
  1109. return false;
  1110. }
  1111. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  1112. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  1113. $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
  1114. $info['quicktime']['display_scale'] = $atom_structure['matrix_a'];
  1115. $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
  1116. break;
  1117. case 'tkhd': // TracK HeaDer atom
  1118. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1119. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1120. $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1121. $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
  1122. $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
  1123. $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
  1124. $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
  1125. $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8));
  1126. $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2));
  1127. $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2));
  1128. $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2));
  1129. $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
  1130. // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html
  1131. // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737
  1132. $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
  1133. $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4));
  1134. $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4));
  1135. $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
  1136. $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4));
  1137. $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4));
  1138. $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
  1139. $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4));
  1140. $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4));
  1141. $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4));
  1142. $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4));
  1143. $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001);
  1144. $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002);
  1145. $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004);
  1146. $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008);
  1147. $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
  1148. $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
  1149. // https://www.getid3.org/phpBB3/viewtopic.php?t=1908
  1150. // attempt to compute rotation from matrix values
  1151. // 2017-Dec-28: uncertain if 90/270 are correctly oriented; values returned by FixedPoint16_16 should perhaps be -1 instead of 65535(?)
  1152. $matrixRotation = 0;
  1153. switch ($atom_structure['matrix_a'].':'.$atom_structure['matrix_b'].':'.$atom_structure['matrix_c'].':'.$atom_structure['matrix_d']) {
  1154. case '1:0:0:1': $matrixRotation = 0; break;
  1155. case '0:1:65535:0': $matrixRotation = 90; break;
  1156. case '65535:0:0:65535': $matrixRotation = 180; break;
  1157. case '0:65535:1:0': $matrixRotation = 270; break;
  1158. default: break;
  1159. }
  1160. // https://www.getid3.org/phpBB3/viewtopic.php?t=2468
  1161. // The rotation matrix can appear in the Quicktime file multiple times, at least once for each track,
  1162. // and it's possible that only the video track (or, in theory, one of the video tracks) is flagged as
  1163. // rotated while the other tracks (e.g. audio) is tagged as rotation=0 (behavior noted on iPhone 8 Plus)
  1164. // The correct solution would be to check if the TrackID associated with the rotation matrix is indeed
  1165. // a video track (or the main video track) and only set the rotation then, but since information about
  1166. // what track is what is not trivially there to be examined, the lazy solution is to set the rotation
  1167. // if it is found to be nonzero, on the assumption that tracks that don't need it will have rotation set
  1168. // to zero (and be effectively ignored) and the video track will have rotation set correctly, which will
  1169. // either be zero and automatically correct, or nonzero and be set correctly.
  1170. if (!isset($info['video']['rotate']) || (($info['video']['rotate'] == 0) && ($matrixRotation > 0))) {
  1171. $info['quicktime']['video']['rotate'] = $info['video']['rotate'] = $matrixRotation;
  1172. }
  1173. if ($atom_structure['flags']['enabled'] == 1) {
  1174. if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
  1175. $info['video']['resolution_x'] = $atom_structure['width'];
  1176. $info['video']['resolution_y'] = $atom_structure['height'];
  1177. }
  1178. $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
  1179. $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
  1180. $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
  1181. $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
  1182. } else {
  1183. // see: https://www.getid3.org/phpBB3/viewtopic.php?t=1295
  1184. //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); }
  1185. //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); }
  1186. //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); }
  1187. }
  1188. break;
  1189. case 'iods': // Initial Object DeScriptor atom
  1190. // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h
  1191. // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html
  1192. $offset = 0;
  1193. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1194. $offset += 1;
  1195. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3));
  1196. $offset += 3;
  1197. $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1198. $offset += 1;
  1199. $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
  1200. //$offset already adjusted by quicktime_read_mp4_descr_length()
  1201. $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));
  1202. $offset += 2;
  1203. $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1204. $offset += 1;
  1205. $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1206. $offset += 1;
  1207. $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1208. $offset += 1;
  1209. $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1210. $offset += 1;
  1211. $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1212. $offset += 1;
  1213. $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields
  1214. for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) {
  1215. $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
  1216. $offset += 1;
  1217. $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
  1218. //$offset already adjusted by quicktime_read_mp4_descr_length()
  1219. $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));
  1220. $offset += 4;
  1221. }
  1222. $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']);
  1223. $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']);
  1224. break;
  1225. case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
  1226. $atom_structure['signature'] = substr($atom_data, 0, 4);
  1227. $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1228. $atom_structure['fourcc'] = substr($atom_data, 8, 4);
  1229. break;
  1230. case 'mdat': // Media DATa atom
  1231. // 'mdat' contains the actual data for the audio/video, possibly also subtitles
  1232. /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */
  1233. // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?)
  1234. $mdat_offset = 0;
  1235. while (true) {
  1236. if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') {
  1237. $mdat_offset += 8;
  1238. } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') {
  1239. $mdat_offset += 8;
  1240. } else {
  1241. break;
  1242. }
  1243. }
  1244. if (substr($atom_data, $mdat_offset, 4) == 'GPRO') {
  1245. $GOPRO_chunk_length = getid3_lib::LittleEndian2Int(substr($atom_data, $mdat_offset + 4, 4));
  1246. $GOPRO_offset = 8;
  1247. $atom_structure['GPRO']['raw'] = substr($atom_data, $mdat_offset + 8, $GOPRO_chunk_length - 8);
  1248. $atom_structure['GPRO']['firmware'] = substr($atom_structure['GPRO']['raw'], 0, 15);
  1249. $atom_structure['GPRO']['unknown1'] = substr($atom_structure['GPRO']['raw'], 15, 16);
  1250. $atom_structure['GPRO']['unknown2'] = substr($atom_structure['GPRO']['raw'], 31, 32);
  1251. $atom_structure['GPRO']['unknown3'] = substr($atom_structure['GPRO']['raw'], 63, 16);
  1252. $atom_structure['GPRO']['camera'] = substr($atom_structure['GPRO']['raw'], 79, 32);
  1253. $info['quicktime']['camera']['model'] = rtrim($atom_structure['GPRO']['camera'], "\x00");
  1254. }
  1255. // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field
  1256. while (($mdat_offset < (strlen($atom_data) - 8))
  1257. && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2)))
  1258. && ($chapter_string_length < 1000)
  1259. && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2))
  1260. && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) {
  1261. list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches;
  1262. $mdat_offset += (2 + $chapter_string_length);
  1263. @$info['quicktime']['comments']['chapters'][] = $chapter_string;
  1264. // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled)
  1265. if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8
  1266. $mdat_offset += 12;
  1267. }
  1268. }
  1269. if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
  1270. $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8;
  1271. $OldAVDataEnd = $info['avdataend'];
  1272. $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
  1273. $getid3_temp = new getID3();
  1274. $getid3_temp->openfile($this->getid3->filename);
  1275. $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1276. $getid3_temp->info['avdataend'] = $info['avdataend'];
  1277. $getid3_mp3 = new getid3_mp3($getid3_temp);
  1278. if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) {
  1279. $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
  1280. if (!empty($getid3_temp->info['warning'])) {
  1281. foreach ($getid3_temp->info['warning'] as $value) {
  1282. $this->warning($value);
  1283. }
  1284. }
  1285. if (!empty($getid3_temp->info['mpeg'])) {
  1286. $info['mpeg'] = $getid3_temp->info['mpeg'];
  1287. if (isset($info['mpeg']['audio'])) {
  1288. $info['audio']['dataformat'] = 'mp3';
  1289. $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')));
  1290. $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  1291. $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
  1292. $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
  1293. $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1294. $info['bitrate'] = $info['audio']['bitrate'];
  1295. }
  1296. }
  1297. }
  1298. unset($getid3_mp3, $getid3_temp);
  1299. $info['avdataend'] = $OldAVDataEnd;
  1300. unset($OldAVDataEnd);
  1301. }
  1302. unset($mdat_offset, $chapter_string_length, $chapter_matches);
  1303. break;
  1304. case 'free': // FREE space atom
  1305. case 'skip': // SKIP atom
  1306. case 'wide': // 64-bit expansion placeholder atom
  1307. // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
  1308. // When writing QuickTime files, it is sometimes necessary to update an atom's size.
  1309. // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
  1310. // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
  1311. // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
  1312. // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
  1313. // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
  1314. // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
  1315. break;
  1316. case 'nsav': // NoSAVe atom
  1317. // http://developer.apple.com/technotes/tn/tn2038.html
  1318. $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  1319. break;
  1320. case 'ctyp': // Controller TYPe atom (seen on QTVR)
  1321. // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
  1322. // some controller names are:
  1323. // 0x00 + 'std' for linear movie
  1324. // 'none' for no controls
  1325. $atom_structure['ctyp'] = substr($atom_data, 0, 4);
  1326. $info['quicktime']['controller'] = $atom_structure['ctyp'];
  1327. switch ($atom_structure['ctyp']) {
  1328. case 'qtvr':
  1329. $info['video']['dataformat'] = 'quicktimevr';
  1330. break;
  1331. }
  1332. break;
  1333. case 'pano': // PANOrama track (seen on QTVR)
  1334. $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
  1335. break;
  1336. case 'hint': // HINT track
  1337. case 'hinf': //
  1338. case 'hinv': //
  1339. case 'hnti': //
  1340. $info['quicktime']['hinting'] = true;
  1341. break;
  1342. case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
  1343. for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) {
  1344. $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
  1345. }
  1346. break;
  1347. // Observed-but-not-handled atom types are just listed here to prevent warnings being generated
  1348. case 'FXTC': // Something to do with Adobe After Effects (?)
  1349. case 'PrmA':
  1350. case 'code':
  1351. case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
  1352. case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html
  1353. // tapt seems to be used to compute the video size [https://www.getid3.org/phpBB3/viewtopic.php?t=838]
  1354. // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html
  1355. // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html
  1356. case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1357. case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1358. case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1359. case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
  1360. //$atom_structure['data'] = $atom_data;
  1361. break;
  1362. case "\xA9".'xyz': // GPS latitude+longitude+altitude
  1363. $atom_structure['data'] = $atom_data;
  1364. if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
  1365. @list($all, $latitude, $longitude, $altitude) = $matches;
  1366. $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude);
  1367. $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude);
  1368. if (!empty($altitude)) {
  1369. $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude);
  1370. }
  1371. } else {
  1372. $this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.');
  1373. }
  1374. break;
  1375. case 'NCDT':
  1376. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1377. // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
  1378. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
  1379. break;
  1380. case 'NCTH': // Nikon Camera THumbnail image
  1381. case 'NCVW': // Nikon Camera preVieW image
  1382. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1383. if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) {
  1384. $atom_structure['data'] = $atom_data;
  1385. $atom_structure['image_mime'] = 'image/jpeg';
  1386. $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image'));
  1387. $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']);
  1388. }
  1389. break;
  1390. case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
  1391. $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
  1392. break;
  1393. case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1394. case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
  1395. case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html
  1396. $atom_structure['data'] = $atom_data;
  1397. break;
  1398. case "\x00\x00\x00\x00":
  1399. // some kind of metacontainer, may contain a big data dump such as:
  1400. // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4
  1401. // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
  1402. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1403. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1404. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  1405. //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  1406. break;
  1407. case 'meta': // METAdata atom
  1408. // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html
  1409. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1410. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1411. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
  1412. break;
  1413. case 'data': // metaDATA atom
  1414. static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other
  1415. // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data
  1416. $atom_structure['language'] = substr($atom_data, 4 + 0, 2);
  1417. $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2));
  1418. $atom_structure['data'] = substr($atom_data, 4 + 4);
  1419. $atom_structure['key_name'] = @$info['quicktime']['temp_meta_key_names'][$metaDATAkey++];
  1420. if ($atom_structure['key_name'] && $atom_structure['data']) {
  1421. @$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data'];
  1422. }
  1423. break;
  1424. case 'keys': // KEYS that may be present in the metadata atom.
  1425. // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21
  1426. // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom.
  1427. // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys".
  1428. $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
  1429. $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
  1430. $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
  1431. $keys_atom_offset = 8;
  1432. for ($i = 1; $i <= $atom_structure['entry_count']; $i++) {
  1433. $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4));
  1434. $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4);
  1435. $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8);
  1436. $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace
  1437. $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value'];
  1438. }
  1439. break;
  1440. case 'gps ':
  1441. // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730
  1442. // The 'gps ' contains simple look up table made up of 8byte rows, that point to the 'free' atoms that contains the actual GPS data.
  1443. // The first row is version/metadata/notsure, I skip that.
  1444. // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file.
  1445. $GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size
  1446. if (strlen($atom_data) > 0) {
  1447. if ((strlen($atom_data) % $GPS_rowsize) == 0) {
  1448. $atom_structure['gps_toc'] = array();
  1449. foreach (str_split($atom_data, $GPS_rowsize) as $counter => $datapair) {
  1450. $atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data, $counter * $GPS_rowsize, $GPS_rowsize));
  1451. }
  1452. $atom_structure['gps_entries'] = array();
  1453. $previous_offset = $this->ftell();
  1454. foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) {
  1455. if ($key == 0) {
  1456. // "The first row is version/metadata/notsure, I skip that."
  1457. continue;
  1458. }
  1459. $this->fseek($gps_pointer['offset']);
  1460. $GPS_free_data = $this->fread($gps_pointer['size']);
  1461. /*
  1462. // 2017-05-10: I see some of the data, notably the Hour-Minute-Second, but cannot reconcile the rest of the data. However, the NMEA "GPRMC" line is there and relatively easy to parse, so I'm using that instead
  1463. // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730
  1464. // The structure of the GPS data atom (the 'free' atoms mentioned above) is following:
  1465. // hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from('<IIIIIIssssfff',data, 48)
  1466. // For those unfamiliar with python struct:
  1467. // I = int
  1468. // s = is string (size 1, in this case)
  1469. // f = float
  1470. //$atom_structure['gps_entries'][$key] = unpack('Vhour/Vminute/Vsecond/Vyear/Vmonth/Vday/Vactive/Vlatitude_b/Vlongitude_b/Vunknown2/flatitude/flongitude/fspeed', substr($GPS_free_data, 48));
  1471. */
  1472. // $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62
  1473. // $GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67
  1474. // $GPRMC,002454,A,3553.5295,N,13938.6570,E,0.0,43.1,180700,7.1,W,A*3F
  1475. // $GPRMC,094347.000,A,5342.0061,N,00737.9908,W,0.01,156.75,140217,,,A*7D
  1476. if (preg_match('#\\$GPRMC,([0-9\\.]*),([AV]),([0-9\\.]*),([NS]),([0-9\\.]*),([EW]),([0-9\\.]*),([0-9\\.]*),([0-9]*),([0-9\\.]*),([EW]?)(,[A])?(\\*[0-9A-F]{2})#', $GPS_free_data, $matches)) {
  1477. $GPS_this_GPRMC = array();
  1478. list(
  1479. $GPS_this_GPRMC['raw']['gprmc'],
  1480. $GPS_this_GPRMC['raw']['timestamp'],
  1481. $GPS_this_GPRMC['raw']['status'],
  1482. $GPS_this_GPRMC['raw']['latitude'],
  1483. $GPS_this_GPRMC['raw']['latitude_direction'],
  1484. $GPS_this_GPRMC['raw']['longitude'],
  1485. $GPS_this_GPRMC['raw']['longitude_direction'],
  1486. $GPS_this_GPRMC['raw']['knots'],
  1487. $GPS_this_GPRMC['raw']['angle'],
  1488. $GPS_this_GPRMC['raw']['datestamp'],
  1489. $GPS_this_GPRMC['raw']['variation'],
  1490. $GPS_this_GPRMC['raw']['variation_direction'],
  1491. $dummy,
  1492. $GPS_this_GPRMC['raw']['checksum'],
  1493. ) = $matches;
  1494. $hour = substr($GPS_this_GPRMC['raw']['timestamp'], 0, 2);
  1495. $minute = substr($GPS_this_GPRMC['raw']['timestamp'], 2, 2);
  1496. $second = substr($GPS_this_GPRMC['raw']['timestamp'], 4, 2);
  1497. $ms = substr($GPS_this_GPRMC['raw']['timestamp'], 6); // may contain decimal seconds
  1498. $day = substr($GPS_this_GPRMC['raw']['datestamp'], 0, 2);
  1499. $month = substr($GPS_this_GPRMC['raw']['datestamp'], 2, 2);
  1500. $year = substr($GPS_this_GPRMC['raw']['datestamp'], 4, 2);
  1501. $year += (($year > 90) ? 1900 : 2000); // complete lack of foresight: datestamps are stored with 2-digit years, take best guess
  1502. $GPS_this_GPRMC['timestamp'] = $year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second.$ms;
  1503. $GPS_this_GPRMC['active'] = ($GPS_this_GPRMC['raw']['status'] == 'A'); // A=Active,V=Void
  1504. foreach (array('latitude','longitude') as $latlon) {
  1505. preg_match('#^([0-9]{1,3})([0-9]{2}\\.[0-9]+)$#', $GPS_this_GPRMC['raw'][$latlon], $matches);
  1506. list($dummy, $deg, $min) = $matches;
  1507. $GPS_this_GPRMC[$latlon] = $deg + ($min / 60);
  1508. }
  1509. $GPS_this_GPRMC['latitude'] *= (($GPS_this_GPRMC['raw']['latitude_direction'] == 'S') ? -1 : 1);
  1510. $GPS_this_GPRMC['longitude'] *= (($GPS_this_GPRMC['raw']['longitude_direction'] == 'W') ? -1 : 1);
  1511. $GPS_this_GPRMC['heading'] = $GPS_this_GPRMC['raw']['angle'];
  1512. $GPS_this_GPRMC['speed_knot'] = $GPS_this_GPRMC['raw']['knots'];
  1513. $GPS_this_GPRMC['speed_kmh'] = $GPS_this_GPRMC['raw']['knots'] * 1.852;
  1514. if ($GPS_this_GPRMC['raw']['variation']) {
  1515. $GPS_this_GPRMC['variation'] = $GPS_this_GPRMC['raw']['variation'];
  1516. $GPS_this_GPRMC['variation'] *= (($GPS_this_GPRMC['raw']['variation_direction'] == 'W') ? -1 : 1);
  1517. }
  1518. $atom_structure['gps_entries'][$key] = $GPS_this_GPRMC;
  1519. @$info['quicktime']['gps_track'][$GPS_this_GPRMC['timestamp']] = array(
  1520. 'latitude' => (float) $GPS_this_GPRMC['latitude'],
  1521. 'longitude' => (float) $GPS_this_GPRMC['longitude'],
  1522. 'speed_kmh' => (float) $GPS_this_GPRMC['speed_kmh'],
  1523. 'heading' => (float) $GPS_this_GPRMC['heading'],
  1524. );
  1525. } else {
  1526. $this->warning('Unhandled GPS format in "free" atom at offset '.$gps_pointer['offset']);
  1527. }
  1528. }
  1529. $this->fseek($previous_offset);
  1530. } else {
  1531. $this->warning('QuickTime atom "'.$atomname.'" is not mod-8 bytes long ('.$atomsize.' bytes) at offset '.$baseoffset);
  1532. }
  1533. } else {
  1534. $this->warning('QuickTime atom "'.$atomname.'" is zero bytes long at offset '.$baseoffset);
  1535. }
  1536. break;
  1537. case 'loci':// 3GP location (El Loco)
  1538. $loffset = 0;
  1539. $info['quicktime']['comments']['gps_flags'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)));
  1540. $info['quicktime']['comments']['gps_lang'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)));
  1541. $info['quicktime']['comments']['gps_location'] = array( $this->LociString(substr($atom_data, 6), $loffset));
  1542. $loci_data = substr($atom_data, 6 + $loffset);
  1543. $info['quicktime']['comments']['gps_role'] = array( getid3_lib::BigEndian2Int(substr($loci_data, 0, 1)));
  1544. $info['quicktime']['comments']['gps_longitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 1, 4)));
  1545. $info['quicktime']['comments']['gps_latitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 5, 4)));
  1546. $info['quicktime']['comments']['gps_altitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 9, 4)));
  1547. $info['quicktime']['comments']['gps_body'] = array( $this->LociString(substr($loci_data, 13 ), $loffset));
  1548. $info['quicktime']['comments']['gps_notes'] = array( $this->LociString(substr($loci_data, 13 + $loffset), $loffset));
  1549. break;
  1550. case 'chpl': // CHaPter List
  1551. // https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf
  1552. $chpl_version = getid3_lib::BigEndian2Int(substr($atom_data, 4, 1)); // Expected to be 0
  1553. $chpl_flags = getid3_lib::BigEndian2Int(substr($atom_data, 5, 3)); // Reserved, set to 0
  1554. $chpl_count = getid3_lib::BigEndian2Int(substr($atom_data, 8, 1));
  1555. $chpl_offset = 9;
  1556. for ($i = 0; $i < $chpl_count; $i++) {
  1557. if (($chpl_offset + 9) >= strlen($atom_data)) {
  1558. $this->warning('QuickTime chapter '.$i.' extends beyond end of "chpl" atom');
  1559. break;
  1560. }
  1561. $info['quicktime']['chapters'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 8)) / 10000000; // timestamps are stored as 100-nanosecond units
  1562. $chpl_offset += 8;
  1563. $chpl_title_size = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 1));
  1564. $chpl_offset += 1;
  1565. $info['quicktime']['chapters'][$i]['title'] = substr($atom_data, $chpl_offset, $chpl_title_size);
  1566. $chpl_offset += $chpl_title_size;
  1567. }
  1568. break;
  1569. case 'FIRM': // FIRMware version(?), seen on GoPro Hero4
  1570. $info['quicktime']['camera']['firmware'] = $atom_data;
  1571. break;
  1572. case 'CAME': // FIRMware version(?), seen on GoPro Hero4
  1573. $info['quicktime']['camera']['serial_hash'] = unpack('H*', $atom_data);
  1574. break;
  1575. case 'dscp':
  1576. case 'rcif':
  1577. // https://www.getid3.org/phpBB3/viewtopic.php?t=1908
  1578. if (substr($atom_data, 0, 7) == "\x00\x00\x00\x00\x55\xC4".'{') {
  1579. if ($json_decoded = @json_decode(rtrim(substr($atom_data, 6), "\x00"), true)) {
  1580. $info['quicktime']['camera'][$atomname] = $json_decoded;
  1581. if (($atomname == 'rcif') && isset($info['quicktime']['camera']['rcif']['wxcamera']['rotate'])) {
  1582. $info['video']['rotate'] = $info['quicktime']['video']['rotate'] = $info['quicktime']['camera']['rcif']['wxcamera']['rotate'];
  1583. }
  1584. } else {
  1585. $this->warning('Failed to JSON decode atom "'.$atomname.'"');
  1586. $atom_structure['data'] = $atom_data;
  1587. }
  1588. unset($json_decoded);
  1589. } else {
  1590. $this->warning('Expecting 55 C4 7B at start of atom "'.$atomname.'", found '.getid3_lib::PrintHexBytes(substr($atom_data, 4, 3)).' instead');
  1591. $atom_structure['data'] = $atom_data;
  1592. }
  1593. break;
  1594. case 'frea':
  1595. // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea
  1596. // may contain "scra" (PreviewImage) and/or "thma" (ThumbnailImage)
  1597. $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
  1598. break;
  1599. case 'tima': // subatom to "frea"
  1600. // no idea what this does, the one sample file I've seen has a value of 0x00000027
  1601. $atom_structure['data'] = $atom_data;
  1602. break;
  1603. case 'ver ': // subatom to "frea"
  1604. // some kind of version number, the one sample file I've seen has a value of "3.00.073"
  1605. $atom_structure['data'] = $atom_data;
  1606. break;
  1607. case 'thma': // subatom to "frea" -- "ThumbnailImage"
  1608. // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea
  1609. if (strlen($atom_data) > 0) {
  1610. $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg');
  1611. }
  1612. break;
  1613. case 'scra': // subatom to "frea" -- "PreviewImage"
  1614. // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea
  1615. // but the only sample file I've seen has no useful data here
  1616. if (strlen($atom_data) > 0) {
  1617. $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg');
  1618. }
  1619. break;
  1620. default:
  1621. $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).'), '.$atomsize.' bytes at offset '.$baseoffset);
  1622. $atom_structure['data'] = $atom_data;
  1623. break;
  1624. }
  1625. }
  1626. array_pop($atomHierarchy);
  1627. return $atom_structure;
  1628. }
  1629. /**
  1630. * @param string $atom_data
  1631. * @param int $baseoffset
  1632. * @param array $atomHierarchy
  1633. * @param bool $ParseAllPossibleAtoms
  1634. *
  1635. * @return array|false
  1636. */
  1637. public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
  1638. $atom_structure = false;
  1639. $subatomoffset = 0;
  1640. $subatomcounter = 0;
  1641. if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) {
  1642. return false;
  1643. }
  1644. while ($subatomoffset < strlen($atom_data)) {
  1645. $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4));
  1646. $subatomname = substr($atom_data, $subatomoffset + 4, 4);
  1647. $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8);
  1648. if ($subatomsize == 0) {
  1649. // Furthermore, for historical reasons the list of atoms is optionally
  1650. // terminated by a 32-bit integer set to 0. If you are writing a program
  1651. // to read user data atoms, you should allow for the terminating 0.
  1652. if (strlen($atom_data) > 12) {
  1653. $subatomoffset += 4;
  1654. continue;
  1655. }
  1656. return $atom_structure;
  1657. }
  1658. $atom_structure[$subatomcounter++] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
  1659. $subatomoffset += $subatomsize;
  1660. }
  1661. return $atom_structure;
  1662. }
  1663. /**
  1664. * @param string $data
  1665. * @param int $offset
  1666. *
  1667. * @return int
  1668. */
  1669. public function quicktime_read_mp4_descr_length($data, &$offset) {
  1670. // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html
  1671. $num_bytes = 0;
  1672. $length = 0;
  1673. do {
  1674. $b = ord(substr($data, $offset++, 1));
  1675. $length = ($length << 7) | ($b & 0x7F);
  1676. } while (($b & 0x80) && ($num_bytes++ < 4));
  1677. return $length;
  1678. }
  1679. /**
  1680. * @param int $languageid
  1681. *
  1682. * @return string
  1683. */
  1684. public function QuicktimeLanguageLookup($languageid) {
  1685. // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353
  1686. static $QuicktimeLanguageLookup = array();
  1687. if (empty($QuicktimeLanguageLookup)) {
  1688. $QuicktimeLanguageLookup[0] = 'English';
  1689. $QuicktimeLanguageLookup[1] = 'French';
  1690. $QuicktimeLanguageLookup[2] = 'German';
  1691. $QuicktimeLanguageLookup[3] = 'Italian';
  1692. $QuicktimeLanguageLookup[4] = 'Dutch';
  1693. $QuicktimeLanguageLookup[5] = 'Swedish';
  1694. $QuicktimeLanguageLookup[6] = 'Spanish';
  1695. $QuicktimeLanguageLookup[7] = 'Danish';
  1696. $QuicktimeLanguageLookup[8] = 'Portuguese';
  1697. $QuicktimeLanguageLookup[9] = 'Norwegian';
  1698. $QuicktimeLanguageLookup[10] = 'Hebrew';
  1699. $QuicktimeLanguageLookup[11] = 'Japanese';
  1700. $QuicktimeLanguageLookup[12] = 'Arabic';
  1701. $QuicktimeLanguageLookup[13] = 'Finnish';
  1702. $QuicktimeLanguageLookup[14] = 'Greek';
  1703. $QuicktimeLanguageLookup[15] = 'Icelandic';
  1704. $QuicktimeLanguageLookup[16] = 'Maltese';
  1705. $QuicktimeLanguageLookup[17] = 'Turkish';
  1706. $QuicktimeLanguageLookup[18] = 'Croatian';
  1707. $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
  1708. $QuicktimeLanguageLookup[20] = 'Urdu';
  1709. $QuicktimeLanguageLookup[21] = 'Hindi';
  1710. $QuicktimeLanguageLookup[22] = 'Thai';
  1711. $QuicktimeLanguageLookup[23] = 'Korean';
  1712. $QuicktimeLanguageLookup[24] = 'Lithuanian';
  1713. $QuicktimeLanguageLookup[25] = 'Polish';
  1714. $QuicktimeLanguageLookup[26] = 'Hungarian';
  1715. $QuicktimeLanguageLookup[27] = 'Estonian';
  1716. $QuicktimeLanguageLookup[28] = 'Lettish';
  1717. $QuicktimeLanguageLookup[28] = 'Latvian';
  1718. $QuicktimeLanguageLookup[29] = 'Saamisk';
  1719. $QuicktimeLanguageLookup[29] = 'Lappish';
  1720. $QuicktimeLanguageLookup[30] = 'Faeroese';
  1721. $QuicktimeLanguageLookup[31] = 'Farsi';
  1722. $QuicktimeLanguageLookup[31] = 'Persian';
  1723. $QuicktimeLanguageLookup[32] = 'Russian';
  1724. $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
  1725. $QuicktimeLanguageLookup[34] = 'Flemish';
  1726. $QuicktimeLanguageLookup[35] = 'Irish';
  1727. $QuicktimeLanguageLookup[36] = 'Albanian';
  1728. $QuicktimeLanguageLookup[37] = 'Romanian';
  1729. $QuicktimeLanguageLookup[38] = 'Czech';
  1730. $QuicktimeLanguageLookup[39] = 'Slovak';
  1731. $QuicktimeLanguageLookup[40] = 'Slovenian';
  1732. $QuicktimeLanguageLookup[41] = 'Yiddish';
  1733. $QuicktimeLanguageLookup[42] = 'Serbian';
  1734. $QuicktimeLanguageLookup[43] = 'Macedonian';
  1735. $QuicktimeLanguageLookup[44] = 'Bulgarian';
  1736. $QuicktimeLanguageLookup[45] = 'Ukrainian';
  1737. $QuicktimeLanguageLookup[46] = 'Byelorussian';
  1738. $QuicktimeLanguageLookup[47] = 'Uzbek';
  1739. $QuicktimeLanguageLookup[48] = 'Kazakh';
  1740. $QuicktimeLanguageLookup[49] = 'Azerbaijani';
  1741. $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
  1742. $QuicktimeLanguageLookup[51] = 'Armenian';
  1743. $QuicktimeLanguageLookup[52] = 'Georgian';
  1744. $QuicktimeLanguageLookup[53] = 'Moldavian';
  1745. $QuicktimeLanguageLookup[54] = 'Kirghiz';
  1746. $QuicktimeLanguageLookup[55] = 'Tajiki';
  1747. $QuicktimeLanguageLookup[56] = 'Turkmen';
  1748. $QuicktimeLanguageLookup[57] = 'Mongolian';
  1749. $QuicktimeLanguageLookup[58] = 'MongolianCyr';
  1750. $QuicktimeLanguageLookup[59] = 'Pashto';
  1751. $QuicktimeLanguageLookup[60] = 'Kurdish';
  1752. $QuicktimeLanguageLookup[61] = 'Kashmiri';
  1753. $QuicktimeLanguageLookup[62] = 'Sindhi';
  1754. $QuicktimeLanguageLookup[63] = 'Tibetan';
  1755. $QuicktimeLanguageLookup[64] = 'Nepali';
  1756. $QuicktimeLanguageLookup[65] = 'Sanskrit';
  1757. $QuicktimeLanguageLookup[66] = 'Marathi';
  1758. $QuicktimeLanguageLookup[67] = 'Bengali';
  1759. $QuicktimeLanguageLookup[68] = 'Assamese';
  1760. $QuicktimeLanguageLookup[69] = 'Gujarati';
  1761. $QuicktimeLanguageLookup[70] = 'Punjabi';
  1762. $QuicktimeLanguageLookup[71] = 'Oriya';
  1763. $QuicktimeLanguageLookup[72] = 'Malayalam';
  1764. $QuicktimeLanguageLookup[73] = 'Kannada';
  1765. $QuicktimeLanguageLookup[74] = 'Tamil';
  1766. $QuicktimeLanguageLookup[75] = 'Telugu';
  1767. $QuicktimeLanguageLookup[76] = 'Sinhalese';
  1768. $QuicktimeLanguageLookup[77] = 'Burmese';
  1769. $QuicktimeLanguageLookup[78] = 'Khmer';
  1770. $QuicktimeLanguageLookup[79] = 'Lao';
  1771. $QuicktimeLanguageLookup[80] = 'Vietnamese';
  1772. $QuicktimeLanguageLookup[81] = 'Indonesian';
  1773. $QuicktimeLanguageLookup[82] = 'Tagalog';
  1774. $QuicktimeLanguageLookup[83] = 'MalayRoman';
  1775. $QuicktimeLanguageLookup[84] = 'MalayArabic';
  1776. $QuicktimeLanguageLookup[85] = 'Amharic';
  1777. $QuicktimeLanguageLookup[86] = 'Tigrinya';
  1778. $QuicktimeLanguageLookup[87] = 'Galla';
  1779. $QuicktimeLanguageLookup[87] = 'Oromo';
  1780. $QuicktimeLanguageLookup[88] = 'Somali';
  1781. $QuicktimeLanguageLookup[89] = 'Swahili';
  1782. $QuicktimeLanguageLookup[90] = 'Ruanda';
  1783. $QuicktimeLanguageLookup[91] = 'Rundi';
  1784. $QuicktimeLanguageLookup[92] = 'Chewa';
  1785. $QuicktimeLanguageLookup[93] = 'Malagasy';
  1786. $QuicktimeLanguageLookup[94] = 'Esperanto';
  1787. $QuicktimeLanguageLookup[128] = 'Welsh';
  1788. $QuicktimeLanguageLookup[129] = 'Basque';
  1789. $QuicktimeLanguageLookup[130] = 'Catalan';
  1790. $QuicktimeLanguageLookup[131] = 'Latin';
  1791. $QuicktimeLanguageLookup[132] = 'Quechua';
  1792. $QuicktimeLanguageLookup[133] = 'Guarani';
  1793. $QuicktimeLanguageLookup[134] = 'Aymara';
  1794. $QuicktimeLanguageLookup[135] = 'Tatar';
  1795. $QuicktimeLanguageLookup[136] = 'Uighur';
  1796. $QuicktimeLanguageLookup[137] = 'Dzongkha';
  1797. $QuicktimeLanguageLookup[138] = 'JavaneseRom';
  1798. $QuicktimeLanguageLookup[32767] = 'Unspecified';
  1799. }
  1800. if (($languageid > 138) && ($languageid < 32767)) {
  1801. /*
  1802. ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php
  1803. Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field.
  1804. The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate
  1805. these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero.
  1806. One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character
  1807. and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character,
  1808. and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least
  1809. significant bits and the most significant bit set to zero.
  1810. */
  1811. $iso_language_id = '';
  1812. $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60);
  1813. $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60);
  1814. $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60);
  1815. $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id);
  1816. }
  1817. return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
  1818. }
  1819. /**
  1820. * @param string $codecid
  1821. *
  1822. * @return string
  1823. */
  1824. public function QuicktimeVideoCodecLookup($codecid) {
  1825. static $QuicktimeVideoCodecLookup = array();
  1826. if (empty($QuicktimeVideoCodecLookup)) {
  1827. $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
  1828. $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
  1829. $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
  1830. $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
  1831. $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
  1832. $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC';
  1833. $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
  1834. $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
  1835. $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
  1836. $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
  1837. $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
  1838. $QuicktimeVideoCodecLookup['base'] = 'Base';
  1839. $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
  1840. $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
  1841. $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
  1842. $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
  1843. $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
  1844. $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
  1845. $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
  1846. $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
  1847. $QuicktimeVideoCodecLookup['fire'] = 'Fire';
  1848. $QuicktimeVideoCodecLookup['flic'] = 'FLC';
  1849. $QuicktimeVideoCodecLookup['gif '] = 'GIF';
  1850. $QuicktimeVideoCodecLookup['h261'] = 'H261';
  1851. $QuicktimeVideoCodecLookup['h263'] = 'H263';
  1852. $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
  1853. $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
  1854. $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
  1855. $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
  1856. $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
  1857. $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
  1858. $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
  1859. $QuicktimeVideoCodecLookup['path'] = 'Vector';
  1860. $QuicktimeVideoCodecLookup['png '] = 'PNG';
  1861. $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
  1862. $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
  1863. $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
  1864. $QuicktimeVideoCodecLookup['raw '] = 'RAW';
  1865. $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
  1866. $QuicktimeVideoCodecLookup['rpza'] = 'Video';
  1867. $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
  1868. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
  1869. $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
  1870. $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
  1871. $QuicktimeVideoCodecLookup['tga '] = 'Targa';
  1872. $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
  1873. $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
  1874. $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
  1875. $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
  1876. $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
  1877. $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
  1878. $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
  1879. }
  1880. return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
  1881. }
  1882. /**
  1883. * @param string $codecid
  1884. *
  1885. * @return mixed|string
  1886. */
  1887. public function QuicktimeAudioCodecLookup($codecid) {
  1888. static $QuicktimeAudioCodecLookup = array();
  1889. if (empty($QuicktimeAudioCodecLookup)) {
  1890. $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
  1891. $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
  1892. $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
  1893. $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
  1894. $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
  1895. $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
  1896. $QuicktimeAudioCodecLookup['dvca'] = 'DV';
  1897. $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
  1898. $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
  1899. $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
  1900. $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
  1901. $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
  1902. $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
  1903. $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
  1904. $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
  1905. $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
  1906. $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
  1907. $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
  1908. $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
  1909. $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
  1910. $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
  1911. $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
  1912. $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
  1913. $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
  1914. $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
  1915. $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
  1916. $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
  1917. $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
  1918. $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
  1919. $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
  1920. $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
  1921. $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
  1922. $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
  1923. $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
  1924. $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
  1925. $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
  1926. $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
  1927. $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
  1928. }
  1929. return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
  1930. }
  1931. /**
  1932. * @param string $compressionid
  1933. *
  1934. * @return string
  1935. */
  1936. public function QuicktimeDCOMLookup($compressionid) {
  1937. static $QuicktimeDCOMLookup = array();
  1938. if (empty($QuicktimeDCOMLookup)) {
  1939. $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
  1940. $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
  1941. }
  1942. return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
  1943. }
  1944. /**
  1945. * @param int $colordepthid
  1946. *
  1947. * @return string
  1948. */
  1949. public function QuicktimeColorNameLookup($colordepthid) {
  1950. static $QuicktimeColorNameLookup = array();
  1951. if (empty($QuicktimeColorNameLookup)) {
  1952. $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
  1953. $QuicktimeColorNameLookup[2] = '4-color';
  1954. $QuicktimeColorNameLookup[4] = '16-color';
  1955. $QuicktimeColorNameLookup[8] = '256-color';
  1956. $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
  1957. $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
  1958. $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
  1959. $QuicktimeColorNameLookup[33] = 'black & white';
  1960. $QuicktimeColorNameLookup[34] = '4-gray';
  1961. $QuicktimeColorNameLookup[36] = '16-gray';
  1962. $QuicktimeColorNameLookup[40] = '256-gray';
  1963. }
  1964. return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
  1965. }
  1966. /**
  1967. * @param int $stik
  1968. *
  1969. * @return string
  1970. */
  1971. public function QuicktimeSTIKLookup($stik) {
  1972. static $QuicktimeSTIKLookup = array();
  1973. if (empty($QuicktimeSTIKLookup)) {
  1974. $QuicktimeSTIKLookup[0] = 'Movie';
  1975. $QuicktimeSTIKLookup[1] = 'Normal';
  1976. $QuicktimeSTIKLookup[2] = 'Audiobook';
  1977. $QuicktimeSTIKLookup[5] = 'Whacked Bookmark';
  1978. $QuicktimeSTIKLookup[6] = 'Music Video';
  1979. $QuicktimeSTIKLookup[9] = 'Short Film';
  1980. $QuicktimeSTIKLookup[10] = 'TV Show';
  1981. $QuicktimeSTIKLookup[11] = 'Booklet';
  1982. $QuicktimeSTIKLookup[14] = 'Ringtone';
  1983. $QuicktimeSTIKLookup[21] = 'Podcast';
  1984. }
  1985. return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid');
  1986. }
  1987. /**
  1988. * @param int $audio_profile_id
  1989. *
  1990. * @return string
  1991. */
  1992. public function QuicktimeIODSaudioProfileName($audio_profile_id) {
  1993. static $QuicktimeIODSaudioProfileNameLookup = array();
  1994. if (empty($QuicktimeIODSaudioProfileNameLookup)) {
  1995. $QuicktimeIODSaudioProfileNameLookup = array(
  1996. 0x00 => 'ISO Reserved (0x00)',
  1997. 0x01 => 'Main Audio Profile @ Level 1',
  1998. 0x02 => 'Main Audio Profile @ Level 2',
  1999. 0x03 => 'Main Audio Profile @ Level 3',
  2000. 0x04 => 'Main Audio Profile @ Level 4',
  2001. 0x05 => 'Scalable Audio Profile @ Level 1',
  2002. 0x06 => 'Scalable Audio Profile @ Level 2',
  2003. 0x07 => 'Scalable Audio Profile @ Level 3',
  2004. 0x08 => 'Scalable Audio Profile @ Level 4',
  2005. 0x09 => 'Speech Audio Profile @ Level 1',
  2006. 0x0A => 'Speech Audio Profile @ Level 2',
  2007. 0x0B => 'Synthetic Audio Profile @ Level 1',
  2008. 0x0C => 'Synthetic Audio Profile @ Level 2',
  2009. 0x0D => 'Synthetic Audio Profile @ Level 3',
  2010. 0x0E => 'High Quality Audio Profile @ Level 1',
  2011. 0x0F => 'High Quality Audio Profile @ Level 2',
  2012. 0x10 => 'High Quality Audio Profile @ Level 3',
  2013. 0x11 => 'High Quality Audio Profile @ Level 4',
  2014. 0x12 => 'High Quality Audio Profile @ Level 5',
  2015. 0x13 => 'High Quality Audio Profile @ Level 6',
  2016. 0x14 => 'High Quality Audio Profile @ Level 7',
  2017. 0x15 => 'High Quality Audio Profile @ Level 8',
  2018. 0x16 => 'Low Delay Audio Profile @ Level 1',
  2019. 0x17 => 'Low Delay Audio Profile @ Level 2',
  2020. 0x18 => 'Low Delay Audio Profile @ Level 3',
  2021. 0x19 => 'Low Delay Audio Profile @ Level 4',
  2022. 0x1A => 'Low Delay Audio Profile @ Level 5',
  2023. 0x1B => 'Low Delay Audio Profile @ Level 6',
  2024. 0x1C => 'Low Delay Audio Profile @ Level 7',
  2025. 0x1D => 'Low Delay Audio Profile @ Level 8',
  2026. 0x1E => 'Natural Audio Profile @ Level 1',
  2027. 0x1F => 'Natural Audio Profile @ Level 2',
  2028. 0x20 => 'Natural Audio Profile @ Level 3',
  2029. 0x21 => 'Natural Audio Profile @ Level 4',
  2030. 0x22 => 'Mobile Audio Internetworking Profile @ Level 1',
  2031. 0x23 => 'Mobile Audio Internetworking Profile @ Level 2',
  2032. 0x24 => 'Mobile Audio Internetworking Profile @ Level 3',
  2033. 0x25 => 'Mobile Audio Internetworking Profile @ Level 4',
  2034. 0x26 => 'Mobile Audio Internetworking Profile @ Level 5',
  2035. 0x27 => 'Mobile Audio Internetworking Profile @ Level 6',
  2036. 0x28 => 'AAC Profile @ Level 1',
  2037. 0x29 => 'AAC Profile @ Level 2',
  2038. 0x2A => 'AAC Profile @ Level 4',
  2039. 0x2B => 'AAC Profile @ Level 5',
  2040. 0x2C => 'High Efficiency AAC Profile @ Level 2',
  2041. 0x2D => 'High Efficiency AAC Profile @ Level 3',
  2042. 0x2E => 'High Efficiency AAC Profile @ Level 4',
  2043. 0x2F => 'High Efficiency AAC Profile @ Level 5',
  2044. 0xFE => 'Not part of MPEG-4 audio profiles',
  2045. 0xFF => 'No audio capability required',
  2046. );
  2047. }
  2048. return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private');
  2049. }
  2050. /**
  2051. * @param int $video_profile_id
  2052. *
  2053. * @return string
  2054. */
  2055. public function QuicktimeIODSvideoProfileName($video_profile_id) {
  2056. static $QuicktimeIODSvideoProfileNameLookup = array();
  2057. if (empty($QuicktimeIODSvideoProfileNameLookup)) {
  2058. $QuicktimeIODSvideoProfileNameLookup = array(
  2059. 0x00 => 'Reserved (0x00) Profile',
  2060. 0x01 => 'Simple Profile @ Level 1',
  2061. 0x02 => 'Simple Profile @ Level 2',
  2062. 0x03 => 'Simple Profile @ Level 3',
  2063. 0x08 => 'Simple Profile @ Level 0',
  2064. 0x10 => 'Simple Scalable Profile @ Level 0',
  2065. 0x11 => 'Simple Scalable Profile @ Level 1',
  2066. 0x12 => 'Simple Scalable Profile @ Level 2',
  2067. 0x15 => 'AVC/H264 Profile',
  2068. 0x21 => 'Core Profile @ Level 1',
  2069. 0x22 => 'Core Profile @ Level 2',
  2070. 0x32 => 'Main Profile @ Level 2',
  2071. 0x33 => 'Main Profile @ Level 3',
  2072. 0x34 => 'Main Profile @ Level 4',
  2073. 0x42 => 'N-bit Profile @ Level 2',
  2074. 0x51 => 'Scalable Texture Profile @ Level 1',
  2075. 0x61 => 'Simple Face Animation Profile @ Level 1',
  2076. 0x62 => 'Simple Face Animation Profile @ Level 2',
  2077. 0x63 => 'Simple FBA Profile @ Level 1',
  2078. 0x64 => 'Simple FBA Profile @ Level 2',
  2079. 0x71 => 'Basic Animated Texture Profile @ Level 1',
  2080. 0x72 => 'Basic Animated Texture Profile @ Level 2',
  2081. 0x81 => 'Hybrid Profile @ Level 1',
  2082. 0x82 => 'Hybrid Profile @ Level 2',
  2083. 0x91 => 'Advanced Real Time Simple Profile @ Level 1',
  2084. 0x92 => 'Advanced Real Time Simple Profile @ Level 2',
  2085. 0x93 => 'Advanced Real Time Simple Profile @ Level 3',
  2086. 0x94 => 'Advanced Real Time Simple Profile @ Level 4',
  2087. 0xA1 => 'Core Scalable Profile @ Level1',
  2088. 0xA2 => 'Core Scalable Profile @ Level2',
  2089. 0xA3 => 'Core Scalable Profile @ Level3',
  2090. 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1',
  2091. 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2',
  2092. 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3',
  2093. 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4',
  2094. 0xC1 => 'Advanced Core Profile @ Level 1',
  2095. 0xC2 => 'Advanced Core Profile @ Level 2',
  2096. 0xD1 => 'Advanced Scalable Texture @ Level1',
  2097. 0xD2 => 'Advanced Scalable Texture @ Level2',
  2098. 0xE1 => 'Simple Studio Profile @ Level 1',
  2099. 0xE2 => 'Simple Studio Profile @ Level 2',
  2100. 0xE3 => 'Simple Studio Profile @ Level 3',
  2101. 0xE4 => 'Simple Studio Profile @ Level 4',
  2102. 0xE5 => 'Core Studio Profile @ Level 1',
  2103. 0xE6 => 'Core Studio Profile @ Level 2',
  2104. 0xE7 => 'Core Studio Profile @ Level 3',
  2105. 0xE8 => 'Core Studio Profile @ Level 4',
  2106. 0xF0 => 'Advanced Simple Profile @ Level 0',
  2107. 0xF1 => 'Advanced Simple Profile @ Level 1',
  2108. 0xF2 => 'Advanced Simple Profile @ Level 2',
  2109. 0xF3 => 'Advanced Simple Profile @ Level 3',
  2110. 0xF4 => 'Advanced Simple Profile @ Level 4',
  2111. 0xF5 => 'Advanced Simple Profile @ Level 5',
  2112. 0xF7 => 'Advanced Simple Profile @ Level 3b',
  2113. 0xF8 => 'Fine Granularity Scalable Profile @ Level 0',
  2114. 0xF9 => 'Fine Granularity Scalable Profile @ Level 1',
  2115. 0xFA => 'Fine Granularity Scalable Profile @ Level 2',
  2116. 0xFB => 'Fine Granularity Scalable Profile @ Level 3',
  2117. 0xFC => 'Fine Granularity Scalable Profile @ Level 4',
  2118. 0xFD => 'Fine Granularity Scalable Profile @ Level 5',
  2119. 0xFE => 'Not part of MPEG-4 Visual profiles',
  2120. 0xFF => 'No visual capability required',
  2121. );
  2122. }
  2123. return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile');
  2124. }
  2125. /**
  2126. * @param int $rtng
  2127. *
  2128. * @return string
  2129. */
  2130. public function QuicktimeContentRatingLookup($rtng) {
  2131. static $QuicktimeContentRatingLookup = array();
  2132. if (empty($QuicktimeContentRatingLookup)) {
  2133. $QuicktimeContentRatingLookup[0] = 'None';
  2134. $QuicktimeContentRatingLookup[2] = 'Clean';
  2135. $QuicktimeContentRatingLookup[4] = 'Explicit';
  2136. }
  2137. return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid');
  2138. }
  2139. /**
  2140. * @param int $akid
  2141. *
  2142. * @return string
  2143. */
  2144. public function QuicktimeStoreAccountTypeLookup($akid) {
  2145. static $QuicktimeStoreAccountTypeLookup = array();
  2146. if (empty($QuicktimeStoreAccountTypeLookup)) {
  2147. $QuicktimeStoreAccountTypeLookup[0] = 'iTunes';
  2148. $QuicktimeStoreAccountTypeLookup[1] = 'AOL';
  2149. }
  2150. return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid');
  2151. }
  2152. /**
  2153. * @param int $sfid
  2154. *
  2155. * @return string
  2156. */
  2157. public function QuicktimeStoreFrontCodeLookup($sfid) {
  2158. static $QuicktimeStoreFrontCodeLookup = array();
  2159. if (empty($QuicktimeStoreFrontCodeLookup)) {
  2160. $QuicktimeStoreFrontCodeLookup[143460] = 'Australia';
  2161. $QuicktimeStoreFrontCodeLookup[143445] = 'Austria';
  2162. $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium';
  2163. $QuicktimeStoreFrontCodeLookup[143455] = 'Canada';
  2164. $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark';
  2165. $QuicktimeStoreFrontCodeLookup[143447] = 'Finland';
  2166. $QuicktimeStoreFrontCodeLookup[143442] = 'France';
  2167. $QuicktimeStoreFrontCodeLookup[143443] = 'Germany';
  2168. $QuicktimeStoreFrontCodeLookup[143448] = 'Greece';
  2169. $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland';
  2170. $QuicktimeStoreFrontCodeLookup[143450] = 'Italy';
  2171. $QuicktimeStoreFrontCodeLookup[143462] = 'Japan';
  2172. $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg';
  2173. $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands';
  2174. $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand';
  2175. $QuicktimeStoreFrontCodeLookup[143457] = 'Norway';
  2176. $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal';
  2177. $QuicktimeStoreFrontCodeLookup[143454] = 'Spain';
  2178. $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden';
  2179. $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland';
  2180. $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom';
  2181. $QuicktimeStoreFrontCodeLookup[143441] = 'United States';
  2182. }
  2183. return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid');
  2184. }
  2185. /**
  2186. * @param string $atom_data
  2187. *
  2188. * @return array
  2189. */
  2190. public function QuicktimeParseNikonNCTG($atom_data) {
  2191. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
  2192. // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
  2193. // Data is stored as records of:
  2194. // * 4 bytes record type
  2195. // * 2 bytes size of data field type:
  2196. // 0x0001 = flag (size field *= 1-byte)
  2197. // 0x0002 = char (size field *= 1-byte)
  2198. // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
  2199. // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
  2200. // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
  2201. // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
  2202. // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
  2203. // * 2 bytes data size field
  2204. // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15")
  2205. // all integers are stored BigEndian
  2206. $NCTGtagName = array(
  2207. 0x00000001 => 'Make',
  2208. 0x00000002 => 'Model',
  2209. 0x00000003 => 'Software',
  2210. 0x00000011 => 'CreateDate',
  2211. 0x00000012 => 'DateTimeOriginal',
  2212. 0x00000013 => 'FrameCount',
  2213. 0x00000016 => 'FrameRate',
  2214. 0x00000022 => 'FrameWidth',
  2215. 0x00000023 => 'FrameHeight',
  2216. 0x00000032 => 'AudioChannels',
  2217. 0x00000033 => 'AudioBitsPerSample',
  2218. 0x00000034 => 'AudioSampleRate',
  2219. 0x02000001 => 'MakerNoteVersion',
  2220. 0x02000005 => 'WhiteBalance',
  2221. 0x0200000b => 'WhiteBalanceFineTune',
  2222. 0x0200001e => 'ColorSpace',
  2223. 0x02000023 => 'PictureControlData',
  2224. 0x02000024 => 'WorldTime',
  2225. 0x02000032 => 'UnknownInfo',
  2226. 0x02000083 => 'LensType',
  2227. 0x02000084 => 'Lens',
  2228. );
  2229. $offset = 0;
  2230. $data = null;
  2231. $datalength = strlen($atom_data);
  2232. $parsed = array();
  2233. while ($offset < $datalength) {
  2234. $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4;
  2235. $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
  2236. $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
  2237. switch ($data_size_type) {
  2238. case 0x0001: // 0x0001 = flag (size field *= 1-byte)
  2239. $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1));
  2240. $offset += ($data_size * 1);
  2241. break;
  2242. case 0x0002: // 0x0002 = char (size field *= 1-byte)
  2243. $data = substr($atom_data, $offset, $data_size * 1);
  2244. $offset += ($data_size * 1);
  2245. $data = rtrim($data, "\x00");
  2246. break;
  2247. case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
  2248. $data = '';
  2249. for ($i = $data_size - 1; $i >= 0; $i--) {
  2250. $data .= substr($atom_data, $offset + ($i * 2), 2);
  2251. }
  2252. $data = getid3_lib::BigEndian2Int($data);
  2253. $offset += ($data_size * 2);
  2254. break;
  2255. case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
  2256. $data = '';
  2257. for ($i = $data_size - 1; $i >= 0; $i--) {
  2258. $data .= substr($atom_data, $offset + ($i * 4), 4);
  2259. }
  2260. $data = getid3_lib::BigEndian2Int($data);
  2261. $offset += ($data_size * 4);
  2262. break;
  2263. case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
  2264. $data = array();
  2265. for ($i = 0; $i < $data_size; $i++) {
  2266. $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4));
  2267. $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4));
  2268. if ($denomninator == 0) {
  2269. $data[$i] = false;
  2270. } else {
  2271. $data[$i] = (double) $numerator / $denomninator;
  2272. }
  2273. }
  2274. $offset += (8 * $data_size);
  2275. if (count($data) == 1) {
  2276. $data = $data[0];
  2277. }
  2278. break;
  2279. case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
  2280. $data = substr($atom_data, $offset, $data_size * 1);
  2281. $offset += ($data_size * 1);
  2282. break;
  2283. case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
  2284. $data = substr($atom_data, $offset, $data_size * 2);
  2285. $offset += ($data_size * 2);
  2286. break;
  2287. default:
  2288. echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>';
  2289. break 2;
  2290. }
  2291. switch ($record_type) {
  2292. case 0x00000011: // CreateDate
  2293. case 0x00000012: // DateTimeOriginal
  2294. $data = strtotime($data);
  2295. break;
  2296. case 0x0200001e: // ColorSpace
  2297. switch ($data) {
  2298. case 1:
  2299. $data = 'sRGB';
  2300. break;
  2301. case 2:
  2302. $data = 'Adobe RGB';
  2303. break;
  2304. }
  2305. break;
  2306. case 0x02000023: // PictureControlData
  2307. $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full');
  2308. $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a');
  2309. $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');
  2310. $data = array(
  2311. 'PictureControlVersion' => substr($data, 0, 4),
  2312. 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"),
  2313. 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"),
  2314. //'?' => substr($data, 44, 4),
  2315. 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))],
  2316. 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)),
  2317. 'Sharpness' => ord(substr($data, 50, 1)),
  2318. 'Contrast' => ord(substr($data, 51, 1)),
  2319. 'Brightness' => ord(substr($data, 52, 1)),
  2320. 'Saturation' => ord(substr($data, 53, 1)),
  2321. 'HueAdjustment' => ord(substr($data, 54, 1)),
  2322. 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))],
  2323. 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))],
  2324. 'ToningSaturation' => ord(substr($data, 57, 1)),
  2325. );
  2326. break;
  2327. case 0x02000024: // WorldTime
  2328. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime
  2329. // timezone is stored as offset from GMT in minutes
  2330. $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2));
  2331. if ($timezone & 0x8000) {
  2332. $timezone = 0 - (0x10000 - $timezone);
  2333. }
  2334. $timezone /= 60;
  2335. $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1));
  2336. switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) {
  2337. case 2:
  2338. $datedisplayformat = 'D/M/Y'; break;
  2339. case 1:
  2340. $datedisplayformat = 'M/D/Y'; break;
  2341. case 0:
  2342. default:
  2343. $datedisplayformat = 'Y/M/D'; break;
  2344. }
  2345. $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat);
  2346. break;
  2347. case 0x02000083: // LensType
  2348. $data = array(
  2349. //'_' => $data,
  2350. 'mf' => (bool) ($data & 0x01),
  2351. 'd' => (bool) ($data & 0x02),
  2352. 'g' => (bool) ($data & 0x04),
  2353. 'vr' => (bool) ($data & 0x08),
  2354. );
  2355. break;
  2356. }
  2357. $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT));
  2358. $parsed[$tag_name] = $data;
  2359. }
  2360. return $parsed;
  2361. }
  2362. /**
  2363. * @param string $keyname
  2364. * @param string|array $data
  2365. * @param string $boxname
  2366. *
  2367. * @return bool
  2368. */
  2369. public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') {
  2370. static $handyatomtranslatorarray = array();
  2371. if (empty($handyatomtranslatorarray)) {
  2372. // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
  2373. // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt
  2374. // http://atomicparsley.sourceforge.net/mpeg-4files.html
  2375. // https://code.google.com/p/mp4v2/wiki/iTunesMetadata
  2376. $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0
  2377. $handyatomtranslatorarray["\xA9".'ART'] = 'artist';
  2378. $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0
  2379. $handyatomtranslatorarray["\xA9".'aut'] = 'author';
  2380. $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0
  2381. $handyatomtranslatorarray["\xA9".'com'] = 'comment';
  2382. $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright';
  2383. $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0
  2384. $handyatomtranslatorarray["\xA9".'dir'] = 'director';
  2385. $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1';
  2386. $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2';
  2387. $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3';
  2388. $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4';
  2389. $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5';
  2390. $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6';
  2391. $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7';
  2392. $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8';
  2393. $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9';
  2394. $handyatomtranslatorarray["\xA9".'enc'] = 'encoded_by';
  2395. $handyatomtranslatorarray["\xA9".'fmt'] = 'format';
  2396. $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0
  2397. $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2
  2398. $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer';
  2399. $handyatomtranslatorarray["\xA9".'inf'] = 'information';
  2400. $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0
  2401. $handyatomtranslatorarray["\xA9".'mak'] = 'make';
  2402. $handyatomtranslatorarray["\xA9".'mod'] = 'model';
  2403. $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0
  2404. $handyatomtranslatorarray["\xA9".'ope'] = 'composer';
  2405. $handyatomtranslatorarray["\xA9".'prd'] = 'producer';
  2406. $handyatomtranslatorarray["\xA9".'PRD'] = 'product';
  2407. $handyatomtranslatorarray["\xA9".'prf'] = 'performers';
  2408. $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements';
  2409. $handyatomtranslatorarray["\xA9".'src'] = 'source_credit';
  2410. $handyatomtranslatorarray["\xA9".'swr'] = 'software';
  2411. $handyatomtranslatorarray["\xA9".'too'] = 'encoding_tool'; // iTunes 4.0
  2412. $handyatomtranslatorarray["\xA9".'trk'] = 'track_number';
  2413. $handyatomtranslatorarray["\xA9".'url'] = 'url';
  2414. $handyatomtranslatorarray["\xA9".'wrn'] = 'warning';
  2415. $handyatomtranslatorarray["\xA9".'wrt'] = 'composer';
  2416. $handyatomtranslatorarray['aART'] = 'album_artist';
  2417. $handyatomtranslatorarray['apID'] = 'purchase_account';
  2418. $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9
  2419. $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0
  2420. $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0
  2421. $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0?
  2422. $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0
  2423. $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0
  2424. $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9
  2425. $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0
  2426. $handyatomtranslatorarray['hdvd'] = 'hd_video'; // iTunes 4.0
  2427. $handyatomtranslatorarray['ldes'] = 'description_long'; //
  2428. $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9
  2429. $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9
  2430. $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0
  2431. $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2
  2432. $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9
  2433. $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0
  2434. $handyatomtranslatorarray['soaa'] = 'sort_album_artist'; //
  2435. $handyatomtranslatorarray['soal'] = 'sort_album'; //
  2436. $handyatomtranslatorarray['soar'] = 'sort_artist'; //
  2437. $handyatomtranslatorarray['soco'] = 'sort_composer'; //
  2438. $handyatomtranslatorarray['sonm'] = 'sort_title'; //
  2439. $handyatomtranslatorarray['sosn'] = 'sort_show'; //
  2440. $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9
  2441. $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0
  2442. $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0
  2443. $handyatomtranslatorarray['tven'] = 'tv_episode_id'; //
  2444. $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0
  2445. $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0
  2446. $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0
  2447. $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0
  2448. // boxnames:
  2449. /*
  2450. $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB';
  2451. $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM';
  2452. $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params';
  2453. $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain';
  2454. $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak';
  2455. $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax';
  2456. $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID';
  2457. $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id';
  2458. $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id';
  2459. $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id';
  2460. $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id';
  2461. $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id';
  2462. // http://age.hobba.nl/audio/tag_frame_reference.html
  2463. $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355
  2464. $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355
  2465. */
  2466. }
  2467. $info = &$this->getid3->info;
  2468. $comment_key = '';
  2469. if ($boxname && ($boxname != $keyname)) {
  2470. $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname);
  2471. } elseif (isset($handyatomtranslatorarray[$keyname])) {
  2472. $comment_key = $handyatomtranslatorarray[$keyname];
  2473. }
  2474. if ($comment_key) {
  2475. if ($comment_key == 'picture') {
  2476. if (!is_array($data)) {
  2477. $image_mime = '';
  2478. if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) {
  2479. $image_mime = 'image/png';
  2480. } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) {
  2481. $image_mime = 'image/jpeg';
  2482. } elseif (preg_match('#^GIF#', $data)) {
  2483. $image_mime = 'image/gif';
  2484. } elseif (preg_match('#^BM#', $data)) {
  2485. $image_mime = 'image/bmp';
  2486. }
  2487. $data = array('data'=>$data, 'image_mime'=>$image_mime);
  2488. }
  2489. }
  2490. $gooddata = array($data);
  2491. if ($comment_key == 'genre') {
  2492. // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal"
  2493. $gooddata = explode(';', $data);
  2494. }
  2495. foreach ($gooddata as $data) {
  2496. $info['quicktime']['comments'][$comment_key][] = $data;
  2497. }
  2498. }
  2499. return true;
  2500. }
  2501. /**
  2502. * @param string $lstring
  2503. * @param int $count
  2504. *
  2505. * @return string
  2506. */
  2507. public function LociString($lstring, &$count) {
  2508. // Loci strings are UTF-8 or UTF-16 and null (x00/x0000) terminated. UTF-16 has a BOM
  2509. // Also need to return the number of bytes the string occupied so additional fields can be extracted
  2510. $len = strlen($lstring);
  2511. if ($len == 0) {
  2512. $count = 0;
  2513. return '';
  2514. }
  2515. if ($lstring[0] == "\x00") {
  2516. $count = 1;
  2517. return '';
  2518. }
  2519. // check for BOM
  2520. if (($len > 2) && ((($lstring[0] == "\xFE") && ($lstring[1] == "\xFF")) || (($lstring[0] == "\xFF") && ($lstring[1] == "\xFE")))) {
  2521. // UTF-16
  2522. if (preg_match('/(.*)\x00/', $lstring, $lmatches)) {
  2523. $count = strlen($lmatches[1]) * 2 + 2; //account for 2 byte characters and trailing \x0000
  2524. return getid3_lib::iconv_fallback_utf16_utf8($lmatches[1]);
  2525. } else {
  2526. return '';
  2527. }
  2528. }
  2529. // UTF-8
  2530. if (preg_match('/(.*)\x00/', $lstring, $lmatches)) {
  2531. $count = strlen($lmatches[1]) + 1; //account for trailing \x00
  2532. return $lmatches[1];
  2533. }
  2534. return '';
  2535. }
  2536. /**
  2537. * @param string $nullterminatedstring
  2538. *
  2539. * @return string
  2540. */
  2541. public function NoNullString($nullterminatedstring) {
  2542. // remove the single null terminator on null terminated strings
  2543. if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
  2544. return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
  2545. }
  2546. return $nullterminatedstring;
  2547. }
  2548. /**
  2549. * @param string $pascalstring
  2550. *
  2551. * @return string
  2552. */
  2553. public function Pascal2String($pascalstring) {
  2554. // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
  2555. return substr($pascalstring, 1);
  2556. }
  2557. /**
  2558. * Helper functions for m4b audiobook chapters
  2559. * code by Steffen Hartmann 2015-Nov-08.
  2560. *
  2561. * @param array $info
  2562. * @param string $tag
  2563. * @param string $history
  2564. * @param array $result
  2565. */
  2566. public function search_tag_by_key($info, $tag, $history, &$result) {
  2567. foreach ($info as $key => $value) {
  2568. $key_history = $history.'/'.$key;
  2569. if ($key === $tag) {
  2570. $result[] = array($key_history, $info);
  2571. } else {
  2572. if (is_array($value)) {
  2573. $this->search_tag_by_key($value, $tag, $key_history, $result);
  2574. }
  2575. }
  2576. }
  2577. }
  2578. /**
  2579. * @param array $info
  2580. * @param string $k
  2581. * @param string $v
  2582. * @param string $history
  2583. * @param array $result
  2584. */
  2585. public function search_tag_by_pair($info, $k, $v, $history, &$result) {
  2586. foreach ($info as $key => $value) {
  2587. $key_history = $history.'/'.$key;
  2588. if (($key === $k) && ($value === $v)) {
  2589. $result[] = array($key_history, $info);
  2590. } else {
  2591. if (is_array($value)) {
  2592. $this->search_tag_by_pair($value, $k, $v, $key_history, $result);
  2593. }
  2594. }
  2595. }
  2596. }
  2597. /**
  2598. * @param array $info
  2599. *
  2600. * @return array
  2601. */
  2602. public function quicktime_time_to_sample_table($info) {
  2603. $res = array();
  2604. $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res);
  2605. foreach ($res as $value) {
  2606. $stbl_res = array();
  2607. $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res);
  2608. if (count($stbl_res) > 0) {
  2609. $stts_res = array();
  2610. $this->search_tag_by_key($value[1], 'time_to_sample_table', $value[0], $stts_res);
  2611. if (count($stts_res) > 0) {
  2612. return $stts_res[0][1]['time_to_sample_table'];
  2613. }
  2614. }
  2615. }
  2616. return array();
  2617. }
  2618. /**
  2619. * @param array $info
  2620. *
  2621. * @return int
  2622. */
  2623. public function quicktime_bookmark_time_scale($info) {
  2624. $time_scale = '';
  2625. $ts_prefix_len = 0;
  2626. $res = array();
  2627. $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res);
  2628. foreach ($res as $value) {
  2629. $stbl_res = array();
  2630. $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res);
  2631. if (count($stbl_res) > 0) {
  2632. $ts_res = array();
  2633. $this->search_tag_by_key($info['quicktime']['moov'], 'time_scale', 'quicktime/moov', $ts_res);
  2634. foreach ($ts_res as $sub_value) {
  2635. $prefix = substr($sub_value[0], 0, -12);
  2636. if ((substr($stbl_res[0][0], 0, strlen($prefix)) === $prefix) && ($ts_prefix_len < strlen($prefix))) {
  2637. $time_scale = $sub_value[1]['time_scale'];
  2638. $ts_prefix_len = strlen($prefix);
  2639. }
  2640. }
  2641. }
  2642. }
  2643. return $time_scale;
  2644. }
  2645. /*
  2646. // END helper functions for m4b audiobook chapters
  2647. */
  2648. }