<Website>

getID3

PHK Home

File: /lib/module.audio-video.matroska.php

Size:58002
Storage flags:strip

<?php
















define
('EBML_ID_CHAPTERS'0x0043A770); 
define('EBML_ID_SEEKHEAD'0x014D9B74); 
define('EBML_ID_TAGS'0x0254C367); 
define('EBML_ID_INFO'0x0549A966); 
define('EBML_ID_TRACKS'0x0654AE6B); 
define('EBML_ID_SEGMENT'0x08538067); 
define('EBML_ID_ATTACHMENTS'0x0941A469); 
define('EBML_ID_EBML'0x0A45DFA3); 
define('EBML_ID_CUES'0x0C53BB6B); 
define('EBML_ID_CLUSTER'0x0F43B675); 
define('EBML_ID_LANGUAGE'0x02B59C); 
define('EBML_ID_TRACKTIMECODESCALE'0x03314F); 
define('EBML_ID_DEFAULTDURATION'0x03E383); 
define('EBML_ID_CODECNAME'0x058688); 
define('EBML_ID_CODECDOWNLOADURL'0x06B240); 
define('EBML_ID_TIMECODESCALE'0x0AD7B1); 
define('EBML_ID_COLOURSPACE'0x0EB524); 
define('EBML_ID_GAMMAVALUE'0x0FB523); 
define('EBML_ID_CODECSETTINGS'0x1A9697); 
define('EBML_ID_CODECINFOURL'0x1B4040); 
define('EBML_ID_PREVFILENAME'0x1C83AB); 
define('EBML_ID_PREVUID'0x1CB923); 
define('EBML_ID_NEXTFILENAME'0x1E83BB); 
define('EBML_ID_NEXTUID'0x1EB923); 
define('EBML_ID_CONTENTCOMPALGO'0x0254); 
define('EBML_ID_CONTENTCOMPSETTINGS'0x0255); 
define('EBML_ID_DOCTYPE'0x0282); 
define('EBML_ID_DOCTYPEREADVERSION'0x0285); 
define('EBML_ID_EBMLVERSION'0x0286); 
define('EBML_ID_DOCTYPEVERSION'0x0287); 
define('EBML_ID_EBMLMAXIDLENGTH'0x02F2); 
define('EBML_ID_EBMLMAXSIZELENGTH'0x02F3); 
define('EBML_ID_EBMLREADVERSION'0x02F7); 
define('EBML_ID_CHAPLANGUAGE'0x037C); 
define('EBML_ID_CHAPCOUNTRY'0x037E); 
define('EBML_ID_SEGMENTFAMILY'0x0444); 
define('EBML_ID_DATEUTC'0x0461); 
define('EBML_ID_TAGLANGUAGE'0x047A); 
define('EBML_ID_TAGDEFAULT'0x0484); 
define('EBML_ID_TAGBINARY'0x0485); 
define('EBML_ID_TAGSTRING'0x0487); 
define('EBML_ID_DURATION'0x0489); 
define('EBML_ID_CHAPPROCESSPRIVATE'0x050D); 
define('EBML_ID_CHAPTERFLAGENABLED'0x0598); 
define('EBML_ID_TAGNAME'0x05A3); 
define('EBML_ID_EDITIONENTRY'0x05B9); 
define('EBML_ID_EDITIONUID'0x05BC); 
define('EBML_ID_EDITIONFLAGHIDDEN'0x05BD); 
define('EBML_ID_EDITIONFLAGDEFAULT'0x05DB); 
define('EBML_ID_EDITIONFLAGORDERED'0x05DD); 
define('EBML_ID_FILEDATA'0x065C); 
define('EBML_ID_FILEMIMETYPE'0x0660); 
define('EBML_ID_FILENAME'0x066E); 
define('EBML_ID_FILEREFERRAL'0x0675); 
define('EBML_ID_FILEDESCRIPTION'0x067E); 
define('EBML_ID_FILEUID'0x06AE); 
define('EBML_ID_CONTENTENCALGO'0x07E1); 
define('EBML_ID_CONTENTENCKEYID'0x07E2); 
define('EBML_ID_CONTENTSIGNATURE'0x07E3); 
define('EBML_ID_CONTENTSIGKEYID'0x07E4); 
define('EBML_ID_CONTENTSIGALGO'0x07E5); 
define('EBML_ID_CONTENTSIGHASHALGO'0x07E6); 
define('EBML_ID_MUXINGAPP'0x0D80); 
define('EBML_ID_SEEK'0x0DBB); 
define('EBML_ID_CONTENTENCODINGORDER'0x1031); 
define('EBML_ID_CONTENTENCODINGSCOPE'0x1032); 
define('EBML_ID_CONTENTENCODINGTYPE'0x1033); 
define('EBML_ID_CONTENTCOMPRESSION'0x1034); 
define('EBML_ID_CONTENTENCRYPTION'0x1035); 
define('EBML_ID_CUEREFNUMBER'0x135F); 
define('EBML_ID_NAME'0x136E); 
define('EBML_ID_CUEBLOCKNUMBER'0x1378); 
define('EBML_ID_TRACKOFFSET'0x137F); 
define('EBML_ID_SEEKID'0x13AB); 
define('EBML_ID_SEEKPOSITION'0x13AC); 
define('EBML_ID_STEREOMODE'0x13B8); 
define('EBML_ID_OLDSTEREOMODE'0x13B9); 
define('EBML_ID_PIXELCROPBOTTOM'0x14AA); 
define('EBML_ID_DISPLAYWIDTH'0x14B0); 
define('EBML_ID_DISPLAYUNIT'0x14B2); 
define('EBML_ID_ASPECTRATIOTYPE'0x14B3); 
define('EBML_ID_DISPLAYHEIGHT'0x14BA); 
define('EBML_ID_PIXELCROPTOP'0x14BB); 
define('EBML_ID_PIXELCROPLEFT'0x14CC); 
define('EBML_ID_PIXELCROPRIGHT'0x14DD); 
define('EBML_ID_FLAGFORCED'0x15AA); 
define('EBML_ID_MAXBLOCKADDITIONID'0x15EE); 
define('EBML_ID_WRITINGAPP'0x1741); 
define('EBML_ID_CLUSTERSILENTTRACKS'0x1854); 
define('EBML_ID_CLUSTERSILENTTRACKNUMBER'0x18D7); 
define('EBML_ID_ATTACHEDFILE'0x21A7); 
define('EBML_ID_CONTENTENCODING'0x2240); 
define('EBML_ID_BITDEPTH'0x2264); 
define('EBML_ID_CODECPRIVATE'0x23A2); 
define('EBML_ID_TARGETS'0x23C0); 
define('EBML_ID_CHAPTERPHYSICALEQUIV'0x23C3); 
define('EBML_ID_TAGCHAPTERUID'0x23C4); 
define('EBML_ID_TAGTRACKUID'0x23C5); 
define('EBML_ID_TAGATTACHMENTUID'0x23C6); 
define('EBML_ID_TAGEDITIONUID'0x23C9); 
define('EBML_ID_TARGETTYPE'0x23CA); 
define('EBML_ID_TRACKTRANSLATE'0x2624); 
define('EBML_ID_TRACKTRANSLATETRACKID'0x26A5); 
define('EBML_ID_TRACKTRANSLATECODEC'0x26BF); 
define('EBML_ID_TRACKTRANSLATEEDITIONUID'0x26FC); 
define('EBML_ID_SIMPLETAG'0x27C8); 
define('EBML_ID_TARGETTYPEVALUE'0x28CA); 
define('EBML_ID_CHAPPROCESSCOMMAND'0x2911); 
define('EBML_ID_CHAPPROCESSTIME'0x2922); 
define('EBML_ID_CHAPTERTRANSLATE'0x2924); 
define('EBML_ID_CHAPPROCESSDATA'0x2933); 
define('EBML_ID_CHAPPROCESS'0x2944); 
define('EBML_ID_CHAPPROCESSCODECID'0x2955); 
define('EBML_ID_CHAPTERTRANSLATEID'0x29A5); 
define('EBML_ID_CHAPTERTRANSLATECODEC'0x29BF); 
define('EBML_ID_CHAPTERTRANSLATEEDITIONUID'0x29FC); 
define('EBML_ID_CONTENTENCODINGS'0x2D80); 
define('EBML_ID_MINCACHE'0x2DE7); 
define('EBML_ID_MAXCACHE'0x2DF8); 
define('EBML_ID_CHAPTERSEGMENTUID'0x2E67); 
define('EBML_ID_CHAPTERSEGMENTEDITIONUID'0x2EBC); 
define('EBML_ID_TRACKOVERLAY'0x2FAB); 
define('EBML_ID_TAG'0x3373); 
define('EBML_ID_SEGMENTFILENAME'0x3384); 
define('EBML_ID_SEGMENTUID'0x33A4); 
define('EBML_ID_CHAPTERUID'0x33C4); 
define('EBML_ID_TRACKUID'0x33C5); 
define('EBML_ID_ATTACHMENTLINK'0x3446); 
define('EBML_ID_CLUSTERBLOCKADDITIONS'0x35A1); 
define('EBML_ID_CHANNELPOSITIONS'0x347B); 
define('EBML_ID_OUTPUTSAMPLINGFREQUENCY'0x38B5); 
define('EBML_ID_TITLE'0x3BA9); 
define('EBML_ID_CHAPTERDISPLAY'0x00); 
define('EBML_ID_TRACKTYPE'0x03); 
define('EBML_ID_CHAPSTRING'0x05); 
define('EBML_ID_CODECID'0x06); 
define('EBML_ID_FLAGDEFAULT'0x08); 
define('EBML_ID_CHAPTERTRACKNUMBER'0x09); 
define('EBML_ID_CLUSTERSLICES'0x0E); 
define('EBML_ID_CHAPTERTRACK'0x0F); 
define('EBML_ID_CHAPTERTIMESTART'0x11); 
define('EBML_ID_CHAPTERTIMEEND'0x12); 
define('EBML_ID_CUEREFTIME'0x16); 
define('EBML_ID_CUEREFCLUSTER'0x17); 
define('EBML_ID_CHAPTERFLAGHIDDEN'0x18); 
define('EBML_ID_FLAGINTERLACED'0x1A); 
define('EBML_ID_CLUSTERBLOCKDURATION'0x1B); 
define('EBML_ID_FLAGLACING'0x1C); 
define('EBML_ID_CHANNELS'0x1F); 
define('EBML_ID_CLUSTERBLOCKGROUP'0x20); 
define('EBML_ID_CLUSTERBLOCK'0x21); 
define('EBML_ID_CLUSTERBLOCKVIRTUAL'0x22); 
define('EBML_ID_CLUSTERSIMPLEBLOCK'0x23); 
define('EBML_ID_CLUSTERCODECSTATE'0x24); 
define('EBML_ID_CLUSTERBLOCKADDITIONAL'0x25); 
define('EBML_ID_CLUSTERBLOCKMORE'0x26); 
define('EBML_ID_CLUSTERPOSITION'0x27); 
define('EBML_ID_CODECDECODEALL'0x2A); 
define('EBML_ID_CLUSTERPREVSIZE'0x2B); 
define('EBML_ID_TRACKENTRY'0x2E); 
define('EBML_ID_CLUSTERENCRYPTEDBLOCK'0x2F); 
define('EBML_ID_PIXELWIDTH'0x30); 
define('EBML_ID_CUETIME'0x33); 
define('EBML_ID_SAMPLINGFREQUENCY'0x35); 
define('EBML_ID_CHAPTERATOM'0x36); 
define('EBML_ID_CUETRACKPOSITIONS'0x37); 
define('EBML_ID_FLAGENABLED'0x39); 
define('EBML_ID_PIXELHEIGHT'0x3A); 
define('EBML_ID_CUEPOINT'0x3B); 
define('EBML_ID_CRC32'0x3F); 
define('EBML_ID_CLUSTERBLOCKADDITIONID'0x4B); 
define('EBML_ID_CLUSTERLACENUMBER'0x4C); 
define('EBML_ID_CLUSTERFRAMENUMBER'0x4D); 
define('EBML_ID_CLUSTERDELAY'0x4E); 
define('EBML_ID_CLUSTERDURATION'0x4F); 
define('EBML_ID_TRACKNUMBER'0x57); 
define('EBML_ID_CUEREFERENCE'0x5B); 
define('EBML_ID_VIDEO'0x60); 
define('EBML_ID_AUDIO'0x61); 
define('EBML_ID_CLUSTERTIMESLICE'0x68); 
define('EBML_ID_CUECODECSTATE'0x6A); 
define('EBML_ID_CUEREFCODECSTATE'0x6B); 
define('EBML_ID_VOID'0x6C); 
define('EBML_ID_CLUSTERTIMECODE'0x67); 
define('EBML_ID_CLUSTERBLOCKADDID'0x6E); 
define('EBML_ID_CUECLUSTERPOSITION'0x71); 
define('EBML_ID_CUETRACK'0x77); 
define('EBML_ID_CLUSTERREFERENCEPRIORITY'0x7A); 
define('EBML_ID_CLUSTERREFERENCEBLOCK'0x7B); 
define('EBML_ID_CLUSTERREFERENCEVIRTUAL'0x7D); 








class 
getid3_matroska extends getid3_handler
{

 public static 
$hide_clusters true
 public static 
$parse_whole_file false


 private 
$EBMLbuffer '';
private 
$EBMLbuffer_offset 0;
private 
$EBMLbuffer_length 0;
private 
$current_offset 0;
private 
$unuseful_elements = array(EBML_ID_CRC32EBML_ID_VOID);

public function 
Analyze()
{
$info = &$this->getid3->info;


 try {
$this->parseEBML($info);
} catch (
Exception $e) {
$info['error'][] = 'EBML parser: '.$e->getMessage();
}


 if (isset(
$info['matroska']['info']) && is_array($info['matroska']['info'])) {
foreach (
$info['matroska']['info'] as $key => $infoarray) {
if (isset(
$infoarray['Duration'])) {

 
$info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
break;
}
}
}


 if (isset(
$info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
foreach (
$info['matroska']['tags'] as $key => $infoarray) {
$this->ExtractCommentsSimpleTag($infoarray);
}
}


 if (isset(
$info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
foreach (
$info['matroska']['tracks']['tracks'] as $key => $trackarray) {

$track_info = array();
$track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']);
$track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true);
if (isset(
$trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; }

switch (
$trackarray['TrackType']) {

case 
1
 
$track_info['resolution_x'] = $trackarray['PixelWidth'];
$track_info['resolution_y'] = $trackarray['PixelHeight'];
$track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0);
$track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']);
$track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']);

if (isset(
$trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; }
if (isset(
$trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; }
if (isset(
$trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; }
if (isset(
$trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; }
if (isset(
$trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 $trackarray['DefaultDuration'], 3); }
if (isset(
$trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }

switch (
$trackarray['CodecID']) {
case 
'V_MS/VFW/FOURCC':
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php'__FILE__true);

$parsed getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
$track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']);
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
break;























}

$info['video']['streams'][] = $track_info;
break;

case 
2
 
$track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0);
$track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1);
$track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng');
if (isset(
$trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; }
if (isset(
$trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }

switch (
$trackarray['CodecID']) {
case 
'A_PCM/INT/LIT':
case 
'A_PCM/INT/BIG':
$track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
break;

case 
'A_AC3':
case 
'A_DTS':
case 
'A_MPEG/L3':
case 
'A_MPEG/L2':
case 
'A_FLAC':
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.($track_info['dataformat'] == 'mp2' 'mp3' $track_info['dataformat']).'.php'__FILE__true);

if (!isset(
$info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
$this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set');
break;
}


 
$getid3_temp = new getID3();
if (
$track_info['dataformat'] != 'flac') {
$getid3_temp->openfile($this->getid3->filename);
}
$getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
if (
$track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') {
$getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
}


 
$class 'getid3_'.($track_info['dataformat'] == 'mp2' 'mp3' $track_info['dataformat']);
$header_data_key $track_info['dataformat'][0] == 'm' 'mpeg' $track_info['dataformat'];
$getid3_audio = new $class($getid3_temp__CLASS__);
if (
$track_info['dataformat'] == 'flac') {
$getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
}
else {
$getid3_audio->Analyze();
}
if (!empty(
$getid3_temp->info[$header_data_key])) {
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
if (isset(
$getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
foreach (
$getid3_temp->info['audio'] as $key => $value) {
$track_info[$key] = $value;
}
}
}
else {
$this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']);
}


 if (!empty(
$getid3_temp->info['error'])) {
foreach (
$getid3_temp->info['error'] as $newerror) {
$this->warning($class.'() says: ['.$newerror.']');
}
}
if (!empty(
$getid3_temp->info['warning'])) {
foreach (
$getid3_temp->info['warning'] as $newerror) {
$this->warning($class.'() says: ['.$newerror.']');
}
}
unset(
$getid3_temp$getid3_audio);
break;

case 
'A_AAC':
case 
'A_AAC/MPEG2/LC':
case 
'A_AAC/MPEG2/LC/SBR':
case 
'A_AAC/MPEG4/LC':
case 
'A_AAC/MPEG4/LC/SBR':
$this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
break;

case 
'A_VORBIS':
if (!isset(
$trackarray['CodecPrivate'])) {
$this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set');
break;
}
$vorbis_offset strpos($trackarray['CodecPrivate'], 'vorbis'1);
if (
$vorbis_offset === false) {
$this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword');
break;
}
$vorbis_offset -= 1;

getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php'__FILE__true);


 
$getid3_temp = new getID3();


 
$getid3_ogg = new getid3_ogg($getid3_temp);
$oggpageinfo['page_seqno'] = 0;
$getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset$oggpageinfo);
if (!empty(
$getid3_temp->info['ogg'])) {
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
if (isset(
$getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
foreach (
$getid3_temp->info['audio'] as $key => $value) {
$track_info[$key] = $value;
}
}
}


 if (!empty(
$getid3_temp->info['error'])) {
foreach (
$getid3_temp->info['error'] as $newerror) {
$this->warning('getid3_ogg() says: ['.$newerror.']');
}
}
if (!empty(
$getid3_temp->info['warning'])) {
foreach (
$getid3_temp->info['warning'] as $newerror) {
$this->warning('getid3_ogg() says: ['.$newerror.']');
}
}

if (!empty(
$getid3_temp->info['ogg']['bitrate_nominal'])) {
$track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal'];
}
unset(
$getid3_temp$getid3_ogg$oggpageinfo$vorbis_offset);
break;

case 
'A_MS/ACM':
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php'__FILE__true);

$parsed getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']);
foreach (
$parsed as $key => $value) {
if (
$key != 'raw') {
$track_info[$key] = $value;
}
}
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
break;

default:
$this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"');
}

$info['audio']['streams'][] = $track_info;
break;
}
}

if (!empty(
$info['video']['streams'])) {
$info['video'] = self::getDefaultStreamInfo($info['video']['streams']);
}
if (!empty(
$info['audio']['streams'])) {
$info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']);
}
}


 if (isset(
$info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) {
foreach (
$info['matroska']['attachments'] as $i => $entry) {
if (
strpos($entry['FileMimeType'], 'image/') === && !empty($entry['FileData'])) {
$info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']);
}
}
}


 if (!empty(
$info['video']['streams'])) {
$info['mime_type'] = ($info['matroska']['doctype'] == 'webm' 'video/webm' 'video/x-matroska');
} elseif (!empty(
$info['audio']['streams'])) {
$info['mime_type'] = ($info['matroska']['doctype'] == 'webm' 'audio/webm' 'audio/x-matroska');
} elseif (isset(
$info['mime_type'])) {
unset(
$info['mime_type']);
}

return 
true;
}

private function 
parseEBML(&$info) {

 
$this->current_offset $info['avdataoffset'];

while (
$this->getEBMLelement($top_element$info['avdataend'])) {
switch (
$top_element['id']) {

case 
EBML_ID_EBML:
$info['matroska']['header']['offset'] = $top_element['offset'];
$info['matroska']['header']['length'] = $top_element['length'];

while (
$this->getEBMLelement($element_data$top_element['end'], true)) {
switch (
$element_data['id']) {

case 
EBML_ID_EBMLVERSION:
case 
EBML_ID_EBMLREADVERSION:
case 
EBML_ID_EBMLMAXIDLENGTH:
case 
EBML_ID_EBMLMAXSIZELENGTH:
case 
EBML_ID_DOCTYPEVERSION:
case 
EBML_ID_DOCTYPEREADVERSION:
$element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']);
break;

case 
EBML_ID_DOCTYPE:
$element_data['data'] = getid3_lib::trimNullByte($element_data['data']);
$info['matroska']['doctype'] = $element_data['data'];
$info['fileformat'] = $element_data['data'];
break;

default:
$this->unhandledElement('header'__LINE__$element_data);
}

unset(
$element_data['offset'], $element_data['end']);
$info['matroska']['header']['elements'][] = $element_data;
}
break;

case 
EBML_ID_SEGMENT:
$info['matroska']['segment'][0]['offset'] = $top_element['offset'];
$info['matroska']['segment'][0]['length'] = $top_element['length'];

while (
$this->getEBMLelement($element_data$top_element['end'])) {
if (
$element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { 
 
$info['matroska']['segments'][] = $element_data;
}
switch (
$element_data['id']) {

case 
EBML_ID_SEEKHEAD

while (
$this->getEBMLelement($seek_entry$element_data['end'])) {
switch (
$seek_entry['id']) {

case 
EBML_ID_SEEK
 while (
$this->getEBMLelement($sub_seek_entry$seek_entry['end'], true)) {

switch (
$sub_seek_entry['id']) {

case 
EBML_ID_SEEKID:
$seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']);
$seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']);
break;

case 
EBML_ID_SEEKPOSITION:
$seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']);
break;

default:
$this->unhandledElement('seekhead.seek'__LINE__$sub_seek_entry); }
}

if (
$seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { 
 
$info['matroska']['seek'][] = $seek_entry;
}
break;

default:
$this->unhandledElement('seekhead'__LINE__$seek_entry);
}
}
break;

case 
EBML_ID_TRACKS
 
$info['matroska']['tracks'] = $element_data;

while (
$this->getEBMLelement($track_entry$element_data['end'])) {
switch (
$track_entry['id']) {

case 
EBML_ID_TRACKENTRY

while (
$this->getEBMLelement($subelement$track_entry['end'], array(EBML_ID_VIDEOEBML_ID_AUDIOEBML_ID_CONTENTENCODINGSEBML_ID_CODECPRIVATE))) {
switch (
$subelement['id']) {

case 
EBML_ID_TRACKNUMBER:
case 
EBML_ID_TRACKUID:
case 
EBML_ID_TRACKTYPE:
case 
EBML_ID_MINCACHE:
case 
EBML_ID_MAXCACHE:
case 
EBML_ID_MAXBLOCKADDITIONID:
case 
EBML_ID_DEFAULTDURATION
 
$track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
break;

case 
EBML_ID_TRACKTIMECODESCALE:
$track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
break;

case 
EBML_ID_CODECID:
case 
EBML_ID_LANGUAGE:
case 
EBML_ID_NAME:
case 
EBML_ID_CODECNAME:
$track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
break;

case 
EBML_ID_CODECPRIVATE:
$track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true);
break;

case 
EBML_ID_FLAGENABLED:
case 
EBML_ID_FLAGDEFAULT:
case 
EBML_ID_FLAGFORCED:
case 
EBML_ID_FLAGLACING:
case 
EBML_ID_CODECDECODEALL:
$track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']);
break;

case 
EBML_ID_VIDEO:

while (
$this->getEBMLelement($sub_subelement$subelement['end'], true)) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_PIXELWIDTH:
case 
EBML_ID_PIXELHEIGHT:
case 
EBML_ID_PIXELCROPBOTTOM:
case 
EBML_ID_PIXELCROPTOP:
case 
EBML_ID_PIXELCROPLEFT:
case 
EBML_ID_PIXELCROPRIGHT:
case 
EBML_ID_DISPLAYWIDTH:
case 
EBML_ID_DISPLAYHEIGHT:
case 
EBML_ID_DISPLAYUNIT:
case 
EBML_ID_ASPECTRATIOTYPE:
case 
EBML_ID_STEREOMODE:
case 
EBML_ID_OLDSTEREOMODE:
$track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_FLAGINTERLACED:
$track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_GAMMAVALUE:
$track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
break;

case 
EBML_ID_COLOURSPACE:
$track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
break;

default:
$this->unhandledElement('track.video'__LINE__$sub_subelement);
}
}
break;

case 
EBML_ID_AUDIO:

while (
$this->getEBMLelement($sub_subelement$subelement['end'], true)) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CHANNELS:
case 
EBML_ID_BITDEPTH:
$track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_SAMPLINGFREQUENCY:
case 
EBML_ID_OUTPUTSAMPLINGFREQUENCY:
$track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
break;

case 
EBML_ID_CHANNELPOSITIONS:
$track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
break;

default:
$this->unhandledElement('track.audio'__LINE__$sub_subelement);
}
}
break;

case 
EBML_ID_CONTENTENCODINGS:

while (
$this->getEBMLelement($sub_subelement$subelement['end'])) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CONTENTENCODING:

while (
$this->getEBMLelement($sub_sub_subelement$sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSIONEBML_ID_CONTENTENCRYPTION))) {
switch (
$sub_sub_subelement['id']) {

case 
EBML_ID_CONTENTENCODINGORDER:
case 
EBML_ID_CONTENTENCODINGSCOPE:
case 
EBML_ID_CONTENTENCODINGTYPE:
$track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
break;

case 
EBML_ID_CONTENTCOMPRESSION:

while (
$this->getEBMLelement($sub_sub_sub_subelement$sub_sub_subelement['end'], true)) {
switch (
$sub_sub_sub_subelement['id']) {

case 
EBML_ID_CONTENTCOMPALGO:
$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']);
break;

case 
EBML_ID_CONTENTCOMPSETTINGS:
$track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
break;

default:
$this->unhandledElement('track.contentencodings.contentencoding.contentcompression'__LINE__$sub_sub_sub_subelement);
}
}
break;

case 
EBML_ID_CONTENTENCRYPTION:

while (
$this->getEBMLelement($sub_sub_sub_subelement$sub_sub_subelement['end'], true)) {
switch (
$sub_sub_sub_subelement['id']) {

case 
EBML_ID_CONTENTENCALGO:
case 
EBML_ID_CONTENTSIGALGO:
case 
EBML_ID_CONTENTSIGHASHALGO:
$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']);
break;

case 
EBML_ID_CONTENTENCKEYID:
case 
EBML_ID_CONTENTSIGNATURE:
case 
EBML_ID_CONTENTSIGKEYID:
$track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
break;

default:
$this->unhandledElement('track.contentencodings.contentencoding.contentcompression'__LINE__$sub_sub_sub_subelement);
}
}
break;

default:
$this->unhandledElement('track.contentencodings.contentencoding'__LINE__$sub_sub_subelement);
}
}
break;

default:
$this->unhandledElement('track.contentencodings'__LINE__$sub_subelement);
}
}
break;

default:
$this->unhandledElement('track'__LINE__$subelement);
}
}

$info['matroska']['tracks']['tracks'][] = $track_entry;
break;

default:
$this->unhandledElement('tracks'__LINE__$track_entry);
}
}
break;

case 
EBML_ID_INFO
 
$info_entry = array();

while (
$this->getEBMLelement($subelement$element_data['end'], true)) {
switch (
$subelement['id']) {

case 
EBML_ID_TIMECODESCALE:
$info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
break;

case 
EBML_ID_DURATION:
$info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
break;

case 
EBML_ID_DATEUTC:
$info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
$info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]);
break;

case 
EBML_ID_SEGMENTUID:
case 
EBML_ID_PREVUID:
case 
EBML_ID_NEXTUID:
$info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
break;

case 
EBML_ID_SEGMENTFAMILY:
$info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']);
break;

case 
EBML_ID_SEGMENTFILENAME:
case 
EBML_ID_PREVFILENAME:
case 
EBML_ID_NEXTFILENAME:
case 
EBML_ID_TITLE:
case 
EBML_ID_MUXINGAPP:
case 
EBML_ID_WRITINGAPP:
$info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
$info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']];
break;

case 
EBML_ID_CHAPTERTRANSLATE:
$chaptertranslate_entry = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], true)) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CHAPTERTRANSLATEEDITIONUID:
$chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_CHAPTERTRANSLATECODEC:
$chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_CHAPTERTRANSLATEID:
$chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
break;

default:
$this->unhandledElement('info.chaptertranslate'__LINE__$sub_subelement);
}
}
$info_entry[$subelement['id_name']] = $chaptertranslate_entry;
break;

default:
$this->unhandledElement('info'__LINE__$subelement);
}
}
$info['matroska']['info'][] = $info_entry;
break;

case 
EBML_ID_CUES
 if (
self::$hide_clusters) { 
 
$this->current_offset $element_data['end'];
break;
}
$cues_entry = array();

while (
$this->getEBMLelement($subelement$element_data['end'])) {
switch (
$subelement['id']) {

case 
EBML_ID_CUEPOINT:
$cuepoint_entry = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CUETRACKPOSITIONS:
$cuetrackpositions_entry = array();

while (
$this->getEBMLelement($sub_sub_subelement$sub_subelement['end'], true)) {
switch (
$sub_sub_subelement['id']) {

case 
EBML_ID_CUETRACK:
case 
EBML_ID_CUECLUSTERPOSITION:
case 
EBML_ID_CUEBLOCKNUMBER:
case 
EBML_ID_CUECODECSTATE:
$cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
break;

default:
$this->unhandledElement('cues.cuepoint.cuetrackpositions'__LINE__$sub_sub_subelement);
}
}
$cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry;
break;

case 
EBML_ID_CUETIME:
$cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

default:
$this->unhandledElement('cues.cuepoint'__LINE__$sub_subelement);
}
}
$cues_entry[] = $cuepoint_entry;
break;

default:
$this->unhandledElement('cues'__LINE__$subelement);
}
}
$info['matroska']['cues'] = $cues_entry;
break;

case 
EBML_ID_TAGS
 
$tags_entry = array();

while (
$this->getEBMLelement($subelement$element_data['end'], false)) {
switch (
$subelement['id']) {

case 
EBML_ID_TAG:
$tag_entry = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], false)) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_TARGETS:
$targets_entry = array();

while (
$this->getEBMLelement($sub_sub_subelement$sub_subelement['end'], true)) {
switch (
$sub_sub_subelement['id']) {

case 
EBML_ID_TARGETTYPEVALUE:
$targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
$targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]);
break;

case 
EBML_ID_TARGETTYPE:
$targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
break;

case 
EBML_ID_TAGTRACKUID:
case 
EBML_ID_TAGEDITIONUID:
case 
EBML_ID_TAGCHAPTERUID:
case 
EBML_ID_TAGATTACHMENTUID:
$targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
break;

default:
$this->unhandledElement('tags.tag.targets'__LINE__$sub_sub_subelement);
}
}
$tag_entry[$sub_subelement['id_name']] = $targets_entry;
break;

case 
EBML_ID_SIMPLETAG:
$tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']);
break;

default:
$this->unhandledElement('tags.tag'__LINE__$sub_subelement);
}
}
$tags_entry[] = $tag_entry;
break;

default:
$this->unhandledElement('tags'__LINE__$subelement);
}
}
$info['matroska']['tags'] = $tags_entry;
break;

case 
EBML_ID_ATTACHMENTS

while (
$this->getEBMLelement($subelement$element_data['end'])) {
switch (
$subelement['id']) {

case 
EBML_ID_ATTACHEDFILE:
$attachedfile_entry = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], array(EBML_ID_FILEDATA))) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_FILEDESCRIPTION:
case 
EBML_ID_FILENAME:
case 
EBML_ID_FILEMIMETYPE:
$attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data'];
break;

case 
EBML_ID_FILEDATA:
$attachedfile_entry['data_offset'] = $this->current_offset;
$attachedfile_entry['data_length'] = $sub_subelement['length'];

$attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment(
$attachedfile_entry['FileName'],
$attachedfile_entry['data_offset'],
$attachedfile_entry['data_length']);

$this->current_offset $sub_subelement['end'];
break;

case 
EBML_ID_FILEUID:
$attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

default:
$this->unhandledElement('attachments.attachedfile'__LINE__$sub_subelement);
}
}
$info['matroska']['attachments'][] = $attachedfile_entry;
break;

default:
$this->unhandledElement('attachments'__LINE__$subelement);
}
}
break;

case 
EBML_ID_CHAPTERS:

while (
$this->getEBMLelement($subelement$element_data['end'])) {
switch (
$subelement['id']) {

case 
EBML_ID_EDITIONENTRY:
$editionentry_entry = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], array(EBML_ID_CHAPTERATOM))) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_EDITIONUID:
$editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_EDITIONFLAGHIDDEN:
case 
EBML_ID_EDITIONFLAGDEFAULT:
case 
EBML_ID_EDITIONFLAGORDERED:
$editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_CHAPTERATOM:
$chapteratom_entry = array();

while (
$this->getEBMLelement($sub_sub_subelement$sub_subelement['end'], array(EBML_ID_CHAPTERTRACKEBML_ID_CHAPTERDISPLAY))) {
switch (
$sub_sub_subelement['id']) {

case 
EBML_ID_CHAPTERSEGMENTUID:
case 
EBML_ID_CHAPTERSEGMENTEDITIONUID:
$chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
break;

case 
EBML_ID_CHAPTERFLAGENABLED:
case 
EBML_ID_CHAPTERFLAGHIDDEN:
$chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
break;

case 
EBML_ID_CHAPTERUID:
case 
EBML_ID_CHAPTERTIMESTART:
case 
EBML_ID_CHAPTERTIMEEND:
$chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
break;

case 
EBML_ID_CHAPTERTRACK:
$chaptertrack_entry = array();

while (
$this->getEBMLelement($sub_sub_sub_subelement$sub_sub_subelement['end'], true)) {
switch (
$sub_sub_sub_subelement['id']) {

case 
EBML_ID_CHAPTERTRACKNUMBER:
$chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
break;

default:
$this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack'__LINE__$sub_sub_sub_subelement);
}
}
$chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry;
break;

case 
EBML_ID_CHAPTERDISPLAY:
$chapterdisplay_entry = array();

while (
$this->getEBMLelement($sub_sub_sub_subelement$sub_sub_subelement['end'], true)) {
switch (
$sub_sub_sub_subelement['id']) {

case 
EBML_ID_CHAPSTRING:
case 
EBML_ID_CHAPLANGUAGE:
case 
EBML_ID_CHAPCOUNTRY:
$chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
break;

default:
$this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay'__LINE__$sub_sub_sub_subelement);
}
}
$chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry;
break;

default:
$this->unhandledElement('chapters.editionentry.chapteratom'__LINE__$sub_sub_subelement);
}
}
$editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry;
break;

default:
$this->unhandledElement('chapters.editionentry'__LINE__$sub_subelement);
}
}
$info['matroska']['chapters'][] = $editionentry_entry;
break;

default:
$this->unhandledElement('chapters'__LINE__$subelement);
}
}
break;

case 
EBML_ID_CLUSTER
 
$cluster_entry = array();

while (
$this->getEBMLelement($subelement$element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKSEBML_ID_CLUSTERBLOCKGROUPEBML_ID_CLUSTERSIMPLEBLOCK))) {
switch (
$subelement['id']) {

case 
EBML_ID_CLUSTERTIMECODE:
case 
EBML_ID_CLUSTERPOSITION:
case 
EBML_ID_CLUSTERPREVSIZE:
$cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
break;

case 
EBML_ID_CLUSTERSILENTTRACKS:
$cluster_silent_tracks = array();

while (
$this->getEBMLelement($sub_subelement$subelement['end'], true)) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CLUSTERSILENTTRACKNUMBER:
$cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

default:
$this->unhandledElement('cluster.silenttracks'__LINE__$sub_subelement);
}
}
$cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks;
break;

case 
EBML_ID_CLUSTERBLOCKGROUP:
$cluster_block_group = array('offset' => $this->current_offset);

while (
$this->getEBMLelement($sub_subelement$subelement['end'], array(EBML_ID_CLUSTERBLOCK))) {
switch (
$sub_subelement['id']) {

case 
EBML_ID_CLUSTERBLOCK:
$cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelementEBML_ID_CLUSTERBLOCK$info);
break;

case 
EBML_ID_CLUSTERREFERENCEPRIORITY
 case 
EBML_ID_CLUSTERBLOCKDURATION
 
$cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
break;

case 
EBML_ID_CLUSTERREFERENCEBLOCK
 
$cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], falsetrue);
break;

case 
EBML_ID_CLUSTERCODECSTATE:
$cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
break;

default:
$this->unhandledElement('clusters.blockgroup'__LINE__$sub_subelement);
}
}
$cluster_entry[$subelement['id_name']][] = $cluster_block_group;
break;

case 
EBML_ID_CLUSTERSIMPLEBLOCK:
$cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelementEBML_ID_CLUSTERSIMPLEBLOCK$info);
break;

default:
$this->unhandledElement('cluster'__LINE__$subelement);
}
$this->current_offset $subelement['end'];
}
if (!
self::$hide_clusters) {
$info['matroska']['cluster'][] = $cluster_entry;
}


 if (!
self::$parse_whole_file) {
if (isset(
$info['matroska']['info']) && is_array($info['matroska']['info'])) {
if (isset(
$info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
if (
count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) {
return;
}
}
}
}
break;

default:
$this->unhandledElement('segment'__LINE__$element_data);
}
}
break;

default:
$this->unhandledElement('root'__LINE__$top_element);
}
}
}

private function 
EnsureBufferHasEnoughData($min_data=1024) {
if ((
$this->current_offset $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length $min_data)) {
$read_bytes max($min_data$this->getid3->fread_buffer_size());

try {
$this->fseek($this->current_offset);
$this->EBMLbuffer_offset $this->current_offset;
$this->EBMLbuffer $this->fread($read_bytes);
$this->EBMLbuffer_length strlen($this->EBMLbuffer);
} catch (
getid3_exception $e) {
$this->warning('EBML parser: '.$e->getMessage());
return 
false;
}

if (
$this->EBMLbuffer_length == && $this->feof()) {
return 
$this->error('EBML parser: ran out of file at offset '.$this->current_offset);
}
}
return 
true;
}

private function 
readEBMLint() {
$actual_offset $this->current_offset $this->EBMLbuffer_offset;


 
$first_byte_int ord($this->EBMLbuffer[$actual_offset]);
if (
0x80 $first_byte_int) {
$length 1;
} elseif (
0x40 $first_byte_int) {
$length 2;
} elseif (
0x20 $first_byte_int) {
$length 3;
} elseif (
0x10 $first_byte_int) {
$length 4;
} elseif (
0x08 $first_byte_int) {
$length 5;
} elseif (
0x04 $first_byte_int) {
$length 6;
} elseif (
0x02 $first_byte_int) {
$length 7;
} elseif (
0x01 $first_byte_int) {
$length 8;
} else {
throw new 
Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset);
}


 
$int_value self::EBML2Int(substr($this->EBMLbuffer$actual_offset$length));
$this->current_offset += $length;

return 
$int_value;
}

private function 
readEBMLelementData($length$check_buffer=false) {
if (
$check_buffer && !$this->EnsureBufferHasEnoughData($length)) {
return 
false;
}
$data substr($this->EBMLbuffer$this->current_offset $this->EBMLbuffer_offset$length);
$this->current_offset += $length;
return 
$data;
}

private function 
getEBMLelement(&$element$parent_end$get_data=false) {
if (
$this->current_offset >= $parent_end) {
return 
false;
}

if (!
$this->EnsureBufferHasEnoughData()) {
$this->current_offset PHP_INT_MAX
 return 
false;
}

$element = array();


 
$element['offset'] = $this->current_offset;


 
$element['id'] = $this->readEBMLint();


 
$element['id_name'] = self::EBMLidName($element['id']);


 
$element['length'] = $this->readEBMLint();


 
$element['end'] = $this->current_offset $element['length'];


 
$dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id']));
if ((
$get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) {
$element['data'] = $this->readEBMLelementData($element['length'], $element);
}

return 
true;
}

private function 
unhandledElement($type$line$element) {

 if (!
in_array($element['id'], $this->unuseful_elements)) {
$this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']);
}


 if (!isset(
$element['data'])) {
$this->current_offset $element['end'];
}
}

private function 
ExtractCommentsSimpleTag($SimpleTagArray) {
if (!empty(
$SimpleTagArray['SimpleTag'])) {
foreach (
$SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) {
if (!empty(
$SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) {
$this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString'];
}
if (!empty(
$SimpleTagData['SimpleTag'])) {
$this->ExtractCommentsSimpleTag($SimpleTagData);
}
}
}

return 
true;
}

private function 
HandleEMBLSimpleTag($parent_end) {
$simpletag_entry = array();

while (
$this->getEBMLelement($element$parent_end, array(EBML_ID_SIMPLETAG))) {
switch (
$element['id']) {

case 
EBML_ID_TAGNAME:
case 
EBML_ID_TAGLANGUAGE:
case 
EBML_ID_TAGSTRING:
case 
EBML_ID_TAGBINARY:
$simpletag_entry[$element['id_name']] = $element['data'];
break;

case 
EBML_ID_SIMPLETAG:
$simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']);
break;

case 
EBML_ID_TAGDEFAULT:
$simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']);
break;

default:
$this->unhandledElement('tag.simpletag'__LINE__$element);
}
}

return 
$simpletag_entry;
}

private function 
HandleEMBLClusterBlock($element$block_type, &$info) {

 

$block_data = array();
$block_data['tracknumber'] = $this->readEBMLint();
$block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), falsetrue);
$block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1));

if (
$block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
$block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7);

 }
else {

 }
$block_data['flags']['invisible'] = (bool)(($block_data['flags_raw'] & 0x08) >> 3);
$block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); 
 if (
$block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
$block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01));
}
else {

 }
$block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']);


 if (
$block_data['flags']['lacing'] > 0) {
$block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1
 if (
$block_data['flags']['lacing'] != 0x02) {
for (
$i 1$i $block_data['lace_frames']; $i ++) { 
 if (
$block_data['flags']['lacing'] == 0x03) { 
 
$block_data['lace_frames_size'][$i] = $this->readEBMLint(); 
 }
else { 
 
$block_data['lace_frames_size'][$i] = 0;
do {
$size getid3_lib::BigEndian2Int($this->readEBMLelementData(1));
$block_data['lace_frames_size'][$i] += $size;
}
while (
$size == 255);
}
}
if (
$block_data['flags']['lacing'] == 0x01) { 
 
$block_data['lace_frames_size'][] = $element['end'] - $this->current_offset array_sum($block_data['lace_frames_size']);
}
}
}

if (!isset(
$info['matroska']['track_data_offsets'][$block_data['tracknumber']])) {
$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset;
$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset;

 }

 


 
$this->current_offset $element['end'];

return 
$block_data;
}

private static function 
EBML2Int($EBMLstring) {



 
 
 
 
 


 
 
 
 
 
 
 
 

$first_byte_int ord($EBMLstring[0]);
if (
0x80 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x7F);
} elseif (
0x40 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x3F);
} elseif (
0x20 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x1F);
} elseif (
0x10 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x0F);
} elseif (
0x08 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x07);
} elseif (
0x04 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x03);
} elseif (
0x02 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x01);
} elseif (
0x01 $first_byte_int) {
$EBMLstring[0] = chr($first_byte_int 0x00);
}

return 
getid3_lib::BigEndian2Int($EBMLstring);
}

private static function 
EBMLdate2unix($EBMLdatestamp) {

 
 return 
round(($EBMLdatestamp 1000000000) + 978307200);
}

public static function 
TargetTypeValue($target_type) {

 static 
$TargetTypeValue = array();
if (empty(
$TargetTypeValue)) {
$TargetTypeValue[10] = 'A: ~ V:shot'
 
$TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'
 
$TargetTypeValue[30] = 'A:track/song ~ V:chapter'
 
$TargetTypeValue[40] = 'A:part/session ~ V:part/session'
 
$TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'
 
$TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'
 
$TargetTypeValue[70] = 'A:collection ~ V:collection'
 }
return (isset(
$TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type);
}

public static function 
BlockLacingType($lacingtype) {

 static 
$BlockLacingType = array();
if (empty(
$BlockLacingType)) {
$BlockLacingType[0x00] = 'no lacing';
$BlockLacingType[0x01] = 'Xiph lacing';
$BlockLacingType[0x02] = 'fixed-size lacing';
$BlockLacingType[0x03] = 'EBML lacing';
}
return (isset(
$BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype);
}

public static function 
CodecIDtoCommonName($codecid) {

 static 
$CodecIDlist = array();
if (empty(
$CodecIDlist)) {
$CodecIDlist['A_AAC'] = 'aac';
$CodecIDlist['A_AAC/MPEG2/LC'] = 'aac';
$CodecIDlist['A_AC3'] = 'ac3';
$CodecIDlist['A_DTS'] = 'dts';
$CodecIDlist['A_FLAC'] = 'flac';
$CodecIDlist['A_MPEG/L1'] = 'mp1';
$CodecIDlist['A_MPEG/L2'] = 'mp2';
$CodecIDlist['A_MPEG/L3'] = 'mp3';
$CodecIDlist['A_PCM/INT/LIT'] = 'pcm'
 
$CodecIDlist['A_PCM/INT/BIG'] = 'pcm'
 
$CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'
 
$CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'
 
$CodecIDlist['A_VORBIS'] = 'vorbis';
$CodecIDlist['V_MPEG1'] = 'mpeg';
$CodecIDlist['V_THEORA'] = 'theora';
$CodecIDlist['V_REAL/RV40'] = 'real';
$CodecIDlist['V_REAL/RV10'] = 'real';
$CodecIDlist['V_REAL/RV20'] = 'real';
$CodecIDlist['V_REAL/RV30'] = 'real';
$CodecIDlist['V_QUICKTIME'] = 'quicktime'
 
$CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4';
$CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4';
$CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264';
$CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4';
$CodecIDlist['V_VP8'] = 'vp8';
$CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'
 
$CodecIDlist['A_MS/ACM'] = 'acm'
 }
return (isset(
$CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid);
}

private static function 
EBMLidName($value) {
static 
$EBMLidList = array();
if (empty(
$EBMLidList)) {
$EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType';
$EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile';
$EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink';
$EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments';
$EBMLidList[EBML_ID_AUDIO] = 'Audio';
$EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth';
$EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions';
$EBMLidList[EBML_ID_CHANNELS] = 'Channels';
$EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry';
$EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage';
$EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess';
$EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID';
$EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand';
$EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData';
$EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate';
$EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime';
$EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString';
$EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom';
$EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay';
$EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled';
$EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden';
$EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv';
$EBMLidList[EBML_ID_CHAPTERS] = 'Chapters';
$EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID';
$EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID';
$EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd';
$EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart';
$EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack';
$EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber';
$EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate';
$EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec';
$EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
$EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID';
$EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID';
$EBMLidList[EBML_ID_CLUSTER] = 'Cluster';
$EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock';
$EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID';
$EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional';
$EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID';
$EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions';
$EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration';
$EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup';
$EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore';
$EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual';
$EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState';
$EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay';
$EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration';
$EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock';
$EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber';
$EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber';
$EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition';
$EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize';
$EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock';
$EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority';
$EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual';
$EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber';
$EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks';
$EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock';
$EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode';
$EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice';
$EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll';
$EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL';
$EBMLidList[EBML_ID_CODECID] = 'CodecID';
$EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL';
$EBMLidList[EBML_ID_CODECNAME] = 'CodecName';
$EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate';
$EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings';
$EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace';
$EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo';
$EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression';
$EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings';
$EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo';
$EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID';
$EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding';
$EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder';
$EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings';
$EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope';
$EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType';
$EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption';
$EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo';
$EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo';
$EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID';
$EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature';
$EBMLidList[EBML_ID_CRC32] = 'CRC32';
$EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber';
$EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition';
$EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState';
$EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint';
$EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster';
$EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState';
$EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference';
$EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber';
$EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime';
$EBMLidList[EBML_ID_CUES] = 'Cues';
$EBMLidList[EBML_ID_CUETIME] = 'CueTime';
$EBMLidList[EBML_ID_CUETRACK] = 'CueTrack';
$EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions';
$EBMLidList[EBML_ID_DATEUTC] = 'DateUTC';
$EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration';
$EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight';
$EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit';
$EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth';
$EBMLidList[EBML_ID_DOCTYPE] = 'DocType';
$EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion';
$EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion';
$EBMLidList[EBML_ID_DURATION] = 'Duration';
$EBMLidList[EBML_ID_EBML] = 'EBML';
$EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength';
$EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength';
$EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion';
$EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion';
$EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry';
$EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault';
$EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden';
$EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered';
$EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID';
$EBMLidList[EBML_ID_FILEDATA] = 'FileData';
$EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription';
$EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType';
$EBMLidList[EBML_ID_FILENAME] = 'FileName';
$EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral';
$EBMLidList[EBML_ID_FILEUID] = 'FileUID';
$EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault';
$EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled';
$EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced';
$EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced';
$EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing';
$EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue';
$EBMLidList[EBML_ID_INFO] = 'Info';
$EBMLidList[EBML_ID_LANGUAGE] = 'Language';
$EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID';
$EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache';
$EBMLidList[EBML_ID_MINCACHE] = 'MinCache';
$EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp';
$EBMLidList[EBML_ID_NAME] = 'Name';
$EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename';
$EBMLidList[EBML_ID_NEXTUID] = 'NextUID';
$EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency';
$EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom';
$EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft';
$EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight';
$EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop';
$EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight';
$EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth';
$EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename';
$EBMLidList[EBML_ID_PREVUID] = 'PrevUID';
$EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency';
$EBMLidList[EBML_ID_SEEK] = 'Seek';
$EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead';
$EBMLidList[EBML_ID_SEEKID] = 'SeekID';
$EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition';
$EBMLidList[EBML_ID_SEGMENT] = 'Segment';
$EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily';
$EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename';
$EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID';
$EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag';
$EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices';
$EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode';
$EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode';
$EBMLidList[EBML_ID_TAG] = 'Tag';
$EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID';
$EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary';
$EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID';
$EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault';
$EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID';
$EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage';
$EBMLidList[EBML_ID_TAGNAME] = 'TagName';
$EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID';
$EBMLidList[EBML_ID_TAGS] = 'Tags';
$EBMLidList[EBML_ID_TAGSTRING] = 'TagString';
$EBMLidList[EBML_ID_TARGETS] = 'Targets';
$EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType';
$EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue';
$EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale';
$EBMLidList[EBML_ID_TITLE] = 'Title';
$EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry';
$EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber';
$EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset';
$EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay';
$EBMLidList[EBML_ID_TRACKS] = 'Tracks';
$EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale';
$EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate';
$EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec';
$EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID';
$EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID';
$EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType';
$EBMLidList[EBML_ID_TRACKUID] = 'TrackUID';
$EBMLidList[EBML_ID_VIDEO] = 'Video';
$EBMLidList[EBML_ID_VOID] = 'Void';
$EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp';
}

return (isset(
$EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
}

public static function 
displayUnit($value) {

 static 
$units = array(
=> 'pixels',
=> 'centimeters',
=> 'inches',
=> 'Display Aspect Ratio');

return (isset(
$units[$value]) ? $units[$value] : 'unknown');
}

private static function 
getDefaultStreamInfo($streams)
{
foreach (
array_reverse($streams) as $stream) {
if (
$stream['default']) {
break;
}
}

$unset = array('default''name');
foreach (
$unset as $u) {
if (isset(
$stream[$u])) {
unset(
$stream[$u]);
}
}

$info $stream;
$info['streams'] = $streams;

return 
$info;
}

}

For more information about the PHK package format: http://phk.tekwire.net