ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Matroska.php
Go to the documentation of this file.
1<?php
2
4
10
13// available at http://getid3.sourceforge.net //
14// or http://www.getid3.org //
16// See readme.txt for more details //
18// //
19// module.audio-video.matroska.php //
20// module for analyzing Matroska containers //
21// dependencies: NONE //
22// ///
24
33class Matroska extends BaseHandler
34{
35 const 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.
36 const EBML_ID_SEEKHEAD = 0x014D9B74; // [11][4D][9B][74] -- Contains the position of other level 1 elements.
37 const 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>.
38 const EBML_ID_INFO = 0x0549A966; // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file.
39 const EBML_ID_TRACKS = 0x0654AE6B; // [16][54][AE][6B] -- A top-level block of information with many tracks described.
40 const 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.
41 const EBML_ID_ATTACHMENTS = 0x0941A469; // [19][41][A4][69] -- Contain attached files.
42 const 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.
43 const EBML_ID_CUES = 0x0C53BB6B; // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment.
44 const EBML_ID_CLUSTER = 0x0F43B675; // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure.
45 const EBML_ID_LANGUAGE = 0x02B59C; // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form.
46 const 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).
47 const EBML_ID_DEFAULTDURATION = 0x03E383; // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame.
48 const EBML_ID_CODECNAME = 0x058688; // [25][86][88] -- A human-readable string specifying the codec.
49 const EBML_ID_CODECDOWNLOADURL = 0x06B240; // [26][B2][40] -- A URL to download about the codec used.
50 const EBML_ID_TIMECODESCALE = 0x0AD7B1; // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds).
51 const EBML_ID_COLOURSPACE = 0x0EB524; // [2E][B5][24] -- Same value as in AVI (32 bits).
52 const EBML_ID_GAMMAVALUE = 0x0FB523; // [2F][B5][23] -- Gamma Value.
53 const EBML_ID_CODECSETTINGS = 0x1A9697; // [3A][96][97] -- A string describing the encoding setting used.
54 const EBML_ID_CODECINFOURL = 0x1B4040; // [3B][40][40] -- A URL to find information about the codec used.
55 const EBML_ID_PREVFILENAME = 0x1C83AB; // [3C][83][AB] -- An escaped filename corresponding to the previous segment.
56 const EBML_ID_PREVUID = 0x1CB923; // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits).
57 const EBML_ID_NEXTFILENAME = 0x1E83BB; // [3E][83][BB] -- An escaped filename corresponding to the next segment.
58 const EBML_ID_NEXTUID = 0x1EB923; // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits).
59 const EBML_ID_CONTENTCOMPALGO = 0x0254; // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are:
60 const 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.
61 const EBML_ID_DOCTYPE = 0x0282; // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case).
62 const EBML_ID_DOCTYPEREADVERSION = 0x0285; // [42][85] -- The minimum DocType version an interpreter has to support to read this file.
63 const EBML_ID_EBMLVERSION = 0x0286; // [42][86] -- The version of EBML parser used to create the file.
64 const EBML_ID_DOCTYPEVERSION = 0x0287; // [42][87] -- The version of DocType interpreter used to create the file.
65 const EBML_ID_EBMLMAXIDLENGTH = 0x02F2; // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska).
66 const 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.
67 const EBML_ID_EBMLREADVERSION = 0x02F7; // [42][F7] -- The minimum EBML version a parser has to support to read this file.
68 const EBML_ID_CHAPLANGUAGE = 0x037C; // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form.
69 const EBML_ID_CHAPCOUNTRY = 0x037E; // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains.
70 const EBML_ID_SEGMENTFAMILY = 0x0444; // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits).
71 const EBML_ID_DATEUTC = 0x0461; // [44][61] -- Date of the origin of timecode (value 0), i.e. production date.
72 const EBML_ID_TAGLANGUAGE = 0x047A; // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form.
73 const EBML_ID_TAGDEFAULT = 0x0484; // [44][84] -- Indication to know if this is the default/original language to use for the given tag.
74 const 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.
75 const EBML_ID_TAGSTRING = 0x0487; // [44][87] -- The value of the Tag.
76 const EBML_ID_DURATION = 0x0489; // [44][89] -- Duration of the segment (based on TimecodeScale).
77 const EBML_ID_CHAPPROCESSPRIVATE = 0x050D; // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent.
78 const 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.
79 const EBML_ID_TAGNAME = 0x05A3; // [45][A3] -- The name of the Tag that is going to be stored.
80 const EBML_ID_EDITIONENTRY = 0x05B9; // [45][B9] -- Contains all information about a segment edition.
81 const EBML_ID_EDITIONUID = 0x05BC; // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition.
82 const 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).
83 const EBML_ID_EDITIONFLAGDEFAULT = 0x05DB; // [45][DB] -- If a flag is set (1) the edition should be used as the default one.
84 const EBML_ID_EDITIONFLAGORDERED = 0x05DD; // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced.
85 const EBML_ID_FILEDATA = 0x065C; // [46][5C] -- The data of the file.
86 const EBML_ID_FILEMIMETYPE = 0x0660; // [46][60] -- MIME type of the file.
87 const EBML_ID_FILENAME = 0x066E; // [46][6E] -- Filename of the attached file.
88 const EBML_ID_FILEREFERRAL = 0x0675; // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed.
89 const EBML_ID_FILEDESCRIPTION = 0x067E; // [46][7E] -- A human-friendly name for the attached file.
90 const EBML_ID_FILEUID = 0x06AE; // [46][AE] -- Unique ID representing the file, as random as possible.
91 const 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:
92 const EBML_ID_CONTENTENCKEYID = 0x07E2; // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with.
93 const EBML_ID_CONTENTSIGNATURE = 0x07E3; // [47][E3] -- A cryptographic signature of the contents.
94 const EBML_ID_CONTENTSIGKEYID = 0x07E4; // [47][E4] -- This is the ID of the private key the data was signed with.
95 const 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:
96 const 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:
97 const EBML_ID_MUXINGAPP = 0x0D80; // [4D][80] -- Muxing application or library ("libmatroska-0.4.3").
98 const EBML_ID_SEEK = 0x0DBB; // [4D][BB] -- Contains a single seek entry to an EBML element.
99 const 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.
100 const 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:
101 const EBML_ID_CONTENTENCODINGTYPE = 0x1033; // [50][33] -- A value describing what kind of transformation has been done. Possible values:
102 const 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.
103 const EBML_ID_CONTENTENCRYPTION = 0x1035; // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise.
104 const EBML_ID_CUEREFNUMBER = 0x135F; // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster.
105 const EBML_ID_NAME = 0x136E; // [53][6E] -- A human-readable track name.
106 const EBML_ID_CUEBLOCKNUMBER = 0x1378; // [53][78] -- Number of the Block in the specified Cluster.
107 const 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.
108 const EBML_ID_SEEKID = 0x13AB; // [53][AB] -- The binary ID corresponding to the element name.
109 const EBML_ID_SEEKPOSITION = 0x13AC; // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element).
110 const EBML_ID_STEREOMODE = 0x13B8; // [53][B8] -- Stereo-3D video mode on 2 bits (0: mono, 1: right eye, 2: left eye, 3: both eyes).
111 const EBML_ID_PIXELCROPBOTTOM = 0x14AA; // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content).
112 const EBML_ID_DISPLAYWIDTH = 0x14B0; // [54][B0] -- Width of the video frames to display.
113 const EBML_ID_DISPLAYUNIT = 0x14B2; // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches).
114 const EBML_ID_ASPECTRATIOTYPE = 0x14B3; // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed).
115 const EBML_ID_DISPLAYHEIGHT = 0x14BA; // [54][BA] -- Height of the video frames to display.
116 const EBML_ID_PIXELCROPTOP = 0x14BB; // [54][BB] -- The number of video pixels to remove at the top of the image.
117 const EBML_ID_PIXELCROPLEFT = 0x14CC; // [54][CC] -- The number of video pixels to remove on the left of the image.
118 const EBML_ID_PIXELCROPRIGHT = 0x14DD; // [54][DD] -- The number of video pixels to remove on the right of the image.
119 const 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.
120 const EBML_ID_MAXBLOCKADDITIONID = 0x15EE; // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track.
121 const EBML_ID_WRITINGAPP = 0x1741; // [57][41] -- Writing application ("mkvmerge-0.3.3").
122 const 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.
123 const 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.
124 const EBML_ID_ATTACHEDFILE = 0x21A7; // [61][A7] -- An attached file.
125 const EBML_ID_CONTENTENCODING = 0x2240; // [62][40] -- Settings for one content encoding like compression or encryption.
126 const EBML_ID_BITDEPTH = 0x2264; // [62][64] -- Bits per sample, mostly used for PCM.
127 const EBML_ID_CODECPRIVATE = 0x23A2; // [63][A2] -- Private data only known to the codec.
128 const EBML_ID_TARGETS = 0x23C0; // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment.
129 const EBML_ID_CHAPTERPHYSICALEQUIV = 0x23C3; // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values.
130 const 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.
131 const 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.
132 const 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.
133 const 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.
134 const 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).
135 const EBML_ID_TRACKTRANSLATE = 0x2624; // [66][24] -- The track identification for the given Chapter Codec.
136 const 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.
137 const EBML_ID_TRACKTRANSLATECODEC = 0x26BF; // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
138 const 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.
139 const EBML_ID_SIMPLETAG = 0x27C8; // [67][C8] -- Contains general information about the target.
140 const EBML_ID_TARGETTYPEVALUE = 0x28CA; // [68][CA] -- A number to indicate the logical level of the target (see TargetType).
141 const EBML_ID_CHAPPROCESSCOMMAND = 0x2911; // [69][11] -- Contains all the commands associated to the Atom.
142 const 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).
143 const EBML_ID_CHAPTERTRANSLATE = 0x2924; // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment.
144 const 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.
145 const EBML_ID_CHAPPROCESS = 0x2944; // [69][44] -- Contains all the commands associated to the Atom.
146 const 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.
147 const 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.
148 const EBML_ID_CHAPTERTRANSLATECODEC = 0x29BF; // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
149 const 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.
150 const EBML_ID_CONTENTENCODINGS = 0x2D80; // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption.
151 const 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.
152 const 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.
153 const 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.
154 const EBML_ID_CHAPTERSEGMENTEDITIONUID = 0x2EBC; // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID.
155 const 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.
156 const EBML_ID_TAG = 0x3373; // [73][73] -- Element containing elements specific to Tracks/Chapters.
157 const EBML_ID_SEGMENTFILENAME = 0x3384; // [73][84] -- A filename corresponding to this segment.
158 const EBML_ID_SEGMENTUID = 0x33A4; // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits).
159 const EBML_ID_CHAPTERUID = 0x33C4; // [73][C4] -- A unique ID to identify the Chapter.
160 const 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.
161 const EBML_ID_ATTACHMENTLINK = 0x3446; // [74][46] -- The UID of an attachment that is used by this codec.
162 const 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.
163 const EBML_ID_CHANNELPOSITIONS = 0x347B; // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix.
164 const EBML_ID_OUTPUTSAMPLINGFREQUENCY = 0x38B5; // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques).
165 const EBML_ID_TITLE = 0x3BA9; // [7B][A9] -- General name of the segment.
166 const EBML_ID_CHAPTERDISPLAY = 0x00; // [80] -- Contains all possible strings to use for the chapter display.
167 const 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).
168 const EBML_ID_CHAPSTRING = 0x05; // [85] -- Contains the string to use as the chapter atom.
169 const EBML_ID_CODECID = 0x06; // [86] -- An ID corresponding to the codec, see the codec page for more info.
170 const EBML_ID_FLAGDEFAULT = 0x08; // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference.
171 const 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.
172 const EBML_ID_CLUSTERSLICES = 0x0E; // [8E] -- Contains slices description.
173 const EBML_ID_CHAPTERTRACK = 0x0F; // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply
174 const EBML_ID_CHAPTERTIMESTART = 0x11; // [91] -- Timecode of the start of Chapter (not scaled).
175 const EBML_ID_CHAPTERTIMEEND = 0x12; // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled).
176 const EBML_ID_CUEREFTIME = 0x16; // [96] -- Timecode of the referenced Block.
177 const EBML_ID_CUEREFCLUSTER = 0x17; // [97] -- Position of the Cluster containing the referenced Block.
178 const 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).
179 const EBML_ID_FLAGINTERLACED = 0x1A; // [9A] -- Set if the video is interlaced.
180 const 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.
181 const EBML_ID_FLAGLACING = 0x1C; // [9C] -- Set if the track may contain blocks using lacing.
182 const EBML_ID_CHANNELS = 0x1F; // [9F] -- Numbers of channels in the track.
183 const EBML_ID_CLUSTERBLOCKGROUP = 0x20; // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock.
184 const EBML_ID_CLUSTERBLOCK = 0x21; // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode.
185 const 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.
186 const 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.
187 const 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.
188 const EBML_ID_CLUSTERBLOCKADDITIONAL = 0x25; // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID).
189 const EBML_ID_CLUSTERBLOCKMORE = 0x26; // [A6] -- Contain the BlockAdditional and some parameters.
190 const 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.
191 const EBML_ID_CODECDECODEALL = 0x2A; // [AA] -- The codec can decode potentially damaged data.
192 const EBML_ID_CLUSTERPREVSIZE = 0x2B; // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing.
193 const EBML_ID_TRACKENTRY = 0x2E; // [AE] -- Describes a track with all elements.
194 const EBML_ID_CLUSTERENCRYPTEDBLOCK = 0x2F; // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed).
195 const EBML_ID_PIXELWIDTH = 0x30; // [B0] -- Width of the encoded video frames in pixels.
196 const EBML_ID_CUETIME = 0x33; // [B3] -- Absolute timecode according to the segment time base.
197 const EBML_ID_SAMPLINGFREQUENCY = 0x35; // [B5] -- Sampling frequency in Hz.
198 const EBML_ID_CHAPTERATOM = 0x36; // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks).
199 const EBML_ID_CUETRACKPOSITIONS = 0x37; // [B7] -- Contain positions for different tracks corresponding to the timecode.
200 const EBML_ID_FLAGENABLED = 0x39; // [B9] -- Set if the track is used.
201 const EBML_ID_PIXELHEIGHT = 0x3A; // [BA] -- Height of the encoded video frames in pixels.
202 const EBML_ID_CUEPOINT = 0x3B; // [BB] -- Contains all information relative to a seek point in the segment.
203 const 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.
204 const EBML_ID_CLUSTERBLOCKADDITIONID = 0x4B; // [CB] -- The ID of the BlockAdditional element (0 is the main Block).
205 const 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.
206 const 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).
207 const EBML_ID_CLUSTERDELAY = 0x4E; // [CE] -- The (scaled) delay to apply to the element.
208 const EBML_ID_CLUSTERDURATION = 0x4F; // [CF] -- The (scaled) duration to apply to the element.
209 const 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).
210 const EBML_ID_CUEREFERENCE = 0x5B; // [DB] -- The Clusters containing the required referenced Blocks.
211 const EBML_ID_VIDEO = 0x60; // [E0] -- Video settings.
212 const EBML_ID_AUDIO = 0x61; // [E1] -- Audio settings.
213 const 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.
214 const 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.
215 const 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.
216 const 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.
217 const EBML_ID_CLUSTERTIMECODE = 0x67; // [E7] -- Absolute timecode of the cluster (based on TimecodeScale).
218 const EBML_ID_CLUSTERBLOCKADDID = 0x6E; // [EE] -- An ID to identify the BlockAdditional level.
219 const EBML_ID_CUECLUSTERPOSITION = 0x71; // [F1] -- The position of the Cluster containing the required Block.
220 const EBML_ID_CUETRACK = 0x77; // [F7] -- The track for which a position is given.
221 const 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.
222 const 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.
223 const EBML_ID_CLUSTERREFERENCEVIRTUAL = 0x7D; // [FD] -- Relative position of the data that should be in position of the virtual block.
224
225 // public options
230 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]
235 public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE]
236
237 // private parser settings/placeholders
242 private $EBMLbuffer = '';
257 private $current_offset = 0;
262 private $unuseful_elements = array(self::EBML_ID_CRC32, self::EBML_ID_VOID);
263
268 public function analyze()
269 {
270 $info = &$this->getid3->info;
271
272 // parse container
273 try {
274 $this->parseEBML($info);
275 } catch (DefaultException $e) {
276 $info['error'][] = 'EBML parser: '.$e->getMessage();
277 }
278
279 // calculate playtime
280 if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
281 foreach ($info['matroska']['info'] as $key => $infoarray) {
282 if (isset($infoarray['Duration'])) {
283 // TimecodeScale is how many nanoseconds each Duration unit is
284 $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
285 break;
286 }
287 }
288 }
289
290 // extract tags
291 if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
292 foreach ($info['matroska']['tags'] as $key => $infoarray) {
293 $this->ExtractCommentsSimpleTag($infoarray);
294 }
295 }
296
297 // process tracks
298 if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
299 foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) {
300
301 $track_info = array();
302 $track_info['dataformat'] = self::MatroskaCodecIDtoCommonName($trackarray['CodecID']);
303 $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true);
304 if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; }
305
306 switch ($trackarray['TrackType']) {
307
308 case 1: // Video
309 $track_info['resolution_x'] = $trackarray['PixelWidth'];
310 $track_info['resolution_y'] = $trackarray['PixelHeight'];
311 if (isset($trackarray['DisplayWidth'])) { $track_info['display_x'] = $trackarray['DisplayWidth']; }
312 if (isset($trackarray['DisplayHeight'])) { $track_info['display_y'] = $trackarray['DisplayHeight']; }
313 if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); }
314 if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }
315
316 switch ($trackarray['CodecID']) {
317 case 'V_MS/VFW/FOURCC':
318 if (!class_exists('GetId3\Module\AudioVideo\Riff')) {
319 $this->getid3->warning('Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "' . str_replace('_', DIRECTORY_SEPARATOR, 'GetId3\Module\AudioVideo\Riff') . '.php"');
320 break;
321 }
322 $parsed = Riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
323 $track_info['codec'] = Riff::RIFFfourccLookup($parsed['fourcc']);
324 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
325 break;
326
327 /*case 'V_MPEG4/ISO/AVC':
328 $h264['profile'] = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1));
329 $h264['level'] = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1));
330 $rn = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1));
331 $h264['NALUlength'] = ($rn & 3) + 1;
332 $rn = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1));
333 $nsps = ($rn & 31);
334 $offset = 6;
335 for ($i = 0; $i < $nsps; $i ++) {
336 $length = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2));
337 $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length);
338 $offset += 2 + $length;
339 }
340 $npps = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1));
341 $offset += 1;
342 for ($i = 0; $i < $npps; $i ++) {
343 $length = GetId3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2));
344 $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length);
345 $offset += 2 + $length;
346 }
347 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264;
348 break;*/
349 }
350
351 $info['video']['streams'][] = $track_info;
352 break;
353
354 case 2: // Audio
355 $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0);
356 $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1);
357 $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng');
358 if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; }
359 if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }
360
361 switch ($trackarray['CodecID']) {
362 case 'A_PCM/INT/LIT':
363 case 'A_PCM/INT/BIG':
364 $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
365 break;
366
367 case 'A_AC3':
368 case 'A_DTS':
369 case 'A_MPEG/L3':
370 case 'A_MPEG/L2':
371 case 'A_FLAC':
372 $class = 'GetId3\\Module\\Audio\\' . ucfirst($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']);
373 if (!class_exists($class)) {
374 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.'.$track_info['dataformat'].'.php"');
375 break;
376 }
377
378 if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
379 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set');
380 break;
381 }
382
383 // create temp instance
384 $getid3_temp = new GetId3Core();
385 if ($track_info['dataformat'] != 'flac') {
386 $getid3_temp->openfile($this->getid3->filename);
387 }
388 $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
389 if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') {
390 $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
391 }
392
393 // analyze
394 $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat'];
395 $getid3_audio = new $class($getid3_temp, __CLASS__);
396 if ($track_info['dataformat'] == 'flac') {
397 $getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
398 } else {
399 $getid3_audio->analyze();
400 }
401 if (!empty($getid3_temp->info[$header_data_key])) {
402 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
403 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
404 foreach ($getid3_temp->info['audio'] as $key => $value) {
405 $track_info[$key] = $value;
406 }
407 }
408 } else {
409 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']);
410 }
411
412 // copy errors and warnings
413 if (!empty($getid3_temp->info['error'])) {
414 foreach ($getid3_temp->info['error'] as $newerror) {
415 $this->getid3->warning($class.'() says: ['.$newerror.']');
416 }
417 }
418 if (!empty($getid3_temp->info['warning'])) {
419 foreach ($getid3_temp->info['warning'] as $newerror) {
420 if ($track_info['dataformat'] == 'mp3' && preg_match('/^Probable truncated file: expecting \d+ bytes of audio data, only found \d+ \‍(short by \d+ bytes\‍)$/', $newerror)) {
421 // LAME/Xing header is probably set, but audio data is chunked into Matroska file and near-impossible to verify if audio stream is complete, so ignore useless warning
422 continue;
423 }
424 $this->getid3->warning($class.'() says: ['.$newerror.']');
425 }
426 }
427 unset($getid3_temp, $getid3_audio);
428 break;
429
430 case 'A_AAC':
431 case 'A_AAC/MPEG2/LC':
432 case 'A_AAC/MPEG4/LC':
433 case 'A_AAC/MPEG4/LC/SBR':
434 $this->getid3->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
435 break;
436
437 case 'A_VORBIS':
438 if (!isset($trackarray['CodecPrivate'])) {
439 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set');
440 break;
441 }
442 $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1);
443 if ($vorbis_offset === false) {
444 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword');
445 break;
446 }
447 $vorbis_offset -= 1;
448
449 if (!class_exists('GetId3\\Module\\Audio\\Ogg')) {
450 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "GetId3\\Module\\Audio\\Ogg.php"');
451 break;
452 }
453
454 // create temp instance
455 $getid3_temp = new GetId3Core();
456
457 // analyze
458 $getid3_ogg = new Ogg($getid3_temp);
459 $oggpageinfo['page_seqno'] = 0;
460 $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo);
461 if (!empty($getid3_temp->info['ogg'])) {
462 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
463 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
464 foreach ($getid3_temp->info['audio'] as $key => $value) {
465 $track_info[$key] = $value;
466 }
467 }
468 }
469
470 // copy errors and warnings
471 if (!empty($getid3_temp->info['error'])) {
472 foreach ($getid3_temp->info['error'] as $newerror) {
473 $this->getid3->warning('getid3_ogg() says: ['.$newerror.']');
474 }
475 }
476 if (!empty($getid3_temp->info['warning'])) {
477 foreach ($getid3_temp->info['warning'] as $newerror) {
478 $this->getid3->warning('getid3_ogg() says: ['.$newerror.']');
479 }
480 }
481
482 if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) {
483 $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal'];
484 }
485 unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset);
486 break;
487
488 case 'A_MS/ACM':
489 if (!class_exists('GetId3\Module\AudioVideo\Riff')) {
490 $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "' . str_replace('_', DIRECTORY_SEPARATOR, 'GetId3\Module\AudioVideo\Riff') . '.php"');
491 break;
492 }
493
494 $parsed = Riff::RIFFparseWAVEFORMATex($trackarray['CodecPrivate']);
495 foreach ($parsed as $key => $value) {
496 if ($key != 'raw') {
497 $track_info[$key] = $value;
498 }
499 }
500 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
501 break;
502
503 default:
504 $this->getid3->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"');
505 }
506
507 $info['audio']['streams'][] = $track_info;
508 break;
509 }
510 }
511
512 if (!empty($info['video']['streams'])) {
513 $info['video'] = self::getDefaultStreamInfo($info['video']['streams']);
514 }
515 if (!empty($info['audio']['streams'])) {
516 $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']);
517 }
518 }
519
520 // determine mime type
521 if (!empty($info['video']['streams'])) {
522 $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska');
523 } elseif (!empty($info['audio']['streams'])) {
524 $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska');
525 } elseif (isset($info['mime_type'])) {
526 unset($info['mime_type']);
527 }
528
529 return true;
530 }
531
533
540 private function parseEBML(&$info)
541 {
542 $this->current_offset = $info['avdataoffset'];
543
544 while ($this->getEBMLelement($top_element, $info['avdataend'])) {
545 switch ($top_element['id']) {
546
548 $info['fileformat'] = 'matroska';
549 $info['matroska']['header']['offset'] = $top_element['offset'];
550 $info['matroska']['header']['length'] = $top_element['length'];
551
552 while ($this->getEBMLelement($element_data, $top_element['end'], true)) {
553 switch ($element_data['id']) {
554
561 $element_data['data'] = Helper::BigEndian2Int($element_data['data']);
562 break;
563
565 $element_data['data'] = Helper::trimNullByte($element_data['data']);
566 $info['matroska']['doctype'] = $element_data['data'];
567 break;
568
569 case self::EBML_ID_CRC32: // not useful, ignore
570 $this->current_offset = $element_data['end'];
571 unset($element_data);
572 break;
573
574 default:
575 $this->unhandledElement('header', __LINE__, $element_data);
576 }
577 if (!empty($element_data)) {
578 unset($element_data['offset'], $element_data['end']);
579 $info['matroska']['header']['elements'][] = $element_data;
580 }
581 }
582 break;
583
585 $info['matroska']['segment'][0]['offset'] = $top_element['offset'];
586 $info['matroska']['segment'][0]['length'] = $top_element['length'];
587
588 while ($this->getEBMLelement($element_data, $top_element['end'])) {
589 if ($element_data['id'] != self::EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
590 $info['matroska']['segments'][] = $element_data;
591 }
592 switch ($element_data['id']) {
593
594 case self::EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements.
595
596 while ($this->getEBMLelement($seek_entry, $element_data['end'])) {
597 switch ($seek_entry['id']) {
598
599 case self::EBML_ID_SEEK: // Contains a single seek entry to an EBML element
600 while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) {
601
602 switch ($sub_seek_entry['id']) {
603
605 $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']);
606 $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']);
607 break;
608
610 $seek_entry['target_offset'] = $element_data['offset'] + Helper::BigEndian2Int($sub_seek_entry['data']);
611 break;
612
613 default:
614 $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); }
615 }
616
617 if ($seek_entry['target_id'] != self::EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
618 $info['matroska']['seek'][] = $seek_entry;
619 }
620 break;
621
622 default:
623 $this->unhandledElement('seekhead', __LINE__, $seek_entry);
624 }
625 }
626 break;
627
628 case self::EBML_ID_TRACKS: // A top-level block of information with many tracks described.
629 $info['matroska']['tracks'] = $element_data;
630
631 while ($this->getEBMLelement($track_entry, $element_data['end'])) {
632 switch ($track_entry['id']) {
633
634 case self::EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements.
635
636 while ($this->getEBMLelement($subelement, $track_entry['end'], array(self::EBML_ID_VIDEO, self::EBML_ID_AUDIO, self::EBML_ID_CONTENTENCODINGS))) {
637 switch ($subelement['id']) {
638
645 case self::EBML_ID_DEFAULTDURATION: // nanoseconds per frame
646 $track_entry[$subelement['id_name']] = Helper::BigEndian2Int($subelement['data']);
647 break;
648
650 $track_entry[$subelement['id_name']] = Helper::BigEndian2Float($subelement['data']);
651 break;
652
657 $track_entry[$subelement['id_name']] = Helper::trimNullByte($subelement['data']);
658 break;
659
661 $track_entry[$subelement['id_name']] = $subelement['data'];
662 break;
663
669 $track_entry[$subelement['id_name']] = (bool) Helper::BigEndian2Int($subelement['data']);
670 break;
671
673
674 while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
675 switch ($sub_subelement['id']) {
676
688 $track_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
689 break;
690
692 $track_entry[$sub_subelement['id_name']] = (bool) Helper::BigEndian2Int($sub_subelement['data']);
693 break;
694
696 $track_entry[$sub_subelement['id_name']] = Helper::BigEndian2Float($sub_subelement['data']);
697 break;
698
700 $track_entry[$sub_subelement['id_name']] = Helper::trimNullByte($sub_subelement['data']);
701 break;
702
703 default:
704 $this->unhandledElement('track.video', __LINE__, $sub_subelement);
705 }
706 }
707 break;
708
710
711 while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
712 switch ($sub_subelement['id']) {
713
716 $track_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
717 break;
718
721 $track_entry[$sub_subelement['id_name']] = Helper::BigEndian2Float($sub_subelement['data']);
722 break;
723
725 $track_entry[$sub_subelement['id_name']] = Helper::trimNullByte($sub_subelement['data']);
726 break;
727
728 default:
729 $this->unhandledElement('track.audio', __LINE__, $sub_subelement);
730 }
731 }
732 break;
733
735
736 while ($this->getEBMLelement($sub_subelement, $subelement['end'])) {
737 switch ($sub_subelement['id']) {
738
740
741 while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(self::EBML_ID_CONTENTCOMPRESSION, self::EBML_ID_CONTENTENCRYPTION))) {
742 switch ($sub_sub_subelement['id']) {
743
747 $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_subelement['data']);
748 break;
749
751
752 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
753 switch ($sub_sub_sub_subelement['id']) {
754
756 $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_sub_subelement['data']);
757 break;
758
760 $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
761 break;
762
763 default:
764 $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
765 }
766 }
767 break;
768
770
771 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
772 switch ($sub_sub_sub_subelement['id']) {
773
777 $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_sub_subelement['data']);
778 break;
779
783 $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
784 break;
785
786 default:
787 $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
788 }
789 }
790 break;
791
792 default:
793 $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement);
794 }
795 }
796 break;
797
798 default:
799 $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement);
800 }
801 }
802 break;
803
804 default:
805 $this->unhandledElement('track', __LINE__, $subelement);
806 }
807 }
808
809 $info['matroska']['tracks']['tracks'][] = $track_entry;
810 break;
811
812 default:
813 $this->unhandledElement('tracks', __LINE__, $track_entry);
814 }
815 }
816 break;
817
818 case self::EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file.
819 $info_entry = array();
820
821 while ($this->getEBMLelement($subelement, $element_data['end'], true)) {
822 switch ($subelement['id']) {
823
825 $info_entry[$subelement['id_name']] = Helper::BigEndian2Int($subelement['data']);
826 break;
827
829 $info_entry[$subelement['id_name']] = Helper::BigEndian2Float($subelement['data']);
830 break;
831
833 $info_entry[$subelement['id_name']] = Helper::BigEndian2Int($subelement['data']);
834 $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]);
835 break;
836
840 $info_entry[$subelement['id_name']] = Helper::trimNullByte($subelement['data']);
841 break;
842
844 $info_entry[$subelement['id_name']][] = Helper::trimNullByte($subelement['data']);
845 break;
846
853 $info_entry[$subelement['id_name']] = Helper::trimNullByte($subelement['data']);
854 $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']];
855 break;
856
858 $chaptertranslate_entry = array();
859
860 while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
861 switch ($sub_subelement['id']) {
862
864 $chaptertranslate_entry[$sub_subelement['id_name']][] = Helper::BigEndian2Int($sub_subelement['data']);
865 break;
866
868 $chaptertranslate_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
869 break;
870
872 $chaptertranslate_entry[$sub_subelement['id_name']] = Helper::trimNullByte($sub_subelement['data']);
873 break;
874
875 default:
876 $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement);
877 }
878 }
879 $info_entry[$subelement['id_name']] = $chaptertranslate_entry;
880 break;
881
882 default:
883 $this->unhandledElement('info', __LINE__, $subelement);
884 }
885 }
886 $info['matroska']['info'][] = $info_entry;
887 break;
888
889 case self::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.
890 if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway
891 $this->current_offset = $element_data['end'];
892 break;
893 }
894 $cues_entry = array();
895
896 while ($this->getEBMLelement($subelement, $element_data['end'])) {
897 switch ($subelement['id']) {
898
900 $cuepoint_entry = array();
901
902 while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(self::EBML_ID_CUETRACKPOSITIONS))) {
903 switch ($sub_subelement['id']) {
904
906 $cuetrackpositions_entry = array();
907
908 while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
909 switch ($sub_sub_subelement['id']) {
910
915 $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_subelement['data']);
916 break;
917
918 default:
919 $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement);
920 }
921 }
922 $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry;
923 break;
924
926 $cuepoint_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
927 break;
928
929 default:
930 $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement);
931 }
932 }
933 $cues_entry[] = $cuepoint_entry;
934 break;
935
936 default:
937 $this->unhandledElement('cues', __LINE__, $subelement);
938 }
939 }
940 $info['matroska']['cues'] = $cues_entry;
941 break;
942
943 case self::EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters.
944 $tags_entry = array();
945
946 while ($this->getEBMLelement($subelement, $element_data['end'], false)) {
947 switch ($subelement['id']) {
948
950 $tag_entry = array();
951
952 while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) {
953 switch ($sub_subelement['id']) {
954
956 $targets_entry = array();
957
958 while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
959 switch ($sub_sub_subelement['id']) {
960
962 $targets_entry[$sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_subelement['data']);
963 $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::MatroskaTargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]);
964 break;
965
967 $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
968 break;
969
974 $targets_entry[$sub_sub_subelement['id_name']][] = Helper::BigEndian2Int($sub_sub_subelement['data']);
975 break;
976
977 default:
978 $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement);
979 }
980 }
981 $tag_entry[$sub_subelement['id_name']] = $targets_entry;
982 break;
983
985 $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']);
986 break;
987
988 default:
989 $this->unhandledElement('tags.tag', __LINE__, $sub_subelement);
990 }
991 }
992 $tags_entry[] = $tag_entry;
993 break;
994
995 default:
996 $this->unhandledElement('tags', __LINE__, $subelement);
997 }
998 }
999 $info['matroska']['tags'] = $tags_entry;
1000 break;
1001
1002 case self::EBML_ID_ATTACHMENTS: // Contain attached files.
1003
1004 while ($this->getEBMLelement($subelement, $element_data['end'])) {
1005 switch ($subelement['id']) {
1006
1008 $attachedfile_entry = array();
1009
1010 while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(self::EBML_ID_FILEDATA))) {
1011 switch ($sub_subelement['id']) {
1012
1016 $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data'];
1017 break;
1018
1020 $attachedfile_entry['data_offset'] = $this->current_offset;
1021 $attachedfile_entry['data_length'] = $sub_subelement['length'];
1022
1023 $this->saveAttachment(
1024 $attachedfile_entry[$sub_subelement['id_name']],
1025 $attachedfile_entry['FileName'],
1026 $attachedfile_entry['data_offset'],
1027 $attachedfile_entry['data_length']);
1028
1029 $this->current_offset = $sub_subelement['end'];
1030 break;
1031
1033 $attachedfile_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
1034 break;
1035
1036 default:
1037 $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement);
1038 }
1039 }
1040 if (!empty($attachedfile_entry['FileData']) && !empty($attachedfile_entry['FileMimeType']) && preg_match('#^image/#i', $attachedfile_entry['FileMimeType'])) {
1041 if ($this->getid3->option_save_attachments === GetId3Core::ATTACHMENTS_INLINE) {
1042 $attachedfile_entry['data'] = $attachedfile_entry['FileData'];
1043 $attachedfile_entry['image_mime'] = $attachedfile_entry['FileMimeType'];
1044 $info['matroska']['comments']['picture'][] = array('data' => $attachedfile_entry['data'], 'image_mime' => $attachedfile_entry['image_mime'], 'filename' => $attachedfile_entry['FileName']);
1045 unset($attachedfile_entry['FileData'], $attachedfile_entry['FileMimeType']);
1046 }
1047 }
1048 if (!empty($attachedfile_entry['image_mime']) && preg_match('#^image/#i', $attachedfile_entry['image_mime'])) {
1049 // don't add a second copy of attached images, which are grouped under the standard location [comments][picture]
1050 } else {
1051 $info['matroska']['attachments'][] = $attachedfile_entry;
1052 }
1053 break;
1054
1055 default:
1056 $this->unhandledElement('attachments', __LINE__, $subelement);
1057 }
1058 }
1059 break;
1060
1062
1063 while ($this->getEBMLelement($subelement, $element_data['end'])) {
1064 switch ($subelement['id']) {
1065
1067 $editionentry_entry = array();
1068
1069 while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(self::EBML_ID_CHAPTERATOM))) {
1070 switch ($sub_subelement['id']) {
1071
1073 $editionentry_entry[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
1074 break;
1075
1079 $editionentry_entry[$sub_subelement['id_name']] = (bool) Helper::BigEndian2Int($sub_subelement['data']);
1080 break;
1081
1083 $chapteratom_entry = array();
1084
1085 while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(self::EBML_ID_CHAPTERTRACK, self::EBML_ID_CHAPTERDISPLAY))) {
1086 switch ($sub_sub_subelement['id']) {
1087
1090 $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
1091 break;
1092
1095 $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool) Helper::BigEndian2Int($sub_sub_subelement['data']);
1096 break;
1097
1101 $chapteratom_entry[$sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_subelement['data']);
1102 break;
1103
1105 $chaptertrack_entry = array();
1106
1107 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
1108 switch ($sub_sub_sub_subelement['id']) {
1109
1111 $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = Helper::BigEndian2Int($sub_sub_sub_subelement['data']);
1112 break;
1113
1114 default:
1115 $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement);
1116 }
1117 }
1118 $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry;
1119 break;
1120
1122 $chapterdisplay_entry = array();
1123
1124 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
1125 switch ($sub_sub_sub_subelement['id']) {
1126
1130 $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
1131 break;
1132
1133 default:
1134 $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement);
1135 }
1136 }
1137 $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry;
1138 break;
1139
1140 default:
1141 $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement);
1142 }
1143 }
1144 $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry;
1145 break;
1146
1147 default:
1148 $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement);
1149 }
1150 }
1151 $info['matroska']['chapters'][] = $editionentry_entry;
1152 break;
1153
1154 default:
1155 $this->unhandledElement('chapters', __LINE__, $subelement);
1156 }
1157 }
1158 break;
1159
1160 case self::EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure.
1161 $cluster_entry = array();
1162
1163 while ($this->getEBMLelement($subelement, $element_data['end'], array(self::EBML_ID_CLUSTERSILENTTRACKS, self::EBML_ID_CLUSTERBLOCKGROUP, self::EBML_ID_CLUSTERSIMPLEBLOCK))) {
1164 switch ($subelement['id']) {
1165
1169 $cluster_entry[$subelement['id_name']] = Helper::BigEndian2Int($subelement['data']);
1170 break;
1171
1173 $cluster_silent_tracks = array();
1174
1175 while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
1176 switch ($sub_subelement['id']) {
1177
1179 $cluster_silent_tracks[] = Helper::BigEndian2Int($sub_subelement['data']);
1180 break;
1181
1182 default:
1183 $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement);
1184 }
1185 }
1186 $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks;
1187 break;
1188
1190 $cluster_block_group = array('offset' => $this->current_offset);
1191
1192 while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(self::EBML_ID_CLUSTERBLOCK))) {
1193 switch ($sub_subelement['id']) {
1194
1196 $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, self::EBML_ID_CLUSTERBLOCK, $info);
1197 break;
1198
1199 case self::EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int
1200 case self::EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int
1201 $cluster_block_group[$sub_subelement['id_name']] = Helper::BigEndian2Int($sub_subelement['data']);
1202 break;
1203
1204 case self::EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int
1205 $cluster_block_group[$sub_subelement['id_name']][] = Helper::BigEndian2Int($sub_subelement['data'], false, true);
1206 break;
1207
1209 $cluster_block_group[$sub_subelement['id_name']] = Helper::trimNullByte($sub_subelement['data']);
1210 break;
1211
1212 default:
1213 $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement);
1214 }
1215 }
1216 $cluster_entry[$subelement['id_name']][] = $cluster_block_group;
1217 break;
1218
1220 $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, self::EBML_ID_CLUSTERSIMPLEBLOCK, $info);
1221 break;
1222
1223 default:
1224 $this->unhandledElement('cluster', __LINE__, $subelement);
1225 }
1226 $this->current_offset = $subelement['end'];
1227 }
1228 if (!self::$hide_clusters) {
1229 $info['matroska']['cluster'][] = $cluster_entry;
1230 }
1231
1232 // check to see if all the data we need exists already, if so, break out of the loop
1233 if (!self::$parse_whole_file) {
1234 if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
1235 if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
1236 if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) {
1237 return;
1238 }
1239 }
1240 }
1241 }
1242 break;
1243
1244 default:
1245 $this->unhandledElement('segment', __LINE__, $element_data);
1246 }
1247 }
1248 break;
1249
1250 default:
1251 $this->unhandledElement('root', __LINE__, $top_element);
1252 }
1253 }
1254 }
1255
1261 private function EnsureBufferHasEnoughData($min_data = 1024)
1262 {
1263 if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) {
1264
1265 if (!Helper::intValueSupported($this->current_offset + $this->getid3->fread_buffer_size())) {
1266 $this->getid3->info['error'][] = 'EBML parser: cannot read past '.$this->current_offset;
1267
1268 return false;
1269 }
1270
1271 $this->fseek($this->current_offset);
1272 $this->EBMLbuffer_offset = $this->current_offset;
1273 $this->EBMLbuffer = $this->fread(max($min_data, $this->getid3->fread_buffer_size()));
1274 $this->EBMLbuffer_length = strlen($this->EBMLbuffer);
1275
1276 if ($this->EBMLbuffer_length == 0 && $this->feof()) {
1277 $this->getid3->info['error'][] = 'EBML parser: ran out of file at offset '.$this->current_offset;
1278
1279 return false;
1280 }
1281 }
1282
1283 return true;
1284 }
1285
1291 private function readEBMLint()
1292 {
1293 $actual_offset = $this->current_offset - $this->EBMLbuffer_offset;
1294
1295 // get length of integer
1296 $first_byte_int = ord($this->EBMLbuffer[$actual_offset]);
1297 if (0x80 & $first_byte_int) {
1298 $length = 1;
1299 } elseif (0x40 & $first_byte_int) {
1300 $length = 2;
1301 } elseif (0x20 & $first_byte_int) {
1302 $length = 3;
1303 } elseif (0x10 & $first_byte_int) {
1304 $length = 4;
1305 } elseif (0x08 & $first_byte_int) {
1306 $length = 5;
1307 } elseif (0x04 & $first_byte_int) {
1308 $length = 6;
1309 } elseif (0x02 & $first_byte_int) {
1310 $length = 7;
1311 } elseif (0x01 & $first_byte_int) {
1312 $length = 8;
1313 } else {
1314 throw new DefaultException('invalid EBML integer (leading 0x00) at '.$this->current_offset);
1315 }
1316
1317 // read
1318 $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length));
1319 $this->current_offset += $length;
1320
1321 return $int_value;
1322 }
1323
1329 private function readEBMLelementData($length)
1330 {
1331 $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length);
1332 $this->current_offset += $length;
1333
1334 return $data;
1335 }
1336
1344 private function getEBMLelement(&$element, $parent_end, $get_data = false)
1345 {
1346 if ($this->current_offset >= $parent_end) {
1347 return false;
1348 }
1349
1350 if (!$this->EnsureBufferHasEnoughData()) {
1351 $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information
1352
1353 return false;
1354 }
1355
1356 $element = array();
1357
1358 // set offset
1359 $element['offset'] = $this->current_offset;
1360
1361 // get ID
1362 $element['id'] = $this->readEBMLint();
1363
1364 // get name
1365 $element['id_name'] = self::EBMLidName($element['id']);
1366
1367 // get length
1368 $element['length'] = $this->readEBMLint();
1369
1370 // get end offset
1371 $element['end'] = $this->current_offset + $element['length'];
1372
1373 // get raw data
1374 $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id']));
1375 if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) {
1376 $element['data'] = $this->readEBMLelementData($element['length'], $element);
1377 }
1378
1379 return true;
1380 }
1381
1388 private function unhandledElement($type, $line, $element)
1389 {
1390 // warn only about unknown and missed elements, not about unuseful
1391 if (!in_array($element['id'], $this->unuseful_elements)) {
1392 $this->getid3->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']);
1393 }
1394
1395 // increase offset for unparsed elements
1396 if (!isset($element['data'])) {
1397 $this->current_offset = $element['end'];
1398 }
1399 }
1400
1406 private function ExtractCommentsSimpleTag($SimpleTagArray)
1407 {
1408 if (!empty($SimpleTagArray['SimpleTag'])) {
1409 foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) {
1410 if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) {
1411 $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString'];
1412 }
1413 if (!empty($SimpleTagData['SimpleTag'])) {
1414 $this->ExtractCommentsSimpleTag($SimpleTagData);
1415 }
1416 }
1417 }
1418
1419 return true;
1420 }
1421
1427 private function HandleEMBLSimpleTag($parent_end)
1428 {
1429 $simpletag_entry = array();
1430
1431 while ($this->getEBMLelement($element, $parent_end, array(self::EBML_ID_SIMPLETAG))) {
1432 switch ($element['id']) {
1433
1438 $simpletag_entry[$element['id_name']] = $element['data'];
1439 break;
1440
1442 $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']);
1443 break;
1444
1446 $simpletag_entry[$element['id_name']] = (bool) Helper::BigEndian2Int($element['data']);
1447 break;
1448
1449 default:
1450 $this->unhandledElement('tag.simpletag', __LINE__, $element);
1451 }
1452 }
1453
1454 return $simpletag_entry;
1455 }
1456
1466 private function HandleEMBLClusterBlock($element, $block_type, &$info)
1467 {
1468 $block_data = array();
1469 $block_data['tracknumber'] = $this->readEBMLint();
1470 $block_data['timecode'] = Helper::BigEndian2Int($this->readEBMLelementData(2), false, true);
1471 $block_data['flags_raw'] = Helper::BigEndian2Int($this->readEBMLelementData(1));
1472
1473 if ($block_type == self::EBML_ID_CLUSTERSIMPLEBLOCK) {
1474 $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7);
1475 //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4);
1476 } else {
1477 //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4);
1478 }
1479 $block_data['flags']['invisible'] = (bool) (($block_data['flags_raw'] & 0x08) >> 3);
1480 $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing
1481 if ($block_type == self::EBML_ID_CLUSTERSIMPLEBLOCK) {
1482 $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01));
1483 } else {
1484 //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0);
1485 }
1486 $block_data['flags']['lacing_type'] = self::MatroskaBlockLacingType($block_data['flags']['lacing']);
1487
1488 // Lace (when lacing bit is set)
1489 if ($block_data['flags']['lacing'] > 0) {
1490 $block_data['lace_frames'] = Helper::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8)
1491 if ($block_data['flags']['lacing'] != 0x02) {
1492 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).
1493 if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing
1494 $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.
1495 } else { // Xiph lacing
1496 $block_data['lace_frames_size'][$i] = 0;
1497 do {
1499 $block_data['lace_frames_size'][$i] += $size;
1500 } while ($size == 255);
1501 }
1502 }
1503 if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly
1504 $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']);
1505 }
1506 }
1507 }
1508
1509 if (!isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) {
1510 $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset;
1511 $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset;
1512 //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0;
1513 }
1514 //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'];
1515 //$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);
1516
1517 // set offset manually
1518 $this->current_offset = $element['end'];
1519
1520 return $block_data;
1521 }
1522
1529 private static function EBML2Int($EBMLstring)
1530 {
1531 // Element ID coded with an UTF-8 like system:
1532 // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X)
1533 // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX)
1534 // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX)
1535 // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX)
1536 // Values with all x at 0 and 1 are reserved (hence the -2).
1537
1538 // Data size, in octets, is also coded with an UTF-8 like system :
1539 // 1xxx xxxx - value 0 to 2^7-2
1540 // 01xx xxxx xxxx xxxx - value 0 to 2^14-2
1541 // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2
1542 // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2
1543 // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2
1544 // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2
1545 // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2
1546 // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2
1547
1548 $first_byte_int = ord($EBMLstring[0]);
1549 if (0x80 & $first_byte_int) {
1550 $EBMLstring[0] = chr($first_byte_int & 0x7F);
1551 } elseif (0x40 & $first_byte_int) {
1552 $EBMLstring[0] = chr($first_byte_int & 0x3F);
1553 } elseif (0x20 & $first_byte_int) {
1554 $EBMLstring[0] = chr($first_byte_int & 0x1F);
1555 } elseif (0x10 & $first_byte_int) {
1556 $EBMLstring[0] = chr($first_byte_int & 0x0F);
1557 } elseif (0x08 & $first_byte_int) {
1558 $EBMLstring[0] = chr($first_byte_int & 0x07);
1559 } elseif (0x04 & $first_byte_int) {
1560 $EBMLstring[0] = chr($first_byte_int & 0x03);
1561 } elseif (0x02 & $first_byte_int) {
1562 $EBMLstring[0] = chr($first_byte_int & 0x01);
1563 } elseif (0x01 & $first_byte_int) {
1564 $EBMLstring[0] = chr($first_byte_int & 0x00);
1565 }
1566
1567 return Helper::BigEndian2Int($EBMLstring);
1568 }
1569
1575 private static function EBMLdate2unix($EBMLdatestamp)
1576 {
1577 // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
1578 // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
1579 return round(($EBMLdatestamp / 1000000000) + 978307200);
1580 }
1581
1590 {
1591 static $MatroskaTargetTypeValue = array();
1592 if (empty($MatroskaTargetTypeValue)) {
1593 $MatroskaTargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies
1594 $MatroskaTargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement)
1595 $MatroskaTargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie
1596 $MatroskaTargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts
1597 $MatroskaTargetTypeValue[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)
1598 $MatroskaTargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together
1599 $MatroskaTargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items
1600 }
1601
1602 return (isset($MatroskaTargetTypeValue[$target_type]) ? $MatroskaTargetTypeValue[$target_type] : $target_type);
1603 }
1604
1612 public static function MatroskaBlockLacingType($lacingtype)
1613 {
1614 static $MatroskaBlockLacingType = array();
1615 if (empty($MatroskaBlockLacingType)) {
1616 $MatroskaBlockLacingType[0x00] = 'no lacing';
1617 $MatroskaBlockLacingType[0x01] = 'Xiph lacing';
1618 $MatroskaBlockLacingType[0x02] = 'fixed-size lacing';
1619 $MatroskaBlockLacingType[0x03] = 'EBML lacing';
1620 }
1621
1622 return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype);
1623 }
1624
1632 public static function MatroskaCodecIDtoCommonName($codecid)
1633 {
1634 static $MatroskaCodecIDlist = array();
1635 if (empty($MatroskaCodecIDlist)) {
1636 $MatroskaCodecIDlist['A_AAC'] = 'aac';
1637 $MatroskaCodecIDlist['A_AAC/MPEG2/LC'] = 'aac';
1638 $MatroskaCodecIDlist['A_AC3'] = 'ac3';
1639 $MatroskaCodecIDlist['A_DTS'] = 'dts';
1640 $MatroskaCodecIDlist['A_FLAC'] = 'flac';
1641 $MatroskaCodecIDlist['A_MPEG/L1'] = 'mp1';
1642 $MatroskaCodecIDlist['A_MPEG/L2'] = 'mp2';
1643 $MatroskaCodecIDlist['A_MPEG/L3'] = 'mp3';
1644 $MatroskaCodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian
1645 $MatroskaCodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian
1646 $MatroskaCodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music
1647 $MatroskaCodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2
1648 $MatroskaCodecIDlist['A_VORBIS'] = 'vorbis';
1649 $MatroskaCodecIDlist['V_MPEG1'] = 'mpeg';
1650 $MatroskaCodecIDlist['V_THEORA'] = 'theora';
1651 $MatroskaCodecIDlist['V_REAL/RV40'] = 'real';
1652 $MatroskaCodecIDlist['V_REAL/RV10'] = 'real';
1653 $MatroskaCodecIDlist['V_REAL/RV20'] = 'real';
1654 $MatroskaCodecIDlist['V_REAL/RV30'] = 'real';
1655 $MatroskaCodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime
1656 $MatroskaCodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4';
1657 $MatroskaCodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4';
1658 $MatroskaCodecIDlist['V_MPEG4/ISO/AVC'] = 'h264';
1659 $MatroskaCodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4';
1660 $MatroskaCodecIDlist['V_VP8'] = 'vp8';
1661 $MatroskaCodecIDlist['V_MS/VFW/FOURCC'] = 'riff';
1662 $MatroskaCodecIDlist['A_MS/ACM'] = 'riff';
1663 }
1664
1665 return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid);
1666 }
1667
1674 private static function EBMLidName($value)
1675 {
1676 static $EBMLidList = array();
1677 if (empty($EBMLidList)) {
1678 $EBMLidList[self::EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType';
1679 $EBMLidList[self::EBML_ID_ATTACHEDFILE] = 'AttachedFile';
1680 $EBMLidList[self::EBML_ID_ATTACHMENTLINK] = 'AttachmentLink';
1681 $EBMLidList[self::EBML_ID_ATTACHMENTS] = 'Attachments';
1682 $EBMLidList[self::EBML_ID_AUDIO] = 'Audio';
1683 $EBMLidList[self::EBML_ID_BITDEPTH] = 'BitDepth';
1684 $EBMLidList[self::EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions';
1685 $EBMLidList[self::EBML_ID_CHANNELS] = 'Channels';
1686 $EBMLidList[self::EBML_ID_CHAPCOUNTRY] = 'ChapCountry';
1687 $EBMLidList[self::EBML_ID_CHAPLANGUAGE] = 'ChapLanguage';
1688 $EBMLidList[self::EBML_ID_CHAPPROCESS] = 'ChapProcess';
1689 $EBMLidList[self::EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID';
1690 $EBMLidList[self::EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand';
1691 $EBMLidList[self::EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData';
1692 $EBMLidList[self::EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate';
1693 $EBMLidList[self::EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime';
1694 $EBMLidList[self::EBML_ID_CHAPSTRING] = 'ChapString';
1695 $EBMLidList[self::EBML_ID_CHAPTERATOM] = 'ChapterAtom';
1696 $EBMLidList[self::EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay';
1697 $EBMLidList[self::EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled';
1698 $EBMLidList[self::EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden';
1699 $EBMLidList[self::EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv';
1700 $EBMLidList[self::EBML_ID_CHAPTERS] = 'Chapters';
1701 $EBMLidList[self::EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID';
1702 $EBMLidList[self::EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID';
1703 $EBMLidList[self::EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd';
1704 $EBMLidList[self::EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart';
1705 $EBMLidList[self::EBML_ID_CHAPTERTRACK] = 'ChapterTrack';
1706 $EBMLidList[self::EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber';
1707 $EBMLidList[self::EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate';
1708 $EBMLidList[self::EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec';
1709 $EBMLidList[self::EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
1710 $EBMLidList[self::EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID';
1711 $EBMLidList[self::EBML_ID_CHAPTERUID] = 'ChapterUID';
1712 $EBMLidList[self::EBML_ID_CLUSTER] = 'Cluster';
1713 $EBMLidList[self::EBML_ID_CLUSTERBLOCK] = 'ClusterBlock';
1714 $EBMLidList[self::EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID';
1715 $EBMLidList[self::EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional';
1716 $EBMLidList[self::EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID';
1717 $EBMLidList[self::EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions';
1718 $EBMLidList[self::EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration';
1719 $EBMLidList[self::EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup';
1720 $EBMLidList[self::EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore';
1721 $EBMLidList[self::EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual';
1722 $EBMLidList[self::EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState';
1723 $EBMLidList[self::EBML_ID_CLUSTERDELAY] = 'ClusterDelay';
1724 $EBMLidList[self::EBML_ID_CLUSTERDURATION] = 'ClusterDuration';
1725 $EBMLidList[self::EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock';
1726 $EBMLidList[self::EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber';
1727 $EBMLidList[self::EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber';
1728 $EBMLidList[self::EBML_ID_CLUSTERPOSITION] = 'ClusterPosition';
1729 $EBMLidList[self::EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize';
1730 $EBMLidList[self::EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock';
1731 $EBMLidList[self::EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority';
1732 $EBMLidList[self::EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual';
1733 $EBMLidList[self::EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber';
1734 $EBMLidList[self::EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks';
1735 $EBMLidList[self::EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock';
1736 $EBMLidList[self::EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode';
1737 $EBMLidList[self::EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice';
1738 $EBMLidList[self::EBML_ID_CODECDECODEALL] = 'CodecDecodeAll';
1739 $EBMLidList[self::EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL';
1740 $EBMLidList[self::EBML_ID_CODECID] = 'CodecID';
1741 $EBMLidList[self::EBML_ID_CODECINFOURL] = 'CodecInfoURL';
1742 $EBMLidList[self::EBML_ID_CODECNAME] = 'CodecName';
1743 $EBMLidList[self::EBML_ID_CODECPRIVATE] = 'CodecPrivate';
1744 $EBMLidList[self::EBML_ID_CODECSETTINGS] = 'CodecSettings';
1745 $EBMLidList[self::EBML_ID_COLOURSPACE] = 'ColourSpace';
1746 $EBMLidList[self::EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo';
1747 $EBMLidList[self::EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression';
1748 $EBMLidList[self::EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings';
1749 $EBMLidList[self::EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo';
1750 $EBMLidList[self::EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID';
1751 $EBMLidList[self::EBML_ID_CONTENTENCODING] = 'ContentEncoding';
1752 $EBMLidList[self::EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder';
1753 $EBMLidList[self::EBML_ID_CONTENTENCODINGS] = 'ContentEncodings';
1754 $EBMLidList[self::EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope';
1755 $EBMLidList[self::EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType';
1756 $EBMLidList[self::EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption';
1757 $EBMLidList[self::EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo';
1758 $EBMLidList[self::EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo';
1759 $EBMLidList[self::EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID';
1760 $EBMLidList[self::EBML_ID_CONTENTSIGNATURE] = 'ContentSignature';
1761 $EBMLidList[self::EBML_ID_CRC32] = 'CRC32';
1762 $EBMLidList[self::EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber';
1763 $EBMLidList[self::EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition';
1764 $EBMLidList[self::EBML_ID_CUECODECSTATE] = 'CueCodecState';
1765 $EBMLidList[self::EBML_ID_CUEPOINT] = 'CuePoint';
1766 $EBMLidList[self::EBML_ID_CUEREFCLUSTER] = 'CueRefCluster';
1767 $EBMLidList[self::EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState';
1768 $EBMLidList[self::EBML_ID_CUEREFERENCE] = 'CueReference';
1769 $EBMLidList[self::EBML_ID_CUEREFNUMBER] = 'CueRefNumber';
1770 $EBMLidList[self::EBML_ID_CUEREFTIME] = 'CueRefTime';
1771 $EBMLidList[self::EBML_ID_CUES] = 'Cues';
1772 $EBMLidList[self::EBML_ID_CUETIME] = 'CueTime';
1773 $EBMLidList[self::EBML_ID_CUETRACK] = 'CueTrack';
1774 $EBMLidList[self::EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions';
1775 $EBMLidList[self::EBML_ID_DATEUTC] = 'DateUTC';
1776 $EBMLidList[self::EBML_ID_DEFAULTDURATION] = 'DefaultDuration';
1777 $EBMLidList[self::EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight';
1778 $EBMLidList[self::EBML_ID_DISPLAYUNIT] = 'DisplayUnit';
1779 $EBMLidList[self::EBML_ID_DISPLAYWIDTH] = 'DisplayWidth';
1780 $EBMLidList[self::EBML_ID_DOCTYPE] = 'DocType';
1781 $EBMLidList[self::EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion';
1782 $EBMLidList[self::EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion';
1783 $EBMLidList[self::EBML_ID_DURATION] = 'Duration';
1784 $EBMLidList[self::EBML_ID_EBML] = 'EBML';
1785 $EBMLidList[self::EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength';
1786 $EBMLidList[self::EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength';
1787 $EBMLidList[self::EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion';
1788 $EBMLidList[self::EBML_ID_EBMLVERSION] = 'EBMLVersion';
1789 $EBMLidList[self::EBML_ID_EDITIONENTRY] = 'EditionEntry';
1790 $EBMLidList[self::EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault';
1791 $EBMLidList[self::EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden';
1792 $EBMLidList[self::EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered';
1793 $EBMLidList[self::EBML_ID_EDITIONUID] = 'EditionUID';
1794 $EBMLidList[self::EBML_ID_FILEDATA] = 'FileData';
1795 $EBMLidList[self::EBML_ID_FILEDESCRIPTION] = 'FileDescription';
1796 $EBMLidList[self::EBML_ID_FILEMIMETYPE] = 'FileMimeType';
1797 $EBMLidList[self::EBML_ID_FILENAME] = 'FileName';
1798 $EBMLidList[self::EBML_ID_FILEREFERRAL] = 'FileReferral';
1799 $EBMLidList[self::EBML_ID_FILEUID] = 'FileUID';
1800 $EBMLidList[self::EBML_ID_FLAGDEFAULT] = 'FlagDefault';
1801 $EBMLidList[self::EBML_ID_FLAGENABLED] = 'FlagEnabled';
1802 $EBMLidList[self::EBML_ID_FLAGFORCED] = 'FlagForced';
1803 $EBMLidList[self::EBML_ID_FLAGINTERLACED] = 'FlagInterlaced';
1804 $EBMLidList[self::EBML_ID_FLAGLACING] = 'FlagLacing';
1805 $EBMLidList[self::EBML_ID_GAMMAVALUE] = 'GammaValue';
1806 $EBMLidList[self::EBML_ID_INFO] = 'Info';
1807 $EBMLidList[self::EBML_ID_LANGUAGE] = 'Language';
1808 $EBMLidList[self::EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID';
1809 $EBMLidList[self::EBML_ID_MAXCACHE] = 'MaxCache';
1810 $EBMLidList[self::EBML_ID_MINCACHE] = 'MinCache';
1811 $EBMLidList[self::EBML_ID_MUXINGAPP] = 'MuxingApp';
1812 $EBMLidList[self::EBML_ID_NAME] = 'Name';
1813 $EBMLidList[self::EBML_ID_NEXTFILENAME] = 'NextFilename';
1814 $EBMLidList[self::EBML_ID_NEXTUID] = 'NextUID';
1815 $EBMLidList[self::EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency';
1816 $EBMLidList[self::EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom';
1817 $EBMLidList[self::EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft';
1818 $EBMLidList[self::EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight';
1819 $EBMLidList[self::EBML_ID_PIXELCROPTOP] = 'PixelCropTop';
1820 $EBMLidList[self::EBML_ID_PIXELHEIGHT] = 'PixelHeight';
1821 $EBMLidList[self::EBML_ID_PIXELWIDTH] = 'PixelWidth';
1822 $EBMLidList[self::EBML_ID_PREVFILENAME] = 'PrevFilename';
1823 $EBMLidList[self::EBML_ID_PREVUID] = 'PrevUID';
1824 $EBMLidList[self::EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency';
1825 $EBMLidList[self::EBML_ID_SEEK] = 'Seek';
1826 $EBMLidList[self::EBML_ID_SEEKHEAD] = 'SeekHead';
1827 $EBMLidList[self::EBML_ID_SEEKID] = 'SeekID';
1828 $EBMLidList[self::EBML_ID_SEEKPOSITION] = 'SeekPosition';
1829 $EBMLidList[self::EBML_ID_SEGMENT] = 'Segment';
1830 $EBMLidList[self::EBML_ID_SEGMENTFAMILY] = 'SegmentFamily';
1831 $EBMLidList[self::EBML_ID_SEGMENTFILENAME] = 'SegmentFilename';
1832 $EBMLidList[self::EBML_ID_SEGMENTUID] = 'SegmentUID';
1833 $EBMLidList[self::EBML_ID_SIMPLETAG] = 'SimpleTag';
1834 $EBMLidList[self::EBML_ID_CLUSTERSLICES] = 'ClusterSlices';
1835 $EBMLidList[self::EBML_ID_STEREOMODE] = 'StereoMode';
1836 $EBMLidList[self::EBML_ID_TAG] = 'Tag';
1837 $EBMLidList[self::EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID';
1838 $EBMLidList[self::EBML_ID_TAGBINARY] = 'TagBinary';
1839 $EBMLidList[self::EBML_ID_TAGCHAPTERUID] = 'TagChapterUID';
1840 $EBMLidList[self::EBML_ID_TAGDEFAULT] = 'TagDefault';
1841 $EBMLidList[self::EBML_ID_TAGEDITIONUID] = 'TagEditionUID';
1842 $EBMLidList[self::EBML_ID_TAGLANGUAGE] = 'TagLanguage';
1843 $EBMLidList[self::EBML_ID_TAGNAME] = 'TagName';
1844 $EBMLidList[self::EBML_ID_TAGTRACKUID] = 'TagTrackUID';
1845 $EBMLidList[self::EBML_ID_TAGS] = 'Tags';
1846 $EBMLidList[self::EBML_ID_TAGSTRING] = 'TagString';
1847 $EBMLidList[self::EBML_ID_TARGETS] = 'Targets';
1848 $EBMLidList[self::EBML_ID_TARGETTYPE] = 'TargetType';
1849 $EBMLidList[self::EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue';
1850 $EBMLidList[self::EBML_ID_TIMECODESCALE] = 'TimecodeScale';
1851 $EBMLidList[self::EBML_ID_TITLE] = 'Title';
1852 $EBMLidList[self::EBML_ID_TRACKENTRY] = 'TrackEntry';
1853 $EBMLidList[self::EBML_ID_TRACKNUMBER] = 'TrackNumber';
1854 $EBMLidList[self::EBML_ID_TRACKOFFSET] = 'TrackOffset';
1855 $EBMLidList[self::EBML_ID_TRACKOVERLAY] = 'TrackOverlay';
1856 $EBMLidList[self::EBML_ID_TRACKS] = 'Tracks';
1857 $EBMLidList[self::EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale';
1858 $EBMLidList[self::EBML_ID_TRACKTRANSLATE] = 'TrackTranslate';
1859 $EBMLidList[self::EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec';
1860 $EBMLidList[self::EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID';
1861 $EBMLidList[self::EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID';
1862 $EBMLidList[self::EBML_ID_TRACKTYPE] = 'TrackType';
1863 $EBMLidList[self::EBML_ID_TRACKUID] = 'TrackUID';
1864 $EBMLidList[self::EBML_ID_VIDEO] = 'Video';
1865 $EBMLidList[self::EBML_ID_VOID] = 'Void';
1866 $EBMLidList[self::EBML_ID_WRITINGAPP] = 'WritingApp';
1867 }
1868
1869 return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
1870 }
1871
1872 private static function getDefaultStreamInfo($streams)
1873 {
1874 foreach (array_reverse($streams) as $stream) {
1875 if ($stream['default']) {
1876 break;
1877 }
1878 }
1879
1880 $unset = array('default', 'name');
1881 foreach ($unset as $u) {
1882 if (isset($stream[$u])) {
1883 unset($stream[$u]);
1884 }
1885 }
1886
1887 $info = $stream;
1888 $info['streams'] = $streams;
1889
1890 return $info;
1891 }
1892
1893}
$size
Definition: RandomTest.php:79
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: GetId3Core.php:26
const ATTACHMENTS_INLINE
Definition: GetId3Core.php:65
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:26
saveAttachment(&$ThisFileInfoIndex, $filename, $offset, $length)
fseek($bytes, $whence=SEEK_SET)
GetId3() by James Heinrich info@getid3.org //.
Definition: Helper.php:27
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374
static intValueSupported($num)
@staticvar null $hasINT64
Definition: Helper.php:130
static trimNullByte($string)
Definition: Helper.php:1811
static BigEndian2Float($byteword)
ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic.
Definition: Helper.php:290
GetId3() by James Heinrich info@getid3.org //.
Definition: Matroska.php:34
unhandledElement($type, $line, $element)
Definition: Matroska.php:1388
static EBMLdate2unix($EBMLdatestamp)
Definition: Matroska.php:1575
ExtractCommentsSimpleTag($SimpleTagArray)
Definition: Matroska.php:1406
HandleEMBLClusterBlock($element, $block_type, &$info)
Definition: Matroska.php:1466
static MatroskaCodecIDtoCommonName($codecid)
@staticvar array $MatroskaCodecIDlist
Definition: Matroska.php:1632
static EBMLidName($value)
@staticvar array $EBMLidList
Definition: Matroska.php:1674
static MatroskaBlockLacingType($lacingtype)
@staticvar array $MatroskaBlockLacingType
Definition: Matroska.php:1612
getEBMLelement(&$element, $parent_end, $get_data=false)
Definition: Matroska.php:1344
static EBML2Int($EBMLstring)
Definition: Matroska.php:1529
EnsureBufferHasEnoughData($min_data=1024)
Definition: Matroska.php:1261
static getDefaultStreamInfo($streams)
Definition: Matroska.php:1872
static MatroskaTargetTypeValue($target_type)
@staticvar array $MatroskaTargetTypeValue
Definition: Matroska.php:1589
static RIFFfourccLookup($fourcc)
Definition: Riff.php:2101
static ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true)
Definition: Riff.php:1805
static RIFFparseWAVEFORMATex($WaveFormatExData)
Definition: Riff.php:1707
GetId3() by James Heinrich info@getid3.org //.
Definition: Ogg.php:31
$info
Definition: example_052.php:80
$target_type
Definition: goto.php:50