module.audio-video.asf.php 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio-video.asf.php //
  11. // module for analyzing ASF, WMA and WMV files //
  12. // dependencies: module.audio-video.riff.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
  16. $GUIDarray = getid3_asf::KnownGUIDs();
  17. foreach ($GUIDarray as $GUIDname => $hexstringvalue) {
  18. // initialize all GUID constants
  19. define($GUIDname, getid3_asf::GUIDtoBytestring($hexstringvalue));
  20. }
  21. class getid3_asf
  22. {
  23. function getid3_asf(&$fd, &$ThisFileInfo) {
  24. // Shortcuts
  25. $thisfile_audio = &$ThisFileInfo['audio'];
  26. $thisfile_video = &$ThisFileInfo['video'];
  27. $ThisFileInfo['asf'] = array();
  28. $thisfile_asf = &$ThisFileInfo['asf'];
  29. $thisfile_asf['comments'] = array();
  30. $thisfile_asf_comments = &$thisfile_asf['comments'];
  31. $thisfile_asf['header_object'] = array();
  32. $thisfile_asf_headerobject = &$thisfile_asf['header_object'];
  33. // ASF structure:
  34. // * Header Object [required]
  35. // * File Properties Object [required] (global file attributes)
  36. // * Stream Properties Object [required] (defines media stream & characteristics)
  37. // * Header Extension Object [required] (additional functionality)
  38. // * Content Description Object (bibliographic information)
  39. // * Script Command Object (commands for during playback)
  40. // * Marker Object (named jumped points within the file)
  41. // * Data Object [required]
  42. // * Data Packets
  43. // * Index Object
  44. // Header Object: (mandatory, one only)
  45. // Field Name Field Type Size (bits)
  46. // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object
  47. // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header
  48. // Number of Header Objects DWORD 32 // number of objects in header object
  49. // Reserved1 BYTE 8 // hardcoded: 0x01
  50. // Reserved2 BYTE 8 // hardcoded: 0x02
  51. $ThisFileInfo['fileformat'] = 'asf';
  52. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  53. $HeaderObjectData = fread($fd, 30);
  54. $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16);
  55. $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']);
  56. if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) {
  57. $ThisFileInfo['warning'][] = 'ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}';
  58. unset($ThisFileInfo['fileformat']);
  59. unset($ThisFileInfo['asf']);
  60. return false;
  61. break;
  62. }
  63. $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8));
  64. $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4));
  65. $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1));
  66. $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1));
  67. $ASFHeaderData = fread($fd, $thisfile_asf_headerobject['objectsize'] - 30);
  68. $offset = 0;
  69. for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) {
  70. $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
  71. $offset += 16;
  72. $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
  73. $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  74. $offset += 8;
  75. switch ($NextObjectGUID) {
  76. case GETID3_ASF_File_Properties_Object:
  77. // File Properties Object: (mandatory, one only)
  78. // Field Name Field Type Size (bits)
  79. // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object
  80. // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header
  81. // File ID GUID 128 // unique ID - identical to File ID in Data Object
  82. // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1
  83. // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1
  84. // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1
  85. // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
  86. // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
  87. // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
  88. // Flags DWORD 32 //
  89. // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid
  90. // * Seekable Flag bits 1 (0x02) // is file seekable
  91. // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero
  92. // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
  93. // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
  94. // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
  95. // shortcut
  96. $thisfile_asf['file_properties_object'] = array();
  97. $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object'];
  98. $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID;
  99. $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
  100. $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize;
  101. $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16);
  102. $offset += 16;
  103. $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']);
  104. $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  105. $offset += 8;
  106. $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  107. $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']);
  108. $offset += 8;
  109. $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  110. $offset += 8;
  111. $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  112. $offset += 8;
  113. $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  114. $offset += 8;
  115. $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  116. $offset += 8;
  117. $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  118. $offset += 4;
  119. $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001);
  120. $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002);
  121. $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  122. $offset += 4;
  123. $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  124. $offset += 4;
  125. $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  126. $offset += 4;
  127. if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) {
  128. // broadcast flag is set, some values invalid
  129. unset($thisfile_asf_filepropertiesobject['filesize']);
  130. unset($thisfile_asf_filepropertiesobject['data_packets']);
  131. unset($thisfile_asf_filepropertiesobject['play_duration']);
  132. unset($thisfile_asf_filepropertiesobject['send_duration']);
  133. unset($thisfile_asf_filepropertiesobject['min_packet_size']);
  134. unset($thisfile_asf_filepropertiesobject['max_packet_size']);
  135. } else {
  136. // broadcast flag NOT set, perform calculations
  137. $ThisFileInfo['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000);
  138. //$ThisFileInfo['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate'];
  139. $ThisFileInfo['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $ThisFileInfo['filesize']) * 8) / $ThisFileInfo['playtime_seconds'];
  140. }
  141. break;
  142. case GETID3_ASF_Stream_Properties_Object:
  143. // Stream Properties Object: (mandatory, one per media stream)
  144. // Field Name Field Type Size (bits)
  145. // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object
  146. // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header
  147. // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media
  148. // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types
  149. // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
  150. // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field
  151. // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field
  152. // Flags WORD 16 //
  153. // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127
  154. // * Reserved bits 8 (0x7F80) // reserved - set to zero
  155. // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set
  156. // Reserved DWORD 32 // reserved - set to zero
  157. // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type
  158. // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type
  159. // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the
  160. // stream number isn't known until halfway through decoding the structure, hence it
  161. // it is decoded to a temporary variable and then stuck in the appropriate index later
  162. $StreamPropertiesObjectData['objectid'] = $NextObjectGUID;
  163. $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext;
  164. $StreamPropertiesObjectData['objectsize'] = $NextObjectSize;
  165. $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
  166. $offset += 16;
  167. $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']);
  168. $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
  169. $offset += 16;
  170. $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
  171. $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  172. $offset += 8;
  173. $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  174. $offset += 4;
  175. $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  176. $offset += 4;
  177. $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  178. $offset += 2;
  179. $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F;
  180. $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
  181. $offset += 4; // reserved - DWORD
  182. $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
  183. $offset += $StreamPropertiesObjectData['type_data_length'];
  184. $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
  185. $offset += $StreamPropertiesObjectData['error_data_length'];
  186. switch ($StreamPropertiesObjectData['stream_type']) {
  187. case GETID3_ASF_Audio_Media:
  188. $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
  189. $thisfile_audio['bitrate_mode'] = (!empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr');
  190. $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16));
  191. unset($audiodata['raw']);
  192. $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio);
  193. break;
  194. case GETID3_ASF_Video_Media:
  195. $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
  196. $thisfile_video['bitrate_mode'] = (!empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr');
  197. break;
  198. case GETID3_ASF_Command_Media:
  199. default:
  200. // do nothing
  201. break;
  202. }
  203. $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
  204. unset($StreamPropertiesObjectData); // clear for next stream, if any
  205. break;
  206. case GETID3_ASF_Header_Extension_Object:
  207. // Header Extension Object: (mandatory, one only)
  208. // Field Name Field Type Size (bits)
  209. // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object
  210. // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header
  211. // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1
  212. // Reserved Field 2 WORD 16 // hardcoded: 0x00000006
  213. // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46
  214. // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects
  215. // shortcut
  216. $thisfile_asf['header_extension_object'] = array();
  217. $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object'];
  218. $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID;
  219. $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext;
  220. $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize;
  221. $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16);
  222. $offset += 16;
  223. $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']);
  224. if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) {
  225. $ThisFileInfo['warning'][] = 'header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')';
  226. //return false;
  227. break;
  228. }
  229. $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  230. $offset += 2;
  231. if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) {
  232. $ThisFileInfo['warning'][] = 'header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"';
  233. //return false;
  234. break;
  235. }
  236. $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  237. $offset += 4;
  238. $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']);
  239. $offset += $thisfile_asf_headerextensionobject['extension_data_size'];
  240. break;
  241. case GETID3_ASF_Codec_List_Object:
  242. // Codec List Object: (optional, one only)
  243. // Field Name Field Type Size (bits)
  244. // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object
  245. // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header
  246. // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
  247. // Codec Entries Count DWORD 32 // number of entries in Codec Entries array
  248. // Codec Entries array of: variable //
  249. // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
  250. // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field
  251. // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content
  252. // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field
  253. // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content
  254. // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field
  255. // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content
  256. // shortcut
  257. $thisfile_asf['codec_list_object'] = array();
  258. $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object'];
  259. $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;
  260. $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext;
  261. $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize;
  262. $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16);
  263. $offset += 16;
  264. $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']);
  265. if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) {
  266. $ThisFileInfo['warning'][] = 'codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}';
  267. //return false;
  268. break;
  269. }
  270. $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  271. $offset += 4;
  272. for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) {
  273. // shortcut
  274. $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array();
  275. $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter];
  276. $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  277. $offset += 2;
  278. $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
  279. $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
  280. $offset += 2;
  281. $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
  282. $offset += $CodecNameLength;
  283. $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
  284. $offset += 2;
  285. $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
  286. $offset += $CodecDescriptionLength;
  287. $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  288. $offset += 2;
  289. $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
  290. $offset += $CodecInformationLength;
  291. if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) {
  292. // audio codec
  293. if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) {
  294. $ThisFileInfo['error'][] = '[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-seperated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"';
  295. return false;
  296. }
  297. list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']));
  298. $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']);
  299. if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
  300. $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
  301. }
  302. //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) {
  303. if (!@$thisfile_video['bitrate'] && @$thisfile_audio['bitrate'] && @$ThisFileInfo['bitrate']) {
  304. //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate'];
  305. $thisfile_video['bitrate'] = $ThisFileInfo['bitrate'] - $thisfile_audio['bitrate'];
  306. }
  307. $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
  308. switch ($AudioCodecFrequency) {
  309. case 8:
  310. case 8000:
  311. $thisfile_audio['sample_rate'] = 8000;
  312. break;
  313. case 11:
  314. case 11025:
  315. $thisfile_audio['sample_rate'] = 11025;
  316. break;
  317. case 12:
  318. case 12000:
  319. $thisfile_audio['sample_rate'] = 12000;
  320. break;
  321. case 16:
  322. case 16000:
  323. $thisfile_audio['sample_rate'] = 16000;
  324. break;
  325. case 22:
  326. case 22050:
  327. $thisfile_audio['sample_rate'] = 22050;
  328. break;
  329. case 24:
  330. case 24000:
  331. $thisfile_audio['sample_rate'] = 24000;
  332. break;
  333. case 32:
  334. case 32000:
  335. $thisfile_audio['sample_rate'] = 32000;
  336. break;
  337. case 44:
  338. case 441000:
  339. $thisfile_audio['sample_rate'] = 44100;
  340. break;
  341. case 48:
  342. case 48000:
  343. $thisfile_audio['sample_rate'] = 48000;
  344. break;
  345. default:
  346. $ThisFileInfo['warning'][] = 'unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')';
  347. break;
  348. }
  349. if (!isset($thisfile_audio['channels'])) {
  350. if (strstr($AudioCodecChannels, 'stereo')) {
  351. $thisfile_audio['channels'] = 2;
  352. } elseif (strstr($AudioCodecChannels, 'mono')) {
  353. $thisfile_audio['channels'] = 1;
  354. }
  355. }
  356. }
  357. }
  358. break;
  359. case GETID3_ASF_Script_Command_Object:
  360. // Script Command Object: (optional, one only)
  361. // Field Name Field Type Size (bits)
  362. // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object
  363. // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header
  364. // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
  365. // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects
  366. // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects
  367. // Command Types array of: variable //
  368. // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name
  369. // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command
  370. // Commands array of: variable //
  371. // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds
  372. // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object
  373. // * Command Name Length WORD 16 // number of Unicode characters for Command Name
  374. // * Command Name WCHAR variable // array of Unicode characters - name of this command
  375. // shortcut
  376. $thisfile_asf['script_command_object'] = array();
  377. $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object'];
  378. $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID;
  379. $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext;
  380. $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize;
  381. $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16);
  382. $offset += 16;
  383. $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']);
  384. if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) {
  385. $ThisFileInfo['warning'][] = 'script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}';
  386. //return false;
  387. break;
  388. }
  389. $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  390. $offset += 2;
  391. $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  392. $offset += 2;
  393. for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) {
  394. $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
  395. $offset += 2;
  396. $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
  397. $offset += $CommandTypeNameLength;
  398. }
  399. for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) {
  400. $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  401. $offset += 4;
  402. $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  403. $offset += 2;
  404. $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
  405. $offset += 2;
  406. $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
  407. $offset += $CommandTypeNameLength;
  408. }
  409. break;
  410. case GETID3_ASF_Marker_Object:
  411. // Marker Object: (optional, one only)
  412. // Field Name Field Type Size (bits)
  413. // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object
  414. // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header
  415. // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
  416. // Markers Count DWORD 32 // number of Marker structures in Marker Object
  417. // Reserved WORD 16 // hardcoded: 0x0000
  418. // Name Length WORD 16 // number of bytes in the Name field
  419. // Name WCHAR variable // name of the Marker Object
  420. // Markers array of: variable //
  421. // * Offset QWORD 64 // byte offset into Data Object
  422. // * Presentation Time QWORD 64 // in 100-nanosecond units
  423. // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
  424. // * Send Time DWORD 32 // in milliseconds
  425. // * Flags DWORD 32 // hardcoded: 0x00000000
  426. // * Marker Description Length DWORD 32 // number of bytes in Marker Description field
  427. // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry
  428. // * Padding BYTESTREAM variable // optional padding bytes
  429. // shortcut
  430. $thisfile_asf['marker_object'] = array();
  431. $thisfile_asf_markerobject = &$thisfile_asf['marker_object'];
  432. $thisfile_asf_markerobject['objectid'] = $NextObjectGUID;
  433. $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext;
  434. $thisfile_asf_markerobject['objectsize'] = $NextObjectSize;
  435. $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16);
  436. $offset += 16;
  437. $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']);
  438. if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) {
  439. $ThisFileInfo['warning'][] = 'marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}';
  440. break;
  441. }
  442. $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  443. $offset += 4;
  444. $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  445. $offset += 2;
  446. if ($thisfile_asf_markerobject['reserved_2'] != 0) {
  447. $ThisFileInfo['warning'][] = 'marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"';
  448. break;
  449. }
  450. $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  451. $offset += 2;
  452. $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']);
  453. $offset += $thisfile_asf_markerobject['name_length'];
  454. for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) {
  455. $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  456. $offset += 8;
  457. $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
  458. $offset += 8;
  459. $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  460. $offset += 2;
  461. $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  462. $offset += 4;
  463. $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  464. $offset += 4;
  465. $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  466. $offset += 4;
  467. $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']);
  468. $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
  469. $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
  470. if ($PaddingLength > 0) {
  471. $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
  472. $offset += $PaddingLength;
  473. }
  474. }
  475. break;
  476. case GETID3_ASF_Bitrate_Mutual_Exclusion_Object:
  477. // Bitrate Mutual Exclusion Object: (optional)
  478. // Field Name Field Type Size (bits)
  479. // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object
  480. // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
  481. // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown)
  482. // Stream Numbers Count WORD 16 // number of video streams
  483. // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127
  484. // shortcut
  485. $thisfile_asf['bitrate_mutual_exclusion_object'] = array();
  486. $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object'];
  487. $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID;
  488. $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext;
  489. $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize;
  490. $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16);
  491. $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']);
  492. $offset += 16;
  493. if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) {
  494. $ThisFileInfo['warning'][] = 'bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}';
  495. //return false;
  496. break;
  497. }
  498. $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  499. $offset += 2;
  500. for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) {
  501. $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  502. $offset += 2;
  503. }
  504. break;
  505. case GETID3_ASF_Error_Correction_Object:
  506. // Error Correction Object: (optional, one only)
  507. // Field Name Field Type Size (bits)
  508. // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object
  509. // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header
  510. // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread)
  511. // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field
  512. // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field
  513. // shortcut
  514. $thisfile_asf['error_correction_object'] = array();
  515. $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object'];
  516. $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID;
  517. $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext;
  518. $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize;
  519. $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
  520. $offset += 16;
  521. $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']);
  522. $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  523. $offset += 4;
  524. switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) {
  525. case GETID3_ASF_No_Error_Correction:
  526. // should be no data, but just in case there is, skip to the end of the field
  527. $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length'];
  528. break;
  529. case GETID3_ASF_Audio_Spread:
  530. // Field Name Field Type Size (bits)
  531. // Span BYTE 8 // number of packets over which audio will be spread.
  532. // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream
  533. // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream
  534. // Silence Data Length WORD 16 // number of bytes in Silence Data field
  535. // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes
  536. $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
  537. $offset += 1;
  538. $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  539. $offset += 2;
  540. $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  541. $offset += 2;
  542. $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  543. $offset += 2;
  544. $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']);
  545. $offset += $thisfile_asf_errorcorrectionobject['silence_data_length'];
  546. break;
  547. default:
  548. $ThisFileInfo['warning'][] = 'error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}';
  549. //return false;
  550. break;
  551. }
  552. break;
  553. case GETID3_ASF_Content_Description_Object:
  554. // Content Description Object: (optional, one only)
  555. // Field Name Field Type Size (bits)
  556. // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object
  557. // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header
  558. // Title Length WORD 16 // number of bytes in Title field
  559. // Author Length WORD 16 // number of bytes in Author field
  560. // Copyright Length WORD 16 // number of bytes in Copyright field
  561. // Description Length WORD 16 // number of bytes in Description field
  562. // Rating Length WORD 16 // number of bytes in Rating field
  563. // Title WCHAR 16 // array of Unicode characters - Title
  564. // Author WCHAR 16 // array of Unicode characters - Author
  565. // Copyright WCHAR 16 // array of Unicode characters - Copyright
  566. // Description WCHAR 16 // array of Unicode characters - Description
  567. // Rating WCHAR 16 // array of Unicode characters - Rating
  568. // shortcut
  569. $thisfile_asf['content_description_object'] = array();
  570. $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object'];
  571. $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID;
  572. $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
  573. $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize;
  574. $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  575. $offset += 2;
  576. $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  577. $offset += 2;
  578. $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  579. $offset += 2;
  580. $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  581. $offset += 2;
  582. $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  583. $offset += 2;
  584. $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']);
  585. $offset += $thisfile_asf_contentdescriptionobject['title_length'];
  586. $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']);
  587. $offset += $thisfile_asf_contentdescriptionobject['author_length'];
  588. $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']);
  589. $offset += $thisfile_asf_contentdescriptionobject['copyright_length'];
  590. $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']);
  591. $offset += $thisfile_asf_contentdescriptionobject['description_length'];
  592. $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']);
  593. $offset += $thisfile_asf_contentdescriptionobject['rating_length'];
  594. $ASFcommentKeysToCopy = array('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating');
  595. foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) {
  596. if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) {
  597. $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]);
  598. }
  599. }
  600. break;
  601. case GETID3_ASF_Extended_Content_Description_Object:
  602. // Extended Content Description Object: (optional, one only)
  603. // Field Name Field Type Size (bits)
  604. // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object
  605. // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
  606. // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list
  607. // Content Descriptors array of: variable //
  608. // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field
  609. // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name
  610. // * Descriptor Value Data Type WORD 16 // Lookup array:
  611. // 0x0000 = Unicode String (variable length)
  612. // 0x0001 = BYTE array (variable length)
  613. // 0x0002 = BOOL (DWORD, 32 bits)
  614. // 0x0003 = DWORD (DWORD, 32 bits)
  615. // 0x0004 = QWORD (QWORD, 64 bits)
  616. // 0x0005 = WORD (WORD, 16 bits)
  617. // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field
  618. // * Descriptor Value variable variable // value for Content Descriptor
  619. // shortcut
  620. $thisfile_asf['extended_content_description_object'] = array();
  621. $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object'];
  622. $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID;
  623. $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
  624. $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize;
  625. $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  626. $offset += 2;
  627. for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) {
  628. // shortcut
  629. $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array();
  630. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter];
  631. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30;
  632. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  633. $offset += 2;
  634. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']);
  635. $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'];
  636. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  637. $offset += 2;
  638. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  639. $offset += 2;
  640. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']);
  641. $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'];
  642. switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
  643. case 0x0000: // Unicode string
  644. break;
  645. case 0x0001: // BYTE array
  646. // do nothing
  647. break;
  648. case 0x0002: // BOOL
  649. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
  650. break;
  651. case 0x0003: // DWORD
  652. case 0x0004: // QWORD
  653. case 0x0005: // WORD
  654. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
  655. break;
  656. default:
  657. $ThisFileInfo['warning'][] = 'extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')';
  658. //return false;
  659. break;
  660. }
  661. switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) {
  662. case 'wm/albumartist':
  663. case 'artist':
  664. $thisfile_asf_comments['artist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  665. break;
  666. case 'wm/albumtitle':
  667. case 'album':
  668. $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  669. break;
  670. case 'wm/genre':
  671. case 'genre':
  672. $thisfile_asf_comments['genre'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  673. break;
  674. case 'wm/tracknumber':
  675. case 'tracknumber':
  676. $thisfile_asf_comments['track'] = array(intval($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])));
  677. break;
  678. case 'wm/track':
  679. if (empty($thisfile_asf_comments['track'])) {
  680. $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  681. }
  682. break;
  683. case 'wm/year':
  684. case 'year':
  685. case 'date':
  686. $thisfile_asf_comments['year'] = array( $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  687. break;
  688. case 'wm/lyrics':
  689. case 'lyrics':
  690. $thisfile_asf_comments['lyrics'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  691. break;
  692. case 'isvbr':
  693. if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) {
  694. $thisfile_audio['bitrate_mode'] = 'vbr';
  695. $thisfile_video['bitrate_mode'] = 'vbr';
  696. }
  697. break;
  698. case 'id3':
  699. // id3v2 module might not be loaded
  700. if (class_exists('getid3_id3v2')) {
  701. $tempfile = tempnam('*', 'getID3');
  702. $tempfilehandle = fopen($tempfile, "wb");
  703. $tempThisfileInfo = array('encoding'=>$ThisFileInfo['encoding']);
  704. fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
  705. fclose($tempfilehandle);
  706. $tempfilehandle = fopen($tempfile, "rb");
  707. $id3 = new getid3_id3v2($tempfilehandle, $tempThisfileInfo);
  708. unset($id3);
  709. fclose($tempfilehandle);
  710. unlink($tempfile);
  711. $ThisFileInfo['id3v2'] = $tempThisfileInfo['id3v2'];
  712. unset($tempThisfileInfo);
  713. }
  714. break;
  715. case 'wm/encodingtime':
  716. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
  717. $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']);
  718. break;
  719. case 'wm/picture':
  720. //typedef struct _WMPicture{
  721. // LPWSTR pwszMIMEType;
  722. // BYTE bPictureType;
  723. // LPWSTR pwszDescription;
  724. // DWORD dwDataLen;
  725. // BYTE* pbData;
  726. //} WM_PICTURE;
  727. $wm_picture_offset = 0;
  728. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1));
  729. $wm_picture_offset += 1;
  730. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
  731. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
  732. $wm_picture_offset += 4;
  733. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
  734. do {
  735. $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
  736. $wm_picture_offset += 2;
  737. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair;
  738. } while ($next_byte_pair !== "\x00\x00");
  739. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = '';
  740. do {
  741. $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
  742. $wm_picture_offset += 2;
  743. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair;
  744. } while ($next_byte_pair !== "\x00\x00");
  745. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset;
  746. $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset);
  747. unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
  748. break;
  749. default:
  750. switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
  751. case 0: // Unicode string
  752. if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') {
  753. $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
  754. }
  755. break;
  756. case 1:
  757. break;
  758. }
  759. break;
  760. }
  761. }
  762. break;
  763. case GETID3_ASF_Stream_Bitrate_Properties_Object:
  764. // Stream Bitrate Properties Object: (optional, one only)
  765. // Field Name Field Type Size (bits)
  766. // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object
  767. // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
  768. // Bitrate Records Count WORD 16 // number of records in Bitrate Records
  769. // Bitrate Records array of: variable //
  770. // * Flags WORD 16 //
  771. // * * Stream Number bits 7 (0x007F) // number of this stream
  772. // * * Reserved bits 9 (0xFF80) // hardcoded: 0
  773. // * Average Bitrate DWORD 32 // in bits per second
  774. // shortcut
  775. $thisfile_asf['stream_bitrate_properties_object'] = array();
  776. $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object'];
  777. $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID;
  778. $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
  779. $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize;
  780. $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  781. $offset += 2;
  782. for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) {
  783. $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
  784. $offset += 2;
  785. $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F;
  786. $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
  787. $offset += 4;
  788. }
  789. break;
  790. case GETID3_ASF_Padding_Object:
  791. // Padding Object: (optional)
  792. // Field Name Field Type Size (bits)
  793. // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object
  794. // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header
  795. // Padding Data BYTESTREAM variable // ignore
  796. // shortcut
  797. $thisfile_asf['padding_object'] = array();
  798. $thisfile_asf_paddingobject = &$thisfile_asf['padding_object'];
  799. $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID;
  800. $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext;
  801. $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize;
  802. $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8;
  803. $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']);
  804. $offset += ($NextObjectSize - 16 - 8);
  805. break;
  806. case GETID3_ASF_Extended_Content_Encryption_Object:
  807. case GETID3_ASF_Content_Encryption_Object:
  808. // WMA DRM - just ignore
  809. $offset += ($NextObjectSize - 16 - 8);
  810. break;
  811. default:
  812. // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
  813. if ($this->GUIDname($NextObjectGUIDtext)) {
  814. $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
  815. } else {
  816. $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
  817. }
  818. $offset += ($NextObjectSize - 16 - 8);
  819. break;
  820. }
  821. }
  822. if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) {
  823. $ASFbitrateAudio = 0;
  824. $ASFbitrateVideo = 0;
  825. for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) {
  826. if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) {
  827. switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) {
  828. case 1:
  829. $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
  830. break;
  831. case 2:
  832. $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
  833. break;
  834. default:
  835. // do nothing
  836. break;
  837. }
  838. }
  839. }
  840. if ($ASFbitrateAudio > 0) {
  841. $thisfile_audio['bitrate'] = $ASFbitrateAudio;
  842. }
  843. if ($ASFbitrateVideo > 0) {
  844. $thisfile_video['bitrate'] = $ASFbitrateVideo;
  845. }
  846. }
  847. if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) {
  848. $thisfile_audio['bitrate'] = 0;
  849. $thisfile_video['bitrate'] = 0;
  850. foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) {
  851. switch ($streamdata['stream_type']) {
  852. case GETID3_ASF_Audio_Media:
  853. // Field Name Field Type Size (bits)
  854. // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
  855. // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
  856. // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
  857. // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
  858. // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
  859. // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
  860. // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
  861. // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
  862. // shortcut
  863. $thisfile_asf['audio_media'][$streamnumber] = array();
  864. $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber];
  865. $audiomediaoffset = 0;
  866. $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
  867. $audiomediaoffset += 16;
  868. $thisfile_audio['lossless'] = false;
  869. switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) {
  870. case 0x0001: // PCM
  871. case 0x0163: // WMA9 Lossless
  872. $thisfile_audio['lossless'] = true;
  873. break;
  874. }
  875. if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
  876. foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
  877. if (@$dataarray['flags']['stream_number'] == $streamnumber) {
  878. $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate'];
  879. $thisfile_audio['bitrate'] += $dataarray['bitrate'];
  880. break;
  881. }
  882. }
  883. } else {
  884. if (@$thisfile_asf_audiomedia_currentstream['bytes_sec']) {
  885. $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8;
  886. } elseif (@$thisfile_asf_audiomedia_currentstream['bitrate']) {
  887. $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate'];
  888. }
  889. }
  890. $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream;
  891. $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag'];
  892. $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless'];
  893. $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
  894. $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma';
  895. unset($thisfile_audio['streams'][$streamnumber]['raw']);
  896. $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
  897. $audiomediaoffset += 2;
  898. $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']);
  899. $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size'];
  900. break;
  901. case GETID3_ASF_Video_Media:
  902. // Field Name Field Type Size (bits)
  903. // Encoded Image Width DWORD 32 // width of image in pixels
  904. // Encoded Image Height DWORD 32 // height of image in pixels
  905. // Reserved Flags BYTE 8 // hardcoded: 0x02
  906. // Format Data Size WORD 16 // size of Format Data field in bytes
  907. // Format Data array of: variable //
  908. // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
  909. // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
  910. // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
  911. // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
  912. // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
  913. // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
  914. // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
  915. // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
  916. // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
  917. // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
  918. // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
  919. // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
  920. // shortcut
  921. $thisfile_asf['video_media'][$streamnumber] = array();
  922. $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber];
  923. $videomediaoffset = 0;
  924. $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  925. $videomediaoffset += 4;
  926. $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  927. $videomediaoffset += 4;
  928. $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
  929. $videomediaoffset += 1;
  930. $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
  931. $videomediaoffset += 2;
  932. $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  933. $videomediaoffset += 4;
  934. $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  935. $videomediaoffset += 4;
  936. $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  937. $videomediaoffset += 4;
  938. $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
  939. $videomediaoffset += 2;
  940. $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
  941. $videomediaoffset += 2;
  942. $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
  943. $videomediaoffset += 4;
  944. $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  945. $videomediaoffset += 4;
  946. $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  947. $videomediaoffset += 4;
  948. $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  949. $videomediaoffset += 4;
  950. $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  951. $videomediaoffset += 4;
  952. $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
  953. $videomediaoffset += 4;
  954. $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
  955. if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
  956. foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
  957. if (@$dataarray['flags']['stream_number'] == $streamnumber) {
  958. $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate'];
  959. $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate'];
  960. $thisfile_video['bitrate'] += $dataarray['bitrate'];
  961. break;
  962. }
  963. }
  964. }
  965. $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']);
  966. $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'];
  967. $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec'];
  968. $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width'];
  969. $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height'];
  970. $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'];
  971. break;
  972. default:
  973. break;
  974. }
  975. }
  976. }
  977. while (ftell($fd) < $ThisFileInfo['avdataend']) {
  978. $NextObjectDataHeader = fread($fd, 24);
  979. $offset = 0;
  980. $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
  981. $offset += 16;
  982. $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
  983. $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
  984. $offset += 8;
  985. switch ($NextObjectGUID) {
  986. case GETID3_ASF_Data_Object:
  987. // Data Object: (mandatory, one only)
  988. // Field Name Field Type Size (bits)
  989. // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object
  990. // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
  991. // File ID GUID 128 // unique identifier. identical to File ID field in Header Object
  992. // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
  993. // Reserved WORD 16 // hardcoded: 0x0101
  994. // shortcut
  995. $thisfile_asf['data_object'] = array();
  996. $thisfile_asf_dataobject = &$thisfile_asf['data_object'];
  997. $DataObjectData = $NextObjectDataHeader.fread($fd, 50 - 24);
  998. $offset = 24;
  999. $thisfile_asf_dataobject['objectid'] = $NextObjectGUID;
  1000. $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext;
  1001. $thisfile_asf_dataobject['objectsize'] = $NextObjectSize;
  1002. $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16);
  1003. $offset += 16;
  1004. $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']);
  1005. $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8));
  1006. $offset += 8;
  1007. $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2));
  1008. $offset += 2;
  1009. if ($thisfile_asf_dataobject['reserved'] != 0x0101) {
  1010. $ThisFileInfo['warning'][] = 'data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"';
  1011. //return false;
  1012. break;
  1013. }
  1014. // Data Packets array of: variable //
  1015. // * Error Correction Flags BYTE 8 //
  1016. // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
  1017. // * * Opaque Data Present bits 1 //
  1018. // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00
  1019. // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure
  1020. // * Error Correction Data
  1021. $ThisFileInfo['avdataoffset'] = ftell($fd);
  1022. fseek($fd, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
  1023. $ThisFileInfo['avdataend'] = ftell($fd);
  1024. break;
  1025. case GETID3_ASF_Simple_Index_Object:
  1026. // Simple Index Object: (optional, recommended, one per video stream)
  1027. // Field Name Field Type Size (bits)
  1028. // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object
  1029. // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header
  1030. // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
  1031. // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units
  1032. // Maximum Packet Count DWORD 32 // maximum packet count for all index entries
  1033. // Index Entries Count DWORD 32 // number of Index Entries structures
  1034. // Index Entries array of: variable //
  1035. // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry
  1036. // * Packet Count WORD 16 // number of Data Packets to sent at this index entry
  1037. // shortcut
  1038. $thisfile_asf['simple_index_object'] = array();
  1039. $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object'];
  1040. $SimpleIndexObjectData = $NextObjectDataHeader.fread($fd, 56 - 24);
  1041. $offset = 24;
  1042. $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID;
  1043. $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext;
  1044. $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize;
  1045. $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
  1046. $offset += 16;
  1047. $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']);
  1048. $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
  1049. $offset += 8;
  1050. $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
  1051. $offset += 4;
  1052. $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
  1053. $offset += 4;
  1054. $IndexEntriesData = $SimpleIndexObjectData.fread($fd, 6 * $thisfile_asf_simpleindexobject['index_entries_count']);
  1055. for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) {
  1056. $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
  1057. $offset += 4;
  1058. $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
  1059. $offset += 2;
  1060. }
  1061. break;
  1062. case GETID3_ASF_Index_Object:
  1063. // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
  1064. // Field Name Field Type Size (bits)
  1065. // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object
  1066. // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
  1067. // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms.
  1068. // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object.
  1069. // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object.
  1070. // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0.
  1071. // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater.
  1072. // Index Specifiers array of: varies //
  1073. // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
  1074. // * Index Type WORD 16 // Specifies Index Type values as follows:
  1075. // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
  1076. // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
  1077. // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
  1078. // Nearest Past Cleanpoint is the most common type of index.
  1079. // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block.
  1080. // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
  1081. // * Index Entries array of: varies //
  1082. // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value
  1083. // shortcut
  1084. $thisfile_asf['asf_index_object'] = array();
  1085. $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object'];
  1086. $ASFIndexObjectData = $NextObjectDataHeader.fread($fd, 34 - 24);
  1087. $offset = 24;
  1088. $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID;
  1089. $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext;
  1090. $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize;
  1091. $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
  1092. $offset += 4;
  1093. $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
  1094. $offset += 2;
  1095. $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
  1096. $offset += 4;
  1097. $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
  1098. for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
  1099. $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
  1100. $offset += 2;
  1101. $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
  1102. $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
  1103. $offset += 2;
  1104. $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
  1105. }
  1106. $ASFIndexObjectData .= fread($fd, 4);
  1107. $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
  1108. $offset += 4;
  1109. $ASFIndexObjectData .= fread($fd, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
  1110. for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
  1111. $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
  1112. $offset += 8;
  1113. }
  1114. $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
  1115. for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) {
  1116. for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
  1117. $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
  1118. $offset += 4;
  1119. }
  1120. }
  1121. break;
  1122. default:
  1123. // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
  1124. if ($this->GUIDname($NextObjectGUIDtext)) {
  1125. $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8);
  1126. } else {
  1127. $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($fd) - 16 - 8);
  1128. }
  1129. fseek($fd, ($NextObjectSize - 16 - 8), SEEK_CUR);
  1130. break;
  1131. }
  1132. }
  1133. if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) {
  1134. foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
  1135. switch ($streamdata['information']) {
  1136. case 'WMV1':
  1137. case 'WMV2':
  1138. case 'WMV3':
  1139. case 'MSS1':
  1140. case 'MSS2':
  1141. case 'WMVA':
  1142. case 'WVC1':
  1143. case 'WMVP':
  1144. case 'WVP2':
  1145. $thisfile_video['dataformat'] = 'wmv';
  1146. $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
  1147. break;
  1148. case 'MP42':
  1149. case 'MP43':
  1150. case 'MP4S':
  1151. case 'mp4s':
  1152. $thisfile_video['dataformat'] = 'asf';
  1153. $ThisFileInfo['mime_type'] = 'video/x-ms-asf';
  1154. break;
  1155. default:
  1156. switch ($streamdata['type_raw']) {
  1157. case 1:
  1158. if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
  1159. $thisfile_video['dataformat'] = 'wmv';
  1160. if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
  1161. $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
  1162. }
  1163. }
  1164. break;
  1165. case 2:
  1166. if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
  1167. $thisfile_audio['dataformat'] = 'wma';
  1168. if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
  1169. $ThisFileInfo['mime_type'] = 'audio/x-ms-wma';
  1170. }
  1171. }
  1172. break;
  1173. }
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. switch (@$thisfile_audio['codec']) {
  1179. case 'MPEG Layer-3':
  1180. $thisfile_audio['dataformat'] = 'mp3';
  1181. break;
  1182. default:
  1183. break;
  1184. }
  1185. if (isset($thisfile_asf_codeclistobject['codec_entries'])) {
  1186. foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
  1187. switch ($streamdata['type_raw']) {
  1188. case 1: // video
  1189. $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
  1190. break;
  1191. case 2: // audio
  1192. $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
  1193. // AH 2003-10-01
  1194. $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']);
  1195. $thisfile_audio['codec'] = $thisfile_audio['encoder'];
  1196. break;
  1197. default:
  1198. $ThisFileInfo['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw'];
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. if (isset($ThisFileInfo['audio'])) {
  1204. $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
  1205. $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf');
  1206. }
  1207. if (!empty($thisfile_video['dataformat'])) {
  1208. $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
  1209. $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1);
  1210. $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
  1211. }
  1212. if (!empty($thisfile_video['streams'])) {
  1213. $thisfile_video['streams']['resolution_x'] = 0;
  1214. $thisfile_video['streams']['resolution_y'] = 0;
  1215. foreach ($thisfile_video['streams'] as $key => $valuearray) {
  1216. if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) {
  1217. $thisfile_video['resolution_x'] = $valuearray['resolution_x'];
  1218. $thisfile_video['resolution_y'] = $valuearray['resolution_y'];
  1219. }
  1220. }
  1221. }
  1222. $ThisFileInfo['bitrate'] = @$thisfile_audio['bitrate'] + @$thisfile_video['bitrate'];
  1223. if ((!isset($ThisFileInfo['playtime_seconds']) || ($ThisFileInfo['playtime_seconds'] <= 0)) && ($ThisFileInfo['bitrate'] > 0)) {
  1224. $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['bitrate'] / 8);
  1225. }
  1226. return true;
  1227. }
  1228. function ASFCodecListObjectTypeLookup($CodecListType) {
  1229. static $ASFCodecListObjectTypeLookup = array();
  1230. if (empty($ASFCodecListObjectTypeLookup)) {
  1231. $ASFCodecListObjectTypeLookup[0x0001] = 'Video Codec';
  1232. $ASFCodecListObjectTypeLookup[0x0002] = 'Audio Codec';
  1233. $ASFCodecListObjectTypeLookup[0xFFFF] = 'Unknown Codec';
  1234. }
  1235. return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type');
  1236. }
  1237. function KnownGUIDs() {
  1238. static $GUIDarray = array();
  1239. if (empty($GUIDarray)) {
  1240. $GUIDarray['GETID3_ASF_Extended_Stream_Properties_Object'] = '14E6A5CB-C672-4332-8399-A96952065B5A';
  1241. $GUIDarray['GETID3_ASF_Padding_Object'] = '1806D474-CADF-4509-A4BA-9AABCB96AAE8';
  1242. $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio'] = '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8';
  1243. $GUIDarray['GETID3_ASF_Script_Command_Object'] = '1EFB1A30-0B62-11D0-A39B-00A0C90348F6';
  1244. $GUIDarray['GETID3_ASF_No_Error_Correction'] = '20FB5700-5B55-11CF-A8FD-00805F5C442B';
  1245. $GUIDarray['GETID3_ASF_Content_Branding_Object'] = '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E';
  1246. $GUIDarray['GETID3_ASF_Content_Encryption_Object'] = '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E';
  1247. $GUIDarray['GETID3_ASF_Digital_Signature_Object'] = '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E';
  1248. $GUIDarray['GETID3_ASF_Extended_Content_Encryption_Object'] = '298AE614-2622-4C17-B935-DAE07EE9289C';
  1249. $GUIDarray['GETID3_ASF_Simple_Index_Object'] = '33000890-E5B1-11CF-89F4-00A0C90349CB';
  1250. $GUIDarray['GETID3_ASF_Degradable_JPEG_Media'] = '35907DE0-E415-11CF-A917-00805F5C442B';
  1251. $GUIDarray['GETID3_ASF_Payload_Extension_System_Timecode'] = '399595EC-8667-4E2D-8FDB-98814CE76C1E';
  1252. $GUIDarray['GETID3_ASF_Binary_Media'] = '3AFB65E2-47EF-40F2-AC2C-70A90D71D343';
  1253. $GUIDarray['GETID3_ASF_Timecode_Index_Object'] = '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C';
  1254. $GUIDarray['GETID3_ASF_Metadata_Library_Object'] = '44231C94-9498-49D1-A141-1D134E457054';
  1255. $GUIDarray['GETID3_ASF_Reserved_3'] = '4B1ACBE3-100B-11D0-A39B-00A0C90348F6';
  1256. $GUIDarray['GETID3_ASF_Reserved_4'] = '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB';
  1257. $GUIDarray['GETID3_ASF_Command_Media'] = '59DACFC0-59E6-11D0-A3AC-00A0C90348F6';
  1258. $GUIDarray['GETID3_ASF_Header_Extension_Object'] = '5FBF03B5-A92E-11CF-8EE3-00C00C205365';
  1259. $GUIDarray['GETID3_ASF_Media_Object_Index_Parameters_Obj'] = '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7';
  1260. $GUIDarray['GETID3_ASF_Header_Object'] = '75B22630-668E-11CF-A6D9-00AA0062CE6C';
  1261. $GUIDarray['GETID3_ASF_Content_Description_Object'] = '75B22633-668E-11CF-A6D9-00AA0062CE6C';
  1262. $GUIDarray['GETID3_ASF_Error_Correction_Object'] = '75B22635-668E-11CF-A6D9-00AA0062CE6C';
  1263. $GUIDarray['GETID3_ASF_Data_Object'] = '75B22636-668E-11CF-A6D9-00AA0062CE6C';
  1264. $GUIDarray['GETID3_ASF_Web_Stream_Media_Subtype'] = '776257D4-C627-41CB-8F81-7AC7FF1C40CC';
  1265. $GUIDarray['GETID3_ASF_Stream_Bitrate_Properties_Object'] = '7BF875CE-468D-11D1-8D82-006097C9A2B2';
  1266. $GUIDarray['GETID3_ASF_Language_List_Object'] = '7C4346A9-EFE0-4BFC-B229-393EDE415C85';
  1267. $GUIDarray['GETID3_ASF_Codec_List_Object'] = '86D15240-311D-11D0-A3A4-00A0C90348F6';
  1268. $GUIDarray['GETID3_ASF_Reserved_2'] = '86D15241-311D-11D0-A3A4-00A0C90348F6';
  1269. $GUIDarray['GETID3_ASF_File_Properties_Object'] = '8CABDCA1-A947-11CF-8EE4-00C00C205365';
  1270. $GUIDarray['GETID3_ASF_File_Transfer_Media'] = '91BD222C-F21C-497A-8B6D-5AA86BFC0185';
  1271. $GUIDarray['GETID3_ASF_Old_RTP_Extension_Data'] = '96800C63-4C94-11D1-837B-0080C7A37F95';
  1272. $GUIDarray['GETID3_ASF_Advanced_Mutual_Exclusion_Object'] = 'A08649CF-4775-4670-8A16-6E35357566CD';
  1273. $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Object'] = 'A69609E6-517B-11D2-B6AF-00C04FD908E9';
  1274. $GUIDarray['GETID3_ASF_Reserved_1'] = 'ABD3D211-A9BA-11cf-8EE6-00C00C205365';
  1275. $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Exclusive'] = 'AF6060AA-5197-11D2-B6AF-00C04FD908E9';
  1276. $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Partial'] = 'AF6060AB-5197-11D2-B6AF-00C04FD908E9';
  1277. $GUIDarray['GETID3_ASF_JFIF_Media'] = 'B61BE100-5B4E-11CF-A8FD-00805F5C442B';
  1278. $GUIDarray['GETID3_ASF_Stream_Properties_Object'] = 'B7DC0791-A9B7-11CF-8EE6-00C00C205365';
  1279. $GUIDarray['GETID3_ASF_Video_Media'] = 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B';
  1280. $GUIDarray['GETID3_ASF_Audio_Spread'] = 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220';
  1281. $GUIDarray['GETID3_ASF_Metadata_Object'] = 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA';
  1282. $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Sample_Duration'] = 'C6BD9450-867F-4907-83A3-C77921B733AD';
  1283. $GUIDarray['GETID3_ASF_Group_Mutual_Exclusion_Object'] = 'D1465A40-5A79-4338-B71B-E36B8FD6C249';
  1284. $GUIDarray['GETID3_ASF_Extended_Content_Description_Object'] = 'D2D0A440-E307-11D2-97F0-00A0C95EA850';
  1285. $GUIDarray['GETID3_ASF_Stream_Prioritization_Object'] = 'D4FED15B-88D3-454F-81F0-ED5C45999E24';
  1286. $GUIDarray['GETID3_ASF_Payload_Ext_System_Content_Type'] = 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC';
  1287. $GUIDarray['GETID3_ASF_Old_File_Properties_Object'] = 'D6E229D0-35DA-11D1-9034-00A0C90349BE';
  1288. $GUIDarray['GETID3_ASF_Old_ASF_Header_Object'] = 'D6E229D1-35DA-11D1-9034-00A0C90349BE';
  1289. $GUIDarray['GETID3_ASF_Old_ASF_Data_Object'] = 'D6E229D2-35DA-11D1-9034-00A0C90349BE';
  1290. $GUIDarray['GETID3_ASF_Index_Object'] = 'D6E229D3-35DA-11D1-9034-00A0C90349BE';
  1291. $GUIDarray['GETID3_ASF_Old_Stream_Properties_Object'] = 'D6E229D4-35DA-11D1-9034-00A0C90349BE';
  1292. $GUIDarray['GETID3_ASF_Old_Content_Description_Object'] = 'D6E229D5-35DA-11D1-9034-00A0C90349BE';
  1293. $GUIDarray['GETID3_ASF_Old_Script_Command_Object'] = 'D6E229D6-35DA-11D1-9034-00A0C90349BE';
  1294. $GUIDarray['GETID3_ASF_Old_Marker_Object'] = 'D6E229D7-35DA-11D1-9034-00A0C90349BE';
  1295. $GUIDarray['GETID3_ASF_Old_Component_Download_Object'] = 'D6E229D8-35DA-11D1-9034-00A0C90349BE';
  1296. $GUIDarray['GETID3_ASF_Old_Stream_Group_Object'] = 'D6E229D9-35DA-11D1-9034-00A0C90349BE';
  1297. $GUIDarray['GETID3_ASF_Old_Scalable_Object'] = 'D6E229DA-35DA-11D1-9034-00A0C90349BE';
  1298. $GUIDarray['GETID3_ASF_Old_Prioritization_Object'] = 'D6E229DB-35DA-11D1-9034-00A0C90349BE';
  1299. $GUIDarray['GETID3_ASF_Bitrate_Mutual_Exclusion_Object'] = 'D6E229DC-35DA-11D1-9034-00A0C90349BE';
  1300. $GUIDarray['GETID3_ASF_Old_Inter_Media_Dependency_Object'] = 'D6E229DD-35DA-11D1-9034-00A0C90349BE';
  1301. $GUIDarray['GETID3_ASF_Old_Rating_Object'] = 'D6E229DE-35DA-11D1-9034-00A0C90349BE';
  1302. $GUIDarray['GETID3_ASF_Index_Parameters_Object'] = 'D6E229DF-35DA-11D1-9034-00A0C90349BE';
  1303. $GUIDarray['GETID3_ASF_Old_Color_Table_Object'] = 'D6E229E0-35DA-11D1-9034-00A0C90349BE';
  1304. $GUIDarray['GETID3_ASF_Old_Language_List_Object'] = 'D6E229E1-35DA-11D1-9034-00A0C90349BE';
  1305. $GUIDarray['GETID3_ASF_Old_Audio_Media'] = 'D6E229E2-35DA-11D1-9034-00A0C90349BE';
  1306. $GUIDarray['GETID3_ASF_Old_Video_Media'] = 'D6E229E3-35DA-11D1-9034-00A0C90349BE';
  1307. $GUIDarray['GETID3_ASF_Old_Image_Media'] = 'D6E229E4-35DA-11D1-9034-00A0C90349BE';
  1308. $GUIDarray['GETID3_ASF_Old_Timecode_Media'] = 'D6E229E5-35DA-11D1-9034-00A0C90349BE';
  1309. $GUIDarray['GETID3_ASF_Old_Text_Media'] = 'D6E229E6-35DA-11D1-9034-00A0C90349BE';
  1310. $GUIDarray['GETID3_ASF_Old_MIDI_Media'] = 'D6E229E7-35DA-11D1-9034-00A0C90349BE';
  1311. $GUIDarray['GETID3_ASF_Old_Command_Media'] = 'D6E229E8-35DA-11D1-9034-00A0C90349BE';
  1312. $GUIDarray['GETID3_ASF_Old_No_Error_Concealment'] = 'D6E229EA-35DA-11D1-9034-00A0C90349BE';
  1313. $GUIDarray['GETID3_ASF_Old_Scrambled_Audio'] = 'D6E229EB-35DA-11D1-9034-00A0C90349BE';
  1314. $GUIDarray['GETID3_ASF_Old_No_Color_Table'] = 'D6E229EC-35DA-11D1-9034-00A0C90349BE';
  1315. $GUIDarray['GETID3_ASF_Old_SMPTE_Time'] = 'D6E229ED-35DA-11D1-9034-00A0C90349BE';
  1316. $GUIDarray['GETID3_ASF_Old_ASCII_Text'] = 'D6E229EE-35DA-11D1-9034-00A0C90349BE';
  1317. $GUIDarray['GETID3_ASF_Old_Unicode_Text'] = 'D6E229EF-35DA-11D1-9034-00A0C90349BE';
  1318. $GUIDarray['GETID3_ASF_Old_HTML_Text'] = 'D6E229F0-35DA-11D1-9034-00A0C90349BE';
  1319. $GUIDarray['GETID3_ASF_Old_URL_Command'] = 'D6E229F1-35DA-11D1-9034-00A0C90349BE';
  1320. $GUIDarray['GETID3_ASF_Old_Filename_Command'] = 'D6E229F2-35DA-11D1-9034-00A0C90349BE';
  1321. $GUIDarray['GETID3_ASF_Old_ACM_Codec'] = 'D6E229F3-35DA-11D1-9034-00A0C90349BE';
  1322. $GUIDarray['GETID3_ASF_Old_VCM_Codec'] = 'D6E229F4-35DA-11D1-9034-00A0C90349BE';
  1323. $GUIDarray['GETID3_ASF_Old_QuickTime_Codec'] = 'D6E229F5-35DA-11D1-9034-00A0C90349BE';
  1324. $GUIDarray['GETID3_ASF_Old_DirectShow_Transform_Filter'] = 'D6E229F6-35DA-11D1-9034-00A0C90349BE';
  1325. $GUIDarray['GETID3_ASF_Old_DirectShow_Rendering_Filter'] = 'D6E229F7-35DA-11D1-9034-00A0C90349BE';
  1326. $GUIDarray['GETID3_ASF_Old_No_Enhancement'] = 'D6E229F8-35DA-11D1-9034-00A0C90349BE';
  1327. $GUIDarray['GETID3_ASF_Old_Unknown_Enhancement_Type'] = 'D6E229F9-35DA-11D1-9034-00A0C90349BE';
  1328. $GUIDarray['GETID3_ASF_Old_Temporal_Enhancement'] = 'D6E229FA-35DA-11D1-9034-00A0C90349BE';
  1329. $GUIDarray['GETID3_ASF_Old_Spatial_Enhancement'] = 'D6E229FB-35DA-11D1-9034-00A0C90349BE';
  1330. $GUIDarray['GETID3_ASF_Old_Quality_Enhancement'] = 'D6E229FC-35DA-11D1-9034-00A0C90349BE';
  1331. $GUIDarray['GETID3_ASF_Old_Number_of_Channels_Enhancement'] = 'D6E229FD-35DA-11D1-9034-00A0C90349BE';
  1332. $GUIDarray['GETID3_ASF_Old_Frequency_Response_Enhancement'] = 'D6E229FE-35DA-11D1-9034-00A0C90349BE';
  1333. $GUIDarray['GETID3_ASF_Old_Media_Object'] = 'D6E229FF-35DA-11D1-9034-00A0C90349BE';
  1334. $GUIDarray['GETID3_ASF_Mutex_Language'] = 'D6E22A00-35DA-11D1-9034-00A0C90349BE';
  1335. $GUIDarray['GETID3_ASF_Mutex_Bitrate'] = 'D6E22A01-35DA-11D1-9034-00A0C90349BE';
  1336. $GUIDarray['GETID3_ASF_Mutex_Unknown'] = 'D6E22A02-35DA-11D1-9034-00A0C90349BE';
  1337. $GUIDarray['GETID3_ASF_Old_ASF_Placeholder_Object'] = 'D6E22A0E-35DA-11D1-9034-00A0C90349BE';
  1338. $GUIDarray['GETID3_ASF_Old_Data_Unit_Extension_Object'] = 'D6E22A0F-35DA-11D1-9034-00A0C90349BE';
  1339. $GUIDarray['GETID3_ASF_Web_Stream_Format'] = 'DA1E6B13-8359-4050-B398-388E965BF00C';
  1340. $GUIDarray['GETID3_ASF_Payload_Ext_System_File_Name'] = 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B';
  1341. $GUIDarray['GETID3_ASF_Marker_Object'] = 'F487CD01-A951-11CF-8EE6-00C00C205365';
  1342. $GUIDarray['GETID3_ASF_Timecode_Index_Parameters_Object'] = 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24';
  1343. $GUIDarray['GETID3_ASF_Audio_Media'] = 'F8699E40-5B4D-11CF-A8FD-00805F5C442B';
  1344. $GUIDarray['GETID3_ASF_Media_Object_Index_Object'] = 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C';
  1345. $GUIDarray['GETID3_ASF_Alt_Extended_Content_Encryption_Obj'] = 'FF889EF1-ADEE-40DA-9E71-98704BB928CE';
  1346. }
  1347. return $GUIDarray;
  1348. }
  1349. function GUIDname($GUIDstring) {
  1350. static $GUIDarray = array();
  1351. if (empty($GUIDarray)) {
  1352. $GUIDarray = $this->KnownGUIDs();
  1353. }
  1354. return array_search($GUIDstring, $GUIDarray);
  1355. }
  1356. function ASFIndexObjectIndexTypeLookup($id) {
  1357. static $ASFIndexObjectIndexTypeLookup = array();
  1358. if (empty($ASFIndexObjectIndexTypeLookup)) {
  1359. $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet';
  1360. $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object';
  1361. $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint';
  1362. }
  1363. return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid');
  1364. }
  1365. function GUIDtoBytestring($GUIDstring) {
  1366. // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way:
  1367. // first 4 bytes are in little-endian order
  1368. // next 2 bytes are appended in little-endian order
  1369. // next 2 bytes are appended in little-endian order
  1370. // next 2 bytes are appended in big-endian order
  1371. // next 6 bytes are appended in big-endian order
  1372. // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string:
  1373. // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp
  1374. $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2)));
  1375. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2)));
  1376. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2)));
  1377. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2)));
  1378. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2)));
  1379. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2)));
  1380. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2)));
  1381. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2)));
  1382. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2)));
  1383. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2)));
  1384. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2)));
  1385. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2)));
  1386. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2)));
  1387. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2)));
  1388. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2)));
  1389. $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2)));
  1390. return $hexbytecharstring;
  1391. }
  1392. function BytestringToGUID($Bytestring) {
  1393. $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT);
  1394. $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT);
  1395. $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT);
  1396. $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT);
  1397. $GUIDstring .= '-';
  1398. $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT);
  1399. $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT);
  1400. $GUIDstring .= '-';
  1401. $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT);
  1402. $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT);
  1403. $GUIDstring .= '-';
  1404. $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT);
  1405. $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT);
  1406. $GUIDstring .= '-';
  1407. $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT);
  1408. $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT);
  1409. $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT);
  1410. $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT);
  1411. $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT);
  1412. $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT);
  1413. return strtoupper($GUIDstring);
  1414. }
  1415. function FILETIMEtoUNIXtime($FILETIME, $round=true) {
  1416. // FILETIME is a 64-bit unsigned integer representing
  1417. // the number of 100-nanosecond intervals since January 1, 1601
  1418. // UNIX timestamp is number of seconds since January 1, 1970
  1419. // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days
  1420. if ($round) {
  1421. return intval(round(($FILETIME - 116444736000000000) / 10000000));
  1422. }
  1423. return ($FILETIME - 116444736000000000) / 10000000;
  1424. }
  1425. function WMpictureTypeLookup($WMpictureType) {
  1426. static $WMpictureTypeLookup = array();
  1427. if (empty($WMpictureTypeLookup)) {
  1428. $WMpictureTypeLookup[0x03] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Front Cover');
  1429. $WMpictureTypeLookup[0x04] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Back Cover');
  1430. $WMpictureTypeLookup[0x00] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'User Defined');
  1431. $WMpictureTypeLookup[0x05] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Leaflet Page');
  1432. $WMpictureTypeLookup[0x06] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Media Label');
  1433. $WMpictureTypeLookup[0x07] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lead Artist');
  1434. $WMpictureTypeLookup[0x08] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Artist');
  1435. $WMpictureTypeLookup[0x09] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Conductor');
  1436. $WMpictureTypeLookup[0x0A] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band');
  1437. $WMpictureTypeLookup[0x0B] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Composer');
  1438. $WMpictureTypeLookup[0x0C] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lyricist');
  1439. $WMpictureTypeLookup[0x0D] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Recording Location');
  1440. $WMpictureTypeLookup[0x0E] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Recording');
  1441. $WMpictureTypeLookup[0x0F] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Performance');
  1442. $WMpictureTypeLookup[0x10] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Video Screen Capture');
  1443. $WMpictureTypeLookup[0x12] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Illustration');
  1444. $WMpictureTypeLookup[0x13] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band Logotype');
  1445. $WMpictureTypeLookup[0x14] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Publisher Logotype');
  1446. }
  1447. return @$WMpictureTypeLookup[$WMpictureType];
  1448. }
  1449. // Remove terminator 00 00 and convert UNICODE to Latin-1
  1450. function TrimConvert($string) {
  1451. // remove terminator, only if present (it should be, but...)
  1452. if (substr($string, strlen($string) - 2, 2) == "\x00\x00") {
  1453. $string = substr($string, 0, strlen($string) - 2);
  1454. }
  1455. // convert
  1456. return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', $string), ' ');
  1457. }
  1458. function TrimTerm($string) {
  1459. // remove terminator, only if present (it should be, but...)
  1460. if (substr($string, -2) == "\x00\x00") {
  1461. $string = substr($string, 0, -2);
  1462. }
  1463. return $string;
  1464. }
  1465. }
  1466. ?>