/wp-includes/ID3/module.audio-video.matroska.php

  1. <?php 
  2. ///////////////////////////////////////////////////////////////// 
  3. /// getID3() by James Heinrich <info@getid3.org> // 
  4. // available at http://getid3.sourceforge.net // 
  5. // or http://www.getid3.org // 
  6. // also https://github.com/JamesHeinrich/getID3 // 
  7. ///////////////////////////////////////////////////////////////// 
  8. // See readme.txt for more details // 
  9. ///////////////////////////////////////////////////////////////// 
  10. // // 
  11. // module.audio-video.matriska.php // 
  12. // module for analyzing Matroska containers // 
  13. // dependencies: NONE // 
  14. // /// 
  15. ///////////////////////////////////////////////////////////////// 
  16.  
  17.  
  18. define('EBML_ID_CHAPTERS', 0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation. 
  19. define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements. 
  20. define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found <http://www.matroska.org/technical/specs/tagging/index.html>. 
  21. define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file. 
  22. define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described. 
  23. define('EBML_ID_SEGMENT', 0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment. 
  24. define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files. 
  25. define('EBML_ID_EBML', 0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this. 
  26. define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment. 
  27. define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure. 
  28. define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form. 
  29. define('EBML_ID_TRACKTIMECODESCALE', 0x03314F); // [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs). 
  30. define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame. 
  31. define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec. 
  32. define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used. 
  33. define('EBML_ID_TIMECODESCALE', 0x0AD7B1); // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds). 
  34. define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits). 
  35. define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value. 
  36. define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used. 
  37. define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used. 
  38. define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment. 
  39. define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits). 
  40. define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment. 
  41. define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits). 
  42. define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are: 
  43. define('EBML_ID_CONTENTCOMPSETTINGS', 0x0255); // [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track. 
  44. define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case). 
  45. define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file. 
  46. define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file. 
  47. define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file. 
  48. define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska). 
  49. define('EBML_ID_EBMLMAXSIZELENGTH', 0x02F3); // [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid. 
  50. define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file. 
  51. define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form. 
  52. define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains. 
  53. define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits). 
  54. define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date. 
  55. define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form. 
  56. define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag. 
  57. define('EBML_ID_TAGBINARY', 0x0485); // [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString. 
  58. define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag. 
  59. define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale). 
  60. define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent. 
  61. define('EBML_ID_CHAPTERFLAGENABLED', 0x0598); // [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter. 
  62. define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored. 
  63. define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition. 
  64. define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition. 
  65. define('EBML_ID_EDITIONFLAGHIDDEN', 0x05BD); // [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks). 
  66. define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one. 
  67. define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced. 
  68. define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file. 
  69. define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file. 
  70. define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file. 
  71. define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed. 
  72. define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file. 
  73. define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible. 
  74. define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values: 
  75. define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with. 
  76. define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents. 
  77. define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with. 
  78. define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: 
  79. define('EBML_ID_CONTENTSIGHASHALGO', 0x07E6); // [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: 
  80. define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3"). 
  81. define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element. 
  82. define('EBML_ID_CONTENTENCODINGORDER', 0x1031); // [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment. 
  83. define('EBML_ID_CONTENTENCODINGSCOPE', 0x1032); // [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values: 
  84. define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values: 
  85. define('EBML_ID_CONTENTCOMPRESSION', 0x1034); // [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking. 
  86. define('EBML_ID_CONTENTENCRYPTION', 0x1035); // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise. 
  87. define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster. 
  88. define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name. 
  89. define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster. 
  90. define('EBML_ID_TRACKOFFSET', 0x137F); // [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track. 
  91. define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name. 
  92. define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element). 
  93. define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode. 
  94. define('EBML_ID_OLDSTEREOMODE', 0x13B9); // [53][B9] -- Bogus StereoMode value used in old versions of libmatroska. DO NOT USE. (0: mono, 1: right eye, 2: left eye, 3: both eyes). 
  95. define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content). 
  96. define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display. 
  97. define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches). 
  98. define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed). 
  99. define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display. 
  100. define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image. 
  101. define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image. 
  102. define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image. 
  103. define('EBML_ID_FLAGFORCED', 0x15AA); // [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind. 
  104. define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track. 
  105. define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3"). 
  106. define('EBML_ID_CLUSTERSILENTTRACKS', 0x1854); // [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use. 
  107. define('EBML_ID_CLUSTERSILENTTRACKNUMBER', 0x18D7); // [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster. 
  108. define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file. 
  109. define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption. 
  110. define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM. 
  111. define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec. 
  112. define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment. 
  113. define('EBML_ID_CHAPTERPHYSICALEQUIV', 0x23C3); // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values. 
  114. define('EBML_ID_TAGCHAPTERUID', 0x23C4); // [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment. 
  115. define('EBML_ID_TAGTRACKUID', 0x23C5); // [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment. 
  116. define('EBML_ID_TAGATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. 
  117. define('EBML_ID_TAGEDITIONUID', 0x23C9); // [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment. 
  118. define('EBML_ID_TARGETTYPE', 0x23CA); // [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType). 
  119. define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec. 
  120. define('EBML_ID_TRACKTRANSLATETRACKID', 0x26A5); // [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used. 
  121. define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). 
  122. define('EBML_ID_TRACKTRANSLATEEDITIONUID', 0x26FC); // [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment. 
  123. define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target. 
  124. define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType). 
  125. define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom. 
  126. define('EBML_ID_CHAPPROCESSTIME', 0x2922); // [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter). 
  127. define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment. 
  128. define('EBML_ID_CHAPPROCESSDATA', 0x2933); // [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands. 
  129. define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom. 
  130. define('EBML_ID_CHAPPROCESSCODECID', 0x2955); // [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later. 
  131. define('EBML_ID_CHAPTERTRANSLATEID', 0x29A5); // [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used. 
  132. define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). 
  133. define('EBML_ID_CHAPTERTRANSLATEEDITIONUID', 0x29FC); // [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment. 
  134. define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption. 
  135. define('EBML_ID_MINCACHE', 0x2DE7); // [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used. 
  136. define('EBML_ID_MAXCACHE', 0x2DF8); // [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed. 
  137. define('EBML_ID_CHAPTERSEGMENTUID', 0x2E67); // [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used. 
  138. define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID. 
  139. define('EBML_ID_TRACKOVERLAY', 0x2FAB); // [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc. 
  140. define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters. 
  141. define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment. 
  142. define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits). 
  143. define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter. 
  144. define('EBML_ID_TRACKUID', 0x33C5); // [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file. 
  145. define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec. 
  146. define('EBML_ID_CLUSTERBLOCKADDITIONS', 0x35A1); // [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data. 
  147. define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix. 
  148. define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques). 
  149. define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment. 
  150. define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display. 
  151. define('EBML_ID_TRACKTYPE', 0x03); // [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control). 
  152. define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom. 
  153. define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info. 
  154. define('EBML_ID_FLAGDEFAULT', 0x08); // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference. 
  155. define('EBML_ID_CHAPTERTRACKNUMBER', 0x09); // [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks. 
  156. define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description. 
  157. define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply 
  158. define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled). 
  159. define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled). 
  160. define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block. 
  161. define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block. 
  162. define('EBML_ID_CHAPTERFLAGHIDDEN', 0x18); // [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks). 
  163. define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced. 
  164. define('EBML_ID_CLUSTERBLOCKDURATION', 0x1B); // [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks. 
  165. define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing. 
  166. define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track. 
  167. define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock. 
  168. define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode. 
  169. define('EBML_ID_CLUSTERBLOCKVIRTUAL', 0x22); // [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order. 
  170. define('EBML_ID_CLUSTERSIMPLEBLOCK', 0x23); // [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed. 
  171. define('EBML_ID_CLUSTERCODECSTATE', 0x24); // [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry. 
  172. define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID). 
  173. define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters. 
  174. define('EBML_ID_CLUSTERPOSITION', 0x27); // [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams. 
  175. define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data. 
  176. define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing. 
  177. define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements. 
  178. define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed). 
  179. define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels. 
  180. define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base. 
  181. define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz. 
  182. define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks). 
  183. define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode. 
  184. define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used. 
  185. define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels. 
  186. define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment. 
  187. define('EBML_ID_CRC32', 0x3F); // [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32. 
  188. define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block). 
  189. define('EBML_ID_CLUSTERLACENUMBER', 0x4C); // [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. 
  190. define('EBML_ID_CLUSTERFRAMENUMBER', 0x4D); // [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame). 
  191. define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element. 
  192. define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element. 
  193. define('EBML_ID_TRACKNUMBER', 0x57); // [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number). 
  194. define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks. 
  195. define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings. 
  196. define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings. 
  197. define('EBML_ID_CLUSTERTIMESLICE', 0x68); // [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. 
  198. define('EBML_ID_CUECODECSTATE', 0x6A); // [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry. 
  199. define('EBML_ID_CUEREFCODECSTATE', 0x6B); // [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry. 
  200. define('EBML_ID_VOID', 0x6C); // [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use. 
  201. define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale). 
  202. define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level. 
  203. define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block. 
  204. define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given. 
  205. define('EBML_ID_CLUSTERREFERENCEPRIORITY', 0x7A); // [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced. 
  206. define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to. 
  207. define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block. 
  208.  
  209.  
  210. /** 
  211. * @tutorial http://www.matroska.org/technical/specs/index.html 
  212. * 
  213. * @todo Rewrite EBML parser to reduce it's size and honor default element values 
  214. * @todo After rewrite implement stream size calculation, that will provide additional useful info and enable AAC/FLAC audio bitrate detection 
  215. */ 
  216. class getid3_matroska extends getid3_handler 
  217. // public options 
  218. public static $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful [default: TRUE] 
  219. public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE] 
  220.  
  221. // private parser settings/placeholders 
  222. private $EBMLbuffer = ''; 
  223. private $EBMLbuffer_offset = 0; 
  224. private $EBMLbuffer_length = 0; 
  225. private $current_offset = 0; 
  226. private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID); 
  227.  
  228. public function Analyze() 
  229. $info = &$this->getid3->info; 
  230.  
  231. // parse container 
  232. try { 
  233. $this->parseEBML($info); 
  234. } catch (Exception $e) { 
  235. $info['error'][] = 'EBML parser: '.$e->getMessage(); 
  236.  
  237. // calculate playtime 
  238. if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { 
  239. foreach ($info['matroska']['info'] as $key => $infoarray) { 
  240. if (isset($infoarray['Duration'])) { 
  241. // TimecodeScale is how many nanoseconds each Duration unit is 
  242. $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); 
  243. break; 
  244.  
  245. // extract tags 
  246. if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) { 
  247. foreach ($info['matroska']['tags'] as $key => $infoarray) { 
  248. $this->ExtractCommentsSimpleTag($infoarray); 
  249.  
  250. // process tracks 
  251. if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { 
  252. foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) { 
  253.  
  254. $track_info = array(); 
  255. $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']); 
  256. $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true); 
  257. if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; } 
  258.  
  259. switch ($trackarray['TrackType']) { 
  260.  
  261. case 1: // Video 
  262. $track_info['resolution_x'] = $trackarray['PixelWidth']; 
  263. $track_info['resolution_y'] = $trackarray['PixelHeight']; 
  264. $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0); 
  265. $track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']); 
  266. $track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']); 
  267.  
  268. if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; } 
  269. if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; } 
  270. if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; } 
  271. if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; } 
  272. if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); } 
  273. if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } 
  274.  
  275. switch ($trackarray['CodecID']) { 
  276. case 'V_MS/VFW/FOURCC': 
  277. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); 
  278.  
  279. $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']); 
  280. $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']); 
  281. $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; 
  282. break; 
  283.  
  284. /**case 'V_MPEG4/ISO/AVC': 
  285. $h264['profile'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1)); 
  286. $h264['level'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1)); 
  287. $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1)); 
  288. $h264['NALUlength'] = ($rn & 3) + 1; 
  289. $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1)); 
  290. $nsps = ($rn & 31); 
  291. $offset = 6; 
  292. for ($i = 0; $i < $nsps; $i ++) { 
  293. $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); 
  294. $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); 
  295. $offset += 2 + $length; 
  296. } 
  297. $npps = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1)); 
  298. $offset += 1; 
  299. for ($i = 0; $i < $npps; $i ++) { 
  300. $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); 
  301. $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); 
  302. $offset += 2 + $length; 
  303. } 
  304. $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264; 
  305. break;*/ 
  306.  
  307. $info['video']['streams'][] = $track_info; 
  308. break; 
  309.  
  310. case 2: // Audio 
  311. $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0); 
  312. $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1); 
  313. $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng'); 
  314. if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; } 
  315. if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } 
  316.  
  317. switch ($trackarray['CodecID']) { 
  318. case 'A_PCM/INT/LIT': 
  319. case 'A_PCM/INT/BIG': 
  320. $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth']; 
  321. break; 
  322.  
  323. case 'A_AC3': 
  324. case 'A_DTS': 
  325. case 'A_MPEG/L3': 
  326. case 'A_MPEG/L2': 
  327. case 'A_FLAC': 
  328. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']).'.php', __FILE__, true); 
  329.  
  330. if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { 
  331. $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'); 
  332. break; 
  333.  
  334. // create temp instance 
  335. $getid3_temp = new getID3(); 
  336. if ($track_info['dataformat'] != 'flac') { 
  337. $getid3_temp->openfile($this->getid3->filename); 
  338. $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset']; 
  339. if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') { 
  340. $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length']; 
  341.  
  342. // analyze 
  343. $class = 'getid3_'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']); 
  344. $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat']; 
  345. $getid3_audio = new $class($getid3_temp, __CLASS__); 
  346. if ($track_info['dataformat'] == 'flac') { 
  347. $getid3_audio->AnalyzeString($trackarray['CodecPrivate']); 
  348. else { 
  349. $getid3_audio->Analyze(); 
  350. if (!empty($getid3_temp->info[$header_data_key])) { 
  351. $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key]; 
  352. if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { 
  353. foreach ($getid3_temp->info['audio'] as $key => $value) { 
  354. $track_info[$key] = $value; 
  355. else { 
  356. $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']); 
  357.  
  358. // copy errors and warnings 
  359. if (!empty($getid3_temp->info['error'])) { 
  360. foreach ($getid3_temp->info['error'] as $newerror) { 
  361. $this->warning($class.'() says: ['.$newerror.']'); 
  362. if (!empty($getid3_temp->info['warning'])) { 
  363. foreach ($getid3_temp->info['warning'] as $newerror) { 
  364. $this->warning($class.'() says: ['.$newerror.']'); 
  365. unset($getid3_temp, $getid3_audio); 
  366. break; 
  367.  
  368. case 'A_AAC': 
  369. case 'A_AAC/MPEG2/LC': 
  370. case 'A_AAC/MPEG2/LC/SBR': 
  371. case 'A_AAC/MPEG4/LC': 
  372. case 'A_AAC/MPEG4/LC/SBR': 
  373. $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated'); 
  374. break; 
  375.  
  376. case 'A_VORBIS': 
  377. if (!isset($trackarray['CodecPrivate'])) { 
  378. $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set'); 
  379. break; 
  380. $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1); 
  381. if ($vorbis_offset === false) { 
  382. $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword'); 
  383. break; 
  384. $vorbis_offset -= 1; 
  385.  
  386. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); 
  387.  
  388. // create temp instance 
  389. $getid3_temp = new getID3(); 
  390.  
  391. // analyze 
  392. $getid3_ogg = new getid3_ogg($getid3_temp); 
  393. $oggpageinfo['page_seqno'] = 0; 
  394. $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo); 
  395. if (!empty($getid3_temp->info['ogg'])) { 
  396. $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg']; 
  397. if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { 
  398. foreach ($getid3_temp->info['audio'] as $key => $value) { 
  399. $track_info[$key] = $value; 
  400.  
  401. // copy errors and warnings 
  402. if (!empty($getid3_temp->info['error'])) { 
  403. foreach ($getid3_temp->info['error'] as $newerror) { 
  404. $this->warning('getid3_ogg() says: ['.$newerror.']'); 
  405. if (!empty($getid3_temp->info['warning'])) { 
  406. foreach ($getid3_temp->info['warning'] as $newerror) { 
  407. $this->warning('getid3_ogg() says: ['.$newerror.']'); 
  408.  
  409. if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) { 
  410. $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal']; 
  411. unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset); 
  412. break; 
  413.  
  414. case 'A_MS/ACM': 
  415. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); 
  416.  
  417. $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']); 
  418. foreach ($parsed as $key => $value) { 
  419. if ($key != 'raw') { 
  420. $track_info[$key] = $value; 
  421. $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; 
  422. break; 
  423.  
  424. default: 
  425. $this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"'); 
  426.  
  427. $info['audio']['streams'][] = $track_info; 
  428. break; 
  429.  
  430. if (!empty($info['video']['streams'])) { 
  431. $info['video'] = self::getDefaultStreamInfo($info['video']['streams']); 
  432. if (!empty($info['audio']['streams'])) { 
  433. $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']); 
  434.  
  435. // process attachments 
  436. if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) { 
  437. foreach ($info['matroska']['attachments'] as $i => $entry) { 
  438. if (strpos($entry['FileMimeType'], 'image/') === 0 && !empty($entry['FileData'])) { 
  439. $info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']); 
  440.  
  441. // determine mime type 
  442. if (!empty($info['video']['streams'])) { 
  443. $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska'); 
  444. } elseif (!empty($info['audio']['streams'])) { 
  445. $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska'); 
  446. } elseif (isset($info['mime_type'])) { 
  447. unset($info['mime_type']); 
  448.  
  449. return true; 
  450.  
  451. private function parseEBML(&$info) { 
  452. // http://www.matroska.org/technical/specs/index.html#EBMLBasics 
  453. $this->current_offset = $info['avdataoffset']; 
  454.  
  455. while ($this->getEBMLelement($top_element, $info['avdataend'])) { 
  456. switch ($top_element['id']) { 
  457.  
  458. case EBML_ID_EBML: 
  459. $info['matroska']['header']['offset'] = $top_element['offset']; 
  460. $info['matroska']['header']['length'] = $top_element['length']; 
  461.  
  462. while ($this->getEBMLelement($element_data, $top_element['end'], true)) { 
  463. switch ($element_data['id']) { 
  464.  
  465. case EBML_ID_EBMLVERSION: 
  466. case EBML_ID_EBMLREADVERSION: 
  467. case EBML_ID_EBMLMAXIDLENGTH: 
  468. case EBML_ID_EBMLMAXSIZELENGTH: 
  469. case EBML_ID_DOCTYPEVERSION: 
  470. case EBML_ID_DOCTYPEREADVERSION: 
  471. $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']); 
  472. break; 
  473.  
  474. case EBML_ID_DOCTYPE: 
  475. $element_data['data'] = getid3_lib::trimNullByte($element_data['data']); 
  476. $info['matroska']['doctype'] = $element_data['data']; 
  477. $info['fileformat'] = $element_data['data']; 
  478. break; 
  479.  
  480. default: 
  481. $this->unhandledElement('header', __LINE__, $element_data); 
  482.  
  483. unset($element_data['offset'], $element_data['end']); 
  484. $info['matroska']['header']['elements'][] = $element_data; 
  485. break; 
  486.  
  487. case EBML_ID_SEGMENT: 
  488. $info['matroska']['segment'][0]['offset'] = $top_element['offset']; 
  489. $info['matroska']['segment'][0]['length'] = $top_element['length']; 
  490.  
  491. while ($this->getEBMLelement($element_data, $top_element['end'])) { 
  492. if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required 
  493. $info['matroska']['segments'][] = $element_data; 
  494. switch ($element_data['id']) { 
  495.  
  496. case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements. 
  497.  
  498. while ($this->getEBMLelement($seek_entry, $element_data['end'])) { 
  499. switch ($seek_entry['id']) { 
  500.  
  501. case EBML_ID_SEEK: // Contains a single seek entry to an EBML element 
  502. while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) { 
  503.  
  504. switch ($sub_seek_entry['id']) { 
  505.  
  506. case EBML_ID_SEEKID: 
  507. $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']); 
  508. $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']); 
  509. break; 
  510.  
  511. case EBML_ID_SEEKPOSITION: 
  512. $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']); 
  513. break; 
  514.  
  515. default: 
  516. $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); } 
  517.  
  518. if ($seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required 
  519. $info['matroska']['seek'][] = $seek_entry; 
  520. break; 
  521.  
  522. default: 
  523. $this->unhandledElement('seekhead', __LINE__, $seek_entry); 
  524. break; 
  525.  
  526. case EBML_ID_TRACKS: // A top-level block of information with many tracks described. 
  527. $info['matroska']['tracks'] = $element_data; 
  528.  
  529. while ($this->getEBMLelement($track_entry, $element_data['end'])) { 
  530. switch ($track_entry['id']) { 
  531.  
  532. case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements. 
  533.  
  534. while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE))) { 
  535. switch ($subelement['id']) { 
  536.  
  537. case EBML_ID_TRACKNUMBER: 
  538. case EBML_ID_TRACKUID: 
  539. case EBML_ID_TRACKTYPE: 
  540. case EBML_ID_MINCACHE: 
  541. case EBML_ID_MAXCACHE: 
  542. case EBML_ID_MAXBLOCKADDITIONID: 
  543. case EBML_ID_DEFAULTDURATION: // nanoseconds per frame 
  544. $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); 
  545. break; 
  546.  
  547. case EBML_ID_TRACKTIMECODESCALE: 
  548. $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); 
  549. break; 
  550.  
  551. case EBML_ID_CODECID: 
  552. case EBML_ID_LANGUAGE: 
  553. case EBML_ID_NAME: 
  554. case EBML_ID_CODECNAME: 
  555. $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); 
  556. break; 
  557.  
  558. case EBML_ID_CODECPRIVATE: 
  559. $track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true); 
  560. break; 
  561.  
  562. case EBML_ID_FLAGENABLED: 
  563. case EBML_ID_FLAGDEFAULT: 
  564. case EBML_ID_FLAGFORCED: 
  565. case EBML_ID_FLAGLACING: 
  566. case EBML_ID_CODECDECODEALL: 
  567. $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']); 
  568. break; 
  569.  
  570. case EBML_ID_VIDEO: 
  571.  
  572. while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { 
  573. switch ($sub_subelement['id']) { 
  574.  
  575. case EBML_ID_PIXELWIDTH: 
  576. case EBML_ID_PIXELHEIGHT: 
  577. case EBML_ID_PIXELCROPBOTTOM: 
  578. case EBML_ID_PIXELCROPTOP: 
  579. case EBML_ID_PIXELCROPLEFT: 
  580. case EBML_ID_PIXELCROPRIGHT: 
  581. case EBML_ID_DISPLAYWIDTH: 
  582. case EBML_ID_DISPLAYHEIGHT: 
  583. case EBML_ID_DISPLAYUNIT: 
  584. case EBML_ID_ASPECTRATIOTYPE: 
  585. case EBML_ID_STEREOMODE: 
  586. case EBML_ID_OLDSTEREOMODE: 
  587. $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  588. break; 
  589.  
  590. case EBML_ID_FLAGINTERLACED: 
  591. $track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); 
  592. break; 
  593.  
  594. case EBML_ID_GAMMAVALUE: 
  595. $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); 
  596. break; 
  597.  
  598. case EBML_ID_COLOURSPACE: 
  599. $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); 
  600. break; 
  601.  
  602. default: 
  603. $this->unhandledElement('track.video', __LINE__, $sub_subelement); 
  604. break; 
  605.  
  606. case EBML_ID_AUDIO: 
  607.  
  608. while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { 
  609. switch ($sub_subelement['id']) { 
  610.  
  611. case EBML_ID_CHANNELS: 
  612. case EBML_ID_BITDEPTH: 
  613. $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  614. break; 
  615.  
  616. case EBML_ID_SAMPLINGFREQUENCY: 
  617. case EBML_ID_OUTPUTSAMPLINGFREQUENCY: 
  618. $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); 
  619. break; 
  620.  
  621. case EBML_ID_CHANNELPOSITIONS: 
  622. $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); 
  623. break; 
  624.  
  625. default: 
  626. $this->unhandledElement('track.audio', __LINE__, $sub_subelement); 
  627. break; 
  628.  
  629. case EBML_ID_CONTENTENCODINGS: 
  630.  
  631. while ($this->getEBMLelement($sub_subelement, $subelement['end'])) { 
  632. switch ($sub_subelement['id']) { 
  633.  
  634. case EBML_ID_CONTENTENCODING: 
  635.  
  636. while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) { 
  637. switch ($sub_sub_subelement['id']) { 
  638.  
  639. case EBML_ID_CONTENTENCODINGORDER: 
  640. case EBML_ID_CONTENTENCODINGSCOPE: 
  641. case EBML_ID_CONTENTENCODINGTYPE: 
  642. $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  643. break; 
  644.  
  645. case EBML_ID_CONTENTCOMPRESSION: 
  646.  
  647. while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { 
  648. switch ($sub_sub_sub_subelement['id']) { 
  649.  
  650. case EBML_ID_CONTENTCOMPALGO: 
  651. $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); 
  652. break; 
  653.  
  654. case EBML_ID_CONTENTCOMPSETTINGS: 
  655. $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; 
  656. break; 
  657.  
  658. default: 
  659. $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); 
  660. break; 
  661.  
  662. case EBML_ID_CONTENTENCRYPTION: 
  663.  
  664. while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { 
  665. switch ($sub_sub_sub_subelement['id']) { 
  666.  
  667. case EBML_ID_CONTENTENCALGO: 
  668. case EBML_ID_CONTENTSIGALGO: 
  669. case EBML_ID_CONTENTSIGHASHALGO: 
  670. $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); 
  671. break; 
  672.  
  673. case EBML_ID_CONTENTENCKEYID: 
  674. case EBML_ID_CONTENTSIGNATURE: 
  675. case EBML_ID_CONTENTSIGKEYID: 
  676. $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; 
  677. break; 
  678.  
  679. default: 
  680. $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); 
  681. break; 
  682.  
  683. default: 
  684. $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement); 
  685. break; 
  686.  
  687. default: 
  688. $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement); 
  689. break; 
  690.  
  691. default: 
  692. $this->unhandledElement('track', __LINE__, $subelement); 
  693.  
  694. $info['matroska']['tracks']['tracks'][] = $track_entry; 
  695. break; 
  696.  
  697. default: 
  698. $this->unhandledElement('tracks', __LINE__, $track_entry); 
  699. break; 
  700.  
  701. case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file. 
  702. $info_entry = array(); 
  703.  
  704. while ($this->getEBMLelement($subelement, $element_data['end'], true)) { 
  705. switch ($subelement['id']) { 
  706.  
  707. case EBML_ID_TIMECODESCALE: 
  708. $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); 
  709. break; 
  710.  
  711. case EBML_ID_DURATION: 
  712. $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); 
  713. break; 
  714.  
  715. case EBML_ID_DATEUTC: 
  716. $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); 
  717. $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]); 
  718. break; 
  719.  
  720. case EBML_ID_SEGMENTUID: 
  721. case EBML_ID_PREVUID: 
  722. case EBML_ID_NEXTUID: 
  723. $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); 
  724. break; 
  725.  
  726. case EBML_ID_SEGMENTFAMILY: 
  727. $info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']); 
  728. break; 
  729.  
  730. case EBML_ID_SEGMENTFILENAME: 
  731. case EBML_ID_PREVFILENAME: 
  732. case EBML_ID_NEXTFILENAME: 
  733. case EBML_ID_TITLE: 
  734. case EBML_ID_MUXINGAPP: 
  735. case EBML_ID_WRITINGAPP: 
  736. $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); 
  737. $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']]; 
  738. break; 
  739.  
  740. case EBML_ID_CHAPTERTRANSLATE: 
  741. $chaptertranslate_entry = array(); 
  742.  
  743. while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { 
  744. switch ($sub_subelement['id']) { 
  745.  
  746. case EBML_ID_CHAPTERTRANSLATEEDITIONUID: 
  747. $chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  748. break; 
  749.  
  750. case EBML_ID_CHAPTERTRANSLATECODEC: 
  751. $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  752. break; 
  753.  
  754. case EBML_ID_CHAPTERTRANSLATEID: 
  755. $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); 
  756. break; 
  757.  
  758. default: 
  759. $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement); 
  760. $info_entry[$subelement['id_name']] = $chaptertranslate_entry; 
  761. break; 
  762.  
  763. default: 
  764. $this->unhandledElement('info', __LINE__, $subelement); 
  765. $info['matroska']['info'][] = $info_entry; 
  766. break; 
  767.  
  768. case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams. 
  769. if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway 
  770. $this->current_offset = $element_data['end']; 
  771. break; 
  772. $cues_entry = array(); 
  773.  
  774. while ($this->getEBMLelement($subelement, $element_data['end'])) { 
  775. switch ($subelement['id']) { 
  776.  
  777. case EBML_ID_CUEPOINT: 
  778. $cuepoint_entry = array(); 
  779.  
  780. while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) { 
  781. switch ($sub_subelement['id']) { 
  782.  
  783. case EBML_ID_CUETRACKPOSITIONS: 
  784. $cuetrackpositions_entry = array(); 
  785.  
  786. while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { 
  787. switch ($sub_sub_subelement['id']) { 
  788.  
  789. case EBML_ID_CUETRACK: 
  790. case EBML_ID_CUECLUSTERPOSITION: 
  791. case EBML_ID_CUEBLOCKNUMBER: 
  792. case EBML_ID_CUECODECSTATE: 
  793. $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  794. break; 
  795.  
  796. default: 
  797. $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement); 
  798. $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry; 
  799. break; 
  800.  
  801. case EBML_ID_CUETIME: 
  802. $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  803. break; 
  804.  
  805. default: 
  806. $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement); 
  807. $cues_entry[] = $cuepoint_entry; 
  808. break; 
  809.  
  810. default: 
  811. $this->unhandledElement('cues', __LINE__, $subelement); 
  812. $info['matroska']['cues'] = $cues_entry; 
  813. break; 
  814.  
  815. case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters. 
  816. $tags_entry = array(); 
  817.  
  818. while ($this->getEBMLelement($subelement, $element_data['end'], false)) { 
  819. switch ($subelement['id']) { 
  820.  
  821. case EBML_ID_TAG: 
  822. $tag_entry = array(); 
  823.  
  824. while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) { 
  825. switch ($sub_subelement['id']) { 
  826.  
  827. case EBML_ID_TARGETS: 
  828. $targets_entry = array(); 
  829.  
  830. while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { 
  831. switch ($sub_sub_subelement['id']) { 
  832.  
  833. case EBML_ID_TARGETTYPEVALUE: 
  834. $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  835. $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]); 
  836. break; 
  837.  
  838. case EBML_ID_TARGETTYPE: 
  839. $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; 
  840. break; 
  841.  
  842. case EBML_ID_TAGTRACKUID: 
  843. case EBML_ID_TAGEDITIONUID: 
  844. case EBML_ID_TAGCHAPTERUID: 
  845. case EBML_ID_TAGATTACHMENTUID: 
  846. $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  847. break; 
  848.  
  849. default: 
  850. $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement); 
  851. $tag_entry[$sub_subelement['id_name']] = $targets_entry; 
  852. break; 
  853.  
  854. case EBML_ID_SIMPLETAG: 
  855. $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']); 
  856. break; 
  857.  
  858. default: 
  859. $this->unhandledElement('tags.tag', __LINE__, $sub_subelement); 
  860. $tags_entry[] = $tag_entry; 
  861. break; 
  862.  
  863. default: 
  864. $this->unhandledElement('tags', __LINE__, $subelement); 
  865. $info['matroska']['tags'] = $tags_entry; 
  866. break; 
  867.  
  868. case EBML_ID_ATTACHMENTS: // Contain attached files. 
  869.  
  870. while ($this->getEBMLelement($subelement, $element_data['end'])) { 
  871. switch ($subelement['id']) { 
  872.  
  873. case EBML_ID_ATTACHEDFILE: 
  874. $attachedfile_entry = array(); 
  875.  
  876. while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) { 
  877. switch ($sub_subelement['id']) { 
  878.  
  879. case EBML_ID_FILEDESCRIPTION: 
  880. case EBML_ID_FILENAME: 
  881. case EBML_ID_FILEMIMETYPE: 
  882. $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data']; 
  883. break; 
  884.  
  885. case EBML_ID_FILEDATA: 
  886. $attachedfile_entry['data_offset'] = $this->current_offset; 
  887. $attachedfile_entry['data_length'] = $sub_subelement['length']; 
  888.  
  889. $attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment( 
  890. $attachedfile_entry['FileName'],  
  891. $attachedfile_entry['data_offset'],  
  892. $attachedfile_entry['data_length']); 
  893.  
  894. $this->current_offset = $sub_subelement['end']; 
  895. break; 
  896.  
  897. case EBML_ID_FILEUID: 
  898. $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  899. break; 
  900.  
  901. default: 
  902. $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement); 
  903. $info['matroska']['attachments'][] = $attachedfile_entry; 
  904. break; 
  905.  
  906. default: 
  907. $this->unhandledElement('attachments', __LINE__, $subelement); 
  908. break; 
  909.  
  910. case EBML_ID_CHAPTERS: 
  911.  
  912. while ($this->getEBMLelement($subelement, $element_data['end'])) { 
  913. switch ($subelement['id']) { 
  914.  
  915. case EBML_ID_EDITIONENTRY: 
  916. $editionentry_entry = array(); 
  917.  
  918. while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) { 
  919. switch ($sub_subelement['id']) { 
  920.  
  921. case EBML_ID_EDITIONUID: 
  922. $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  923. break; 
  924.  
  925. case EBML_ID_EDITIONFLAGHIDDEN: 
  926. case EBML_ID_EDITIONFLAGDEFAULT: 
  927. case EBML_ID_EDITIONFLAGORDERED: 
  928. $editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); 
  929. break; 
  930.  
  931. case EBML_ID_CHAPTERATOM: 
  932. $chapteratom_entry = array(); 
  933.  
  934. while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) { 
  935. switch ($sub_sub_subelement['id']) { 
  936.  
  937. case EBML_ID_CHAPTERSEGMENTUID: 
  938. case EBML_ID_CHAPTERSEGMENTEDITIONUID: 
  939. $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; 
  940. break; 
  941.  
  942. case EBML_ID_CHAPTERFLAGENABLED: 
  943. case EBML_ID_CHAPTERFLAGHIDDEN: 
  944. $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  945. break; 
  946.  
  947. case EBML_ID_CHAPTERUID: 
  948. case EBML_ID_CHAPTERTIMESTART: 
  949. case EBML_ID_CHAPTERTIMEEND: 
  950. $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); 
  951. break; 
  952.  
  953. case EBML_ID_CHAPTERTRACK: 
  954. $chaptertrack_entry = array(); 
  955.  
  956. while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { 
  957. switch ($sub_sub_sub_subelement['id']) { 
  958.  
  959. case EBML_ID_CHAPTERTRACKNUMBER: 
  960. $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); 
  961. break; 
  962.  
  963. default: 
  964. $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement); 
  965. $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry; 
  966. break; 
  967.  
  968. case EBML_ID_CHAPTERDISPLAY: 
  969. $chapterdisplay_entry = array(); 
  970.  
  971. while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { 
  972. switch ($sub_sub_sub_subelement['id']) { 
  973.  
  974. case EBML_ID_CHAPSTRING: 
  975. case EBML_ID_CHAPLANGUAGE: 
  976. case EBML_ID_CHAPCOUNTRY: 
  977. $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; 
  978. break; 
  979.  
  980. default: 
  981. $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement); 
  982. $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry; 
  983. break; 
  984.  
  985. default: 
  986. $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement); 
  987. $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry; 
  988. break; 
  989.  
  990. default: 
  991. $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement); 
  992. $info['matroska']['chapters'][] = $editionentry_entry; 
  993. break; 
  994.  
  995. default: 
  996. $this->unhandledElement('chapters', __LINE__, $subelement); 
  997. break; 
  998.  
  999. case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure. 
  1000. $cluster_entry = array(); 
  1001.  
  1002. while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) { 
  1003. switch ($subelement['id']) { 
  1004.  
  1005. case EBML_ID_CLUSTERTIMECODE: 
  1006. case EBML_ID_CLUSTERPOSITION: 
  1007. case EBML_ID_CLUSTERPREVSIZE: 
  1008. $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); 
  1009. break; 
  1010.  
  1011. case EBML_ID_CLUSTERSILENTTRACKS: 
  1012. $cluster_silent_tracks = array(); 
  1013.  
  1014. while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { 
  1015. switch ($sub_subelement['id']) { 
  1016.  
  1017. case EBML_ID_CLUSTERSILENTTRACKNUMBER: 
  1018. $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  1019. break; 
  1020.  
  1021. default: 
  1022. $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement); 
  1023. $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks; 
  1024. break; 
  1025.  
  1026. case EBML_ID_CLUSTERBLOCKGROUP: 
  1027. $cluster_block_group = array('offset' => $this->current_offset); 
  1028.  
  1029. while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) { 
  1030. switch ($sub_subelement['id']) { 
  1031.  
  1032. case EBML_ID_CLUSTERBLOCK: 
  1033. $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info); 
  1034. break; 
  1035.  
  1036. case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int 
  1037. case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int 
  1038. $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); 
  1039. break; 
  1040.  
  1041. case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int 
  1042. $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true); 
  1043. break; 
  1044.  
  1045. case EBML_ID_CLUSTERCODECSTATE: 
  1046. $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); 
  1047. break; 
  1048.  
  1049. default: 
  1050. $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement); 
  1051. $cluster_entry[$subelement['id_name']][] = $cluster_block_group; 
  1052. break; 
  1053.  
  1054. case EBML_ID_CLUSTERSIMPLEBLOCK: 
  1055. $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info); 
  1056. break; 
  1057.  
  1058. default: 
  1059. $this->unhandledElement('cluster', __LINE__, $subelement); 
  1060. $this->current_offset = $subelement['end']; 
  1061. if (!self::$hide_clusters) { 
  1062. $info['matroska']['cluster'][] = $cluster_entry; 
  1063.  
  1064. // check to see if all the data we need exists already, if so, break out of the loop 
  1065. if (!self::$parse_whole_file) { 
  1066. if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { 
  1067. if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { 
  1068. if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) { 
  1069. return; 
  1070. break; 
  1071.  
  1072. default: 
  1073. $this->unhandledElement('segment', __LINE__, $element_data); 
  1074. break; 
  1075.  
  1076. default: 
  1077. $this->unhandledElement('root', __LINE__, $top_element); 
  1078.  
  1079. private function EnsureBufferHasEnoughData($min_data=1024) { 
  1080. if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) { 
  1081. $read_bytes = max($min_data, $this->getid3->fread_buffer_size()); 
  1082.  
  1083. try { 
  1084. $this->fseek($this->current_offset); 
  1085. $this->EBMLbuffer_offset = $this->current_offset; 
  1086. $this->EBMLbuffer = $this->fread($read_bytes); 
  1087. $this->EBMLbuffer_length = strlen($this->EBMLbuffer); 
  1088. } catch (getid3_exception $e) { 
  1089. $this->warning('EBML parser: '.$e->getMessage()); 
  1090. return false; 
  1091.  
  1092. if ($this->EBMLbuffer_length == 0 && $this->feof()) { 
  1093. return $this->error('EBML parser: ran out of file at offset '.$this->current_offset); 
  1094. return true; 
  1095.  
  1096. private function readEBMLint() { 
  1097. $actual_offset = $this->current_offset - $this->EBMLbuffer_offset; 
  1098.  
  1099. // get length of integer 
  1100. $first_byte_int = ord($this->EBMLbuffer[$actual_offset]); 
  1101. if (0x80 & $first_byte_int) { 
  1102. $length = 1; 
  1103. } elseif (0x40 & $first_byte_int) { 
  1104. $length = 2; 
  1105. } elseif (0x20 & $first_byte_int) { 
  1106. $length = 3; 
  1107. } elseif (0x10 & $first_byte_int) { 
  1108. $length = 4; 
  1109. } elseif (0x08 & $first_byte_int) { 
  1110. $length = 5; 
  1111. } elseif (0x04 & $first_byte_int) { 
  1112. $length = 6; 
  1113. } elseif (0x02 & $first_byte_int) { 
  1114. $length = 7; 
  1115. } elseif (0x01 & $first_byte_int) { 
  1116. $length = 8; 
  1117. } else { 
  1118. throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset); 
  1119.  
  1120. // read 
  1121. $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length)); 
  1122. $this->current_offset += $length; 
  1123.  
  1124. return $int_value; 
  1125.  
  1126. private function readEBMLelementData($length, $check_buffer=false) { 
  1127. if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) { 
  1128. return false; 
  1129. $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length); 
  1130. $this->current_offset += $length; 
  1131. return $data; 
  1132.  
  1133. private function getEBMLelement(&$element, $parent_end, $get_data=false) { 
  1134. if ($this->current_offset >= $parent_end) { 
  1135. return false; 
  1136.  
  1137. if (!$this->EnsureBufferHasEnoughData()) { 
  1138. $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information 
  1139. return false; 
  1140.  
  1141. $element = array(); 
  1142.  
  1143. // set offset 
  1144. $element['offset'] = $this->current_offset; 
  1145.  
  1146. // get ID 
  1147. $element['id'] = $this->readEBMLint(); 
  1148.  
  1149. // get name 
  1150. $element['id_name'] = self::EBMLidName($element['id']); 
  1151.  
  1152. // get length 
  1153. $element['length'] = $this->readEBMLint(); 
  1154.  
  1155. // get end offset 
  1156. $element['end'] = $this->current_offset + $element['length']; 
  1157.  
  1158. // get raw data 
  1159. $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id'])); 
  1160. if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) { 
  1161. $element['data'] = $this->readEBMLelementData($element['length'], $element); 
  1162.  
  1163. return true; 
  1164.  
  1165. private function unhandledElement($type, $line, $element) { 
  1166. // warn only about unknown and missed elements, not about unuseful 
  1167. if (!in_array($element['id'], $this->unuseful_elements)) { 
  1168. $this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']); 
  1169.  
  1170. // increase offset for unparsed elements 
  1171. if (!isset($element['data'])) { 
  1172. $this->current_offset = $element['end']; 
  1173.  
  1174. private function ExtractCommentsSimpleTag($SimpleTagArray) { 
  1175. if (!empty($SimpleTagArray['SimpleTag'])) { 
  1176. foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) { 
  1177. if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) { 
  1178. $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString']; 
  1179. if (!empty($SimpleTagData['SimpleTag'])) { 
  1180. $this->ExtractCommentsSimpleTag($SimpleTagData); 
  1181.  
  1182. return true; 
  1183.  
  1184. private function HandleEMBLSimpleTag($parent_end) { 
  1185. $simpletag_entry = array(); 
  1186.  
  1187. while ($this->getEBMLelement($element, $parent_end, array(EBML_ID_SIMPLETAG))) { 
  1188. switch ($element['id']) { 
  1189.  
  1190. case EBML_ID_TAGNAME: 
  1191. case EBML_ID_TAGLANGUAGE: 
  1192. case EBML_ID_TAGSTRING: 
  1193. case EBML_ID_TAGBINARY: 
  1194. $simpletag_entry[$element['id_name']] = $element['data']; 
  1195. break; 
  1196.  
  1197. case EBML_ID_SIMPLETAG: 
  1198. $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']); 
  1199. break; 
  1200.  
  1201. case EBML_ID_TAGDEFAULT: 
  1202. $simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']); 
  1203. break; 
  1204.  
  1205. default: 
  1206. $this->unhandledElement('tag.simpletag', __LINE__, $element); 
  1207.  
  1208. return $simpletag_entry; 
  1209.  
  1210. private function HandleEMBLClusterBlock($element, $block_type, &$info) { 
  1211. // http://www.matroska.org/technical/specs/index.html#block_structure 
  1212. // http://www.matroska.org/technical/specs/index.html#simpleblock_structure 
  1213.  
  1214. $block_data = array(); 
  1215. $block_data['tracknumber'] = $this->readEBMLint(); 
  1216. $block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), false, true); 
  1217. $block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); 
  1218.  
  1219. if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { 
  1220. $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7); 
  1221. //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4); 
  1222. else { 
  1223. //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4); 
  1224. $block_data['flags']['invisible'] = (bool)(($block_data['flags_raw'] & 0x08) >> 3); 
  1225. $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing 
  1226. if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { 
  1227. $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01)); 
  1228. else { 
  1229. //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0); 
  1230. $block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']); 
  1231.  
  1232. // Lace (when lacing bit is set) 
  1233. if ($block_data['flags']['lacing'] > 0) { 
  1234. $block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8) 
  1235. if ($block_data['flags']['lacing'] != 0x02) { 
  1236. for ($i = 1; $i < $block_data['lace_frames']; $i ++) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). 
  1237. if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing 
  1238. $block_data['lace_frames_size'][$i] = $this->readEBMLint(); // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing. 
  1239. else { // Xiph lacing 
  1240. $block_data['lace_frames_size'][$i] = 0; 
  1241. do { 
  1242. $size = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); 
  1243. $block_data['lace_frames_size'][$i] += $size; 
  1244. while ($size == 255); 
  1245. if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly 
  1246. $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']); 
  1247.  
  1248. if (!isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) { 
  1249. $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset; 
  1250. $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset; 
  1251. //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0; 
  1252. //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length']; 
  1253. //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['duration'] = $block_data['timecode'] * ((isset($info['matroska']['info'][0]['TimecodeScale']) ? $info['matroska']['info'][0]['TimecodeScale'] : 1000000) / 1000000000); 
  1254.  
  1255. // set offset manually 
  1256. $this->current_offset = $element['end']; 
  1257.  
  1258. return $block_data; 
  1259.  
  1260. private static function EBML2Int($EBMLstring) { 
  1261. // http://matroska.org/specs/ 
  1262.  
  1263. // Element ID coded with an UTF-8 like system: 
  1264. // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X) 
  1265. // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX) 
  1266. // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX) 
  1267. // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX) 
  1268. // Values with all x at 0 and 1 are reserved (hence the -2). 
  1269.  
  1270. // Data size, in octets, is also coded with an UTF-8 like system : 
  1271. // 1xxx xxxx - value 0 to 2^7-2 
  1272. // 01xx xxxx xxxx xxxx - value 0 to 2^14-2 
  1273. // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2 
  1274. // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2 
  1275. // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2 
  1276. // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2 
  1277. // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2 
  1278. // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2 
  1279.  
  1280. $first_byte_int = ord($EBMLstring[0]); 
  1281. if (0x80 & $first_byte_int) { 
  1282. $EBMLstring[0] = chr($first_byte_int & 0x7F); 
  1283. } elseif (0x40 & $first_byte_int) { 
  1284. $EBMLstring[0] = chr($first_byte_int & 0x3F); 
  1285. } elseif (0x20 & $first_byte_int) { 
  1286. $EBMLstring[0] = chr($first_byte_int & 0x1F); 
  1287. } elseif (0x10 & $first_byte_int) { 
  1288. $EBMLstring[0] = chr($first_byte_int & 0x0F); 
  1289. } elseif (0x08 & $first_byte_int) { 
  1290. $EBMLstring[0] = chr($first_byte_int & 0x07); 
  1291. } elseif (0x04 & $first_byte_int) { 
  1292. $EBMLstring[0] = chr($first_byte_int & 0x03); 
  1293. } elseif (0x02 & $first_byte_int) { 
  1294. $EBMLstring[0] = chr($first_byte_int & 0x01); 
  1295. } elseif (0x01 & $first_byte_int) { 
  1296. $EBMLstring[0] = chr($first_byte_int & 0x00); 
  1297.  
  1298. return getid3_lib::BigEndian2Int($EBMLstring); 
  1299.  
  1300. private static function EBMLdate2unix($EBMLdatestamp) { 
  1301. // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00, 000000000 UTC) 
  1302. // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC 
  1303. return round(($EBMLdatestamp / 1000000000) + 978307200); 
  1304.  
  1305. public static function TargetTypeValue($target_type) { 
  1306. // http://www.matroska.org/technical/specs/tagging/index.html 
  1307. static $TargetTypeValue = array(); 
  1308. if (empty($TargetTypeValue)) { 
  1309. $TargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies 
  1310. $TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement) 
  1311. $TargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie 
  1312. $TargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts 
  1313. $TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series) 
  1314. $TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together 
  1315. $TargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items 
  1316. return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type); 
  1317.  
  1318. public static function BlockLacingType($lacingtype) { 
  1319. // http://matroska.org/technical/specs/index.html#block_structure 
  1320. static $BlockLacingType = array(); 
  1321. if (empty($BlockLacingType)) { 
  1322. $BlockLacingType[0x00] = 'no lacing'; 
  1323. $BlockLacingType[0x01] = 'Xiph lacing'; 
  1324. $BlockLacingType[0x02] = 'fixed-size lacing'; 
  1325. $BlockLacingType[0x03] = 'EBML lacing'; 
  1326. return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype); 
  1327.  
  1328. public static function CodecIDtoCommonName($codecid) { 
  1329. // http://www.matroska.org/technical/specs/codecid/index.html 
  1330. static $CodecIDlist = array(); 
  1331. if (empty($CodecIDlist)) { 
  1332. $CodecIDlist['A_AAC'] = 'aac'; 
  1333. $CodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; 
  1334. $CodecIDlist['A_AC3'] = 'ac3'; 
  1335. $CodecIDlist['A_DTS'] = 'dts'; 
  1336. $CodecIDlist['A_FLAC'] = 'flac'; 
  1337. $CodecIDlist['A_MPEG/L1'] = 'mp1'; 
  1338. $CodecIDlist['A_MPEG/L2'] = 'mp2'; 
  1339. $CodecIDlist['A_MPEG/L3'] = 'mp3'; 
  1340. $CodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian 
  1341. $CodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian 
  1342. $CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music 
  1343. $CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 
  1344. $CodecIDlist['A_VORBIS'] = 'vorbis'; 
  1345. $CodecIDlist['V_MPEG1'] = 'mpeg'; 
  1346. $CodecIDlist['V_THEORA'] = 'theora'; 
  1347. $CodecIDlist['V_REAL/RV40'] = 'real'; 
  1348. $CodecIDlist['V_REAL/RV10'] = 'real'; 
  1349. $CodecIDlist['V_REAL/RV20'] = 'real'; 
  1350. $CodecIDlist['V_REAL/RV30'] = 'real'; 
  1351. $CodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime 
  1352. $CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; 
  1353. $CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; 
  1354. $CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; 
  1355. $CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; 
  1356. $CodecIDlist['V_VP8'] = 'vp8'; 
  1357. $CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM) 
  1358. $CodecIDlist['A_MS/ACM'] = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM) 
  1359. return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid); 
  1360.  
  1361. private static function EBMLidName($value) { 
  1362. static $EBMLidList = array(); 
  1363. if (empty($EBMLidList)) { 
  1364. $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType'; 
  1365. $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile'; 
  1366. $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink'; 
  1367. $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments'; 
  1368. $EBMLidList[EBML_ID_AUDIO] = 'Audio'; 
  1369. $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth'; 
  1370. $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions'; 
  1371. $EBMLidList[EBML_ID_CHANNELS] = 'Channels'; 
  1372. $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry'; 
  1373. $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage'; 
  1374. $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess'; 
  1375. $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID'; 
  1376. $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand'; 
  1377. $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData'; 
  1378. $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate'; 
  1379. $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime'; 
  1380. $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString'; 
  1381. $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom'; 
  1382. $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay'; 
  1383. $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled'; 
  1384. $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden'; 
  1385. $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv'; 
  1386. $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters'; 
  1387. $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID'; 
  1388. $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID'; 
  1389. $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd'; 
  1390. $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart'; 
  1391. $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack'; 
  1392. $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber'; 
  1393. $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate'; 
  1394. $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec'; 
  1395. $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID'; 
  1396. $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID'; 
  1397. $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID'; 
  1398. $EBMLidList[EBML_ID_CLUSTER] = 'Cluster'; 
  1399. $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock'; 
  1400. $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID'; 
  1401. $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional'; 
  1402. $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID'; 
  1403. $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions'; 
  1404. $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration'; 
  1405. $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup'; 
  1406. $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore'; 
  1407. $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual'; 
  1408. $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState'; 
  1409. $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay'; 
  1410. $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration'; 
  1411. $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock'; 
  1412. $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber'; 
  1413. $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber'; 
  1414. $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition'; 
  1415. $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize'; 
  1416. $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock'; 
  1417. $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority'; 
  1418. $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual'; 
  1419. $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber'; 
  1420. $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks'; 
  1421. $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock'; 
  1422. $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode'; 
  1423. $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice'; 
  1424. $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll'; 
  1425. $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL'; 
  1426. $EBMLidList[EBML_ID_CODECID] = 'CodecID'; 
  1427. $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL'; 
  1428. $EBMLidList[EBML_ID_CODECNAME] = 'CodecName'; 
  1429. $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate'; 
  1430. $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings'; 
  1431. $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace'; 
  1432. $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo'; 
  1433. $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression'; 
  1434. $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings'; 
  1435. $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo'; 
  1436. $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID'; 
  1437. $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding'; 
  1438. $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder'; 
  1439. $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings'; 
  1440. $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope'; 
  1441. $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType'; 
  1442. $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption'; 
  1443. $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo'; 
  1444. $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo'; 
  1445. $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID'; 
  1446. $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature'; 
  1447. $EBMLidList[EBML_ID_CRC32] = 'CRC32'; 
  1448. $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber'; 
  1449. $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition'; 
  1450. $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState'; 
  1451. $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint'; 
  1452. $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster'; 
  1453. $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState'; 
  1454. $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference'; 
  1455. $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber'; 
  1456. $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime'; 
  1457. $EBMLidList[EBML_ID_CUES] = 'Cues'; 
  1458. $EBMLidList[EBML_ID_CUETIME] = 'CueTime'; 
  1459. $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack'; 
  1460. $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions'; 
  1461. $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC'; 
  1462. $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration'; 
  1463. $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight'; 
  1464. $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit'; 
  1465. $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth'; 
  1466. $EBMLidList[EBML_ID_DOCTYPE] = 'DocType'; 
  1467. $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion'; 
  1468. $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion'; 
  1469. $EBMLidList[EBML_ID_DURATION] = 'Duration'; 
  1470. $EBMLidList[EBML_ID_EBML] = 'EBML'; 
  1471. $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength'; 
  1472. $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength'; 
  1473. $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion'; 
  1474. $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion'; 
  1475. $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry'; 
  1476. $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault'; 
  1477. $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden'; 
  1478. $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered'; 
  1479. $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID'; 
  1480. $EBMLidList[EBML_ID_FILEDATA] = 'FileData'; 
  1481. $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription'; 
  1482. $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType'; 
  1483. $EBMLidList[EBML_ID_FILENAME] = 'FileName'; 
  1484. $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral'; 
  1485. $EBMLidList[EBML_ID_FILEUID] = 'FileUID'; 
  1486. $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault'; 
  1487. $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled'; 
  1488. $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced'; 
  1489. $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced'; 
  1490. $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing'; 
  1491. $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue'; 
  1492. $EBMLidList[EBML_ID_INFO] = 'Info'; 
  1493. $EBMLidList[EBML_ID_LANGUAGE] = 'Language'; 
  1494. $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID'; 
  1495. $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache'; 
  1496. $EBMLidList[EBML_ID_MINCACHE] = 'MinCache'; 
  1497. $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp'; 
  1498. $EBMLidList[EBML_ID_NAME] = 'Name'; 
  1499. $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename'; 
  1500. $EBMLidList[EBML_ID_NEXTUID] = 'NextUID'; 
  1501. $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency'; 
  1502. $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom'; 
  1503. $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft'; 
  1504. $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight'; 
  1505. $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop'; 
  1506. $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight'; 
  1507. $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth'; 
  1508. $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename'; 
  1509. $EBMLidList[EBML_ID_PREVUID] = 'PrevUID'; 
  1510. $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency'; 
  1511. $EBMLidList[EBML_ID_SEEK] = 'Seek'; 
  1512. $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead'; 
  1513. $EBMLidList[EBML_ID_SEEKID] = 'SeekID'; 
  1514. $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition'; 
  1515. $EBMLidList[EBML_ID_SEGMENT] = 'Segment'; 
  1516. $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily'; 
  1517. $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename'; 
  1518. $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID'; 
  1519. $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag'; 
  1520. $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices'; 
  1521. $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode'; 
  1522. $EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode'; 
  1523. $EBMLidList[EBML_ID_TAG] = 'Tag'; 
  1524. $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID'; 
  1525. $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary'; 
  1526. $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID'; 
  1527. $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault'; 
  1528. $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID'; 
  1529. $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage'; 
  1530. $EBMLidList[EBML_ID_TAGNAME] = 'TagName'; 
  1531. $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID'; 
  1532. $EBMLidList[EBML_ID_TAGS] = 'Tags'; 
  1533. $EBMLidList[EBML_ID_TAGSTRING] = 'TagString'; 
  1534. $EBMLidList[EBML_ID_TARGETS] = 'Targets'; 
  1535. $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType'; 
  1536. $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue'; 
  1537. $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale'; 
  1538. $EBMLidList[EBML_ID_TITLE] = 'Title'; 
  1539. $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry'; 
  1540. $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber'; 
  1541. $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset'; 
  1542. $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay'; 
  1543. $EBMLidList[EBML_ID_TRACKS] = 'Tracks'; 
  1544. $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale'; 
  1545. $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate'; 
  1546. $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec'; 
  1547. $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID'; 
  1548. $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID'; 
  1549. $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType'; 
  1550. $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID'; 
  1551. $EBMLidList[EBML_ID_VIDEO] = 'Video'; 
  1552. $EBMLidList[EBML_ID_VOID] = 'Void'; 
  1553. $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp'; 
  1554.  
  1555. return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value)); 
  1556.  
  1557. public static function displayUnit($value) { 
  1558. // http://www.matroska.org/technical/specs/index.html#DisplayUnit 
  1559. static $units = array( 
  1560. 0 => 'pixels',  
  1561. 1 => 'centimeters',  
  1562. 2 => 'inches',  
  1563. 3 => 'Display Aspect Ratio'); 
  1564.  
  1565. return (isset($units[$value]) ? $units[$value] : 'unknown'); 
  1566.  
  1567. private static function getDefaultStreamInfo($streams) 
  1568. foreach (array_reverse($streams) as $stream) { 
  1569. if ($stream['default']) { 
  1570. break; 
  1571.  
  1572. $unset = array('default', 'name'); 
  1573. foreach ($unset as $u) { 
  1574. if (isset($stream[$u])) { 
  1575. unset($stream[$u]); 
  1576.  
  1577. $info = $stream; 
  1578. $info['streams'] = $streams; 
  1579.  
  1580. return $info; 
  1581.  
.