Nessuna descrizione

module.audio-video.quicktime.php 155KB

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