function getid3_exe(&$fd, &$ThisFileInfo) { fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $EXEheader = fread($fd, 28); if (substr($EXEheader, 0, 2) != 'MZ') { $ThisFileInfo['error'][] = 'Expecting "MZ" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($EXEheader, 0, 2) . '" instead.'; return false; } $ThisFileInfo['fileformat'] = 'exe'; $ThisFileInfo['exe']['mz']['magic'] = 'MZ'; $ThisFileInfo['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); $ThisFileInfo['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); $ThisFileInfo['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); $ThisFileInfo['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); $ThisFileInfo['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); $ThisFileInfo['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); $ThisFileInfo['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); $ThisFileInfo['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); $ThisFileInfo['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); $ThisFileInfo['exe']['mz']['byte_size'] = ($ThisFileInfo['exe']['mz']['raw']['page_count'] - 1) * 512 + $ThisFileInfo['exe']['mz']['raw']['last_page_size']; $ThisFileInfo['exe']['mz']['header_size'] = $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] * 16; $ThisFileInfo['exe']['mz']['memory_minimum'] = $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] * 16; $ThisFileInfo['exe']['mz']['memory_recommended'] = $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] * 16; $ThisFileInfo['error'][] = 'EXE parsing not enabled in this version of getID3()'; return false; }
public function Analyze() { $info =& $this->getid3->info; $this->fseek($info['avdataoffset']); $EXEheader = $this->fread(28); $magic = 'MZ'; if (substr($EXEheader, 0, 2) != $magic) { $info['error'][] = 'Expecting "' . getid3_lib::PrintHexBytes($magic) . '" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($EXEheader, 0, 2)) . '"'; return false; } $info['fileformat'] = 'exe'; $info['exe']['mz']['magic'] = 'MZ'; $info['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); $info['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); $info['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); $info['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); $info['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); $info['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); $info['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); $info['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); $info['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); $info['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); $info['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); $info['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); $info['exe']['mz']['byte_size'] = ($info['exe']['mz']['raw']['page_count'] - 1) * 512 + $info['exe']['mz']['raw']['last_page_size']; $info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16; $info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16; $info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16; $info['error'][] = 'EXE parsing not enabled in this version of getID3() [' . $this->getid3->version() . ']'; return false; }
public function Analyze() { $getid3 = $this->getid3; // http://www.uni-jena.de/~pfk/mpp/sv8/header.html $getid3->info['mpc']['header'] = array(); $info_mpc_header =& $getid3->info['mpc']['header']; $getid3->info['fileformat'] = 'mpc'; $getid3->info['audio']['dataformat'] = 'mpc'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; $getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only $getid3->info['audio']['lossless'] = false; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $info_mpc_header['size'] = 8; $getid3->info['avdataoffset'] += $info_mpc_header['size']; $mpc_header_data = fread($getid3->fp, $info_mpc_header['size']); // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) $header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4)); $header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4)); // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA // aaaa aaaa abcd dddd dddd deee eeff ffff // // a = bitrate = anything // b = IS = anything // c = MS = anything // d = streamversion = 0000000004 or 0000000005 or 0000000006 // e = maxband = anything // f = blocksize = 000001 for SV5+, anything(?) for SV4 $info_mpc_header['target_bitrate'] = ($header_dword[0] & 4286578688.0) >> 23; $info_mpc_header['intensity_stereo'] = (bool) (($header_dword[0] & 0x400000) >> 22); $info_mpc_header['mid-side_stereo'] = (bool) (($header_dword[0] & 0x200000) >> 21); $info_mpc_header['stream_major_version'] = ($header_dword[0] & 0x1ff800) >> 11; $info_mpc_header['stream_minor_version'] = 0; $info_mpc_header['max_band'] = ($header_dword[0] & 0x7c0) >> 6; // related to lowpass frequency, not sure how it translates exactly $info_mpc_header['block_size'] = $header_dword[0] & 0x3f; switch ($info_mpc_header['stream_major_version']) { case 4: $info_mpc_header['frame_count'] = $header_dword[1] >> 16; break; case 5: case 6: $info_mpc_header['frame_count'] = $header_dword[1]; break; default: throw new getid3_exception('Expecting 4, 5 or 6 in version field, found ' . $info_mpc_header['stream_major_version'] . ' instead'); } if ($info_mpc_header['stream_major_version'] > 4 && $info_mpc_header['block_size'] != 1) { $getid3->warning('Block size expected to be 1, actual value found: ' . $info_mpc_header['block_size']); } $info_mpc_header['sample_rate'] = $getid3->info['audio']['sample_rate'] = 44100; // AB: used by all files up to SV7 $info_mpc_header['samples'] = $info_mpc_header['frame_count'] * 1152 * $getid3->info['audio']['channels']; $getid3->info['audio']['bitrate_mode'] = $info_mpc_header['target_bitrate'] == 0 ? 'vbr' : 'cbr'; $getid3->info['mpc']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152; $getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate']; $getid3->info['audio']['encoder'] = 'SV' . $info_mpc_header['stream_major_version']; return true; }
public function Analyze() { $info =& $this->getid3->info; $this->fseek($info['avdataoffset']); $DSSheader = $this->fread(1540); if (!preg_match('#^[\\x02-\\x06]ds[s2]#', $DSSheader)) { $info['error'][] = 'Expecting "[02-06] 64 73 [73|32]" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)) . '"'; return false; } // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed $info['dss'] = array(); $info['fileformat'] = 'dss'; $info['mime_type'] = 'audio/x-' . substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" $info['audio']['bitrate_mode'] = 'cbr'; $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen $info['dss']['date_create_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); $info['dss']['date_complete_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); $info['dss']['playtime_sec'] = intval(substr($DSSheader, 62, 2) * 3600 + substr($DSSheader, 64, 2) * 60 + substr($DSSheader, 66, 2)); // approximate file playtime in HHMMSS if ($info['dss']['version'] <= 3) { $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); $info['dss']['sample_rate_index'] = ord(substr($DSSheader, 1538, 1)); // this isn't certain, this may or may not be where the sample rate info is stored, but it seems consistent on my small selection of sample files $info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']); } else { $this->getid3->warning('DSS above version 3 not fully supported in this version of getID3. Any additional documentation or format specifications would be welcome. This file is version ' . $info['dss']['version']); } $info['audio']['bits_per_sample'] = 16; // maybe, maybe not -- most compressed audio formats don't have a fixed bits-per-sample value, but this is a reasonable approximation $info['audio']['channels'] = 1; if (!empty($info['dss']['playtime_ms']) && floor($info['dss']['playtime_ms'] / 1000) == $info['dss']['playtime_sec']) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; } else { $info['playtime_seconds'] = $info['dss']['playtime_sec']; if (!empty($info['dss']['playtime_ms'])) { $this->getid3->warning('playtime_ms (' . number_format($info['dss']['playtime_ms'] / 1000, 3) . ') does not match playtime_sec (' . number_format($info['dss']['playtime_sec']) . ') - using playtime_sec value'); } } $info['audio']['bitrate'] = $info['filesize'] * 8 / $info['playtime_seconds']; return true; }
function ParseBink(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'bink'; $ThisFileInfo['video']['dataformat'] = 'bink'; $fileData = 'BIK' . fread($fd, 13); $ThisFileInfo['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); $ThisFileInfo['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); if ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] != $ThisFileInfo['bink']['data_size'] + 8) { $ThisFileInfo['error'][] = 'Probably truncated file: expecting ' . $ThisFileInfo['bink']['data_size'] . ' bytes, found ' . ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); } return true; }
function getid3_tta(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'tta'; $ThisFileInfo['audio']['dataformat'] = 'tta'; $ThisFileInfo['audio']['lossless'] = true; $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $ttaheader = fread($fd, 20); $ThisFileInfo['tta']['magic'] = substr($ttaheader, 0, 3); if ($ThisFileInfo['tta']['magic'] != 'TTA') { $ThisFileInfo['error'][] = 'Expecting "TTA" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . $ThisFileInfo['tta']['magic'] . '"'; unset($ThisFileInfo['fileformat']); unset($ThisFileInfo['audio']); unset($ThisFileInfo['tta']); return false; } switch ($ttaheader[3]) { case "": case "": case "": $ThisFileInfo['tta']['major_version'] = 1; $ThisFileInfo['avdataoffset'] = 16; $ThisFileInfo['tta']['compression_level'] = ord($ttaheader[3]); $ThisFileInfo['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); $ThisFileInfo['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); $ThisFileInfo['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4)); $ThisFileInfo['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['tta']['samples_per_channel'] / $ThisFileInfo['tta']['sample_rate']; break; case '2': $ThisFileInfo['tta']['major_version'] = 2; $ThisFileInfo['avdataoffset'] = 20; $ThisFileInfo['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); $ThisFileInfo['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); $ThisFileInfo['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); $ThisFileInfo['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2)); $ThisFileInfo['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); $ThisFileInfo['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4)); $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['tta']['data_length'] / $ThisFileInfo['tta']['sample_rate']; break; default: $ThisFileInfo['error'][] = 'This version of getID3() only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v' . $ttaheader[3]; break; } $ThisFileInfo['audio']['encoder_options'] = '-e' . $ThisFileInfo['tta']['compression_level']; $ThisFileInfo['audio']['encoder'] = 'TTA v' . $ThisFileInfo['tta']['major_version']; $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['tta']['bits_per_sample']; $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['tta']['sample_rate']; $ThisFileInfo['audio']['channels'] = $ThisFileInfo['tta']['channels']; $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; return true; }
public function ParseBink() { $info =& $this->getid3->info; $info['fileformat'] = 'bink'; $info['video']['dataformat'] = 'bink'; $fileData = 'BIK' . fread($this->getid3->fp, 13); $info['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); $info['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); if ($info['avdataend'] - $info['avdataoffset'] != $info['bink']['data_size'] + 8) { $info['error'][] = 'Probably truncated file: expecting ' . $info['bink']['data_size'] . ' bytes, found ' . ($info['avdataend'] - $info['avdataoffset']); } return true; }
function Analyze() { $info =& $this->getid3->info; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $RKAUHeader = fread($this->getid3->fp, 20); $magic = 'RKA'; if (substr($RKAUHeader, 0, 3) != $magic) { $info['error'][] = 'Expecting "' . getid3_lib::PrintHexBytes($magic) . '" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($RKAUHeader, 0, 3)) . '"'; return false; } $info['fileformat'] = 'rkau'; $info['audio']['dataformat'] = 'rkau'; $info['audio']['bitrate_mode'] = 'vbr'; $info['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1)); $info['rkau']['version'] = '1.' . str_pad($info['rkau']['raw']['version'] & 0xf, 2, '0', STR_PAD_LEFT); if ($info['rkau']['version'] > 1.07 || $info['rkau']['version'] < 1.06) { $info['error'][] = 'This version of getID3() [' . $this->getid3->version() . '] can only parse RKAU files v1.06 and 1.07 (this file is v' . $info['rkau']['version'] . ')'; unset($info['rkau']); return false; } $info['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4)); $info['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4)); $info['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1)); $info['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1)); $info['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1)); $this->RKAUqualityLookup($info['rkau']); $info['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1)); $info['rkau']['flags']['joint_stereo'] = (bool) (!($info['rkau']['raw']['flags'] & 0x1)); $info['rkau']['flags']['streaming'] = (bool) ($info['rkau']['raw']['flags'] & 0x2); $info['rkau']['flags']['vrq_lossy_mode'] = (bool) ($info['rkau']['raw']['flags'] & 0x4); if ($info['rkau']['flags']['streaming']) { $info['avdataoffset'] += 20; $info['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4)); } else { $info['avdataoffset'] += 16; $info['rkau']['compressed_bytes'] = $info['avdataend'] - $info['avdataoffset'] - 1; } // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, // sometimes it's more, sometimes less. No idea why(?) $info['audio']['lossless'] = $info['rkau']['lossless']; $info['audio']['channels'] = $info['rkau']['channels']; $info['audio']['bits_per_sample'] = $info['rkau']['bits_per_sample']; $info['audio']['sample_rate'] = $info['rkau']['sample_rate']; $info['playtime_seconds'] = $info['rkau']['source_bytes'] / ($info['rkau']['sample_rate'] * $info['rkau']['channels'] * ($info['rkau']['bits_per_sample'] / 8)); $info['audio']['bitrate'] = $info['rkau']['compressed_bytes'] * 8 / $info['playtime_seconds']; return true; }
public function Analyze() { $getid3 = $this->getid3; $getid3->include_module('audio-video.riff'); fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $shn_header = fread($getid3->fp, 8); // Magic bytes: "ajkg" $getid3->info['fileformat'] = 'shn'; $getid3->info['audio']['dataformat'] = 'shn'; $getid3->info['audio']['lossless'] = true; $getid3->info['audio']['bitrate_mode'] = 'vbr'; $getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header[4]); fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET); $seek_table_signature_test = fread($getid3->fp, 12); $getid3->info['shn']['seektable']['present'] = (bool) (substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK'); if ($getid3->info['shn']['seektable']['present']) { $getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4)); $getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length']; fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET); $seek_table_magic = fread($getid3->fp, 4); if ($seek_table_magic != 'SEEK') { throw new getid3_exception('Expecting "SEEK" at offset ' . $getid3->info['shn']['seektable']['offset'] . ', found "' . $seek_table_magic . '"'); } $seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16); $getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80); } $commandline = 'shorten -x ' . escapeshellarg(realpath($getid3->filename)) . ' - | head -c 64'; $output = `{$commandline}`; if (@$output && substr($output, 12, 4) == 'fmt ') { $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4)); $decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size)); $getid3->info['audio']['channels'] = $decoded_wav_format_ex['channels']; $getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample']; $getid3->info['audio']['sample_rate'] = $decoded_wav_format_ex['sample_rate']; if (substr($output, 20 + $fmt_size, 4) == 'data') { $getid3->info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $decoded_wav_format_ex['raw']['nAvgBytesPerSec']; } else { throw new getid3_exception('shorten failed to decode DATA chunk to expected location, cannot determine playtime'); } $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['playtime_seconds'] * 8; } else { throw new getid3_exception('shorten failed to decode file to WAV for parsing'); return false; } return true; }
public function Analyze() { $getid3 = $this->getid3; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $rkau_header = fread($getid3->fp, 20); // Magic bytes 'RKA' $getid3->info['fileformat'] = 'rkau'; $getid3->info['audio']['dataformat'] = 'rkau'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; // Shortcut $getid3->info['rkau'] = array(); $info_rkau =& $getid3->info['rkau']; $info_rkau['raw']['version'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 3, 1)); $info_rkau['version'] = '1.' . str_pad($info_rkau['raw']['version'] & 0xf, 2, '0', STR_PAD_LEFT); if ($info_rkau['version'] > 1.07 || $info_rkau['version'] < 1.06) { throw new getid3_exception('This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v' . $info_rkau['version'] . ')'); } getid3_lib::ReadSequence('LittleEndian2Int', $info_rkau, $rkau_header, 4, array('source_bytes' => 4, 'sample_rate' => 4, 'channels' => 1, 'bits_per_sample' => 1)); $info_rkau['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 14, 1)); $quality = $info_rkau['raw']['quality'] & 0xf; $info_rkau['lossless'] = $quality == 0 ? true : false; $info_rkau['compression_level'] = (($info_rkau['raw']['quality'] & 0xf0) >> 4) + 1; if (!$info_rkau['lossless']) { $info_rkau['quality_setting'] = $quality; } $info_rkau['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 15, 1)); $info_rkau['flags']['joint_stereo'] = (bool) (!($info_rkau['raw']['flags'] & 0x1)); $info_rkau['flags']['streaming'] = (bool) ($info_rkau['raw']['flags'] & 0x2); $info_rkau['flags']['vrq_lossy_mode'] = (bool) ($info_rkau['raw']['flags'] & 0x4); if ($info_rkau['flags']['streaming']) { $getid3->info['avdataoffset'] += 20; $info_rkau['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 16, 4)); } else { $getid3->info['avdataoffset'] += 16; $info_rkau['compressed_bytes'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'] - 1; } // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, // sometimes it's more, sometimes less. No idea why(?) $getid3->info['audio']['lossless'] = $info_rkau['lossless']; $getid3->info['audio']['channels'] = $info_rkau['channels']; $getid3->info['audio']['bits_per_sample'] = $info_rkau['bits_per_sample']; $getid3->info['audio']['sample_rate'] = $info_rkau['sample_rate']; $getid3->info['playtime_seconds'] = $info_rkau['source_bytes'] / ($info_rkau['sample_rate'] * $info_rkau['channels'] * ($info_rkau['bits_per_sample'] / 8)); $getid3->info['audio']['bitrate'] = $info_rkau['compressed_bytes'] * 8 / $getid3->info['playtime_seconds']; return true; }
public function Analyze() { $info =& $this->getid3->info; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $DSSheader = fread($this->getid3->fp, 1256); if (!preg_match('#^(\\x02|\\x03)ds[s2]#', $DSSheader)) { $info['error'][] = 'Expecting "[02-03] 64 73 [73|32]" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)) . '"'; return false; } // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed $info['dss'] = array(); $info['fileformat'] = 'dss'; $info['mime_type'] = 'audio/x-' . substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" $info['audio']['bitrate_mode'] = 'cbr'; $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen $info['dss']['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); $info['dss']['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); $info['dss']['playtime_sec'] = intval(substr($DSSheader, 62, 2) * 3600 + substr($DSSheader, 64, 2) * 60 + substr($DSSheader, 66, 2)); // approximate file playtime in HHMMSS $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); //$info['audio']['bits_per_sample'] = ?; //$info['audio']['sample_rate'] = ?; $info['audio']['channels'] = 1; $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; if (floor($info['dss']['playtime_ms'] / 1000) != $info['dss']['playtime_sec']) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check $info['playtime_seconds'] = $info['dss']['playtime_sec']; $this->getid3->warning('playtime_ms (' . number_format($info['dss']['playtime_ms'] / 1000, 3) . ') does not match playtime_sec (' . number_format($info['dss']['playtime_sec']) . ') - using playtime_sec value'); } $info['audio']['bitrate'] = $info['filesize'] * 8 / $info['playtime_seconds']; return true; }
function getid3_svg(&$fd, &$ThisFileInfo) { fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); // I'm making this up, please modify as appropriate $SVGheader = fread($fd, 32); $ThisFileInfo['svg']['magic'] = substr($SVGheader, 0, 4); if ($ThisFileInfo['svg']['magic'] == 'aBcD') { $ThisFileInfo['fileformat'] = 'svg'; $ThisFileInfo['video']['dataformat'] = 'svg'; $ThisFileInfo['video']['lossless'] = true; $ThisFileInfo['video']['bits_per_sample'] = 24; $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1; $ThisFileInfo['svg']['width'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); $ThisFileInfo['svg']['height'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 4)); $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['svg']['width']; $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['svg']['height']; return true; } $ThisFileInfo['error'][] = 'Did not find SVG magic bytes "aBcD" at ' . $ThisFileInfo['avdataoffset']; unset($ThisFileInfo['fileformat']); return false; }
function EitherEndian2Int(&$ThisFileInfo, $byteword, $signed = false) { if ($ThisFileInfo['fileformat'] == 'riff') { return getid3_lib::LittleEndian2Int($byteword, $signed); } return getid3_lib::BigEndian2Int($byteword, false, $signed); }
function Analyze() { $info =& $this->getid3->info; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); while (true) { $wavpackheader = fread($this->getid3->fp, 32); if (ftell($this->getid3->fp) >= $info['avdataend']) { break; } elseif (feof($this->getid3->fp)) { break; } elseif (isset($info['wavpack']['blockheader']['total_samples']) && isset($info['wavpack']['blockheader']['block_samples']) && $info['wavpack']['blockheader']['total_samples'] > 0 && $info['wavpack']['blockheader']['block_samples'] > 0 && (!isset($info['wavpack']['riff_trailer_size']) || $info['wavpack']['riff_trailer_size'] <= 0) && (isset($info['wavpack']['config_flags']['md5_checksum']) && $info['wavpack']['config_flags']['md5_checksum'] === false || !empty($info['md5_data_source']))) { break; } $blockheader_offset = ftell($this->getid3->fp) - 32; $blockheader_magic = substr($wavpackheader, 0, 4); $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4)); $magic = 'wvpk'; if ($blockheader_magic != $magic) { $info['error'][] = 'Expecting "' . getid3_lib::PrintHexBytes($magic) . '" at offset ' . $blockheader_offset . ', found "' . getid3_lib::PrintHexBytes($blockheader_magic) . '"'; switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { case 'wavpack': case 'wvc': break; default: unset($info['fileformat']); unset($info['audio']); unset($info['wavpack']); break; } return false; } if (empty($info['wavpack']['blockheader']['block_samples']) || empty($info['wavpack']['blockheader']['total_samples']) || $info['wavpack']['blockheader']['block_samples'] <= 0 || $info['wavpack']['blockheader']['total_samples'] <= 0) { // Also, it is possible that the first block might not have // any samples (block_samples == 0) and in this case you should skip blocks // until you find one with samples because the other information (like // total_samples) are not guaranteed to be correct until (block_samples > 0) // Finally, I have defined a format for files in which the length is not known // (for example when raw files are created using pipes). In these cases // total_samples will be -1 and you must seek to the final block to determine // the total number of samples. $info['audio']['dataformat'] = 'wavpack'; $info['fileformat'] = 'wavpack'; $info['audio']['lossless'] = true; $info['audio']['bitrate_mode'] = 'vbr'; $info['wavpack']['blockheader']['offset'] = $blockheader_offset; $info['wavpack']['blockheader']['magic'] = $blockheader_magic; $info['wavpack']['blockheader']['size'] = $blockheader_size; if ($info['wavpack']['blockheader']['size'] >= 0x100000) { $info['error'][] = 'Expecting WavPack block size less than "0x100000", found "' . $info['wavpack']['blockheader']['size'] . '" at offset ' . $info['wavpack']['blockheader']['offset']; switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { case 'wavpack': case 'wvc': break; default: unset($info['fileformat']); unset($info['audio']); unset($info['wavpack']); break; } return false; } $info['wavpack']['blockheader']['minor_version'] = ord($wavpackheader[8]); $info['wavpack']['blockheader']['major_version'] = ord($wavpackheader[9]); if ($info['wavpack']['blockheader']['major_version'] != 4 || $info['wavpack']['blockheader']['minor_version'] < 4 && $info['wavpack']['blockheader']['minor_version'] > 16) { $info['error'][] = 'Expecting WavPack version between "4.2" and "4.16", found version "' . $info['wavpack']['blockheader']['major_version'] . '.' . $info['wavpack']['blockheader']['minor_version'] . '" at offset ' . $info['wavpack']['blockheader']['offset']; switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { case 'wavpack': case 'wvc': break; default: unset($info['fileformat']); unset($info['audio']); unset($info['wavpack']); break; } return false; } $info['wavpack']['blockheader']['track_number'] = ord($wavpackheader[10]); // unused $info['wavpack']['blockheader']['index_number'] = ord($wavpackheader[11]); // unused $info['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4)); $info['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4)); $info['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4)); $info['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4)); $info['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4)); $info['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($info['wavpack']['blockheader']['flags_raw'] & 0x3); $info['wavpack']['blockheader']['flags']['mono'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x4); $info['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x8); $info['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x10); $info['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x20); $info['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x40); $info['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x80); $info['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x100); $info['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x200); $info['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x400); $info['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x800); $info['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x1000); $info['audio']['lossless'] = !$info['wavpack']['blockheader']['flags']['hybrid']; } while (!feof($this->getid3->fp) && ftell($this->getid3->fp) < $blockheader_offset + $blockheader_size + 8) { $metablock = array('offset' => ftell($this->getid3->fp)); $metablockheader = fread($this->getid3->fp, 2); if (feof($this->getid3->fp)) { break; } $metablock['id'] = ord($metablockheader[0]); $metablock['function_id'] = $metablock['id'] & 0x3f; $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']); // The 0x20 bit in the id of the meta subblocks (which is defined as // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that // if a decoder encounters an id that it does not know about, it uses // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set // then the decoder simply ignores the metadata, but if it is zero // then the decoder should quit because it means that an understanding // of the metadata is required to correctly decode the audio. $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); if ($metablock['large_block']) { $metablockheader .= fread($this->getid3->fp, 2); } $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2; // size is stored in words $metablock['data'] = null; if ($metablock['size'] > 0) { switch ($metablock['function_id']) { case 0x21: // ID_RIFF_HEADER // ID_RIFF_HEADER case 0x22: // ID_RIFF_TRAILER // ID_RIFF_TRAILER case 0x23: // ID_REPLAY_GAIN // ID_REPLAY_GAIN case 0x24: // ID_CUESHEET // ID_CUESHEET case 0x25: // ID_CONFIG_BLOCK // ID_CONFIG_BLOCK case 0x26: // ID_MD5_CHECKSUM $metablock['data'] = fread($this->getid3->fp, $metablock['size']); if ($metablock['padded_data']) { // padded to the nearest even byte $metablock['size']--; $metablock['data'] = substr($metablock['data'], 0, -1); } break; case 0x0: // ID_DUMMY // ID_DUMMY case 0x1: // ID_ENCODER_INFO // ID_ENCODER_INFO case 0x2: // ID_DECORR_TERMS // ID_DECORR_TERMS case 0x3: // ID_DECORR_WEIGHTS // ID_DECORR_WEIGHTS case 0x4: // ID_DECORR_SAMPLES // ID_DECORR_SAMPLES case 0x5: // ID_ENTROPY_VARS // ID_ENTROPY_VARS case 0x6: // ID_HYBRID_PROFILE // ID_HYBRID_PROFILE case 0x7: // ID_SHAPING_WEIGHTS // ID_SHAPING_WEIGHTS case 0x8: // ID_FLOAT_INFO // ID_FLOAT_INFO case 0x9: // ID_INT32_INFO // ID_INT32_INFO case 0xa: // ID_WV_BITSTREAM // ID_WV_BITSTREAM case 0xb: // ID_WVC_BITSTREAM // ID_WVC_BITSTREAM case 0xc: // ID_WVX_BITSTREAM // ID_WVX_BITSTREAM case 0xd: // ID_CHANNEL_INFO fseek($this->getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET); break; default: $info['warning'][] = 'Unexpected metablock type "0x' . str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT) . '" at offset ' . $metablock['offset']; fseek($this->getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET); break; } switch ($metablock['function_id']) { case 0x21: // ID_RIFF_HEADER getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true); $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); $getid3_temp = new getID3(); $getid3_temp->openfile($this->getid3->filename); $getid3_riff = new getid3_riff($getid3_temp); $getid3_riff->ParseRIFFdata($metablock['data']); $metablock['riff'] = $getid3_temp->info['riff']; $info['audio']['sample_rate'] = $getid3_temp->info['riff']['raw']['fmt ']['nSamplesPerSec']; unset($getid3_riff, $getid3_temp); $metablock['riff']['original_filesize'] = $original_wav_filesize; $info['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; $info['playtime_seconds'] = $info['wavpack']['blockheader']['total_samples'] / $info['audio']['sample_rate']; // Safe RIFF header in case there's a RIFF footer later $metablockRIFFheader = $metablock['data']; break; case 0x22: // ID_RIFF_TRAILER $metablockRIFFfooter = $metablockRIFFheader . $metablock['data']; getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true); $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); $getid3_temp = new getID3(); $getid3_temp->openfile($this->getid3->filename); $getid3_temp->info['avdataend'] = $info['avdataend']; $getid3_temp->info['fileformat'] = 'riff'; $getid3_riff = new getid3_riff($getid3_temp); $metablock['riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock['size']); if (!empty($metablock['riff']['INFO'])) { $getid3_riff->RIFFcommentsParse($metablock['riff']['INFO'], $metablock['comments']); $info['tags']['riff'] = $metablock['comments']; } unset($getid3_temp, $getid3_riff); break; case 0x23: // ID_REPLAY_GAIN $info['warning'][] = 'WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset ' . $metablock['offset']; break; case 0x24: // ID_CUESHEET $info['warning'][] = 'WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset ' . $metablock['offset']; break; case 0x25: // ID_CONFIG_BLOCK $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3)); $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x1); // "adobe" mode for 32-bit floats $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x2); // fast mode $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x4); // double fast $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x8); // high quality mode $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x10); // double high (not used yet) $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x20); // bitrate is kbps, not bits / sample $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x40); // automatic noise shaping $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x80); // shaping mode specified $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x100); // joint-stereo mode specified $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x200); // copy file-time from source $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x400); // create executable $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x800); // create correction file $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x1000); // maximize bybrid compression $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x2000); // psychoacoustic quality mode $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x4000); // raw mode (not implemented yet) $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x8000); // calc noise in hybrid mode $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x10000); // obsolete (for information) $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x20000); // extra processing mode $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x40000); // no wvx stream w/ floats & big ints $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x80000); // compute & store MD5 signature $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000); // don't report progress % $info['wavpack']['config_flags'] = $metablock['flags']; $info['audio']['encoder_options'] = ''; if ($info['wavpack']['blockheader']['flags']['hybrid']) { $info['audio']['encoder_options'] .= ' -b???'; } $info['audio']['encoder_options'] .= $metablock['flags']['adobe_mode'] ? ' -a' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['optimize_wvc'] ? ' -cc' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['create_exe'] ? ' -e' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['fast_flag'] ? ' -f' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['joint_override'] ? ' -j?' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['high_flag'] ? ' -h' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['md5_checksum'] ? ' -m' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['calc_noise'] ? ' -n' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['shape_override'] ? ' -s?' : ''; $info['audio']['encoder_options'] .= $metablock['flags']['extra_mode'] ? ' -x?' : ''; if (!empty($info['audio']['encoder_options'])) { $info['audio']['encoder_options'] = trim($info['audio']['encoder_options']); } elseif (isset($info['audio']['encoder_options'])) { unset($info['audio']['encoder_options']); } break; case 0x26: // ID_MD5_CHECKSUM if (strlen($metablock['data']) == 16) { $info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false)); } else { $info['warning'][] = 'Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset ' . $metablock['offset'] . ', but found ' . strlen($metablock['data']) . ' bytes'; } break; case 0x0: // ID_DUMMY // ID_DUMMY case 0x1: // ID_ENCODER_INFO // ID_ENCODER_INFO case 0x2: // ID_DECORR_TERMS // ID_DECORR_TERMS case 0x3: // ID_DECORR_WEIGHTS // ID_DECORR_WEIGHTS case 0x4: // ID_DECORR_SAMPLES // ID_DECORR_SAMPLES case 0x5: // ID_ENTROPY_VARS // ID_ENTROPY_VARS case 0x6: // ID_HYBRID_PROFILE // ID_HYBRID_PROFILE case 0x7: // ID_SHAPING_WEIGHTS // ID_SHAPING_WEIGHTS case 0x8: // ID_FLOAT_INFO // ID_FLOAT_INFO case 0x9: // ID_INT32_INFO // ID_INT32_INFO case 0xa: // ID_WV_BITSTREAM // ID_WV_BITSTREAM case 0xb: // ID_WVC_BITSTREAM // ID_WVC_BITSTREAM case 0xc: // ID_WVX_BITSTREAM // ID_WVX_BITSTREAM case 0xd: // ID_CHANNEL_INFO unset($metablock); break; } } if (!empty($metablock)) { $info['wavpack']['metablocks'][] = $metablock; } } } $info['audio']['encoder'] = 'WavPack v' . $info['wavpack']['blockheader']['major_version'] . '.' . str_pad($info['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT); $info['audio']['bits_per_sample'] = $info['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8; $info['audio']['channels'] = $info['wavpack']['blockheader']['flags']['mono'] ? 1 : 2; if (!empty($info['playtime_seconds'])) { $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; } else { $info['audio']['dataformat'] = 'wvc'; } return true; }
static function MultiByteCharString2HTML($string, $charset = 'ISO-8859-1') { $HTMLstring = ''; switch ($charset) { case 'ISO-8859-1': case 'ISO8859-1': case 'ISO-8859-15': case 'ISO8859-15': case 'cp866': case 'ibm866': case '866': case 'cp1251': case 'Windows-1251': case 'win-1251': case '1251': case 'cp1252': case 'Windows-1252': case '1252': case 'KOI8-R': case 'koi8-ru': case 'koi8r': case 'BIG5': case '950': case 'GB2312': case '936': case 'BIG5-HKSCS': case 'Shift_JIS': case 'SJIS': case '932': case 'EUC-JP': case 'EUCJP': $HTMLstring = htmlentities($string, ENT_COMPAT, $charset); break; case 'UTF-8': $strlen = strlen($string); for ($i = 0; $i < $strlen; $i++) { $char_ord_val = ord($string[$i]); $charval = 0; if ($char_ord_val < 0x80) { $charval = $char_ord_val; } elseif (($char_ord_val & 0xf0) >> 4 == 0xf && $i + 3 < $strlen) { $charval = ($char_ord_val & 0x7) << 18; $charval += (ord($string[++$i]) & 0x3f) << 12; $charval += (ord($string[++$i]) & 0x3f) << 6; $charval += ord($string[++$i]) & 0x3f; } elseif (($char_ord_val & 0xe0) >> 5 == 0x7 && $i + 2 < $strlen) { $charval = ($char_ord_val & 0xf) << 12; $charval += (ord($string[++$i]) & 0x3f) << 6; $charval += ord($string[++$i]) & 0x3f; } elseif (($char_ord_val & 0xc0) >> 6 == 0x3 && $i + 1 < $strlen) { $charval = ($char_ord_val & 0x1f) << 6; $charval += ord($string[++$i]) & 0x3f; } if ($charval >= 32 && $charval <= 127) { $HTMLstring .= htmlentities(chr($charval)); } else { $HTMLstring .= '&#' . $charval . ';'; } } break; case 'UTF-16LE': for ($i = 0; $i < strlen($string); $i += 2) { $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2)); if ($charval >= 32 && $charval <= 127) { $HTMLstring .= chr($charval); } else { $HTMLstring .= '&#' . $charval . ';'; } } break; case 'UTF-16BE': for ($i = 0; $i < strlen($string); $i += 2) { $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2)); if ($charval >= 32 && $charval <= 127) { $HTMLstring .= chr($charval); } else { $HTMLstring .= '&#' . $charval . ';'; } } break; default: $HTMLstring = 'ERROR: Character set "' . $charset . '" not supported in MultiByteCharString2HTML()'; break; } return $HTMLstring; }
function ParseDirectoryRecord(&$fd, $directorydata, &$ThisFileInfo) { if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor'])) { $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode } else { $TextEncoding = 'ISO-8859-1'; // Latin-1 } fseek($fd, $directorydata['location_bytes'], SEEK_SET); $DirectoryRecordData = fread($fd, 1); while (ord($DirectoryRecordData[0]) > 33) { $DirectoryRecordData .= fread($fd, ord($DirectoryRecordData[0]) - 1); $ThisDirectoryRecord['raw']['length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 0, 1)); $ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 1, 1)); $ThisDirectoryRecord['raw']['offset_logical'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 2, 4)); $ThisDirectoryRecord['raw']['filesize'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 10, 4)); $ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData, 18, 7); $ThisDirectoryRecord['raw']['file_flags'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 25, 1)); $ThisDirectoryRecord['raw']['file_unit_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 26, 1)); $ThisDirectoryRecord['raw']['interleave_gap_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 27, 1)); $ThisDirectoryRecord['raw']['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 28, 2)); $ThisDirectoryRecord['raw']['file_identifier_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1)); $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']); $ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $ThisFileInfo['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize']; $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048; $ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x1); $ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x2); $ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x4); $ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x8); $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10); $ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80); $ThisDirectoryRecord['recording_timestamp'] = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']); if ($ThisDirectoryRecord['file_flags']['directory']) { $ThisDirectoryRecord['filename'] = $directorydata['full_path']; } else { $ThisDirectoryRecord['filename'] = $directorydata['full_path'] . $this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']); $ThisFileInfo['iso']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); } $DirectoryRecord[] = $ThisDirectoryRecord; $DirectoryRecordData = fread($fd, 1); } return $DirectoryRecord; }
public function Analyze() { $getid3 = $this->getid3; $getid3->include_module('audio-video.riff'); fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); $getid3->info['fileformat'] = 'la'; $getid3->info['audio']['dataformat'] = 'la'; $getid3->info['audio']['lossless'] = true; $getid3->info['la']['version_major'] = (int) $raw_data[2]; $getid3->info['la']['version_minor'] = (int) $raw_data[3]; $getid3->info['la']['version'] = (double) $getid3->info['la']['version_major'] + $getid3->info['la']['version_minor'] / 10; $getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4)); $wave_chunk = substr($raw_data, 8, 4); if ($wave_chunk !== 'WAVE') { throw new getid3_exception('Expected "WAVE" (' . getid3_lib::PrintHexBytes('WAVE') . ') at offset 8, found "' . $wave_chunk . '" (' . getid3_lib::PrintHexBytes($wave_chunk) . ') instead.'); } $offset = 12; $getid3->info['la']['fmt_size'] = 24; if ($getid3->info['la']['version'] >= 0.3) { $getid3->info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $getid3->info['la']['header_size'] = 49 + $getid3->info['la']['fmt_size'] - 24; $offset += 4; } else { // version 0.2 didn't support additional data blocks $getid3->info['la']['header_size'] = 41; } $fmt_chunk = substr($raw_data, $offset, 4); if ($fmt_chunk !== 'fmt ') { throw new getid3_exception('Expected "fmt " (' . getid3_lib::PrintHexBytes('fmt ') . ') at offset ' . $offset . ', found "' . $fmt_chunk . '" (' . getid3_lib::PrintHexBytes($fmt_chunk) . ') instead.'); } $offset += 4; $fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; $getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2)); $offset += 2; getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['la'], $raw_data, $offset, array('channels' => 2, 'sample_rate' => 4, 'bytes_per_second' => 4, 'bytes_per_sample' => 2, 'bits_per_sample' => 2, 'samples' => 4)); $offset += 18; $getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data[$offset++]); $getid3->info['la']['flags']['seekable'] = (bool) ($getid3->info['la']['raw']['flags'] & 0x1); if ($getid3->info['la']['version'] >= 0.4) { $getid3->info['la']['flags']['high_compression'] = (bool) ($getid3->info['la']['raw']['flags'] & 0x2); } $getid3->info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; // mikeØbevin*de // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 // in earlier versions. A seekpoint is added every blocksize * seekevery // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should // give the number of bytes used for the seekpoints. Of course, if seeking // is disabled, there are no seekpoints stored. if ($getid3->info['la']['version'] >= 0.4) { $getid3->info['la']['blocksize'] = 61440; $getid3->info['la']['seekevery'] = 19; } else { $getid3->info['la']['blocksize'] = 73728; $getid3->info['la']['seekevery'] = 16; } $getid3->info['la']['seekpoint_count'] = 0; if ($getid3->info['la']['flags']['seekable']) { $getid3->info['la']['seekpoint_count'] = floor($getid3->info['la']['samples'] / ($getid3->info['la']['blocksize'] * $getid3->info['la']['seekevery'])); for ($i = 0; $i < $getid3->info['la']['seekpoint_count']; $i++) { $getid3->info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; } } if ($getid3->info['la']['version'] >= 0.3) { // Following the main header information, the program outputs all of the // seekpoints. Following these is what I called the 'footer start', // i.e. the position immediately after the La audio data is finished. $getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; if ($getid3->info['la']['footerstart'] > $getid3->info['filesize']) { $getid3->warning('FooterStart value points to offset ' . $getid3->info['la']['footerstart'] . ' which is beyond end-of-file (' . $getid3->info['filesize'] . ')'); $getid3->info['la']['footerstart'] = $getid3->info['filesize']; } } else { // La v0.2 didn't have FooterStart value $getid3->info['la']['footerstart'] = $getid3->info['avdataend']; } if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) { // Create riff header $riff_data = 'WAVE'; if ($getid3->info['la']['version'] == 0.2) { $riff_data .= substr($raw_data, 12, 24); } else { $riff_data .= substr($raw_data, 16, 24); } if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) { fseek($getid3->fp, $getid3->info['la']['footerstart'], SEEK_SET); $riff_data .= fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['la']['footerstart']); } $riff_data = 'RIFF' . getid3_lib::LittleEndian2String(strlen($riff_data), 4, false) . $riff_data; // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; // Analyze clone by string $riff = new getid3_riff($clone); $riff->AnalyzeString($riff_data); // Import from clone and destroy $getid3->info['riff'] = $clone->info['riff']; $getid3->warnings($clone->warnings()); unset($clone); } // $getid3->info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway $getid3->info['avdataend'] = $getid3->info['avdataoffset'] + $getid3->info['la']['footerstart']; $getid3->info['avdataoffset'] = $getid3->info['avdataoffset'] + $offset; $getid3->info['la']['compression_ratio'] = (double) (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['la']['uncompressed_size']); $getid3->info['playtime_seconds'] = (double) ($getid3->info['la']['samples'] / $getid3->info['la']['sample_rate']) / $getid3->info['la']['channels']; $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds']; $getid3->info['audio']['bits_per_sample'] = $getid3->info['la']['bits_per_sample']; $getid3->info['audio']['channels'] = $getid3->info['la']['channels']; $getid3->info['audio']['sample_rate'] = (int) $getid3->info['la']['sample_rate']; $getid3->info['audio']['encoder'] = 'LA v' . $getid3->info['la']['version']; return true; }
public function Analyze() { $getid3 = $this->getid3; // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp // all versions // WORD bfType; // DWORD bfSize; // WORD bfReserved1; // WORD bfReserved2; // DWORD bfOffBits; // shortcuts $getid3->info['bmp']['header']['raw'] = array(); $info_bmp =& $getid3->info['bmp']; $info_bmp_header =& $info_bmp['header']; $info_bmp_header_raw =& $info_bmp_header['raw']; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $bmp_header = fread($getid3->fp, 14 + 40); // Magic bytes $info_bmp_header_raw['identifier'] = 'BM'; getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 2, array('filesize' => 4, 'reserved1' => 2, 'reserved2' => 2, 'data_offset' => 4, 'header_size' => 4)); // Check if the hardcoded-to-1 "planes" is at offset 22 or 26 $planes22 = getid3_lib::LittleEndian2Int(substr($bmp_header, 22, 2)); $planes26 = getid3_lib::LittleEndian2Int(substr($bmp_header, 26, 2)); if ($planes22 == 1 && $planes26 != 1) { $info_bmp['type_os'] = 'OS/2'; $info_bmp['type_version'] = 1; } elseif ($planes26 == 1 && $planes22 != 1) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 1; } elseif ($info_bmp_header_raw['header_size'] == 12) { $info_bmp['type_os'] = 'OS/2'; $info_bmp['type_version'] = 1; } elseif ($info_bmp_header_raw['header_size'] == 40) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 1; } elseif ($info_bmp_header_raw['header_size'] == 84) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 4; } elseif ($info_bmp_header_raw['header_size'] == 100) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 5; } else { throw new getid3_exception('Unknown BMP subtype (or not a BMP file)'); } $getid3->info['fileformat'] = 'bmp'; $getid3->info['video']['dataformat'] = 'bmp'; $getid3->info['video']['lossless'] = true; $getid3->info['video']['pixel_aspect_ratio'] = (double) 1; if ($info_bmp['type_os'] == 'OS/2') { // OS/2-format BMP // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm // DWORD Size; /* Size of this structure in bytes */ // DWORD Width; /* Bitmap width in pixels */ // DWORD Height; /* Bitmap height in pixel */ // WORD NumPlanes; /* Number of bit planes (color depth) */ // WORD BitsPerPixel; /* Number of bits per pixel per plane */ getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, array('width' => 2, 'height' => 2, 'planes' => 2, 'bits_per_pixel' => 2)); $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; $getid3->info['video']['codec'] = 'BI_RGB ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit'; $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel']; if ($info_bmp['type_version'] >= 2) { // DWORD Compression; /* Bitmap compression scheme */ // DWORD ImageDataSize; /* Size of bitmap data in bytes */ // DWORD XResolution; /* X resolution of display device */ // DWORD YResolution; /* Y resolution of display device */ // DWORD ColorsUsed; /* Number of color table indices used */ // DWORD ColorsImportant; /* Number of important color indices */ // WORD Units; /* Type of units used to measure resolution */ // WORD Reserved; /* Pad structure to 4-byte boundary */ // WORD Recording; /* Recording algorithm */ // WORD Rendering; /* Halftoning algorithm used */ // DWORD Size1; /* Reserved for halftoning algorithm use */ // DWORD Size2; /* Reserved for halftoning algorithm use */ // DWORD ColorEncoding; /* Color model used in bitmap */ // DWORD Identifier; /* Reserved for application use */ getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 26, array('compression' => 4, 'bmp_data_size' => 4, 'resolution_h' => 4, 'resolution_v' => 4, 'colors_used' => 4, 'colors_important' => 4, 'resolution_units' => 2, 'reserved1' => 2, 'recording' => 2, 'rendering' => 2, 'size1' => 4, 'size2' => 4, 'color_encoding' => 4, 'identifier' => 4)); $info_bmp_header['compression'] = getid3_bmp::BMPcompressionOS2Lookup($info_bmp_header_raw['compression']); $getid3->info['video']['codec'] = $info_bmp_header['compression'] . ' ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit'; } return true; } if ($info_bmp['type_os'] == 'Windows') { // Windows-format BMP // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp // all versions // DWORD biSize; // LONG biWidth; // LONG biHeight; // WORD biPlanes; // WORD biBitCount; // DWORD biCompression; // DWORD biSizeImage; // LONG biXPelsPerMeter; // LONG biYPelsPerMeter; // DWORD biClrUsed; // DWORD biClrImportant; getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, array('width' => -4, 'height' => -4, 'planes' => 2, 'bits_per_pixel' => 2, 'compression' => 4, 'bmp_data_size' => 4, 'resolution_h' => -4, 'resolution_v' => -4, 'colors_used' => 4, 'colors_important' => 4)); foreach (array('width', 'height', 'resolution_h', 'resolution_v') as $key) { $info_bmp_header_raw[$key] = getid3_lib::LittleEndian2Int($info_bmp_header_raw[$key], true); } $info_bmp_header['compression'] = getid3_bmp::BMPcompressionWindowsLookup($info_bmp_header_raw['compression']); $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; $getid3->info['video']['codec'] = $info_bmp_header['compression'] . ' ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit'; $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel']; // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen if ($info_bmp['type_version'] >= 4 || $info_bmp_header_raw['compression'] == 3) { $bmp_header .= fread($getid3->fp, 44); // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp // Win95+, WinNT4.0+ // DWORD bV4RedMask; // DWORD bV4GreenMask; // DWORD bV4BlueMask; // DWORD bV4AlphaMask; // DWORD bV4CSType; // CIEXYZTRIPLE bV4Endpoints; // DWORD bV4GammaRed; // DWORD bV4GammaGreen; // DWORD bV4GammaBlue; getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 54, array('red_mask' => 4, 'green_mask' => 4, 'blue_mask' => 4, 'alpha_mask' => 4, 'cs_type' => 4, 'ciexyz_red' => -4, 'ciexyz_green' => -4, 'ciexyz_blue' => -4, 'gamma_red' => 4, 'gamma_green' => 4, 'gamma_blue' => 4)); $info_bmp_header['ciexyz_red'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_red'])); $info_bmp_header['ciexyz_green'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_green'])); $info_bmp_header['ciexyz_blue'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_blue'])); if ($info_bmp['type_version'] >= 5) { $bmp_header .= fread($getid3->fp, 16); // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp // Win98+, Win2000+ // DWORD bV5Intent; // DWORD bV5ProfileData; // DWORD bV5ProfileSize; // DWORD bV5Reserved; getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 98, array('intent' => 4, 'profile_data_offset' => 4, 'profile_data_size' => 4, 'reserved3' => 4)); } } return true; } throw new getid3_exception('Unknown BMP format in header.'); }
public function Analyze() { $info =& $this->getid3->info; $info['fileformat'] = 'swf'; $info['video']['dataformat'] = 'swf'; // http://www.openswf.org/spec/SWFfileformat.html $this->fseek($info['avdataoffset']); $SWFfileData = $this->fread($info['avdataend'] - $info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data $info['swf']['header']['signature'] = substr($SWFfileData, 0, 3); switch ($info['swf']['header']['signature']) { case 'FWS': $info['swf']['header']['compressed'] = false; break; case 'CWS': $info['swf']['header']['compressed'] = true; break; default: $info['error'][] = 'Expecting "FWS" or "CWS" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes($info['swf']['header']['signature']) . '"'; unset($info['swf']); unset($info['fileformat']); return false; break; } $info['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1)); $info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4)); if ($info['swf']['header']['compressed']) { $SWFHead = substr($SWFfileData, 0, 8); $SWFfileData = substr($SWFfileData, 8); if ($decompressed = @gzuncompress($SWFfileData)) { $SWFfileData = $SWFHead . $decompressed; } else { $info['error'][] = 'Error decompressing compressed SWF data (' . strlen($SWFfileData) . ' bytes compressed, should be ' . ($info['swf']['header']['length'] - 8) . ' bytes uncompressed)'; return false; } } $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xf8) >> 3; $FrameSizeDataLength = ceil((5 + 4 * $FrameSizeBitsPerValue) / 8); $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x7), 3, '0', STR_PAD_LEFT); for ($i = 1; $i < $FrameSizeDataLength; $i++) { $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); } list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); $info['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); $info['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm // Next in the header is the frame rate, which is kind of weird. // It is supposed to be stored as a 16bit integer, but the first byte // (or last depending on how you look at it) is completely ignored. // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. // Byte at (8 + $FrameSizeDataLength) is always zero and ignored $info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); $info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); $info['video']['frame_rate'] = $info['swf']['header']['frame_rate']; $info['video']['resolution_x'] = intval(round($info['swf']['header']['frame_width'] / 20)); $info['video']['resolution_y'] = intval(round($info['swf']['header']['frame_height'] / 20)); $info['video']['pixel_aspect_ratio'] = (double) 1; if ($info['swf']['header']['frame_count'] > 0 && $info['swf']['header']['frame_rate'] > 0) { $info['playtime_seconds'] = $info['swf']['header']['frame_count'] / $info['swf']['header']['frame_rate']; } //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; // SWF tags $CurrentOffset = 12 + $FrameSizeDataLength; $SWFdataLength = strlen($SWFfileData); while ($CurrentOffset < $SWFdataLength) { //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); $TagID = ($TagIDTagLength & 0xfffc) >> 6; $TagLength = $TagIDTagLength & 0x3f; $CurrentOffset += 2; if ($TagLength == 0x3f) { $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); $CurrentOffset += 4; } unset($TagData); $TagData['offset'] = $CurrentOffset; $TagData['size'] = $TagLength; $TagData['id'] = $TagID; $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); switch ($TagID) { case 0: // end of movie break 2; case 9: // Set background color //$info['swf']['tags'][] = $TagData; $info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); break; default: if ($this->ReturnAllTagData) { $info['swf']['tags'][] = $TagData; } break; } $CurrentOffset += $TagLength; } return true; }
function ParseOptimFROGheader45(&$fd, &$ThisFileInfo) { // for fileformat of v4.50a and higher $RIFFdata = ''; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); while (!feof($fd) && ftell($fd) < $ThisFileInfo['avdataend']) { $BlockOffset = ftell($fd); $BlockData = fread($fd, 8); $offset = 8; $BlockName = substr($BlockData, 0, 4); $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); if ($BlockName == 'OFRX') { $BlockName = 'OFR '; } if (!isset($ThisFileInfo['ofr'][$BlockName])) { $ThisFileInfo['ofr'][$BlockName] = array(); } $thisfile_ofr_thisblock =& $ThisFileInfo['ofr'][$BlockName]; switch ($BlockName) { case 'OFR ': // shortcut $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; $ThisFileInfo['audio']['encoder'] = 'OptimFROG 4.50 alpha'; switch ($BlockSize) { case 12: case 15: // good break; default: $ThisFileInfo['warning'][] = '"' . $BlockName . '" contains more data than expected (expected 12 or 15 bytes, found ' . $BlockSize . ' bytes)'; break; } $BlockData .= fread($fd, $BlockSize); $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6)); $offset += 6; $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); $offset += 1; $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config']; $offset += 1; $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); $offset += 4; if ($BlockSize > 12) { // OFR 4.504b or higher $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']); $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']); $offset += 2; $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']); $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']); $offset += 1; $ThisFileInfo['audio']['encoder'] = 'OptimFROG ' . $thisfile_ofr_thisblock['encoder']; $ThisFileInfo['audio']['encoder_options'] = '--mode ' . $thisfile_ofr_thisblock['compression']; if (($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xf0) >> 4 == 7) { // v4.507 if (strtolower(getid3_lib::fileextension($ThisFileInfo['filename'])) == 'ofs') { // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference // between lossless and lossy other than the file extension. $ThisFileInfo['audio']['dataformat'] = 'ofs'; $ThisFileInfo['audio']['lossless'] = true; } } } $ThisFileInfo['audio']['channels'] = $thisfile_ofr_thisblock['channels']; $ThisFileInfo['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate']; $ThisFileInfo['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); break; case 'COMP': // unlike other block types, there CAN be multiple COMP blocks $COMPdata['offset'] = $BlockOffset; $COMPdata['size'] = $BlockSize; if ($ThisFileInfo['avdataoffset'] == 0) { $ThisFileInfo['avdataoffset'] = $BlockOffset; } // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data $BlockData .= fread($fd, 14); fseek($fd, $BlockSize - 14, SEEK_CUR); $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); $offset += 4; $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); $offset += 4; $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']); $offset += 1; $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']); $offset += 1; $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']); $offset += 2; if ($ThisFileInfo['ofr']['OFR ']['size'] > 12) { // OFR 4.504b or higher $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']); $offset += 2; } if ($COMPdata['crc_32'] == 0x454e4f4e) { // ASCII value of 'NONE' - placeholder value in v4.50a $COMPdata['crc_32'] = false; } $thisfile_ofr_thisblock[] = $COMPdata; break; case 'HEAD': $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; $RIFFdata .= fread($fd, $BlockSize); break; case 'TAIL': $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; if ($BlockSize > 0) { $RIFFdata .= fread($fd, $BlockSize); } break; case 'RECV': // block contains no useful meta data - simply note and skip $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; fseek($fd, $BlockSize, SEEK_CUR); break; case 'APET': // APEtag v2 $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; $ThisFileInfo['warning'][] = 'APEtag processing inside OptimFROG not supported in this version (' . GETID3_VERSION . ') of getID3()'; fseek($fd, $BlockSize, SEEK_CUR); break; case 'MD5 ': // APEtag v2 $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; if ($BlockSize == 16) { $thisfile_ofr_thisblock['md5_binary'] = fread($fd, $BlockSize); $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false); $ThisFileInfo['md5_data_source'] = $thisfile_ofr_thisblock['md5_string']; } else { $ThisFileInfo['warning'][] = 'Expecting block size of 16 in "MD5 " chunk, found ' . $BlockSize . ' instead'; fseek($fd, $BlockSize, SEEK_CUR); } break; default: $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; $ThisFileInfo['warning'][] = 'Unhandled OptimFROG block type "' . $BlockName . '" at offset ' . $thisfile_ofr_thisblock['offset']; fseek($fd, $BlockSize, SEEK_CUR); break; } } if (isset($ThisFileInfo['ofr']['TAIL']['offset'])) { $ThisFileInfo['avdataend'] = $ThisFileInfo['ofr']['TAIL']['offset']; } $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['ofr']['OFR ']['total_samples'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']); $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk $RIFFdata = substr($RIFFdata, 0, 36) . substr($RIFFdata, 44) . substr($RIFFdata, 36, 8); getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo); return true; }
private function EitherEndian2Int($byteword, $signed = false) { if ($this->container == 'riff') { return getid3_lib::LittleEndian2Int($byteword, $signed); } return getid3_lib::BigEndian2Int($byteword, false, $signed); }
function HandleBonkTags(&$fd, &$BonkTagName, &$ThisFileInfo) { switch ($BonkTagName) { case 'BONK': // shortcut $thisfile_bonk_BONK =& $ThisFileInfo['bonk']['BONK']; $BonkData = "" . 'BONK' . fread($fd, 17); $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4)); $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4)); $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1)); $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1)); $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1)); $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2)); $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1)); $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2)); $ThisFileInfo['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17; $ThisFileInfo['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size']; $ThisFileInfo['fileformat'] = 'bonk'; $ThisFileInfo['audio']['dataformat'] = 'bonk'; $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; // assumed $ThisFileInfo['audio']['channels'] = $thisfile_bonk_BONK['channels']; $ThisFileInfo['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate']; $ThisFileInfo['audio']['channelmode'] = $thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo'; $ThisFileInfo['audio']['lossless'] = $thisfile_bonk_BONK['lossless']; $ThisFileInfo['audio']['codec'] = 'bonk'; $ThisFileInfo['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']); if ($ThisFileInfo['playtime_seconds'] > 0) { $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['bonk']['dataend'] - $ThisFileInfo['bonk']['dataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; } break; case 'INFO': // shortcut $thisfile_bonk_INFO =& $ThisFileInfo['bonk']['INFO']; $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($fd, 1)); $thisfile_bonk_INFO['entries_count'] = 0; $NextInfoDataPair = fread($fd, 5); if (!$this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { while (!feof($fd)) { //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4)); //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1)); //$thisfile_bonk_INFO[] = $CurrentSeekInfo; $NextInfoDataPair = fread($fd, 5); if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { fseek($fd, -5, SEEK_CUR); break; } $thisfile_bonk_INFO['entries_count']++; } } break; case 'META': $BonkData = "" . 'META' . fread($fd, $ThisFileInfo['bonk']['META']['size'] - 5); $ThisFileInfo['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); $MetaTagEntries = floor((strlen($BonkData) - 8 - 6) / 8); // BonkData - xxxxmeta - ØMETA $offset = 6; for ($i = 0; $i < $MetaTagEntries; $i++) { $MetaEntryTagName = substr($BonkData, $offset, 4); $offset += 4; $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4)); $offset += 4; $ThisFileInfo['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset; } break; case ' ID3': $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+'; // ID3v2 checking is optional if (class_exists('getid3_id3v2')) { $ThisFileInfo['bonk'][' ID3']['valid'] = new getid3_id3v2($fd, $ThisFileInfo, $ThisFileInfo['bonk'][' ID3']['offset'] + 2); } break; default: $ThisFileInfo['warning'][] = 'Unexpected Bonk tag "' . $BonkTagName . '" at offset ' . $ThisFileInfo['bonk'][$BonkTagName]['offset']; break; } }
function TIFFendian2Int($bytestring, $byteorder) { if ($byteorder == 'Intel') { return getid3_lib::LittleEndian2Int($bytestring); } elseif ($byteorder == 'Motorola') { return getid3_lib::BigEndian2Int($bytestring); } return false; }
public function Analyze() { $getid3 = $this->getid3; // http://www.atsc.org/standards/a_52a.pdf $getid3->info['fileformat'] = 'ac3'; $getid3->info['audio']['dataformat'] = 'ac3'; $getid3->info['audio']['bitrate_mode'] = 'cbr'; $getid3->info['audio']['lossless'] = false; $getid3->info['ac3']['raw']['bsi'] = array(); $info_ac3 =& $getid3->info['ac3']; $info_ac3_raw =& $info_ac3['raw']; $info_ac3_raw_bsi =& $info_ac3_raw['bsi']; // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 // new audio samples per channel. A synchronization information (SI) header at the beginning // of each frame contains information needed to acquire and maintain synchronization. A // bit stream information (BSI) header follows SI, and contains parameters describing the coded // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the // end of each frame is an error check field that includes a CRC word for error detection. An // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. // // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC $this->fseek($getid3->info['avdataoffset'], SEEK_SET); $ac3_header['syncinfo'] = $this->fread(5); $info_ac3_raw['synchinfo']['synchword'] = substr($ac3_header['syncinfo'], 0, 2); if ($info_ac3_raw['synchinfo']['synchword'] != "\vw") { throw new getid3_exception('Expecting "\\x0B\\x77" at offset ' . $getid3->info['avdataoffset'] . ', found \\x' . strtoupper(dechex($ac3_header['syncinfo'][0])) . '\\x' . strtoupper(dechex($ac3_header['syncinfo'][1])) . ' instead'); } // syncinfo() { // syncword 16 // crc1 16 // fscod 2 // frmsizecod 6 // } /* end of syncinfo */ $info_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 2, 2)); $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 4, 1)); $info_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xc0) >> 6; $info_ac3_raw['synchinfo']['frmsizecod'] = $ac3_synchinfo_fscod_frmsizecod & 0x3f; $info_ac3['sample_rate'] = getid3_ac3::AC3sampleRateCodeLookup($info_ac3_raw['synchinfo']['fscod']); if ($info_ac3_raw['synchinfo']['fscod'] <= 3) { $getid3->info['audio']['sample_rate'] = $info_ac3['sample_rate']; } $info_ac3['frame_length'] = getid3_ac3::AC3frameSizeLookup($info_ac3_raw['synchinfo']['frmsizecod'], $info_ac3_raw['synchinfo']['fscod']); $info_ac3['bitrate'] = getid3_ac3::AC3bitrateLookup($info_ac3_raw['synchinfo']['frmsizecod']); $getid3->info['audio']['bitrate'] = $info_ac3['bitrate']; $ac3_header['bsi'] = getid3_lib::BigEndian2Bin($this->fread(15)); $info_ac3_raw_bsi['bsid'] = bindec(substr($ac3_header['bsi'], 0, 5)); if ($info_ac3_raw_bsi['bsid'] > 8) { // Decoders which can decode version 8 will thus be able to decode version numbers less than 8. // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used. // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8. throw new getid3_exception('Bit stream identification is version ' . $info_ac3_raw_bsi['bsid'] . ', but getID3() only understands up to version 8'); } $info_ac3_raw_bsi['bsmod'] = bindec(substr($ac3_header['bsi'], 5, 3)); $info_ac3_raw_bsi['acmod'] = bindec(substr($ac3_header['bsi'], 8, 3)); $info_ac3['service_type'] = getid3_ac3::AC3serviceTypeLookup($info_ac3_raw_bsi['bsmod'], $info_ac3_raw_bsi['acmod']); $ac3_coding_mode = getid3_ac3::AC3audioCodingModeLookup($info_ac3_raw_bsi['acmod']); foreach ($ac3_coding_mode as $key => $value) { $info_ac3[$key] = $value; } switch ($info_ac3_raw_bsi['acmod']) { case 0: case 1: $getid3->info['audio']['channelmode'] = 'mono'; break; case 3: case 4: $getid3->info['audio']['channelmode'] = 'stereo'; break; default: $getid3->info['audio']['channelmode'] = 'surround'; break; } $getid3->info['audio']['channels'] = $info_ac3['num_channels']; $offset = 11; if ($info_ac3_raw_bsi['acmod'] & 0x1) { // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. $info_ac3_raw_bsi['cmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $info_ac3['center_mix_level'] = getid3_ac3::AC3centerMixLevelLookup($info_ac3_raw_bsi['cmixlev']); $offset += 2; } if ($info_ac3_raw_bsi['acmod'] & 0x4) { // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. $info_ac3_raw_bsi['surmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $info_ac3['surround_mix_level'] = getid3_ac3::AC3surroundMixLevelLookup($info_ac3_raw_bsi['surmixlev']); $offset += 2; } if ($info_ac3_raw_bsi['acmod'] == 0x2) { // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. $info_ac3_raw_bsi['dsurmod'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $info_ac3['dolby_surround_mode'] = getid3_ac3::AC3dolbySurroundModeLookup($info_ac3_raw_bsi['dsurmod']); $offset += 2; } $info_ac3_raw_bsi['lfeon'] = $ac3_header['bsi'][$offset++] == '1'; $info_ac3['lfe_enabled'] = $info_ac3_raw_bsi['lfeon']; if ($info_ac3_raw_bsi['lfeon']) { $getid3->info['audio']['channels'] .= '.1'; } $info_ac3['channels_enabled'] = getid3_ac3::AC3channelsEnabledLookup($info_ac3_raw_bsi['acmod'], $info_ac3_raw_bsi['lfeon']); // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1–31. // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. $info_ac3_raw_bsi['dialnorm'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; $info_ac3['dialogue_normalization'] = '-' . $info_ac3_raw_bsi['dialnorm'] . 'dB'; $info_ac3_raw_bsi['compre_flag'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['compre_flag']) { $info_ac3_raw_bsi['compr'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; $info_ac3['heavy_compression'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr']); } $info_ac3_raw_bsi['langcode_flag'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['langcode_flag']) { $info_ac3_raw_bsi['langcod'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; } $info_ac3_raw_bsi['audprodie'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['audprodie']) { $info_ac3_raw_bsi['mixlevel'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; $info_ac3_raw_bsi['roomtyp'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $offset += 2; $info_ac3['mixing_level'] = 80 + $info_ac3_raw_bsi['mixlevel'] . 'dB'; $info_ac3['room_type'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp']); } if ($info_ac3_raw_bsi['acmod'] == 0x0) { // If acmod is 0, then two completely independent program channels (dual mono) // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case, // a number of additional items are present in BSI or audblk to fully describe Ch2. // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1–31. // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. $info_ac3_raw_bsi['dialnorm2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; $info_ac3['dialogue_normalization2'] = '-' . $info_ac3_raw_bsi['dialnorm2'] . 'dB'; $info_ac3_raw_bsi['compre_flag2'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['compre_flag2']) { $info_ac3_raw_bsi['compr2'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; $info_ac3['heavy_compression2'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr2']); } $info_ac3_raw_bsi['langcode_flag2'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['langcode_flag2']) { $info_ac3_raw_bsi['langcod2'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; } $info_ac3_raw_bsi['audprodie2'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['audprodie2']) { $info_ac3_raw_bsi['mixlevel2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; $info_ac3_raw_bsi['roomtyp2'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $offset += 2; $info_ac3['mixing_level2'] = 80 + $info_ac3_raw_bsi['mixlevel2'] . 'dB'; $info_ac3['room_type2'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp2']); } } $info_ac3_raw_bsi['copyright'] = $ac3_header['bsi'][$offset++] == '1'; $info_ac3_raw_bsi['original'] = $ac3_header['bsi'][$offset++] == '1'; $info_ac3_raw_bsi['timecode1_flag'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['timecode1_flag']) { $info_ac3_raw_bsi['timecode1'] = bindec(substr($ac3_header['bsi'], $offset, 14)); $offset += 14; } $info_ac3_raw_bsi['timecode2_flag'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['timecode2_flag']) { $info_ac3_raw_bsi['timecode2'] = bindec(substr($ac3_header['bsi'], $offset, 14)); $offset += 14; } $info_ac3_raw_bsi['addbsi_flag'] = $ac3_header['bsi'][$offset++] == '1'; if ($info_ac3_raw_bsi['addbsi_flag']) { $info_ac3_raw_bsi['addbsi_length'] = bindec(substr($ac3_header['bsi'], $offset, 6)); $offset += 6; $ac3_header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($info_ac3_raw_bsi['addbsi_length'])); $info_ac3_raw_bsi['addbsi_data'] = substr($ac3_header['bsi'], 119, $info_ac3_raw_bsi['addbsi_length'] * 8); } return true; }
public function ParseMPCsv6() { // this is SV4 - SV6 $info =& $this->getid3->info; $thisfile_mpc_header =& $info['mpc']['header']; $offset = 0; $thisfile_mpc_header['size'] = 8; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $MPCheaderData = fread($this->getid3->fp, $thisfile_mpc_header['size']); // add size of file header to avdataoffset - calc bitrate correctly + MD5 data $info['avdataoffset'] += $thisfile_mpc_header['size']; // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) $HeaderDWORD[0] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 0, 4)); $HeaderDWORD[1] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 4, 4)); // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA // aaaa aaaa abcd dddd dddd deee eeff ffff // // a = bitrate = anything // b = IS = anything // c = MS = anything // d = streamversion = 0000000004 or 0000000005 or 0000000006 // e = maxband = anything // f = blocksize = 000001 for SV5+, anything(?) for SV4 $thisfile_mpc_header['target_bitrate'] = ($HeaderDWORD[0] & 0xff800000) >> 23; $thisfile_mpc_header['intensity_stereo'] = (bool) (($HeaderDWORD[0] & 0x400000) >> 22); $thisfile_mpc_header['mid_side_stereo'] = (bool) (($HeaderDWORD[0] & 0x200000) >> 21); $thisfile_mpc_header['stream_version_major'] = ($HeaderDWORD[0] & 0x1ff800) >> 11; $thisfile_mpc_header['stream_version_minor'] = 0; // no sub-version numbers before SV7 $thisfile_mpc_header['max_band'] = ($HeaderDWORD[0] & 0x7c0) >> 6; // related to lowpass frequency, not sure how it translates exactly $thisfile_mpc_header['block_size'] = $HeaderDWORD[0] & 0x3f; switch ($thisfile_mpc_header['stream_version_major']) { case 4: $thisfile_mpc_header['frame_count'] = $HeaderDWORD[1] >> 16; break; case 5: case 6: $thisfile_mpc_header['frame_count'] = $HeaderDWORD[1]; break; default: $info['error'] = 'Expecting 4, 5 or 6 in version field, found ' . $thisfile_mpc_header['stream_version_major'] . ' instead'; unset($info['mpc']); return false; break; } if ($thisfile_mpc_header['stream_version_major'] > 4 && $thisfile_mpc_header['block_size'] != 1) { $info['warning'][] = 'Block size expected to be 1, actual value found: ' . $thisfile_mpc_header['block_size']; } $thisfile_mpc_header['sample_rate'] = 44100; // AB: used by all files up to SV7 $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $info['audio']['channels']; if ($thisfile_mpc_header['target_bitrate'] == 0) { $info['audio']['bitrate_mode'] = 'vbr'; } else { $info['audio']['bitrate_mode'] = 'cbr'; } $info['mpc']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152; $info['audio']['bitrate'] = $info['mpc']['bitrate']; $info['audio']['encoder'] = 'SV' . $thisfile_mpc_header['stream_version_major']; return true; }
public function Analyze() { $getid3 = $this->getid3; // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de> // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html $getid3->info['fileformat'] = 'mac'; $getid3->info['audio']['dataformat'] = 'mac'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; $getid3->info['audio']['lossless'] = true; $getid3->info['monkeys_audio']['raw'] = array(); $info_monkeys_audio =& $getid3->info['monkeys_audio']; $info_monkeys_audio_raw =& $info_monkeys_audio['raw']; // Read file header fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $mac_header_data = fread($getid3->fp, 74); $info_monkeys_audio_raw['magic'] = 'MAC '; // Magic bytes // Read MAC version $info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2)); // appears to be uint32 in 3.98+ // Parse MAC Header < v3980 if ($info_monkeys_audio_raw['nVersion'] < 3980) { getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6, array('nCompressionLevel' => 2, 'nFormatFlags' => 2, 'nChannels' => 2, 'nSampleRate' => 4, 'nHeaderDataBytes' => 4, 'nWAVTerminatingBytes' => 4, 'nTotalFrames' => 4, 'nFinalFrameSamples' => 4, 'nPeakLevel' => 4, 'IGNORE-1' => 2, 'nSeekElements' => 2)); } else { getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8, array('nDescriptorBytes' => 4, 'nHeaderBytes' => 4, 'nSeekTableBytes' => 4, 'nHeaderDataBytes' => 4, 'nAPEFrameDataBytes' => 4, 'nAPEFrameDataBytesHigh' => 4, 'nTerminatingDataBytes' => 4, 'cFileMD5' => -16, 'nCompressionLevel' => 2, 'nFormatFlags' => 2, 'nBlocksPerFrame' => 4, 'nFinalFrameBlocks' => 4, 'nTotalFrames' => 4, 'nBitsPerSample' => 2, 'nChannels' => 2, 'nSampleRate' => 4)); } // Process data $info_monkeys_audio['flags']['8-bit'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x1); $info_monkeys_audio['flags']['crc-32'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x2); $info_monkeys_audio['flags']['peak_level'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x4); $info_monkeys_audio['flags']['24-bit'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x8); $info_monkeys_audio['flags']['seek_elements'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x10); $info_monkeys_audio['flags']['no_wav_header'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x20); $info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000; $info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']); $info_monkeys_audio['bits_per_sample'] = $info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16); $info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels']; $getid3->info['audio']['channels'] = $info_monkeys_audio['channels']; $info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate']; $getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate']; if ($info_monkeys_audio['flags']['peak_level']) { $info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel']; $info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1); } // MAC >= v3980 if ($info_monkeys_audio_raw['nVersion'] >= 3980) { $info_monkeys_audio['samples'] = ($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame'] + $info_monkeys_audio_raw['nFinalFrameBlocks']; } else { $info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']); $info_monkeys_audio['samples'] = ($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame'] + $info_monkeys_audio_raw['nFinalFrameSamples']; } $info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate']; $getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime']; $info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset']; $info_monkeys_audio['uncompressed_size'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * ($info_monkeys_audio['bits_per_sample'] / 8); $info_monkeys_audio['compression_ratio'] = $info_monkeys_audio['compressed_size'] / ($info_monkeys_audio['uncompressed_size'] + $info_monkeys_audio_raw['nHeaderDataBytes']); $info_monkeys_audio['bitrate'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * $info_monkeys_audio['bits_per_sample'] / $info_monkeys_audio['playtime'] * $info_monkeys_audio['compression_ratio']; $getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate']; $getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample']; $getid3->info['audio']['encoder'] = 'MAC v' . number_format($info_monkeys_audio['version'], 2); $getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']) . ' compression'; // MAC >= v3980 - get avdataoffsets from MAC header if ($info_monkeys_audio_raw['nVersion'] >= 3980) { $getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes']; $getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes']; } else { $getid3->info['avdataoffset'] += 8; } // Convert md5sum to 32 byte string if (@$info_monkeys_audio_raw['cFileMD5']) { if ($info_monkeys_audio_raw['cFileMD5'] !== str_repeat("", 16)) { $getid3->info['md5_data_source'] = ''; $md5 = $info_monkeys_audio_raw['cFileMD5']; for ($i = 0; $i < strlen($md5); $i++) { $getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); } if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) { unset($getid3->info['md5_data_source']); } } } return true; }
public function Analyze() { $getid3 = $this->getid3; $getid3->include_module('audio-video.riff'); !isset($getid3->info['audio']) and $getid3->info['audio'] = array(); !isset($getid3->info['video']) and $getid3->info['video'] = array(); $getid3->info['asf']['comments'] = $getid3->info['asf']['header_object'] = array(); $info_audio =& $getid3->info['audio']; $info_video =& $getid3->info['video']; $info_asf =& $getid3->info['asf']; $info_asf_comments =& $info_asf['comments']; $info_asf_header_object =& $info_asf['header_object']; // ASF structure: // * Header Object [required] // * File Properties Object [required] (global file attributes) // * Stream Properties Object [required] (defines media stream & characteristics) // * Header Extension Object [required] (additional functionality) // * Content Description Object (bibliographic information) // * Script Command Object (commands for during playback) // * Marker Object (named jumped points within the file) // * Data Object [required] // * Data Packets // * Index Object // Header Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for header object - getid3_asf::Header_Object // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header // Number of Header Objects DWORD 32 // number of objects in header object // Reserved1 BYTE 8 // hardcoded: 0x01 // Reserved2 BYTE 8 // hardcoded: 0x02 $getid3->info['fileformat'] = 'asf'; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $header_object_data = fread($getid3->fp, 30); $info_asf_header_object['objectid_guid'] = getid3_asf::BytestringToGUID(substr($header_object_data, 0, 16)); if ($info_asf_header_object['objectid_guid'] != getid3_asf::Header_Object) { throw new getid3_exception('ASF header GUID {' . $info_asf_header_object['objectid_guid'] . '} does not match expected "getid3_asf::Header_Object" GUID {' . getid3_asf::Header_Object . '}'); } getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_header_object, $header_object_data, 16, array('objectsize' => 8, 'headerobjects' => 4, 'reserved1' => 1, 'reserved2' => 1)); $asf_header_data = fread($getid3->fp, $info_asf_header_object['objectsize'] - 30); $offset = 0; for ($header_objects_counter = 0; $header_objects_counter < $info_asf_header_object['headerobjects']; $header_objects_counter++) { $next_object_guid = substr($asf_header_data, $offset, 16); $offset += 16; $next_object_size = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 8)); $offset += 8; $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid); switch ($next_object_guidtext) { case getid3_asf::File_Properties_Object: // File Properties Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for file properties object - getid3_asf::File_Properties_Object // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header // File ID GUID 128 // unique ID - identical to File ID in Data Object // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1 // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1 // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1 // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1 // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1 // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount // Flags DWORD 32 // // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid // * Seekable Flag bits 1 (0x02) // is file seekable // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1 // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1 // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead $info_asf['file_properties_object'] = array(); $info_asf_file_properties_object =& $info_asf['file_properties_object']; $info_asf_file_properties_object['objectid_guid'] = $next_object_guidtext; $info_asf_file_properties_object['objectsize'] = $next_object_size; $info_asf_file_properties_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_file_properties_object, $asf_header_data, $offset, array('filesize' => 8, 'creation_date' => 8, 'data_packets' => 8, 'play_duration' => 8, 'send_duration' => 8, 'preroll' => 8, 'flags_raw' => 4, 'min_packet_size' => 4, 'max_packet_size' => 4, 'max_bitrate' => 4)); $offset += 64; if ($info_asf_file_properties_object['filesize'] > $getid3->info['filesize']) { $getid3->warning('Probable truncated file: file_properties_object.filesize (' . number_format($info_asf_file_properties_object['filesize']) . ') > filesize (' . number_format($getid3->info['filesize']) . ')'); } $info_asf_file_properties_object['creation_date_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_file_properties_object['creation_date']); $info_asf_file_properties_object['flags']['broadcast'] = (bool) ($info_asf_file_properties_object['flags_raw'] & 0x1); $info_asf_file_properties_object['flags']['seekable'] = (bool) ($info_asf_file_properties_object['flags_raw'] & 0x2); $getid3->info['playtime_seconds'] = $info_asf_file_properties_object['play_duration'] / 10000000 - $info_asf_file_properties_object['preroll'] / 1000; $getid3->info['bitrate'] = $info_asf_file_properties_object['filesize'] * 8 / $getid3->info['playtime_seconds']; break; case getid3_asf::Stream_Properties_Object: // Stream Properties Object: (mandatory, one per media stream) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for stream properties object - getid3_asf::Stream_Properties_Object // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header // Stream Type GUID 128 // getid3_asf::Audio_Media, getid3_asf::Video_Media or getid3_asf::Command_Media // Error Correction Type GUID 128 // getid3_asf::Audio_Spread for audio-only streams, getid3_asf::No_Error_Correction for other stream types // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field // Flags WORD 16 // // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127 // * Reserved bits 8 (0x7F80) // reserved - set to zero // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set // Reserved DWORD 32 // reserved - set to zero // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type // There is one getid3_asf::Stream_Properties_Object for each stream (audio, video) but the // stream number isn't known until halfway through decoding the structure, hence it // it is decoded to a temporary variable and then stuck in the appropriate index later $stream_properties_object_data['objectid_guid'] = $next_object_guidtext; $stream_properties_object_data['objectsize'] = $next_object_size; getid3_lib::ReadSequence('LittleEndian2Int', $stream_properties_object_data, $asf_header_data, $offset, array('stream_type' => -16, 'error_correct_type' => -16, 'time_offset' => 8, 'type_data_length' => 4, 'error_data_length' => 4, 'flags_raw' => 2)); $stream_properties_stream_number = $stream_properties_object_data['flags_raw'] & 0x7f; $stream_properties_object_data['flags']['encrypted'] = (bool) ($stream_properties_object_data['flags_raw'] & 0x8000); $stream_properties_object_data['stream_type_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['stream_type']); $stream_properties_object_data['error_correct_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['error_correct_type']); $offset += 54; // 50 bytes + 4 bytes reserved - DWORD $stream_properties_object_data['type_specific_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['type_data_length']); $offset += $stream_properties_object_data['type_data_length']; $stream_properties_object_data['error_correct_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['error_data_length']); $offset += $stream_properties_object_data['error_data_length']; switch ($stream_properties_object_data['stream_type_guid']) { case getid3_asf::Audio_Media: $info_audio['dataformat'] = @$info_audio['dataformat'] ? $info_audio['dataformat'] : 'asf'; $info_audio['bitrate_mode'] = @$info_audio['bitrate_mode'] ? $info_audio['bitrate_mode'] : 'cbr'; $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_properties_object_data['type_specific_data'], 0, 16)); unset($audiodata['raw']); $info_audio = getid3_riff::array_merge_noclobber($audiodata, $info_audio); break; case getid3_asf::Video_Media: $info_video['dataformat'] = @$info_video['dataformat'] ? $info_video['dataformat'] : 'asf'; $info_video['bitrate_mode'] = @$info_video['bitrate_mode'] ? $info_video['bitrate_mode'] : 'cbr'; break; /* does nothing but eat memory case getid3_asf::Command_Media: default: // do nothing break; */ } $info_asf['stream_properties_object'][$stream_properties_stream_number] = $stream_properties_object_data; unset($stream_properties_object_data); // clear for next stream, if any break; case getid3_asf::Header_Extension_Object: // Header Extension Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Header Extension object - getid3_asf::Header_Extension_Object // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header // Reserved Field 1 GUID 128 // hardcoded: getid3_asf::Reserved_1 // Reserved Field 2 WORD 16 // hardcoded: 0x00000006 // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46 // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects $info_asf['header_extension_object'] = array(); $info_asf_header_extension_object =& $info_asf['header_extension_object']; $info_asf_header_extension_object['objectid_guid'] = $next_object_guidtext; $info_asf_header_extension_object['objectsize'] = $next_object_size; $info_asf_header_extension_object['reserved_1_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; if ($info_asf_header_extension_object['reserved_1_guid'] != getid3_asf::Reserved_1) { $getid3->warning('header_extension_object.reserved_1 GUID (' . $info_asf_header_extension_object['reserved_1_guid'] . ') does not match expected "getid3_asf::Reserved_1" GUID (' . getid3_asf::Reserved_1 . ')'); break; } $info_asf_header_extension_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; if ($info_asf_header_extension_object['reserved_2'] != 6) { $getid3->warning('header_extension_object.reserved_2 (' . getid3_lib::PrintHexBytes($info_asf_header_extension_object['reserved_2']) . ') does not match expected value of "6"'); break; } $info_asf_header_extension_object['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; $info_asf_header_extension_object['extension_data'] = substr($asf_header_data, $offset, $info_asf_header_extension_object['extension_data_size']); $offset += $info_asf_header_extension_object['extension_data_size']; break; case getid3_asf::Codec_List_Object: // Codec List Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Codec List object - getid3_asf::Codec_List_Object // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6 // Codec Entries Count DWORD 32 // number of entries in Codec Entries array // Codec Entries array of: variable // // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content $info_asf['codec_list_object'] = array(); $info_asf_codec_list_object =& $info_asf['codec_list_object']; $info_asf_codec_list_object['objectid_guid'] = $next_object_guidtext; $info_asf_codec_list_object['objectsize'] = $next_object_size; $info_asf_codec_list_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; if ($info_asf_codec_list_object['reserved_guid'] != '86D15241-311D-11D0-A3A4-00A0C90348F6') { $getid3->warning('codec_list_object.reserved GUID {' . $info_asf_codec_list_object['reserved_guid'] . '} does not match expected "getid3_asf::Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'); break; } $info_asf_codec_list_object['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; for ($codec_entry_counter = 0; $codec_entry_counter < $info_asf_codec_list_object['codec_entries_count']; $codec_entry_counter++) { $info_asf_codec_list_object['codec_entries'][$codec_entry_counter] = array(); $info_asf_codec_list_object_codecentries_current =& $info_asf_codec_list_object['codec_entries'][$codec_entry_counter]; $info_asf_codec_list_object_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_codec_list_object_codecentries_current['type'] = getid3_asf::ASFCodecListObjectTypeLookup($info_asf_codec_list_object_codecentries_current['type_raw']); $codec_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; $info_asf_codec_list_object_codecentries_current['name'] = substr($asf_header_data, $offset, $codec_name_length); $offset += $codec_name_length; $codec_description_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; $info_asf_codec_list_object_codecentries_current['description'] = substr($asf_header_data, $offset, $codec_description_length); $offset += $codec_description_length; $codec_information_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_codec_list_object_codecentries_current['information'] = substr($asf_header_data, $offset, $codec_information_length); $offset += $codec_information_length; if ($info_asf_codec_list_object_codecentries_current['type_raw'] == 2) { // audio codec if (strpos($info_asf_codec_list_object_codecentries_current['description'], ',') === false) { $getid3->warning('[asf][codec_list_object][codec_entries][' . $codec_entry_counter . '][description] expected to contain comma-seperated list of parameters: "' . $info_asf_codec_list_object_codecentries_current['description'] . '"'); } else { list($audio_codec_bitrate, $audio_codec_frequency, $audio_codec_channels) = explode(',', $this->TrimConvert($info_asf_codec_list_object_codecentries_current['description'])); $info_audio['codec'] = $this->TrimConvert($info_asf_codec_list_object_codecentries_current['name']); if (!isset($info_audio['bitrate']) && strstr($audio_codec_bitrate, 'kbps')) { $info_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $audio_codec_bitrate)) * 1000); } if (!isset($info_video['bitrate']) && isset($info_audio['bitrate']) && isset($info_asf['file_properties_object']['max_bitrate']) && $info_asf_codec_list_object['codec_entries_count'] > 1) { $info_video['bitrate'] = $info_asf['file_properties_object']['max_bitrate'] - $info_audio['bitrate']; } if (!@$info_video['bitrate'] && @$info_audio['bitrate'] && @$getid3->info['bitrate']) { $info_video['bitrate'] = $getid3->info['bitrate'] - $info_audio['bitrate']; } $audio_codec_frequency = (int) trim(str_replace('kHz', '', $audio_codec_frequency)); static $sample_rate_lookup = array(8 => 8000, 8000 => 8000, 11 => 11025, 11025 => 11025, 12 => 12000, 12000 => 12000, 16 => 16000, 16000 => 16000, 22 => 22050, 22050 => 22050, 24 => 24000, 24000 => 24000, 32 => 32000, 32000 => 32000, 44 => 44100, 44100 => 44100, 48 => 48000, 48000 => 48000); $info_audio['sample_rate'] = @$sample_rate_lookup[$audio_codec_frequency]; if (!$info_audio['sample_rate']) { $getid3->warning('unknown frequency: "' . $audio_codec_frequency . '" (' . $this->TrimConvert($info_asf_codec_list_object_codecentries_current['description']) . ')'); break; } if (!isset($info_audio['channels'])) { if (strstr($audio_codec_channels, 'stereo')) { $info_audio['channels'] = 2; } elseif (strstr($audio_codec_channels, 'mono')) { $info_audio['channels'] = 1; } } } } } break; case getid3_asf::Script_Command_Object: // Script Command Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Script Command object - getid3_asf::Script_Command_Object // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6 // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects // Command Types array of: variable // // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command // Commands array of: variable // // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object // * Command Name Length WORD 16 // number of Unicode characters for Command Name // * Command Name WCHAR variable // array of Unicode characters - name of this command // shortcut $info_asf['script_command_object'] = array(); $info_asf_script_command_object =& $info_asf['script_command_object']; $info_asf_script_command_object['objectid_guid'] = $next_object_guidtext; $info_asf_script_command_object['objectsize'] = $next_object_size; $info_asf_script_command_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; if ($info_asf_script_command_object['reserved_guid'] != '4B1ACBE3-100B-11D0-A39B-00A0C90348F6') { $getid3->warning('script_command_object.reserved GUID {' . $info_asf_script_command_object['reserved_guid'] . '} does not match expected GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'); break; } $info_asf_script_command_object['commands_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_script_command_object['command_types_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; for ($command_types_counter = 0; $command_types_counter < $info_asf_script_command_object['command_types_count']; $command_types_counter++) { $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; $info_asf_script_command_object['command_types'][$command_types_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length); $offset += $command_type_name_length; } for ($commands_counter = 0; $commands_counter < $info_asf_script_command_object['commands_count']; $commands_counter++) { $info_asf_script_command_object['commands'][$commands_counter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; $info_asf_script_command_object['commands'][$commands_counter]['type_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; $info_asf_script_command_object['commands'][$commands_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length); $offset += $command_type_name_length; } break; case getid3_asf::Marker_Object: // Marker Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Marker object - getid3_asf::Marker_Object // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB // Markers Count DWORD 32 // number of Marker structures in Marker Object // Reserved WORD 16 // hardcoded: 0x0000 // Name Length WORD 16 // number of bytes in the Name field // Name WCHAR variable // name of the Marker Object // Markers array of: variable // // * Offset QWORD 64 // byte offset into Data Object // * Presentation Time QWORD 64 // in 100-nanosecond units // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding) // * Send Time DWORD 32 // in milliseconds // * Flags DWORD 32 // hardcoded: 0x00000000 // * Marker Description Length DWORD 32 // number of bytes in Marker Description field // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry // * Padding BYTESTREAM variable // optional padding bytes $info_asf['marker_object'] = array(); $info_asf_marker_object =& $info_asf['marker_object']; $info_asf_marker_object['objectid_guid'] = $next_object_guidtext; $info_asf_marker_object['objectsize'] = $next_object_size; $info_asf_marker_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; if ($info_asf_marker_object['reserved_guid'] != '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB') { $getid3->warning('marker_object.reserved GUID {' . $info_asf_marker_object['reserved_guid'] . '} does not match expected GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'); break; } $info_asf_marker_object['markers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; $info_asf_marker_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; if ($info_asf_marker_object['reserved_2'] != 0) { $getid3->warning('marker_object.reserved_2 (' . getid3_lib::PrintHexBytes($info_asf_marker_object['reserved_2']) . ') does not match expected value of "0"'); break; } $info_asf_marker_object['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_marker_object['name'] = substr($asf_header_data, $offset, $info_asf_marker_object['name_length']); $offset += $info_asf_marker_object['name_length']; for ($markers_counter = 0; $markers_counter < $info_asf_marker_object['markers_count']; $markers_counter++) { getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_marker_object['markers'][$markers_counter], $asf_header_data, $offset, array('offset' => 8, 'presentation_time' => 8, 'entry_length' => 2, 'send_time' => 4, 'flags' => 4, 'marker_description_length' => 4)); $offset += 30; $info_asf_marker_object['markers'][$markers_counter]['marker_description'] = substr($asf_header_data, $offset, $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']); $offset += $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']; $padding_length = $info_asf_marker_object['markers'][$markers_counter]['entry_length'] - 4 - 4 - 4 - $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']; if ($padding_length > 0) { $info_asf_marker_object['markers'][$markers_counter]['padding'] = substr($asf_header_data, $offset, $padding_length); $offset += $padding_length; } } break; case getid3_asf::Bitrate_Mutual_Exclusion_Object: // Bitrate Mutual Exclusion Object: (optional) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - getid3_asf::Bitrate_Mutual_Exclusion_Object // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (getid3_asf::Mutex_Bitrate, getid3_asf::Mutex_Unknown) // Stream Numbers Count WORD 16 // number of video streams // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127 // shortcut $info_asf['bitrate_mutual_exclusion_object'] = array(); $info_asf_bitrate_mutual_exclusion_object =& $info_asf['bitrate_mutual_exclusion_object']; $info_asf_bitrate_mutual_exclusion_object['objectid_guid'] = $next_object_guidtext; $info_asf_bitrate_mutual_exclusion_object['objectsize'] = $next_object_size; $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; if ($info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Bitrate && $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Unknown) { $getid3->warning('bitrate_mutual_exclusion_object.reserved GUID {' . $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] . '} does not match expected "getid3_asf::Mutex_Bitrate" GUID {' . getid3_asf::Mutex_Bitrate . '} or "getid3_asf::Mutex_Unknown" GUID {' . getid3_asf::Mutex_Unknown . '}'); break; } $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; for ($stream_number_counter = 0; $stream_number_counter < $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count']; $stream_number_counter++) { $info_asf_bitrate_mutual_exclusion_object['stream_numbers'][$stream_number_counter] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; } break; case getid3_asf::Error_Correction_Object: // Error Correction Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Error Correction object - getid3_asf::Error_Correction_Object // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header // Error Correction Type GUID 128 // type of error correction. one of: (getid3_asf::No_Error_Correction, getid3_asf::Audio_Spread) // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field $info_asf['error_correction_object'] = array(); $info_asf_error_correction_object =& $info_asf['error_correction_object']; $info_asf_error_correction_object['objectid_guid'] = $next_object_guidtext; $info_asf_error_correction_object['objectsize'] = $next_object_size; $info_asf_error_correction_object['error_correction_type'] = substr($asf_header_data, $offset, 16); $offset += 16; $info_asf_error_correction_object['error_correction_guid'] = getid3_asf::BytestringToGUID($info_asf_error_correction_object['error_correction_type']); $info_asf_error_correction_object['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; switch ($info_asf_error_correction_object['error_correction_type_guid']) { case getid3_asf::No_Error_Correction: // should be no data, but just in case there is, skip to the end of the field $offset += $info_asf_error_correction_object['error_correction_data_length']; break; case getid3_asf::Audio_Spread: // Field Name Field Type Size (bits) // Span BYTE 8 // number of packets over which audio will be spread. // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream // Silence Data Length WORD 16 // number of bytes in Silence Data field // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_error_correction_object, $asf_header_data, $offset, array('span' => 1, 'virtual_packet_length' => 2, 'virtual_chunk_length' => 2, 'silence_data_length' => 2)); $offset += 7; $info_asf_error_correction_object['silence_data'] = substr($asf_header_data, $offset, $info_asf_error_correction_object['silence_data_length']); $offset += $info_asf_error_correction_object['silence_data_length']; break; default: $getid3->warning('error_correction_object.error_correction_type GUID {' . $info_asf_error_correction_object['reserved_guid'] . '} does not match expected "getid3_asf::No_Error_Correction" GUID {' . getid3_asf::No_Error_Correction . '} or "getid3_asf::Audio_Spread" GUID {' . getid3_asf::Audio_Spread . '}'); break; } break; case getid3_asf::Content_Description_Object: // Content Description Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Content Description object - getid3_asf::Content_Description_Object // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header // Title Length WORD 16 // number of bytes in Title field // Author Length WORD 16 // number of bytes in Author field // Copyright Length WORD 16 // number of bytes in Copyright field // Description Length WORD 16 // number of bytes in Description field // Rating Length WORD 16 // number of bytes in Rating field // Title WCHAR 16 // array of Unicode characters - Title // Author WCHAR 16 // array of Unicode characters - Author // Copyright WCHAR 16 // array of Unicode characters - Copyright // Description WCHAR 16 // array of Unicode characters - Description // Rating WCHAR 16 // array of Unicode characters - Rating $info_asf['content_description_object'] = array(); $info_asf_content_description_object =& $info_asf['content_description_object']; $info_asf_content_description_object['objectid_guid'] = $next_object_guidtext; $info_asf_content_description_object['objectsize'] = $next_object_size; getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_content_description_object, $asf_header_data, $offset, array('title_length' => 2, 'author_length' => 2, 'copyright_length' => 2, 'description_length' => 2, 'rating_length' => 2)); $offset += 10; $info_asf_content_description_object['title'] = substr($asf_header_data, $offset, $info_asf_content_description_object['title_length']); $offset += $info_asf_content_description_object['title_length']; $info_asf_content_description_object['author'] = substr($asf_header_data, $offset, $info_asf_content_description_object['author_length']); $offset += $info_asf_content_description_object['author_length']; $info_asf_content_description_object['copyright'] = substr($asf_header_data, $offset, $info_asf_content_description_object['copyright_length']); $offset += $info_asf_content_description_object['copyright_length']; $info_asf_content_description_object['description'] = substr($asf_header_data, $offset, $info_asf_content_description_object['description_length']); $offset += $info_asf_content_description_object['description_length']; $info_asf_content_description_object['rating'] = substr($asf_header_data, $offset, $info_asf_content_description_object['rating_length']); $offset += $info_asf_content_description_object['rating_length']; foreach (array('title' => 'title', 'author' => 'artist', 'copyright' => 'copyright', 'description' => 'comment', 'rating' => 'rating') as $key_to_copy_from => $key_to_copy_to) { if (!empty($info_asf_content_description_object[$key_to_copy_from])) { $info_asf_comments[$key_to_copy_to][] = getid3_asf::TrimTerm($info_asf_content_description_object[$key_to_copy_from]); } } break; case getid3_asf::Extended_Content_Description_Object: // Extended Content Description Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Extended Content Description object - getid3_asf::Extended_Content_Description_Object // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list // Content Descriptors array of: variable // // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name // * Descriptor Value Data Type WORD 16 // Lookup array: // 0x0000 = Unicode String (variable length) // 0x0001 = BYTE array (variable length) // 0x0002 = BOOL (DWORD, 32 bits) // 0x0003 = DWORD (DWORD, 32 bits) // 0x0004 = QWORD (QWORD, 64 bits) // 0x0005 = WORD (WORD, 16 bits) // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field // * Descriptor Value variable variable // value for Content Descriptor $info_asf['extended_content_description_object'] = array(); $info_asf_extended_content_description_object =& $info_asf['extended_content_description_object']; $info_asf_extended_content_description_object['objectid_guid'] = $next_object_guidtext; $info_asf_extended_content_description_object['objectsize'] = $next_object_size; $info_asf_extended_content_description_object['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; for ($extended_content_descriptors_counter = 0; $extended_content_descriptors_counter < $info_asf_extended_content_description_object['content_descriptors_count']; $extended_content_descriptors_counter++) { $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter] = array(); $info_asf_extended_content_description_object_content_descriptor_current =& $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter]; $info_asf_extended_content_description_object_content_descriptor_current['base_offset'] = $offset + 30; $info_asf_extended_content_description_object_content_descriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_extended_content_description_object_content_descriptor_current['name'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['name_length']); $offset += $info_asf_extended_content_description_object_content_descriptor_current['name_length']; $info_asf_extended_content_description_object_content_descriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_extended_content_description_object_content_descriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_extended_content_description_object_content_descriptor_current['value'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['value_length']); $offset += $info_asf_extended_content_description_object_content_descriptor_current['value_length']; switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) { case 0x0: // Unicode string break; case 0x1: // BYTE array // do nothing break; case 0x2: // BOOL $info_asf_extended_content_description_object_content_descriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']); break; case 0x3: // DWORD // DWORD case 0x4: // QWORD // QWORD case 0x5: // WORD $info_asf_extended_content_description_object_content_descriptor_current['value'] = getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']); break; default: $getid3->warning('extended_content_description.content_descriptors.' . $extended_content_descriptors_counter . '.value_type is invalid (' . $info_asf_extended_content_description_object_content_descriptor_current['value_type'] . ')'); break; } switch ($this->TrimConvert(strtolower($info_asf_extended_content_description_object_content_descriptor_current['name']))) { case 'wm/albumartist': case 'artist': $info_asf_comments['albumartist'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; case 'wm/albumtitle': case 'album': $info_asf_comments['album'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; case 'wm/genre': case 'genre': $genre = getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']); $info_asf_comments['genre'] = array($genre); break; case 'wm/tracknumber': case 'tracknumber': // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character) $info_asf_comments['track'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); foreach ($info_asf_comments['track'] as $key => $value) { if (preg_match('/^[0-9\\x00]+$/', $value)) { $info_asf_comments['track'][$key] = intval(str_replace("", '', $value)); } } break; case 'wm/partofset': $info_asf_comments['partofset'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; case 'wm/track': if (empty($info_asf_comments['track'])) { $info_asf_comments['track'] = array(1 + $this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['value'])); } break; case 'wm/year': case 'year': case 'date': $info_asf_comments['year'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; case 'wm/lyrics': case 'lyrics': $info_asf_comments['lyrics'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; case 'isvbr': if ($info_asf_extended_content_description_object_content_descriptor_current['value']) { $info_audio['bitrate_mode'] = 'vbr'; $info_video['bitrate_mode'] = 'vbr'; } break; case 'id3': // id3v2 parsing might not be enabled if (class_exists('getid3_id3v2')) { // Clone getid3 $clone = clone $getid3; // Analyse clone by string $id3v2 = new getid3_id3v2($clone); $id3v2->AnalyzeString($info_asf_extended_content_description_object_content_descriptor_current['value']); // Import from clone and destroy $getid3->info['id3v2'] = $clone->info['id3v2']; $getid3->warnings($clone->warnings()); unset($clone); } break; case 'wm/encodingtime': $info_asf_extended_content_description_object_content_descriptor_current['encoding_time_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_extended_content_description_object_content_descriptor_current['value']); $info_asf_comments['encoding_time_unix'] = array($info_asf_extended_content_description_object_content_descriptor_current['encoding_time_unix']); break; case 'wm/picture': //typedef struct _WMPicture{ // LPWSTR pwszMIMEType; // BYTE bPictureType; // LPWSTR pwszDescription; // DWORD dwDataLen; // BYTE* pbData; //} WM_PICTURE; $info_asf_extended_content_description_object_content_descriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value'][0]); $info_asf_extended_content_description_object_content_descriptor_current['image_type'] = getid3_asf::WMpictureTypeLookup($info_asf_extended_content_description_object_content_descriptor_current['image_type_id']); $info_asf_extended_content_description_object_content_descriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($info_asf_extended_content_description_object_content_descriptor_current['value'], 1, 4)); $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] = ''; $wm_picture_offset = 5; do { $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2); $wm_picture_offset += 2; $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] .= $next_byte_pair; } while ($next_byte_pair !== ""); $info_asf_extended_content_description_object_content_descriptor_current['image_description'] = ''; do { $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2); $wm_picture_offset += 2; $info_asf_extended_content_description_object_content_descriptor_current['image_description'] .= $next_byte_pair; } while ($next_byte_pair !== ""); $info_asf_extended_content_description_object_content_descriptor_current['dataoffset'] = $wm_picture_offset; $info_asf_extended_content_description_object_content_descriptor_current['data'] = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset); unset($info_asf_extended_content_description_object_content_descriptor_current['value']); $info_asf_comments['picture'] = $info_asf_extended_content_description_object_content_descriptor_current['data']; break; default: switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) { case 0: // Unicode string if (substr($this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['name']), 0, 3) == 'WM/') { $info_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['name'])))] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); } break; case 1: break; } break; } } break; case getid3_asf::Stream_Bitrate_Properties_Object: // Stream Bitrate Properties Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Stream Bitrate Properties object - getid3_asf::Stream_Bitrate_Properties_Object // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header // Bitrate Records Count WORD 16 // number of records in Bitrate Records // Bitrate Records array of: variable // // * Flags WORD 16 // // * * Stream Number bits 7 (0x007F) // number of this stream // * * Reserved bits 9 (0xFF80) // hardcoded: 0 // * Average Bitrate DWORD 32 // in bits per second // shortcut $info_asf['stream_bitrate_properties_object'] = array(); $info_asf_stream_bitrate_properties_object =& $info_asf['stream_bitrate_properties_object']; $info_asf_stream_bitrate_properties_object['objectid_guid'] = $next_object_guidtext; $info_asf_stream_bitrate_properties_object['objectsize'] = $next_object_size; $info_asf_stream_bitrate_properties_object['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties_object['bitrate_records_count']; $bitrate_records_counter++) { $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags']['stream_number'] = $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] & 0x7f; $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; } break; case getid3_asf::Padding_Object: // Padding Object: (optional) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Padding object - getid3_asf::Padding_Object // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header // Padding Data BYTESTREAM variable // ignore // shortcut $info_asf['padding_object'] = array(); $info_asf_paddingobject =& $info_asf['padding_object']; $info_asf_paddingobject['objectid_guid'] = $next_object_guidtext; $info_asf_paddingobject['objectsize'] = $next_object_size; $info_asf_paddingobject['padding_length'] = $info_asf_paddingobject['objectsize'] - 16 - 8; $info_asf_paddingobject['padding'] = substr($asf_header_data, $offset, $info_asf_paddingobject['padding_length']); $offset += $next_object_size - 16 - 8; break; case getid3_asf::Extended_Content_Encryption_Object: case getid3_asf::Content_Encryption_Object: // WMA DRM - just ignore $offset += $next_object_size - 16 - 8; break; default: // Implementations shall ignore any standard or non-standard object that they do not know how to handle. if (getid3_asf::GUIDname($next_object_guidtext)) { $getid3->warning('unhandled GUID "' . getid3_asf::GUIDname($next_object_guidtext) . '" {' . $next_object_guidtext . '} in ASF header at offset ' . ($offset - 16 - 8)); } else { $getid3->warning('unknown GUID {' . $next_object_guidtext . '} in ASF header at offset ' . ($offset - 16 - 8)); } $offset += $next_object_size - 16 - 8; break; } } if (isset($info_asf_stream_bitrate_properties['bitrate_records_count'])) { $asf_bitrate_audio = 0; $asf_bitrate_video = 0; for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties['bitrate_records_count']; $bitrate_records_counter++) { if (isset($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter])) { switch ($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter]['type_raw']) { case 1: $asf_bitrate_video += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate']; break; case 2: $asf_bitrate_audio += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate']; break; } } } if ($asf_bitrate_audio > 0) { $info_audio['bitrate'] = $asf_bitrate_audio; } if ($asf_bitrate_video > 0) { $info_video['bitrate'] = $asf_bitrate_video; } } if (isset($info_asf['stream_properties_object']) && is_array($info_asf['stream_properties_object'])) { $info_audio['bitrate'] = 0; $info_video['bitrate'] = 0; foreach ($info_asf['stream_properties_object'] as $stream_number => $stream_data) { switch ($stream_data['stream_type_guid']) { case getid3_asf::Audio_Media: // Field Name Field Type Size (bits) // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes // shortcut $info_asf['audio_media'][$stream_number] = array(); $info_asf_audio_media_current_stream =& $info_asf['audio_media'][$stream_number]; $audio_media_offset = 0; $info_asf_audio_media_current_stream = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_data['type_specific_data'], $audio_media_offset, 16)); $audio_media_offset += 16; $info_audio['lossless'] = false; switch ($info_asf_audio_media_current_stream['raw']['wFormatTag']) { case 0x1: // PCM // PCM case 0x163: // WMA9 Lossless $info_audio['lossless'] = true; break; } if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) { foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) { if (@$data_array['flags']['stream_number'] == $stream_number) { $info_asf_audio_media_current_stream['bitrate'] = $data_array['bitrate']; $info_audio['bitrate'] += $data_array['bitrate']; break; } } } else { if (@$info_asf_audio_media_current_stream['bytes_sec']) { $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bytes_sec'] * 8; } elseif (@$info_asf_audio_media_current_stream['bitrate']) { $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bitrate']; } } $info_audio['streams'][$stream_number] = $info_asf_audio_media_current_stream; $info_audio['streams'][$stream_number]['wformattag'] = $info_asf_audio_media_current_stream['raw']['wFormatTag']; $info_audio['streams'][$stream_number]['lossless'] = $info_audio['lossless']; $info_audio['streams'][$stream_number]['bitrate'] = $info_audio['bitrate']; unset($info_audio['streams'][$stream_number]['raw']); $info_asf_audio_media_current_stream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($stream_data['type_specific_data'], $audio_media_offset, 2)); $audio_media_offset += 2; $info_asf_audio_media_current_stream['codec_data'] = substr($stream_data['type_specific_data'], $audio_media_offset, $info_asf_audio_media_current_stream['codec_data_size']); $audio_media_offset += $info_asf_audio_media_current_stream['codec_data_size']; break; case getid3_asf::Video_Media: // Field Name Field Type Size (bits) // Encoded Image Width DWORD 32 // width of image in pixels // Encoded Image Height DWORD 32 // height of image in pixels // Reserved Flags BYTE 8 // hardcoded: 0x02 // Format Data Size WORD 16 // size of Format Data field in bytes // Format Data array of: variable // // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes $info_asf['video_media'][$stream_number] = array(); $info_asf_video_media_current_stream =& $info_asf['video_media'][$stream_number]; getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream, $stream_data['type_specific_data'], 0, array('image_width' => 4, 'image_height' => 4, 'flags' => 1, 'format_data_size' => 2)); getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream['format_data'], $stream_data['type_specific_data'], 11, array('format_data_size' => 4, 'image_width' => 4, 'image_height' => 4, 'reserved' => 2, 'bits_per_pixel' => 2, 'codec_fourcc' => -4, 'image_size' => 4, 'horizontal_pels' => 4, 'vertical_pels' => 4, 'colors_used' => 4, 'colors_important' => 4)); $info_asf_video_media_current_stream['format_data']['codec_data'] = substr($stream_data['type_specific_data'], 51); if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) { foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) { if (@$data_array['flags']['stream_number'] == $stream_number) { $info_asf_video_media_current_stream['bitrate'] = $data_array['bitrate']; $info_video['streams'][$stream_number]['bitrate'] = $data_array['bitrate']; $info_video['bitrate'] += $data_array['bitrate']; break; } } } $info_asf_video_media_current_stream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($info_asf_video_media_current_stream['format_data']['codec_fourcc']); $info_video['streams'][$stream_number]['fourcc'] = $info_asf_video_media_current_stream['format_data']['codec_fourcc']; $info_video['streams'][$stream_number]['codec'] = $info_asf_video_media_current_stream['format_data']['codec']; $info_video['streams'][$stream_number]['resolution_x'] = $info_asf_video_media_current_stream['image_width']; $info_video['streams'][$stream_number]['resolution_y'] = $info_asf_video_media_current_stream['image_height']; $info_video['streams'][$stream_number]['bits_per_sample'] = $info_asf_video_media_current_stream['format_data']['bits_per_pixel']; break; default: break; } } } while (ftell($getid3->fp) < $getid3->info['avdataend']) { $next_object_data_header = fread($getid3->fp, 24); $offset = 0; $next_object_guid = substr($next_object_data_header, 0, 16); $offset += 16; $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid); $next_object_size = getid3_lib::LittleEndian2Int(substr($next_object_data_header, $offset, 8)); $offset += 8; switch ($next_object_guidtext) { case getid3_asf::Data_Object: // Data Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Data object - getid3_asf::Data_Object // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1 // File ID GUID 128 // unique identifier. identical to File ID field in Header Object // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1 // Reserved WORD 16 // hardcoded: 0x0101 // shortcut $info_asf['data_object'] = array(); $info_asf_data_object =& $info_asf['data_object']; $data_object_data = $next_object_data_header . fread($getid3->fp, 50 - 24); $offset = 24; $info_asf_data_object['objectid_guid'] = $next_object_guidtext; $info_asf_data_object['objectsize'] = $next_object_size; $info_asf_data_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($data_object_data, $offset, 16)); $offset += 16; $info_asf_data_object['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 8)); $offset += 8; $info_asf_data_object['reserved'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 2)); $offset += 2; if ($info_asf_data_object['reserved'] != 0x101) { $getid3->warning('data_object.reserved (' . getid3_lib::PrintHexBytes($info_asf_data_object['reserved']) . ') does not match expected value of "0x0101"'); break; } // Data Packets array of: variable // // * Error Correction Flags BYTE 8 // // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000 // * * Opaque Data Present bits 1 // // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00 // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure // * Error Correction Data $getid3->info['avdataoffset'] = ftell($getid3->fp); fseek($getid3->fp, $info_asf_data_object['objectsize'] - 50, SEEK_CUR); // skip actual audio/video data $getid3->info['avdataend'] = ftell($getid3->fp); break; case getid3_asf::Simple_Index_Object: // Simple Index Object: (optional, recommended, one per video stream) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Simple Index object - getid3_asf::Data_Object // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units // Maximum Packet Count DWORD 32 // maximum packet count for all index entries // Index Entries Count DWORD 32 // number of Index Entries structures // Index Entries array of: variable // // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry // * Packet Count WORD 16 // number of Data Packets to sent at this index entry // shortcut $info_asf['simple_index_object'] = array(); $info_asf_simple_index_object =& $info_asf['simple_index_object']; $info_asf_simple_index_object['objectid_guid'] = $next_object_guidtext; $info_asf_simple_index_object['objectsize'] = $next_object_size; $simple_index_object_data = $next_object_data_header . fread($getid3->fp, 56 - 24); $info_asf_simple_index_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($simple_index_object_data, 24, 16)); getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_simple_index_object, $simple_index_object_data, 40, array('index_entry_time_interval' => 8, 'maximum_packet_count' => 4, 'index_entries_count' => 4)); $offset = 56; $index_entries_data = $simple_index_object_data . fread($getid3->fp, 6 * $info_asf_simple_index_object['index_entries_count']); for ($index_entries_counter = 0; $index_entries_counter < $info_asf_simple_index_object['index_entries_count']; $index_entries_counter++) { $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4)); $offset += 4; $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4)); $offset += 2; } break; case getid3_asf::Index_Object: // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for the Index Object - getid3_asf::Index_Object // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms. // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object. // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object. // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0. // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater. // Index Specifiers array of: varies // // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127. // * Index Type WORD 16 // Specifies Index Type values as follows: // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time. // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object. // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set. // Nearest Past Cleanpoint is the most common type of index. // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block. // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed. // * Index Entries array of: varies // // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value // shortcut $info_asf['asf_index_object'] = array(); $info_asf_asf_index_object =& $info_asf['asf_index_object']; $asf_index_object_data = $next_object_data_header . fread($getid3->fp, 34 - 24); $info_asf_asf_index_object['objectid_guid'] = $next_object_guidtext; $info_asf_asf_index_object['objectsize'] = $next_object_size; getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_asf_index_object, $asf_index_object_data, 24, array('entry_time_interval' => 4, 'index_specifiers_count' => 2, 'index_blocks_count' => 4)); $offset = 34; $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count']); for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { $index_specifier_stream_number = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2)); $offset += 2; $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['stream_number'] = $index_specifier_stream_number; $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2)); $offset += 2; $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type_text'] = getid3_asf::ASFIndexObjectIndexTypeLookup($info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type']); } $asf_index_object_data .= fread($getid3->fp, 4); $info_asf_asf_index_object['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4)); $offset += 4; $asf_index_object_data .= fread($getid3->fp, 8 * $info_asf_asf_index_object['index_specifiers_count']); for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { $info_asf_asf_index_object['block_positions'][$index_specifiers_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 8)); $offset += 8; } $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count'] * $info_asf_asf_index_object['index_entry_count']); for ($index_entry_counter = 0; $index_entry_counter < $info_asf_asf_index_object['index_entry_count']; $index_entry_counter++) { for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { $info_asf_asf_index_object['offsets'][$index_specifiers_counter][$index_entry_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4)); $offset += 4; } } break; default: // Implementations shall ignore any standard or non-standard object that they do not know how to handle. if (getid3_asf::GUIDname($next_object_guidtext)) { $getid3->warning('unhandled GUID "' . getid3_asf::GUIDname($next_object_guidtext) . '" {' . $next_object_guidtext . '} in ASF body at offset ' . ($offset - 16 - 8)); } else { $getid3->warning('unknown GUID {' . $next_object_guidtext . '} in ASF body at offset ' . (ftell($getid3->fp) - 16 - 8)); } fseek($getid3->fp, $next_object_size - 16 - 8, SEEK_CUR); break; } } if (isset($info_asf_codec_list_object['codec_entries']) && is_array($info_asf_codec_list_object['codec_entries'])) { foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) { switch ($stream_data['information']) { case 'WMV1': case 'WMV2': case 'WMV3': case 'MSS1': case 'MSS2': case 'WMVA': case 'WVC1': case 'WMVP': case 'WVP2': $info_video['dataformat'] = 'wmv'; $getid3->info['mime_type'] = 'video/x-ms-wmv'; break; case 'MP42': case 'MP43': case 'MP4S': case 'mp4s': $info_video['dataformat'] = 'asf'; $getid3->info['mime_type'] = 'video/x-ms-asf'; break; default: switch ($stream_data['type_raw']) { case 1: if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) { $info_video['dataformat'] = 'wmv'; if ($getid3->info['mime_type'] == 'video/x-ms-asf') { $getid3->info['mime_type'] = 'video/x-ms-wmv'; } } break; case 2: if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) { $info_audio['dataformat'] = 'wma'; if ($getid3->info['mime_type'] == 'video/x-ms-asf') { $getid3->info['mime_type'] = 'audio/x-ms-wma'; } } break; } break; } } } switch (@$info_audio['codec']) { case 'MPEG Layer-3': $info_audio['dataformat'] = 'mp3'; break; default: break; } if (isset($info_asf_codec_list_object['codec_entries'])) { foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) { switch ($stream_data['type_raw']) { case 1: // video $info_video['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']); break; case 2: // audio $info_audio['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']); $info_audio['encoder_options'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][0]['description']); $info_audio['codec'] = $info_audio['encoder']; break; default: $getid3->warning('Unknown streamtype: [codec_list_object][codec_entries][' . $stream_number . '][type_raw] == ' . $stream_data['type_raw']); break; } } } if (isset($getid3->info['audio'])) { $info_audio['lossless'] = isset($info_audio['lossless']) ? $info_audio['lossless'] : false; $info_audio['dataformat'] = !empty($info_audio['dataformat']) ? $info_audio['dataformat'] : 'asf'; } if (!empty($info_video['dataformat'])) { $info_video['lossless'] = isset($info_audio['lossless']) ? $info_audio['lossless'] : false; $info_video['pixel_aspect_ratio'] = isset($info_audio['pixel_aspect_ratio']) ? $info_audio['pixel_aspect_ratio'] : (double) 1; $info_video['dataformat'] = !empty($info_video['dataformat']) ? $info_video['dataformat'] : 'asf'; } $getid3->info['bitrate'] = @$info_audio['bitrate'] + @$info_video['bitrate']; if (empty($info_audio)) { unset($getid3->info['audio']); } if (empty($info_video)) { unset($getid3->info['video']); } return true; }
private function getNSVfHeader($file_offset = 0, $get_toc_offsets = false) { $getid3 = $this->getid3; fseek($getid3->fp, $file_offset, SEEK_SET); $nsvf_header = fread($getid3->fp, 28); $getid3->info['nsv']['NSVf'] = array(); $info_nsv_NSVf =& $getid3->info['nsv']['NSVf']; $info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4); if ($info_nsv_NSVf['identifier'] != 'NSVf') { throw new getid3_exception('expected "NSVf" at offset (' . $file_offset . '), found "' . $info_nsv_NSVf['identifier'] . '" instead'); } $getid3->info['nsv']['NSVs']['offset'] = $file_offset; getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVf, $nsvf_header, 4, array('header_length' => 4, 'file_size' => 4, 'playtime_ms' => 4, 'meta_size' => 4, 'TOC_entries_1' => 4, 'TOC_entries_2' => 4)); if ($info_nsv_NSVf['playtime_ms'] == 0) { throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero'); } if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) { $getid3->warning('truncated file - NSVf header indicates ' . $info_nsv_NSVf['file_size'] . ' bytes, file actually ' . $getid3->info['avdataend'] . ' bytes'); } $nsvf_header .= fread($getid3->fp, $info_nsv_NSVf['meta_size'] + 4 * $info_nsv_NSVf['TOC_entries_1'] + 4 * $info_nsv_NSVf['TOC_entries_2']); $nsvf_headerlength = strlen($nsvf_header); $info_nsv_NSVf['metadata'] = substr($nsvf_header, 28, $info_nsv_NSVf['meta_size']); $offset = 28 + $info_nsv_NSVf['meta_size']; if ($get_toc_offsets) { $toc_counter = 0; while ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) { if ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) { $info_nsv_NSVf['TOC_1'][$toc_counter] = getid3_lib::LittleEndian2Int(substr($nsvf_header, $offset, 4)); $offset += 4; $toc_counter++; } } } if (trim($info_nsv_NSVf['metadata']) != '') { $info_nsv_NSVf['metadata'] = str_replace('`', "", $info_nsv_NSVf['metadata']); $comment_pair_array = explode("" . ' ', $info_nsv_NSVf['metadata']); foreach ($comment_pair_array as $comment_pair) { if (strstr($comment_pair, '=' . "")) { list($key, $value) = explode('=' . "", $comment_pair, 2); $getid3->info['nsv']['comments'][strtolower($key)][] = trim(str_replace("", '', $value)); } } } $getid3->info['playtime_seconds'] = $info_nsv_NSVf['playtime_ms'] / 1000; $getid3->info['bitrate'] = $info_nsv_NSVf['file_size'] * 8 / $getid3->info['playtime_seconds']; return true; }
function getid3_bmp(&$fd, &$ThisFileInfo, $ExtractPalette = false, $ExtractData = false) { // shortcuts $ThisFileInfo['bmp']['header']['raw'] = array(); $thisfile_bmp =& $ThisFileInfo['bmp']; $thisfile_bmp_header =& $thisfile_bmp['header']; $thisfile_bmp_header_raw =& $thisfile_bmp_header['raw']; // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp // all versions // WORD bfType; // DWORD bfSize; // WORD bfReserved1; // WORD bfReserved2; // DWORD bfOffBits; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $offset = 0; $BMPheader = fread($fd, 14 + 40); $thisfile_bmp_header_raw['identifier'] = substr($BMPheader, $offset, 2); $offset += 2; if ($thisfile_bmp_header_raw['identifier'] != 'BM') { $ThisFileInfo['error'][] = 'Expecting "BM" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . $thisfile_bmp_header_raw['identifier'] . '"'; unset($ThisFileInfo['fileformat']); unset($ThisFileInfo['bmp']); return false; } $thisfile_bmp_header_raw['filesize'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['reserved2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['header_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; // check if the hardcoded-to-1 "planes" is at offset 22 or 26 $planes22 = getid3_lib::LittleEndian2Int(substr($BMPheader, 22, 2)); $planes26 = getid3_lib::LittleEndian2Int(substr($BMPheader, 26, 2)); if ($planes22 == 1 && $planes26 != 1) { $thisfile_bmp['type_os'] = 'OS/2'; $thisfile_bmp['type_version'] = 1; } elseif ($planes26 == 1 && $planes22 != 1) { $thisfile_bmp['type_os'] = 'Windows'; $thisfile_bmp['type_version'] = 1; } elseif ($thisfile_bmp_header_raw['header_size'] == 12) { $thisfile_bmp['type_os'] = 'OS/2'; $thisfile_bmp['type_version'] = 1; } elseif ($thisfile_bmp_header_raw['header_size'] == 40) { $thisfile_bmp['type_os'] = 'Windows'; $thisfile_bmp['type_version'] = 1; } elseif ($thisfile_bmp_header_raw['header_size'] == 84) { $thisfile_bmp['type_os'] = 'Windows'; $thisfile_bmp['type_version'] = 4; } elseif ($thisfile_bmp_header_raw['header_size'] == 100) { $thisfile_bmp['type_os'] = 'Windows'; $thisfile_bmp['type_version'] = 5; } else { $ThisFileInfo['error'][] = 'Unknown BMP subtype (or not a BMP file)'; unset($ThisFileInfo['fileformat']); unset($ThisFileInfo['bmp']); return false; } $ThisFileInfo['fileformat'] = 'bmp'; $ThisFileInfo['video']['dataformat'] = 'bmp'; $ThisFileInfo['video']['lossless'] = true; $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1; if ($thisfile_bmp['type_os'] == 'OS/2') { // OS/2-format BMP // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm // DWORD Size; /* Size of this structure in bytes */ // DWORD Width; /* Bitmap width in pixels */ // DWORD Height; /* Bitmap height in pixel */ // WORD NumPlanes; /* Number of bit planes (color depth) */ // WORD BitsPerPixel; /* Number of bits per pixel per plane */ $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; $ThisFileInfo['video']['codec'] = 'BI_RGB ' . $thisfile_bmp_header_raw['bits_per_pixel'] . '-bit'; $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; if ($thisfile_bmp['type_version'] >= 2) { // DWORD Compression; /* Bitmap compression scheme */ // DWORD ImageDataSize; /* Size of bitmap data in bytes */ // DWORD XResolution; /* X resolution of display device */ // DWORD YResolution; /* Y resolution of display device */ // DWORD ColorsUsed; /* Number of color table indices used */ // DWORD ColorsImportant; /* Number of important color indices */ // WORD Units; /* Type of units used to measure resolution */ // WORD Reserved; /* Pad structure to 4-byte boundary */ // WORD Recording; /* Recording algorithm */ // WORD Rendering; /* Halftoning algorithm used */ // DWORD Size1; /* Reserved for halftoning algorithm use */ // DWORD Size2; /* Reserved for halftoning algorithm use */ // DWORD ColorEncoding; /* Color model used in bitmap */ // DWORD Identifier; /* Reserved for application use */ $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['resolution_units'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['recording'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['rendering'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['size1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['size2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['color_encoding'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['identifier'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header['compression'] = $this->BMPcompressionOS2Lookup($thisfile_bmp_header_raw['compression']); $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'] . ' ' . $thisfile_bmp_header_raw['bits_per_pixel'] . '-bit'; } } elseif ($thisfile_bmp['type_os'] == 'Windows') { // Windows-format BMP // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp // all versions // DWORD biSize; // LONG biWidth; // LONG biHeight; // WORD biPlanes; // WORD biBitCount; // DWORD biCompression; // DWORD biSizeImage; // LONG biXPelsPerMeter; // LONG biYPelsPerMeter; // DWORD biClrUsed; // DWORD biClrImportant; $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); $offset += 4; $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); $offset += 4; $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); $offset += 4; $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); $offset += 4; $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header['compression'] = $this->BMPcompressionWindowsLookup($thisfile_bmp_header_raw['compression']); $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'] . ' ' . $thisfile_bmp_header_raw['bits_per_pixel'] . '-bit'; $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; if ($thisfile_bmp['type_version'] >= 4) { $BMPheader .= fread($fd, 44); // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp // Win95+, WinNT4.0+ // DWORD bV4RedMask; // DWORD bV4GreenMask; // DWORD bV4BlueMask; // DWORD bV4AlphaMask; // DWORD bV4CSType; // CIEXYZTRIPLE bV4Endpoints; // DWORD bV4GammaRed; // DWORD bV4GammaGreen; // DWORD bV4GammaBlue; $thisfile_bmp_header_raw['red_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['green_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['blue_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['alpha_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['cs_type'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['ciexyz_red'] = substr($BMPheader, $offset, 4); $offset += 4; $thisfile_bmp_header_raw['ciexyz_green'] = substr($BMPheader, $offset, 4); $offset += 4; $thisfile_bmp_header_raw['ciexyz_blue'] = substr($BMPheader, $offset, 4); $offset += 4; $thisfile_bmp_header_raw['gamma_red'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['gamma_green'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['gamma_blue'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header['ciexyz_red'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_red'])); $thisfile_bmp_header['ciexyz_green'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_green'])); $thisfile_bmp_header['ciexyz_blue'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_blue'])); } if ($thisfile_bmp['type_version'] >= 5) { $BMPheader .= fread($fd, 16); // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp // Win98+, Win2000+ // DWORD bV5Intent; // DWORD bV5ProfileData; // DWORD bV5ProfileSize; // DWORD bV5Reserved; $thisfile_bmp_header_raw['intent'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['profile_data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['profile_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; $thisfile_bmp_header_raw['reserved3'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); $offset += 4; } } else { $ThisFileInfo['error'][] = 'Unknown BMP format in header.'; return false; } if ($ExtractPalette || $ExtractData) { $PaletteEntries = 0; if ($thisfile_bmp_header_raw['bits_per_pixel'] < 16) { $PaletteEntries = pow(2, $thisfile_bmp_header_raw['bits_per_pixel']); } elseif (isset($thisfile_bmp_header_raw['colors_used']) && $thisfile_bmp_header_raw['colors_used'] > 0 && $thisfile_bmp_header_raw['colors_used'] <= 256) { $PaletteEntries = $thisfile_bmp_header_raw['colors_used']; } if ($PaletteEntries > 0) { $BMPpalette = fread($fd, 4 * $PaletteEntries); $paletteoffset = 0; for ($i = 0; $i < $PaletteEntries; $i++) { // RGBQUAD - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp // BYTE rgbBlue; // BYTE rgbGreen; // BYTE rgbRed; // BYTE rgbReserved; //$thisfile_bmp['palette']['blue'][$i] = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); //$thisfile_bmp['palette']['green'][$i] = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); //$thisfile_bmp['palette']['red'][$i] = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); $blue = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); $green = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); $red = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); if ($thisfile_bmp['type_os'] == 'OS/2' && $thisfile_bmp['type_version'] == 1) { // no padding byte } else { $paletteoffset++; // padding byte } $thisfile_bmp['palette'][$i] = $red << 16 | $green << 8 | $blue; } } } if ($ExtractData) { fseek($fd, $thisfile_bmp_header_raw['data_offset'], SEEK_SET); $RowByteLength = ceil($thisfile_bmp_header_raw['width'] * ($thisfile_bmp_header_raw['bits_per_pixel'] / 8) / 4) * 4; // round up to nearest DWORD boundry $BMPpixelData = fread($fd, $thisfile_bmp_header_raw['height'] * $RowByteLength); $pixeldataoffset = 0; switch ($thisfile_bmp_header_raw['compression']) { case 0: // BI_RGB switch ($thisfile_bmp_header_raw['bits_per_pixel']) { case 1: for ($row = $thisfile_bmp_header_raw['height'] - 1; $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); for ($i = 7; $i >= 0; $i--) { $paletteindex = ($paletteindexbyte & 0x1 << $i) >> $i; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; $col++; } } while ($pixeldataoffset % 4 != 0) { // lines are padded to nearest DWORD $pixeldataoffset++; } } break; case 4: for ($row = $thisfile_bmp_header_raw['height'] - 1; $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); for ($i = 1; $i >= 0; $i--) { $paletteindex = ($paletteindexbyte & 0xf << 4 * $i) >> 4 * $i; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; $col++; } } while ($pixeldataoffset % 4 != 0) { // lines are padded to nearest DWORD $pixeldataoffset++; } } break; case 8: for ($row = $thisfile_bmp_header_raw['height'] - 1; $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { $paletteindex = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; } while ($pixeldataoffset % 4 != 0) { // lines are padded to nearest DWORD $pixeldataoffset++; } } break; case 24: case 32: for ($row = $thisfile_bmp_header_raw['height'] - 1; $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { $blue = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $green = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $red = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); if ($thisfile_bmp_header_raw['bits_per_pixel'] == 32) { $paletteoffset++; // filler byte } $thisfile_bmp['data'][$row][$col] = $red << 16 | $green << 8 | $blue; } while ($pixeldataoffset % 4 != 0) { // lines are padded to nearest DWORD $pixeldataoffset++; } } break; case 16: default: $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value (' . $thisfile_bmp_header_raw['bits_per_pixel'] . ') - cannot read pixel data'; break; } break; case 1: // BI_RLE8 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp switch ($thisfile_bmp_header_raw['bits_per_pixel']) { case 8: $pixelcounter = 0; while ($pixeldataoffset < strlen($BMPpixelData)) { $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); if ($firstbyte == 0) { // escaped/absolute mode - the first byte of the pair can be set to zero to // indicate an escape character that denotes the end of a line, the end of // a bitmap, or a delta, depending on the value of the second byte. switch ($secondbyte) { case 0: // end of line // no need for special processing, just ignore break; case 1: // end of bitmap $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case break; case 2: // delta - The 2 bytes following the escape contain unsigned values // indicating the horizontal and vertical offsets of the next pixel // from the current position. $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $col = $pixelcounter % $thisfile_bmp_header_raw['width'] + $colincrement; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width'] - $rowincrement; $pixelcounter = $row * $thisfile_bmp_header_raw['width'] + $col; break; default: // In absolute mode, the first byte is zero and the second byte is a // value in the range 03H through FFH. The second byte represents the // number of bytes that follow, each of which contains the color index // of a single pixel. Each run must be aligned on a word boundary. for ($i = 0; $i < $secondbyte; $i++) { $paletteindex = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $col = $pixelcounter % $thisfile_bmp_header_raw['width']; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width']; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; $pixelcounter++; } while ($pixeldataoffset % 2 != 0) { // Each run must be aligned on a word boundary. $pixeldataoffset++; } break; } } else { // encoded mode - the first byte specifies the number of consecutive pixels // to be drawn using the color index contained in the second byte. for ($i = 0; $i < $firstbyte; $i++) { $col = $pixelcounter % $thisfile_bmp_header_raw['width']; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width']; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$secondbyte]; $pixelcounter++; } } } break; default: $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value (' . $thisfile_bmp_header_raw['bits_per_pixel'] . ') - cannot read pixel data'; break; } break; case 2: // BI_RLE4 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp switch ($thisfile_bmp_header_raw['bits_per_pixel']) { case 4: $pixelcounter = 0; while ($pixeldataoffset < strlen($BMPpixelData)) { $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); if ($firstbyte == 0) { // escaped/absolute mode - the first byte of the pair can be set to zero to // indicate an escape character that denotes the end of a line, the end of // a bitmap, or a delta, depending on the value of the second byte. switch ($secondbyte) { case 0: // end of line // no need for special processing, just ignore break; case 1: // end of bitmap $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case break; case 2: // delta - The 2 bytes following the escape contain unsigned values // indicating the horizontal and vertical offsets of the next pixel // from the current position. $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $col = $pixelcounter % $thisfile_bmp_header_raw['width'] + $colincrement; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width'] - $rowincrement; $pixelcounter = $row * $thisfile_bmp_header_raw['width'] + $col; break; default: // In absolute mode, the first byte is zero. The second byte contains the number // of color indexes that follow. Subsequent bytes contain color indexes in their // high- and low-order 4 bits, one color index for each pixel. In absolute mode, // each run must be aligned on a word boundary. unset($paletteindexes); for ($i = 0; $i < ceil($secondbyte / 2); $i++) { $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $paletteindexes[] = ($paletteindexbyte & 0xf0) >> 4; $paletteindexes[] = $paletteindexbyte & 0xf; } while ($pixeldataoffset % 2 != 0) { // Each run must be aligned on a word boundary. $pixeldataoffset++; } foreach ($paletteindexes as $paletteindex) { $col = $pixelcounter % $thisfile_bmp_header_raw['width']; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width']; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; $pixelcounter++; } break; } } else { // encoded mode - the first byte of the pair contains the number of pixels to be // drawn using the color indexes in the second byte. The second byte contains two // color indexes, one in its high-order 4 bits and one in its low-order 4 bits. // The first of the pixels is drawn using the color specified by the high-order // 4 bits, the second is drawn using the color in the low-order 4 bits, the third // is drawn using the color in the high-order 4 bits, and so on, until all the // pixels specified by the first byte have been drawn. $paletteindexes[0] = ($secondbyte & 0xf0) >> 4; $paletteindexes[1] = $secondbyte & 0xf; for ($i = 0; $i < $firstbyte; $i++) { $col = $pixelcounter % $thisfile_bmp_header_raw['width']; $row = $thisfile_bmp_header_raw['height'] - 1 - ($pixelcounter - $col) / $thisfile_bmp_header_raw['width']; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindexes[$i % 2]]; $pixelcounter++; } } } break; default: $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value (' . $thisfile_bmp_header_raw['bits_per_pixel'] . ') - cannot read pixel data'; break; } break; case 3: // BI_BITFIELDS switch ($thisfile_bmp_header_raw['bits_per_pixel']) { case 16: case 32: $redshift = 0; $greenshift = 0; $blueshift = 0; while (($thisfile_bmp_header_raw['red_mask'] >> $redshift & 0x1) == 0) { $redshift++; } while (($thisfile_bmp_header_raw['green_mask'] >> $greenshift & 0x1) == 0) { $greenshift++; } while (($thisfile_bmp_header_raw['blue_mask'] >> $blueshift & 0x1) == 0) { $blueshift++; } for ($row = $thisfile_bmp_header_raw['height'] - 1; $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { $pixelvalue = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw['bits_per_pixel'] / 8)); $pixeldataoffset += $thisfile_bmp_header_raw['bits_per_pixel'] / 8; $red = intval(round((($pixelvalue & $thisfile_bmp_header_raw['red_mask']) >> $redshift) / ($thisfile_bmp_header_raw['red_mask'] >> $redshift) * 255)); $green = intval(round((($pixelvalue & $thisfile_bmp_header_raw['green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw['green_mask'] >> $greenshift) * 255)); $blue = intval(round((($pixelvalue & $thisfile_bmp_header_raw['blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw['blue_mask'] >> $blueshift) * 255)); $thisfile_bmp['data'][$row][$col] = $red << 16 | $green << 8 | $blue; } while ($pixeldataoffset % 4 != 0) { // lines are padded to nearest DWORD $pixeldataoffset++; } } break; default: $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value (' . $thisfile_bmp_header_raw['bits_per_pixel'] . ') - cannot read pixel data'; break; } break; default: // unhandled compression type $ThisFileInfo['error'][] = 'Unknown/unhandled compression type value (' . $thisfile_bmp_header_raw['compression'] . ') - cannot decompress pixel data'; break; } } return true; }
function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets = false) { $info =& $this->getid3->info; fseek($this->getid3->fp, $fileoffset, SEEK_SET); $NSVfheader = fread($this->getid3->fp, 28); $offset = 0; $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4); $offset += 4; if ($info['nsv']['NSVf']['identifier'] != 'NSVf') { $info['error'][] = 'expected "NSVf" at offset (' . $fileoffset . '), found "' . $info['nsv']['NSVf']['identifier'] . '" instead'; unset($info['nsv']['NSVf']); return false; } $info['nsv']['NSVs']['offset'] = $fileoffset; $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; $info['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) { $info['warning'][] = 'truncated file - NSVf header indicates ' . $info['nsv']['NSVf']['file_size'] . ' bytes, file actually ' . $info['avdataend'] . ' bytes'; } $info['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; $info['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; if ($info['nsv']['NSVf']['playtime_ms'] == 0) { $info['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero'; return false; } $NSVfheader .= fread($this->getid3->fp, $info['nsv']['NSVf']['meta_size'] + 4 * $info['nsv']['NSVf']['TOC_entries_1'] + 4 * $info['nsv']['NSVf']['TOC_entries_2']); $NSVfheaderlength = strlen($NSVfheader); $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']); $offset += $info['nsv']['NSVf']['meta_size']; if ($getTOCoffsets) { $TOCcounter = 0; while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); $offset += 4; $TOCcounter++; } } } if (trim($info['nsv']['NSVf']['metadata']) != '') { $info['nsv']['NSVf']['metadata'] = str_replace('`', "", $info['nsv']['NSVf']['metadata']); $CommentPairArray = explode("" . ' ', $info['nsv']['NSVf']['metadata']); foreach ($CommentPairArray as $CommentPair) { if (strstr($CommentPair, '=' . "")) { list($key, $value) = explode('=' . "", $CommentPair, 2); $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("", '', $value)); } } } $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000; $info['bitrate'] = $info['nsv']['NSVf']['file_size'] * 8 / $info['playtime_seconds']; return true; }