module.audio-video.quicktime.php 128 KB

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