Edit File by line
/home/barbar84/public_h.../wp-inclu.../ID3
File: module.audio.ogg.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/////////////////////////////////////////////////////////////////
[2] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[3] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[4] Fix | Delete
// or https://www.getid3.org //
[5] Fix | Delete
// or http://getid3.sourceforge.net //
[6] Fix | Delete
// see readme.txt for more details //
[7] Fix | Delete
/////////////////////////////////////////////////////////////////
[8] Fix | Delete
// //
[9] Fix | Delete
// module.audio.ogg.php //
[10] Fix | Delete
// module for analyzing Ogg Vorbis, OggFLAC and Speex files //
[11] Fix | Delete
// dependencies: module.audio.flac.php //
[12] Fix | Delete
// ///
[13] Fix | Delete
/////////////////////////////////////////////////////////////////
[14] Fix | Delete
[15] Fix | Delete
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
[16] Fix | Delete
exit;
[17] Fix | Delete
}
[18] Fix | Delete
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.flac.php', __FILE__, true);
[19] Fix | Delete
[20] Fix | Delete
class getid3_ogg extends getid3_handler
[21] Fix | Delete
{
[22] Fix | Delete
/**
[23] Fix | Delete
* @link http://xiph.org/vorbis/doc/Vorbis_I_spec.html
[24] Fix | Delete
*
[25] Fix | Delete
* @return bool
[26] Fix | Delete
*/
[27] Fix | Delete
public function Analyze() {
[28] Fix | Delete
$info = &$this->getid3->info;
[29] Fix | Delete
[30] Fix | Delete
$info['fileformat'] = 'ogg';
[31] Fix | Delete
[32] Fix | Delete
// Warn about illegal tags - only vorbiscomments are allowed
[33] Fix | Delete
if (isset($info['id3v2'])) {
[34] Fix | Delete
$this->warning('Illegal ID3v2 tag present.');
[35] Fix | Delete
}
[36] Fix | Delete
if (isset($info['id3v1'])) {
[37] Fix | Delete
$this->warning('Illegal ID3v1 tag present.');
[38] Fix | Delete
}
[39] Fix | Delete
if (isset($info['ape'])) {
[40] Fix | Delete
$this->warning('Illegal APE tag present.');
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
[44] Fix | Delete
// Page 1 - Stream Header
[45] Fix | Delete
[46] Fix | Delete
$this->fseek($info['avdataoffset']);
[47] Fix | Delete
[48] Fix | Delete
$oggpageinfo = $this->ParseOggPageHeader();
[49] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
[50] Fix | Delete
[51] Fix | Delete
if ($this->ftell() >= $this->getid3->fread_buffer_size()) {
[52] Fix | Delete
$this->error('Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)');
[53] Fix | Delete
unset($info['fileformat']);
[54] Fix | Delete
unset($info['ogg']);
[55] Fix | Delete
return false;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
$filedata = $this->fread($oggpageinfo['page_length']);
[59] Fix | Delete
$filedataoffset = 0;
[60] Fix | Delete
[61] Fix | Delete
if (substr($filedata, 0, 4) == 'fLaC') {
[62] Fix | Delete
[63] Fix | Delete
$info['audio']['dataformat'] = 'flac';
[64] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[65] Fix | Delete
$info['audio']['lossless'] = true;
[66] Fix | Delete
[67] Fix | Delete
} elseif (substr($filedata, 1, 6) == 'vorbis') {
[68] Fix | Delete
[69] Fix | Delete
$this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
[70] Fix | Delete
[71] Fix | Delete
} elseif (substr($filedata, 0, 8) == 'OpusHead') {
[72] Fix | Delete
[73] Fix | Delete
if ($this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) === false) {
[74] Fix | Delete
return false;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
} elseif (substr($filedata, 0, 8) == 'Speex ') {
[78] Fix | Delete
[79] Fix | Delete
// http://www.speex.org/manual/node10.html
[80] Fix | Delete
[81] Fix | Delete
$info['audio']['dataformat'] = 'speex';
[82] Fix | Delete
$info['mime_type'] = 'audio/speex';
[83] Fix | Delete
$info['audio']['bitrate_mode'] = 'abr';
[84] Fix | Delete
$info['audio']['lossless'] = false;
[85] Fix | Delete
[86] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex '
[87] Fix | Delete
$filedataoffset += 8;
[88] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20);
[89] Fix | Delete
$filedataoffset += 20;
[90] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[91] Fix | Delete
$filedataoffset += 4;
[92] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[93] Fix | Delete
$filedataoffset += 4;
[94] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[95] Fix | Delete
$filedataoffset += 4;
[96] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[97] Fix | Delete
$filedataoffset += 4;
[98] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[99] Fix | Delete
$filedataoffset += 4;
[100] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[101] Fix | Delete
$filedataoffset += 4;
[102] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[103] Fix | Delete
$filedataoffset += 4;
[104] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[105] Fix | Delete
$filedataoffset += 4;
[106] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[107] Fix | Delete
$filedataoffset += 4;
[108] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[109] Fix | Delete
$filedataoffset += 4;
[110] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[111] Fix | Delete
$filedataoffset += 4;
[112] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[113] Fix | Delete
$filedataoffset += 4;
[114] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[115] Fix | Delete
$filedataoffset += 4;
[116] Fix | Delete
[117] Fix | Delete
$info['speex']['speex_version'] = trim($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']);
[118] Fix | Delete
$info['speex']['sample_rate'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'];
[119] Fix | Delete
$info['speex']['channels'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'];
[120] Fix | Delete
$info['speex']['vbr'] = (bool) $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'];
[121] Fix | Delete
$info['speex']['band_type'] = $this->SpeexBandModeLookup($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']);
[122] Fix | Delete
[123] Fix | Delete
$info['audio']['sample_rate'] = $info['speex']['sample_rate'];
[124] Fix | Delete
$info['audio']['channels'] = $info['speex']['channels'];
[125] Fix | Delete
if ($info['speex']['vbr']) {
[126] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
} elseif (substr($filedata, 0, 7) == "\x80".'theora') {
[130] Fix | Delete
[131] Fix | Delete
// http://www.theora.org/doc/Theora.pdf (section 6.2)
[132] Fix | Delete
[133] Fix | Delete
$info['ogg']['pageheader']['theora']['theora_magic'] = substr($filedata, $filedataoffset, 7); // hard-coded to "\x80.'theora'
[134] Fix | Delete
$filedataoffset += 7;
[135] Fix | Delete
$info['ogg']['pageheader']['theora']['version_major'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[136] Fix | Delete
$filedataoffset += 1;
[137] Fix | Delete
$info['ogg']['pageheader']['theora']['version_minor'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[138] Fix | Delete
$filedataoffset += 1;
[139] Fix | Delete
$info['ogg']['pageheader']['theora']['version_revision'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[140] Fix | Delete
$filedataoffset += 1;
[141] Fix | Delete
$info['ogg']['pageheader']['theora']['frame_width_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
[142] Fix | Delete
$filedataoffset += 2;
[143] Fix | Delete
$info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
[144] Fix | Delete
$filedataoffset += 2;
[145] Fix | Delete
$info['ogg']['pageheader']['theora']['resolution_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
[146] Fix | Delete
$filedataoffset += 3;
[147] Fix | Delete
$info['ogg']['pageheader']['theora']['resolution_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
[148] Fix | Delete
$filedataoffset += 3;
[149] Fix | Delete
$info['ogg']['pageheader']['theora']['picture_offset_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[150] Fix | Delete
$filedataoffset += 1;
[151] Fix | Delete
$info['ogg']['pageheader']['theora']['picture_offset_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[152] Fix | Delete
$filedataoffset += 1;
[153] Fix | Delete
$info['ogg']['pageheader']['theora']['frame_rate_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4));
[154] Fix | Delete
$filedataoffset += 4;
[155] Fix | Delete
$info['ogg']['pageheader']['theora']['frame_rate_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4));
[156] Fix | Delete
$filedataoffset += 4;
[157] Fix | Delete
$info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
[158] Fix | Delete
$filedataoffset += 3;
[159] Fix | Delete
$info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
[160] Fix | Delete
$filedataoffset += 3;
[161] Fix | Delete
$info['ogg']['pageheader']['theora']['color_space_id'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
[162] Fix | Delete
$filedataoffset += 1;
[163] Fix | Delete
$info['ogg']['pageheader']['theora']['nominal_bitrate'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
[164] Fix | Delete
$filedataoffset += 3;
[165] Fix | Delete
$info['ogg']['pageheader']['theora']['flags'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
[166] Fix | Delete
$filedataoffset += 2;
[167] Fix | Delete
[168] Fix | Delete
$info['ogg']['pageheader']['theora']['quality'] = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10;
[169] Fix | Delete
$info['ogg']['pageheader']['theora']['kfg_shift'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >> 5;
[170] Fix | Delete
$info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >> 3;
[171] Fix | Delete
$info['ogg']['pageheader']['theora']['reserved'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >> 0; // should be 0
[172] Fix | Delete
$info['ogg']['pageheader']['theora']['color_space'] = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']);
[173] Fix | Delete
$info['ogg']['pageheader']['theora']['pixel_format'] = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']);
[174] Fix | Delete
[175] Fix | Delete
$info['video']['dataformat'] = 'theora';
[176] Fix | Delete
$info['mime_type'] = 'video/ogg';
[177] Fix | Delete
//$info['audio']['bitrate_mode'] = 'abr';
[178] Fix | Delete
//$info['audio']['lossless'] = false;
[179] Fix | Delete
$info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x'];
[180] Fix | Delete
$info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y'];
[181] Fix | Delete
if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) {
[182] Fix | Delete
$info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator'];
[183] Fix | Delete
}
[184] Fix | Delete
if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) {
[185] Fix | Delete
$info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
[186] Fix | Delete
}
[187] Fix | Delete
$this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable');
[188] Fix | Delete
[189] Fix | Delete
[190] Fix | Delete
} elseif (substr($filedata, 0, 8) == "fishead\x00") {
[191] Fix | Delete
[192] Fix | Delete
// Ogg Skeleton version 3.0 Format Specification
[193] Fix | Delete
// http://xiph.org/ogg/doc/skeleton.html
[194] Fix | Delete
$filedataoffset += 8;
[195] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['version_major'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2));
[196] Fix | Delete
$filedataoffset += 2;
[197] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['version_minor'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2));
[198] Fix | Delete
$filedataoffset += 2;
[199] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[200] Fix | Delete
$filedataoffset += 8;
[201] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[202] Fix | Delete
$filedataoffset += 8;
[203] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[204] Fix | Delete
$filedataoffset += 8;
[205] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[206] Fix | Delete
$filedataoffset += 8;
[207] Fix | Delete
$info['ogg']['skeleton']['fishead']['raw']['utc'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 20));
[208] Fix | Delete
$filedataoffset += 20;
[209] Fix | Delete
[210] Fix | Delete
$info['ogg']['skeleton']['fishead']['version'] = $info['ogg']['skeleton']['fishead']['raw']['version_major'].'.'.$info['ogg']['skeleton']['fishead']['raw']['version_minor'];
[211] Fix | Delete
$info['ogg']['skeleton']['fishead']['presentationtime'] = $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'];
[212] Fix | Delete
$info['ogg']['skeleton']['fishead']['basetime'] = $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'];
[213] Fix | Delete
$info['ogg']['skeleton']['fishead']['utc'] = $info['ogg']['skeleton']['fishead']['raw']['utc'];
[214] Fix | Delete
[215] Fix | Delete
[216] Fix | Delete
$counter = 0;
[217] Fix | Delete
do {
[218] Fix | Delete
$oggpageinfo = $this->ParseOggPageHeader();
[219] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno'].'.'.$counter++] = $oggpageinfo;
[220] Fix | Delete
$filedata = $this->fread($oggpageinfo['page_length']);
[221] Fix | Delete
$this->fseek($oggpageinfo['page_end_offset']);
[222] Fix | Delete
[223] Fix | Delete
if (substr($filedata, 0, 8) == "fisbone\x00") {
[224] Fix | Delete
[225] Fix | Delete
$filedataoffset = 8;
[226] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['message_header_offset'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[227] Fix | Delete
$filedataoffset += 4;
[228] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['serial_number'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[229] Fix | Delete
$filedataoffset += 4;
[230] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['number_header_packets'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[231] Fix | Delete
$filedataoffset += 4;
[232] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['granulerate_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[233] Fix | Delete
$filedataoffset += 8;
[234] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['granulerate_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[235] Fix | Delete
$filedataoffset += 8;
[236] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['basegranule'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
[237] Fix | Delete
$filedataoffset += 8;
[238] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['preroll'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[239] Fix | Delete
$filedataoffset += 4;
[240] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['granuleshift'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
[241] Fix | Delete
$filedataoffset += 1;
[242] Fix | Delete
$info['ogg']['skeleton']['fisbone']['raw']['padding'] = substr($filedata, $filedataoffset, 3);
[243] Fix | Delete
$filedataoffset += 3;
[244] Fix | Delete
[245] Fix | Delete
} elseif (substr($filedata, 1, 6) == 'theora') {
[246] Fix | Delete
[247] Fix | Delete
$info['video']['dataformat'] = 'theora1';
[248] Fix | Delete
$this->error('Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']');
[249] Fix | Delete
//break;
[250] Fix | Delete
[251] Fix | Delete
} elseif (substr($filedata, 1, 6) == 'vorbis') {
[252] Fix | Delete
[253] Fix | Delete
$this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
[254] Fix | Delete
[255] Fix | Delete
} else {
[256] Fix | Delete
$this->error('unexpected');
[257] Fix | Delete
//break;
[258] Fix | Delete
}
[259] Fix | Delete
//} while ($oggpageinfo['page_seqno'] == 0);
[260] Fix | Delete
} while (($oggpageinfo['page_seqno'] == 0) && (substr($filedata, 0, 8) != "fisbone\x00"));
[261] Fix | Delete
[262] Fix | Delete
$this->fseek($oggpageinfo['page_start_offset']);
[263] Fix | Delete
[264] Fix | Delete
$this->error('Ogg Skeleton not correctly handled in this version of getID3 ['.$this->getid3->version().']');
[265] Fix | Delete
//return false;
[266] Fix | Delete
[267] Fix | Delete
} elseif (substr($filedata, 0, 5) == "\x7F".'FLAC') {
[268] Fix | Delete
// https://xiph.org/flac/ogg_mapping.html
[269] Fix | Delete
[270] Fix | Delete
$info['audio']['dataformat'] = 'flac';
[271] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[272] Fix | Delete
$info['audio']['lossless'] = true;
[273] Fix | Delete
[274] Fix | Delete
$info['ogg']['flac']['header']['version_major'] = ord(substr($filedata, 5, 1));
[275] Fix | Delete
$info['ogg']['flac']['header']['version_minor'] = ord(substr($filedata, 6, 1));
[276] Fix | Delete
$info['ogg']['flac']['header']['header_packets'] = getid3_lib::BigEndian2Int(substr($filedata, 7, 2)) + 1; // "A two-byte, big-endian binary number signifying the number of header (non-audio) packets, not including this one. This number may be zero (0x0000) to signify 'unknown' but be aware that some decoders may not be able to handle such streams."
[277] Fix | Delete
$info['ogg']['flac']['header']['magic'] = substr($filedata, 9, 4);
[278] Fix | Delete
if ($info['ogg']['flac']['header']['magic'] != 'fLaC') {
[279] Fix | Delete
$this->error('Ogg-FLAC expecting "fLaC", found "'.$info['ogg']['flac']['header']['magic'].'" ('.trim(getid3_lib::PrintHexBytes($info['ogg']['flac']['header']['magic'])).')');
[280] Fix | Delete
return false;
[281] Fix | Delete
}
[282] Fix | Delete
$info['ogg']['flac']['header']['STREAMINFO_bytes'] = getid3_lib::BigEndian2Int(substr($filedata, 13, 4));
[283] Fix | Delete
$info['flac']['STREAMINFO'] = getid3_flac::parseSTREAMINFOdata(substr($filedata, 17, 34));
[284] Fix | Delete
if (!empty($info['flac']['STREAMINFO']['sample_rate'])) {
[285] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[286] Fix | Delete
$info['audio']['sample_rate'] = $info['flac']['STREAMINFO']['sample_rate'];
[287] Fix | Delete
$info['audio']['channels'] = $info['flac']['STREAMINFO']['channels'];
[288] Fix | Delete
$info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
[289] Fix | Delete
$info['playtime_seconds'] = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate'];
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
} else {
[293] Fix | Delete
[294] Fix | Delete
$this->error('Expecting one of "vorbis", "Speex", "OpusHead", "vorbis", "fishhead", "theora", "fLaC" identifier strings, found "'.substr($filedata, 0, 8).'"');
[295] Fix | Delete
unset($info['ogg']);
[296] Fix | Delete
unset($info['mime_type']);
[297] Fix | Delete
return false;
[298] Fix | Delete
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
// Page 2 - Comment Header
[302] Fix | Delete
$oggpageinfo = $this->ParseOggPageHeader();
[303] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
[304] Fix | Delete
[305] Fix | Delete
switch ($info['audio']['dataformat']) {
[306] Fix | Delete
case 'vorbis':
[307] Fix | Delete
$filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
[308] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1));
[309] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis'
[310] Fix | Delete
[311] Fix | Delete
$this->ParseVorbisComments();
[312] Fix | Delete
break;
[313] Fix | Delete
[314] Fix | Delete
case 'flac':
[315] Fix | Delete
$flac = new getid3_flac($this->getid3);
[316] Fix | Delete
if (!$flac->parseMETAdata()) {
[317] Fix | Delete
$this->error('Failed to parse FLAC headers');
[318] Fix | Delete
return false;
[319] Fix | Delete
}
[320] Fix | Delete
unset($flac);
[321] Fix | Delete
break;
[322] Fix | Delete
[323] Fix | Delete
case 'speex':
[324] Fix | Delete
$this->fseek($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR);
[325] Fix | Delete
$this->ParseVorbisComments();
[326] Fix | Delete
break;
[327] Fix | Delete
[328] Fix | Delete
case 'opus':
[329] Fix | Delete
$filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
[330] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 0, 8); // hard-coded to 'OpusTags'
[331] Fix | Delete
if(substr($filedata, 0, 8) != 'OpusTags') {
[332] Fix | Delete
$this->error('Expected "OpusTags" as header but got "'.substr($filedata, 0, 8).'"');
[333] Fix | Delete
return false;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$this->ParseVorbisComments();
[337] Fix | Delete
break;
[338] Fix | Delete
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
// Last Page - Number of Samples
[342] Fix | Delete
if (!getid3_lib::intValueSupported($info['avdataend'])) {
[343] Fix | Delete
[344] Fix | Delete
$this->warning('Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)');
[345] Fix | Delete
[346] Fix | Delete
} else {
[347] Fix | Delete
[348] Fix | Delete
$this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0));
[349] Fix | Delete
$LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size()));
[350] Fix | Delete
if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) {
[351] Fix | Delete
$this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO')));
[352] Fix | Delete
$info['avdataend'] = $this->ftell();
[353] Fix | Delete
$info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader();
[354] Fix | Delete
$info['ogg']['samples'] = $info['ogg']['pageheader']['eos']['pcm_abs_position'];
[355] Fix | Delete
if ($info['ogg']['samples'] == 0) {
[356] Fix | Delete
$this->error('Corrupt Ogg file: eos.number of samples == zero');
[357] Fix | Delete
return false;
[358] Fix | Delete
}
[359] Fix | Delete
if (!empty($info['audio']['sample_rate'])) {
[360] Fix | Delete
$info['ogg']['bitrate_average'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['ogg']['samples'] / $info['audio']['sample_rate']);
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if (!empty($info['ogg']['bitrate_average'])) {
[367] Fix | Delete
$info['audio']['bitrate'] = $info['ogg']['bitrate_average'];
[368] Fix | Delete
} elseif (!empty($info['ogg']['bitrate_nominal'])) {
[369] Fix | Delete
$info['audio']['bitrate'] = $info['ogg']['bitrate_nominal'];
[370] Fix | Delete
} elseif (!empty($info['ogg']['bitrate_min']) && !empty($info['ogg']['bitrate_max'])) {
[371] Fix | Delete
$info['audio']['bitrate'] = ($info['ogg']['bitrate_min'] + $info['ogg']['bitrate_max']) / 2;
[372] Fix | Delete
}
[373] Fix | Delete
if (isset($info['audio']['bitrate']) && !isset($info['playtime_seconds'])) {
[374] Fix | Delete
if ($info['audio']['bitrate'] == 0) {
[375] Fix | Delete
$this->error('Corrupt Ogg file: bitrate_audio == zero');
[376] Fix | Delete
return false;
[377] Fix | Delete
}
[378] Fix | Delete
$info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']);
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
if (isset($info['ogg']['vendor'])) {
[382] Fix | Delete
$info['audio']['encoder'] = preg_replace('/^Encoded with /', '', $info['ogg']['vendor']);
[383] Fix | Delete
[384] Fix | Delete
// Vorbis only
[385] Fix | Delete
if ($info['audio']['dataformat'] == 'vorbis') {
[386] Fix | Delete
[387] Fix | Delete
// Vorbis 1.0 starts with Xiph.Org
[388] Fix | Delete
if (preg_match('/^Xiph.Org/', $info['audio']['encoder'])) {
[389] Fix | Delete
[390] Fix | Delete
if ($info['audio']['bitrate_mode'] == 'abr') {
[391] Fix | Delete
[392] Fix | Delete
// Set -b 128 on abr files
[393] Fix | Delete
$info['audio']['encoder_options'] = '-b '.round($info['ogg']['bitrate_nominal'] / 1000);
[394] Fix | Delete
[395] Fix | Delete
} elseif (($info['audio']['bitrate_mode'] == 'vbr') && ($info['audio']['channels'] == 2) && ($info['audio']['sample_rate'] >= 44100) && ($info['audio']['sample_rate'] <= 48000)) {
[396] Fix | Delete
// Set -q N on vbr files
[397] Fix | Delete
$info['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($info['ogg']['bitrate_nominal']);
[398] Fix | Delete
[399] Fix | Delete
}
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
if (empty($info['audio']['encoder_options']) && !empty($info['ogg']['bitrate_nominal'])) {
[403] Fix | Delete
$info['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($info['ogg']['bitrate_nominal'] / 1000)).'kbps';
[404] Fix | Delete
}
[405] Fix | Delete
}
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
return true;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* @param string $filedata
[413] Fix | Delete
* @param int $filedataoffset
[414] Fix | Delete
* @param array $oggpageinfo
[415] Fix | Delete
*
[416] Fix | Delete
* @return bool
[417] Fix | Delete
*/
[418] Fix | Delete
public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
[419] Fix | Delete
$info = &$this->getid3->info;
[420] Fix | Delete
$info['audio']['dataformat'] = 'vorbis';
[421] Fix | Delete
$info['audio']['lossless'] = false;
[422] Fix | Delete
[423] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
[424] Fix | Delete
$filedataoffset += 1;
[425] Fix | Delete
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis'
[426] Fix | Delete
$filedataoffset += 6;
[427] Fix | Delete
$info['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[428] Fix | Delete
$filedataoffset += 4;
[429] Fix | Delete
$info['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
[430] Fix | Delete
$filedataoffset += 1;
[431] Fix | Delete
$info['audio']['channels'] = $info['ogg']['numberofchannels'];
[432] Fix | Delete
$info['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[433] Fix | Delete
$filedataoffset += 4;
[434] Fix | Delete
if ($info['ogg']['samplerate'] == 0) {
[435] Fix | Delete
$this->error('Corrupt Ogg file: sample rate == zero');
[436] Fix | Delete
return false;
[437] Fix | Delete
}
[438] Fix | Delete
$info['audio']['sample_rate'] = $info['ogg']['samplerate'];
[439] Fix | Delete
$info['ogg']['samples'] = 0; // filled in later
[440] Fix | Delete
$info['ogg']['bitrate_average'] = 0; // filled in later
[441] Fix | Delete
$info['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[442] Fix | Delete
$filedataoffset += 4;
[443] Fix | Delete
$info['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[444] Fix | Delete
$filedataoffset += 4;
[445] Fix | Delete
$info['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
[446] Fix | Delete
$filedataoffset += 4;
[447] Fix | Delete
$info['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F);
[448] Fix | Delete
$info['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4);
[449] Fix | Delete
$info['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet
[450] Fix | Delete
[451] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr
[452] Fix | Delete
if ($info['ogg']['bitrate_max'] == 0xFFFFFFFF) {
[453] Fix | Delete
unset($info['ogg']['bitrate_max']);
[454] Fix | Delete
$info['audio']['bitrate_mode'] = 'abr';
[455] Fix | Delete
}
[456] Fix | Delete
if ($info['ogg']['bitrate_nominal'] == 0xFFFFFFFF) {
[457] Fix | Delete
unset($info['ogg']['bitrate_nominal']);
[458] Fix | Delete
}
[459] Fix | Delete
if ($info['ogg']['bitrate_min'] == 0xFFFFFFFF) {
[460] Fix | Delete
unset($info['ogg']['bitrate_min']);
[461] Fix | Delete
$info['audio']['bitrate_mode'] = 'abr';
[462] Fix | Delete
}
[463] Fix | Delete
return true;
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
/**
[467] Fix | Delete
* @link http://tools.ietf.org/html/draft-ietf-codec-oggopus-03
[468] Fix | Delete
*
[469] Fix | Delete
* @param string $filedata
[470] Fix | Delete
* @param int $filedataoffset
[471] Fix | Delete
* @param array $oggpageinfo
[472] Fix | Delete
*
[473] Fix | Delete
* @return bool
[474] Fix | Delete
*/
[475] Fix | Delete
public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
[476] Fix | Delete
$info = &$this->getid3->info;
[477] Fix | Delete
$info['audio']['dataformat'] = 'opus';
[478] Fix | Delete
$info['mime_type'] = 'audio/ogg; codecs=opus';
[479] Fix | Delete
[480] Fix | Delete
/** @todo find a usable way to detect abr (vbr that is padded to be abr) */
[481] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[482] Fix | Delete
[483] Fix | Delete
$info['audio']['lossless'] = false;
[484] Fix | Delete
[485] Fix | Delete
$info['ogg']['pageheader']['opus']['opus_magic'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'OpusHead'
[486] Fix | Delete
$filedataoffset += 8;
[487] Fix | Delete
$info['ogg']['pageheader']['opus']['version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
[488] Fix | Delete
$filedataoffset += 1;
[489] Fix | Delete
[490] Fix | Delete
if ($info['ogg']['pageheader']['opus']['version'] < 1 || $info['ogg']['pageheader']['opus']['version'] > 15) {
[491] Fix | Delete
$this->error('Unknown opus version number (only accepting 1-15)');
[492] Fix | Delete
return false;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
$info['ogg']['pageheader']['opus']['out_channel_count'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
[496] Fix | Delete
$filedataoffset += 1;
[497] Fix | Delete
[498] Fix | Delete
if ($info['ogg']['pageheader']['opus']['out_channel_count'] == 0) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function