module.audio-video.quicktime.php 157 KB

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