module.audio-video.quicktime.php 161 KB

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