Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

module.audio-video.quicktime.php 161KB

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