本文整理匯總了PHP中getid3_lib::BigEndian2Bin方法的典型用法代碼示例。如果您正苦於以下問題:PHP getid3_lib::BigEndian2Bin方法的具體用法?PHP getid3_lib::BigEndian2Bin怎麽用?PHP getid3_lib::BigEndian2Bin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類getid3_lib
的用法示例。
在下文中一共展示了getid3_lib::BigEndian2Bin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ParseID3v2Frame
//.........這裏部分代碼省略.........
// Type of event $xx
// Time stamp $xx (xx ...)
// The 'Time stamp' is set to zero if directly at the beginning of the sound
// or after the previous event. All events MUST be sorted in chronological order.
$frame_offset = 0;
$parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
while ($frame_offset < strlen($parsedFrame['data'])) {
$parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1);
$parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']);
$parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
$frame_offset += 4;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'MLLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'MLL') {
// 4.7 MLL MPEG location lookup table
// There may only be one 'MLLT' frame in each tag
// <Header for 'Location lookup table', ID: 'MLLT'>
// MPEG frames between reference $xx xx
// Bytes between reference $xx xx xx
// Milliseconds between reference $xx xx xx
// Bits for bytes deviation $xx
// Bits for milliseconds dev. $xx
// Then for every reference the following data is included;
// Deviation in bytes %xxx....
// Deviation in milliseconds %xxx....
$frame_offset = 0;
$parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2));
$parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3));
$parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3));
$parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1));
$parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1));
$parsedFrame['data'] = substr($parsedFrame['data'], 10);
while ($frame_offset < strlen($parsedFrame['data'])) {
$deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
}
$reference_counter = 0;
while (strlen($deviationbitstream) > 0) {
$parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation']));
$parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation']));
$deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']);
$reference_counter++;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'SYTC' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'STC') {
// 4.8 STC Synchronised tempo codes
// There may only be one 'SYTC' frame in each tag
// <Header for 'Synchronised tempo codes', ID: 'SYTC'>
// Time stamp format $xx
// Tempo data <binary data>
// Where time stamp format is:
// $01 (32-bit value) MPEG frames from beginning of file
// $02 (32-bit value) milliseconds from beginning of file
$frame_offset = 0;
$parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
$timestamp_counter = 0;
while ($frame_offset < strlen($parsedFrame['data'])) {
$parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
if ($parsedFrame[$timestamp_counter]['tempo'] == 255) {
$parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1));
}
$parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
$frame_offset += 4;
$timestamp_counter++;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'USLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'ULT') {
示例2: getid3_dts
function getid3_dts(&$fd, &$ThisFileInfo)
{
// Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)"
// (http://pda.etsi.org/pda/queryform.asp)
// With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
$ThisFileInfo['fileformat'] = 'dts';
fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
$DTSheader = fread($fd, 16);
$ThisFileInfo['dts']['raw']['magic'] = getid3_lib::BigEndian2Int(substr($DTSheader, 0, 4));
if ($ThisFileInfo['dts']['raw']['magic'] != 0x7ffe8001) {
$ThisFileInfo['error'][] = 'Expecting "0x7FFE8001" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "0x' . str_pad(strtoupper(dechex($ThisFileInfo['dts']['raw']['magic'])), 8, '0', STR_PAD_LEFT) . '"';
unset($ThisFileInfo['fileformat']);
unset($ThisFileInfo['dts']);
return false;
}
$fhBS = getid3_lib::BigEndian2Bin(substr($DTSheader, 4, 12));
$bsOffset = 0;
$ThisFileInfo['dts']['raw']['frame_type'] = bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['deficit_samples'] = bindec(substr($fhBS, $bsOffset, 5));
$bsOffset += 5;
$ThisFileInfo['dts']['flags']['crc_present'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['pcm_sample_blocks'] = bindec(substr($fhBS, $bsOffset, 7));
$bsOffset += 7;
$ThisFileInfo['dts']['raw']['frame_byte_size'] = bindec(substr($fhBS, $bsOffset, 14));
$bsOffset += 14;
$ThisFileInfo['dts']['raw']['channel_arrangement'] = bindec(substr($fhBS, $bsOffset, 6));
$bsOffset += 6;
$ThisFileInfo['dts']['raw']['sample_frequency'] = bindec(substr($fhBS, $bsOffset, 4));
$bsOffset += 4;
$ThisFileInfo['dts']['raw']['bitrate'] = bindec(substr($fhBS, $bsOffset, 5));
$bsOffset += 5;
$ThisFileInfo['dts']['flags']['embedded_downmix'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['dynamicrange'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['timestamp'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['auxdata'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['hdcd'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['extension_audio'] = bindec(substr($fhBS, $bsOffset, 3));
$bsOffset += 3;
$ThisFileInfo['dts']['flags']['extended_coding'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['lfe_effects'] = bindec(substr($fhBS, $bsOffset, 2));
$bsOffset += 2;
$ThisFileInfo['dts']['flags']['predictor_history'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
if ($ThisFileInfo['dts']['flags']['crc_present']) {
$ThisFileInfo['dts']['raw']['crc16'] = bindec(substr($fhBS, $bsOffset, 16));
$bsOffset += 16;
}
$ThisFileInfo['dts']['flags']['mri_perfect_reconst'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['encoder_soft_version'] = bindec(substr($fhBS, $bsOffset, 4));
$bsOffset += 4;
$ThisFileInfo['dts']['raw']['copy_history'] = bindec(substr($fhBS, $bsOffset, 2));
$bsOffset += 2;
$ThisFileInfo['dts']['raw']['bits_per_sample'] = bindec(substr($fhBS, $bsOffset, 2));
$bsOffset += 2;
$ThisFileInfo['dts']['flags']['surround_es'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['front_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['flags']['surround_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1));
$bsOffset += 1;
$ThisFileInfo['dts']['raw']['dialog_normalization'] = bindec(substr($fhBS, $bsOffset, 4));
$bsOffset += 4;
$ThisFileInfo['dts']['bitrate'] = $this->DTSbitrateLookup($ThisFileInfo['dts']['raw']['bitrate']);
$ThisFileInfo['dts']['bits_per_sample'] = $this->DTSbitPerSampleLookup($ThisFileInfo['dts']['raw']['bits_per_sample']);
$ThisFileInfo['dts']['sample_rate'] = $this->DTSsampleRateLookup($ThisFileInfo['dts']['raw']['sample_frequency']);
$ThisFileInfo['dts']['dialog_normalization'] = $this->DTSdialogNormalization($ThisFileInfo['dts']['raw']['dialog_normalization'], $ThisFileInfo['dts']['raw']['encoder_soft_version']);
$ThisFileInfo['dts']['flags']['lossless'] = $ThisFileInfo['dts']['raw']['bitrate'] == 31 ? true : false;
$ThisFileInfo['dts']['bitrate_mode'] = $ThisFileInfo['dts']['raw']['bitrate'] == 30 ? 'vbr' : 'cbr';
$ThisFileInfo['dts']['channels'] = $this->DTSnumChannelsLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
$ThisFileInfo['dts']['channel_arrangement'] = $this->DTSchannelArrangementLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
$ThisFileInfo['audio']['dataformat'] = 'dts';
$ThisFileInfo['audio']['lossless'] = $ThisFileInfo['dts']['flags']['lossless'];
$ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['dts']['bitrate_mode'];
$ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['dts']['bits_per_sample'];
$ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['dts']['sample_rate'];
$ThisFileInfo['audio']['channels'] = $ThisFileInfo['dts']['channels'];
$ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['dts']['bitrate'];
if (isset($ThisFileInfo['avdataend'])) {
$ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['dts']['bitrate'] / 8);
}
return true;
}
示例3: FixedPoint2_30
public static function FixedPoint2_30($raw_data)
{
$binary_string = getid3_lib::BigEndian2Bin($raw_data);
return bindec(substr($binary_string, 0, 2)) + (double) (bindec(substr($binary_string, 2, 30)) / 1073741824);
// pow(2, 30) = 1073741824
}
示例4: Analyze
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.
//.........這裏部分代碼省略.........
示例5: FLACparseSTREAMINFO
private function FLACparseSTREAMINFO($meta_data_block_data)
{
$getid3 = $this->getid3;
getid3_lib::ReadSequence('BigEndian2Int', $getid3->info['flac']['STREAMINFO'], $meta_data_block_data, 0, array('min_block_size' => 2, 'max_block_size' => 2, 'min_frame_size' => 3, 'max_frame_size' => 3));
$sample_rate_channels_sample_bits_stream_samples = getid3_lib::BigEndian2Bin(substr($meta_data_block_data, 10, 8));
$getid3->info['flac']['STREAMINFO']['sample_rate'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 0, 20));
$getid3->info['flac']['STREAMINFO']['channels'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 20, 3)) + 1;
$getid3->info['flac']['STREAMINFO']['bits_per_sample'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 23, 5)) + 1;
$getid3->info['flac']['STREAMINFO']['samples_stream'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 28, 36));
// bindec() returns float in case of int overrun
$getid3->info['flac']['STREAMINFO']['audio_signature'] = substr($meta_data_block_data, 18, 16);
if (!empty($getid3->info['flac']['STREAMINFO']['sample_rate'])) {
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['sample_rate'] = $getid3->info['flac']['STREAMINFO']['sample_rate'];
$getid3->info['audio']['channels'] = $getid3->info['flac']['STREAMINFO']['channels'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['flac']['STREAMINFO']['bits_per_sample'];
$getid3->info['playtime_seconds'] = $getid3->info['flac']['STREAMINFO']['samples_stream'] / $getid3->info['flac']['STREAMINFO']['sample_rate'];
$getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
} else {
throw new getid3_exception('Corrupt METAdata block: STREAMINFO');
}
unset($getid3->info['flac']['STREAMINFO']['raw']);
return true;
}
示例6: getAACADIFheaderFilepointer
function getAACADIFheaderFilepointer()
{
$info =& $this->getid3->info;
$info['fileformat'] = 'aac';
$info['audio']['dataformat'] = 'aac';
$info['audio']['lossless'] = false;
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
$AACheader = fread($this->getid3->fp, 1024);
$offset = 0;
if (substr($AACheader, 0, 4) == 'ADIF') {
// http://faac.sourceforge.net/wiki/index.php?page=ADIF
// http://libmpeg.org/mpeg4/doc/w2203tfs.pdf
// adif_header() {
// adif_id 32
// copyright_id_present 1
// if( copyright_id_present )
// copyright_id 72
// original_copy 1
// home 1
// bitstream_type 1
// bitrate 23
// num_program_config_elements 4
// for (i = 0; i < num_program_config_elements + 1; i++ ) {
// if( bitstream_type == '0' )
// adif_buffer_fullness 20
// program_config_element()
// }
// }
$AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader);
$bitoffset = 0;
$info['aac']['header_type'] = 'ADIF';
$bitoffset += 32;
$info['aac']['header']['mpeg_version'] = 4;
$info['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
$bitoffset += 1;
if ($info['aac']['header']['copyright']) {
$info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72));
$bitoffset += 72;
}
$info['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
$bitoffset += 1;
$info['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
$bitoffset += 1;
$info['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
$bitoffset += 1;
if ($info['aac']['header']['is_vbr']) {
$info['audio']['bitrate_mode'] = 'vbr';
$info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
$bitoffset += 23;
} else {
$info['audio']['bitrate_mode'] = 'cbr';
$info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
$bitoffset += 23;
$info['audio']['bitrate'] = $info['aac']['header']['bitrate'];
}
if ($info['audio']['bitrate'] == 0) {
$info['error'][] = 'Corrupt AAC file: bitrate_audio == zero';
return false;
}
$info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
$bitoffset += 4;
for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) {
// http://www.audiocoding.com/wiki/index.php?page=program_config_element
// buffer_fullness 20
// element_instance_tag 4
// object_type 2
// sampling_frequency_index 4
// num_front_channel_elements 4
// num_side_channel_elements 4
// num_back_channel_elements 4
// num_lfe_channel_elements 2
// num_assoc_data_elements 3
// num_valid_cc_elements 4
// mono_mixdown_present 1
// mono_mixdown_element_number 4 if mono_mixdown_present == 1
// stereo_mixdown_present 1
// stereo_mixdown_element_number 4 if stereo_mixdown_present == 1
// matrix_mixdown_idx_present 1
// matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1
// pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1
// for (i = 0; i < num_front_channel_elements; i++) {
// front_element_is_cpe[i] 1
// front_element_tag_select[i] 4
// }
// for (i = 0; i < num_side_channel_elements; i++) {
// side_element_is_cpe[i] 1
// side_element_tag_select[i] 4
// }
// for (i = 0; i < num_back_channel_elements; i++) {
// back_element_is_cpe[i] 1
// back_element_tag_select[i] 4
// }
// for (i = 0; i < num_lfe_channel_elements; i++) {
// lfe_element_tag_select[i] 4
// }
// for (i = 0; i < num_assoc_data_elements; i++) {
// assoc_data_element_tag_select[i] 4
// }
// for (i = 0; i < num_valid_cc_elements; i++) {
// cc_element_is_ind_sw[i] 1
//.........這裏部分代碼省略.........
示例7: BigEndian2Float
public static function BigEndian2Float($byte_word)
{
// ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
// http://www.psc.edu/general/software/packages/ieee/ieee.html
// http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
$bit_word = getid3_lib::BigEndian2Bin($byte_word);
if (!$bit_word) {
return 0;
}
$sign_bit = $bit_word[0];
switch (strlen($byte_word) * 8) {
case 32:
$exponent_bits = 8;
$fraction_bits = 23;
break;
case 64:
$exponent_bits = 11;
$fraction_bits = 52;
break;
case 80:
// 80-bit Apple SANE format
// http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
$exponent_string = substr($bit_word, 1, 15);
$is_normalized = intval($bit_word[16]);
$fraction_string = substr($bit_word, 17, 63);
$exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383);
$fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string);
$float_value = $exponent * $fraction;
if ($sign_bit == '1') {
$float_value *= -1;
}
return $float_value;
break;
default:
return false;
break;
}
$exponent_string = substr($bit_word, 1, $exponent_bits);
$fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits);
$exponent = bindec($exponent_string);
$fraction = bindec($fraction_string);
if ($exponent == pow(2, $exponent_bits) - 1 && $fraction != 0) {
// Not a Number
$float_value = false;
} elseif ($exponent == pow(2, $exponent_bits) - 1 && $fraction == 0) {
if ($sign_bit == '1') {
$float_value = '-infinity';
} else {
$float_value = '+infinity';
}
} elseif ($exponent == 0 && $fraction == 0) {
if ($sign_bit == '1') {
$float_value = -0;
} else {
$float_value = 0;
}
$float_value = $sign_bit ? 0 : -0;
} elseif ($exponent == 0 && $fraction != 0) {
// These are 'unnormalized' values
$float_value = pow(2, -1 * (pow(2, $exponent_bits - 1) - 2)) * getid3_lib::DecimalBinary2Float($fraction_string);
if ($sign_bit == '1') {
$float_value *= -1;
}
} elseif ($exponent != 0) {
$float_value = pow(2, $exponent - (pow(2, $exponent_bits - 1) - 1)) * (1 + getid3_lib::DecimalBinary2Float($fraction_string));
if ($sign_bit == '1') {
$float_value *= -1;
}
}
return (double) $float_value;
}
示例8: Analyze
public function Analyze()
{
$info =& $this->getid3->info;
// Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)"
// (http://pda.etsi.org/pda/queryform.asp)
// With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
$info['fileformat'] = 'dts';
$this->fseek($info['avdataoffset']);
$DTSheader = $this->fread(16);
if (strpos($DTSheader, self::syncword) === 0) {
$info['dts']['raw']['magic'] = self::syncword;
$offset = 4;
} else {
if (!$this->isDependencyFor('matroska')) {
unset($info['fileformat']);
return $this->error('Expecting "' . getid3_lib::PrintHexBytes(self::syncword) . '" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($DTSheader, 0, 4)) . '"');
}
$offset = 0;
}
$fhBS = getid3_lib::BigEndian2Bin(substr($DTSheader, $offset, 12));
$bsOffset = 0;
$info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, $bsOffset, 5);
$info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, $bsOffset, 7);
$info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, $bsOffset, 14);
$info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, $bsOffset, 6);
$info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, $bsOffset, 4);
$info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, $bsOffset, 5);
$info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, $bsOffset, 3);
$info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, $bsOffset, 2);
$info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
if ($info['dts']['flags']['crc_present']) {
$info['dts']['raw']['crc16'] = $this->readBinData($fhBS, $bsOffset, 16);
}
$info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, $bsOffset, 4);
$info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, $bsOffset, 2);
$info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, $bsOffset, 2);
$info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
$info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, $bsOffset, 4);
$info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
$info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
$info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
$info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
$info['dts']['flags']['lossless'] = $info['dts']['raw']['bitrate'] == 31 ? true : false;
$info['dts']['bitrate_mode'] = $info['dts']['raw']['bitrate'] == 30 ? 'vbr' : 'cbr';
$info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
$info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
$info['audio']['dataformat'] = 'dts';
$info['audio']['lossless'] = $info['dts']['flags']['lossless'];
$info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
$info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
$info['audio']['sample_rate'] = $info['dts']['sample_rate'];
$info['audio']['channels'] = $info['dts']['channels'];
$info['audio']['bitrate'] = $info['dts']['bitrate'];
if (isset($info['avdataend'])) {
$info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
}
return true;
}
示例9: ParseID3v2Frame
//.........這裏部分代碼省略.........
// Type of event $xx
// Time stamp $xx (xx ...)
// The 'Time stamp' is set to zero if directly at the beginning of the sound
// or after the previous event. All events MUST be sorted in chronological order.
$frame_offset = 0;
$parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
while ($frame_offset < strlen($parsedFrame['data'])) {
$parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1);
$parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']);
$parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
$frame_offset += 4;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'MLLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'MLL') {
// 4.7 MLL MPEG location lookup table
// There may only be one 'MLLT' frame in each tag
// <Header for 'Location lookup table', ID: 'MLLT'>
// MPEG frames between reference $xx xx
// Bytes between reference $xx xx xx
// Milliseconds between reference $xx xx xx
// Bits for bytes deviation $xx
// Bits for milliseconds dev. $xx
// Then for every reference the following data is included;
// Deviation in bytes %xxx....
// Deviation in milliseconds %xxx....
$frame_offset = 0;
$parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2));
$parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3));
$parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3));
$parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1));
$parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1));
$parsedFrame['data'] = substr($parsedFrame['data'], 10);
while ($frame_offset < strlen($parsedFrame['data'])) {
$deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
}
$reference_counter = 0;
while (strlen($deviationbitstream) > 0) {
$parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation']));
$parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation']));
$deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']);
$reference_counter++;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'SYTC' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'STC') {
// 4.8 STC Synchronised tempo codes
// There may only be one 'SYTC' frame in each tag
// <Header for 'Synchronised tempo codes', ID: 'SYTC'>
// Time stamp format $xx
// Tempo data <binary data>
// Where time stamp format is:
// $01 (32-bit value) MPEG frames from beginning of file
// $02 (32-bit value) milliseconds from beginning of file
$frame_offset = 0;
$parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
$timestamp_counter = 0;
while ($frame_offset < strlen($parsedFrame['data'])) {
$parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
if ($parsedFrame[$timestamp_counter]['tempo'] == 255) {
$parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1));
}
$parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
$frame_offset += 4;
$timestamp_counter++;
}
unset($parsedFrame['data']);
} elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'USLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'ULT') {
示例10: FLACparseSTREAMINFO
function FLACparseSTREAMINFO($METAdataBlockData, &$ThisFileInfo)
{
$offset = 0;
$ThisFileInfo['flac']['STREAMINFO']['min_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
$offset += 2;
$ThisFileInfo['flac']['STREAMINFO']['max_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2));
$offset += 2;
$ThisFileInfo['flac']['STREAMINFO']['min_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
$offset += 3;
$ThisFileInfo['flac']['STREAMINFO']['max_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3));
$offset += 3;
$SampleRateChannelsSampleBitsStreamSamples = getid3_lib::BigEndian2Bin(substr($METAdataBlockData, $offset, 8));
$ThisFileInfo['flac']['STREAMINFO']['sample_rate'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 0, 20));
$ThisFileInfo['flac']['STREAMINFO']['channels'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 20, 3)) + 1;
$ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 23, 5)) + 1;
$ThisFileInfo['flac']['STREAMINFO']['samples_stream'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 28, 36));
$offset += 8;
$ThisFileInfo['flac']['STREAMINFO']['audio_signature'] = substr($METAdataBlockData, $offset, 16);
$offset += 16;
if (!empty($ThisFileInfo['flac']['STREAMINFO']['sample_rate'])) {
$ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
$ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
$ThisFileInfo['audio']['channels'] = $ThisFileInfo['flac']['STREAMINFO']['channels'];
$ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'];
$ThisFileInfo['playtime_seconds'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] / $ThisFileInfo['flac']['STREAMINFO']['sample_rate'];
$ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
} else {
$ThisFileInfo['error'][] = 'Corrupt METAdata block: STREAMINFO';
return false;
}
return true;
}
示例11: Analyze
public function Analyze()
{
$getid3 = $this->getid3;
$getid3->info['mpeg']['video']['raw'] = array();
$info_mpeg_video =& $getid3->info['mpeg']['video'];
$info_mpeg_video_raw =& $info_mpeg_video['raw'];
$getid3->info['video'] = array();
$info_video =& $getid3->info['video'];
$getid3->include_module('audio.mp3');
if ($getid3->info['avdataend'] <= $getid3->info['avdataoffset']) {
throw new getid3_exception('"avdataend" (' . $getid3->info['avdataend'] . ') is unexpectedly less-than-or-equal-to "avdataoffset" (' . $getid3->info['avdataoffset'] . ')');
}
$getid3->info['fileformat'] = 'mpeg';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$mpeg_stream_data = fread($getid3->fp, min(100000, $getid3->info['avdataend'] - $getid3->info['avdataoffset']));
$mpeg_stream_data_length = strlen($mpeg_stream_data);
$video_chunk_offset = 0;
while (substr($mpeg_stream_data, $video_chunk_offset++, 4) !== getid3_mpeg::VIDEO_SEQUENCE_HEADER) {
if ($video_chunk_offset >= $mpeg_stream_data_length) {
throw new getid3_exception('Could not find start of video block in the first 100,000 bytes (or before end of file) - this might not be an MPEG-video file?');
}
}
// Start code 32 bits
// horizontal frame size 12 bits
// vertical frame size 12 bits
// pixel aspect ratio 4 bits
// frame rate 4 bits
// bitrate 18 bits
// marker bit 1 bit
// VBV buffer size 10 bits
// constrained parameter flag 1 bit
// intra quant. matrix flag 1 bit
// intra quant. matrix values 512 bits (present if matrix flag == 1)
// non-intra quant. matrix flag 1 bit
// non-intra quant. matrix values 512 bits (present if matrix flag == 1)
$info_video['dataformat'] = 'mpeg';
$video_chunk_offset += strlen(getid3_mpeg::VIDEO_SEQUENCE_HEADER) - 1;
$frame_size_dword = getid3_lib::BigEndian2Int(substr($mpeg_stream_data, $video_chunk_offset, 3));
$video_chunk_offset += 3;
$aspect_ratio_frame_rate_dword = getid3_lib::BigEndian2Int(substr($mpeg_stream_data, $video_chunk_offset, 1));
$video_chunk_offset += 1;
$assorted_information = getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 4));
$video_chunk_offset += 4;
$info_mpeg_video_raw['framesize_horizontal'] = ($frame_size_dword & 0xfff000) >> 12;
// 12 bits for horizontal frame size
$info_mpeg_video_raw['framesize_vertical'] = $frame_size_dword & 0xfff;
// 12 bits for vertical frame size
$info_mpeg_video_raw['pixel_aspect_ratio'] = ($aspect_ratio_frame_rate_dword & 0xf0) >> 4;
$info_mpeg_video_raw['frame_rate'] = $aspect_ratio_frame_rate_dword & 0xf;
$info_mpeg_video['framesize_horizontal'] = $info_mpeg_video_raw['framesize_horizontal'];
$info_mpeg_video['framesize_vertical'] = $info_mpeg_video_raw['framesize_vertical'];
$info_mpeg_video['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($info_mpeg_video_raw['pixel_aspect_ratio']);
$info_mpeg_video['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($info_mpeg_video_raw['pixel_aspect_ratio']);
$info_mpeg_video['frame_rate'] = $this->MPEGvideoFramerateLookup($info_mpeg_video_raw['frame_rate']);
$info_mpeg_video_raw['bitrate'] = bindec(substr($assorted_information, 0, 18));
$info_mpeg_video_raw['marker_bit'] = (bool) bindec($assorted_information[18]);
$info_mpeg_video_raw['vbv_buffer_size'] = bindec(substr($assorted_information, 19, 10));
$info_mpeg_video_raw['constrained_param_flag'] = (bool) bindec($assorted_information[29]);
$info_mpeg_video_raw['intra_quant_flag'] = (bool) bindec($assorted_information[30]);
if ($info_mpeg_video_raw['intra_quant_flag']) {
// read 512 bits
$info_mpeg_video_raw['intra_quant'] = getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 64));
$video_chunk_offset += 64;
$info_mpeg_video_raw['non_intra_quant_flag'] = (bool) bindec($info_mpeg_video_raw['intra_quant'][511]);
$info_mpeg_video_raw['intra_quant'] = bindec($assorted_information[31]) . substr(getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 64)), 0, 511);
if ($info_mpeg_video_raw['non_intra_quant_flag']) {
$info_mpeg_video_raw['non_intra_quant'] = substr($mpeg_stream_data, $video_chunk_offset, 64);
$video_chunk_offset += 64;
}
} else {
$info_mpeg_video_raw['non_intra_quant_flag'] = (bool) bindec($assorted_information[31]);
if ($info_mpeg_video_raw['non_intra_quant_flag']) {
$info_mpeg_video_raw['non_intra_quant'] = substr($mpeg_stream_data, $video_chunk_offset, 64);
$video_chunk_offset += 64;
}
}
if ($info_mpeg_video_raw['bitrate'] == 0x3ffff) {
// 18 set bits
$getid3->warning('This version of getID3() cannot determine average bitrate of VBR MPEG video files');
$info_mpeg_video['bitrate_mode'] = 'vbr';
} else {
$info_mpeg_video['bitrate'] = $info_mpeg_video_raw['bitrate'] * 400;
$info_mpeg_video['bitrate_mode'] = 'cbr';
$info_video['bitrate'] = $info_mpeg_video['bitrate'];
}
$info_video['resolution_x'] = $info_mpeg_video['framesize_horizontal'];
$info_video['resolution_y'] = $info_mpeg_video['framesize_vertical'];
$info_video['frame_rate'] = $info_mpeg_video['frame_rate'];
$info_video['bitrate_mode'] = $info_mpeg_video['bitrate_mode'];
$info_video['pixel_aspect_ratio'] = $info_mpeg_video['pixel_aspect_ratio'];
$info_video['lossless'] = false;
$info_video['bits_per_sample'] = 24;
//0x000001B3 begins the sequence_header of every MPEG video stream.
//But in MPEG-2, this header must immediately be followed by an
//extension_start_code (0x000001B5) with a sequence_extension ID (1).
//(This extension contains all the additional MPEG-2 stuff.)
//MPEG-1 doesn't have this extension, so that's a sure way to tell the
//difference between MPEG-1 and MPEG-2 video streams.
$info_video['codec'] = substr($mpeg_stream_data, $video_chunk_offset, 4) == getid3_mpeg::VIDEO_EXTENSION_START ? 'MPEG-2' : 'MPEG-1';
$audio_chunk_offset = 0;
//.........這裏部分代碼省略.........
示例12: Analyze
public function Analyze()
{
$info =& $this->getid3->info;
$info['fileformat'] = 'mpeg';
$this->fseek($info['avdataoffset']);
$MPEGstreamData = $this->fread($this->getid3->option_fread_buffer_size);
$MPEGstreamBaseOffset = 0;
// how far are we from the beginning of the file data ($info['avdataoffset'])
$MPEGstreamDataOffset = 0;
// how far are we from the beginning of the buffer data (~32kB)
$StartCodeValue = false;
$prevStartCodeValue = false;
$GOPcounter = -1;
$FramesByGOP = array();
$ParsedAVchannels = array();
do {
//echo $MPEGstreamDataOffset.' vs '.(strlen($MPEGstreamData) - 1024).'<Br>';
if ($MPEGstreamDataOffset > strlen($MPEGstreamData) - 16384) {
// buffer running low, get more data
//echo 'reading more data<br>';
$MPEGstreamData .= $this->fread($this->getid3->option_fread_buffer_size);
if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) {
$MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset);
$MPEGstreamBaseOffset += $MPEGstreamDataOffset;
$MPEGstreamDataOffset = 0;
}
}
if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === false) {
//echo 'no more start codes found.<br>';
break;
} else {
$MPEGstreamDataOffset = $StartCodeOffset;
$prevStartCodeValue = $StartCodeValue;
$StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1));
//echo 'Found "'.strtoupper(dechex($StartCodeValue)).'" at offset '.($MPEGstreamBaseOffset + $StartCodeOffset).' ($MPEGstreamDataOffset = '.$MPEGstreamDataOffset.')<br>';
}
$MPEGstreamDataOffset += 4;
switch ($StartCodeValue) {
case 0x0:
// picture_start_code
if ($info['mpeg']['video']['bitrate_mode'] == 'vbr') {
$bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4));
$bitstreamoffset = 0;
$PictureHeader = array();
$PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10);
// 10-bit unsigned integer associated with each input picture. It is incremented by one, modulo 1024, for each input frame. When a frame is coded as two fields the temporal reference in the picture header of both fields is the same. Following a group start header the temporal reference of the earliest picture (in display order) shall be reset to zero.
$PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3);
// 3 bits for picture_coding_type
$PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 16);
// 16 bits for vbv_delay
//... etc
$FramesByGOP[$GOPcounter][] = $PictureHeader;
}
break;
case 0xb3:
// sequence_header_code
/*
Note: purposely doing the less-pretty (and probably a bit slower) method of using string of bits rather than bitwise operations.
Mostly because PHP 32-bit doesn't handle unsigned integers well for bitwise operation.
Also the MPEG stream is designed as a bitstream and often doesn't align nicely with byte boundaries.
*/
$info['video']['codec'] = 'MPEG-1';
// will be updated if extension_start_code found
$bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8));
$bitstreamoffset = 0;
$info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12);
// 12 bits for horizontal frame size. Note: horizontal_size_extension, if present, will add 2 most-significant bits to this value
$info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12);
// 12 bits for vertical frame size. Note: vertical_size_extension, if present, will add 2 most-significant bits to this value
$info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4);
// 4 bits for aspect_ratio_information
$info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4);
// 4 bits for Frame Rate id code
$info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 18);
// 18 bits for bit_rate_value (18 set bits = VBR, otherwise bitrate = this value * 400)
$marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1);
// The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation.
$info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10);
// 10 bits vbv_buffer_size_value
$info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1);
// 1 bit flag: constrained_param_flag
$info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1);
// 1 bit flag: load_intra_quantiser_matrix
if ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) {
$bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12, 64));
for ($i = 0; $i < 64; $i++) {
$info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8);
}
}
$info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1);
if ($info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix']) {
$bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] ? 64 : 0), 64));
for ($i = 0; $i < 64; $i++) {
$info['mpeg']['video']['raw']['non_intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8);
}
}
$info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information']);
$info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information']);
$info['mpeg']['video']['frame_rate'] = self::videoFramerateLookup($info['mpeg']['video']['raw']['frame_rate_code']);
if ($info['mpeg']['video']['raw']['bitrate'] == 0x3ffff) {
//.........這裏部分代碼省略.........
示例13: Analyze
public function Analyze()
{
$getid3 = $this->getid3;
$getid3->info['dts'] = array();
$info_dts =& $getid3->info['dts'];
$getid3->info['fileformat'] = 'dts';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$header = fread($getid3->fp, 16);
$fhBS = getid3_lib::BigEndian2Bin(substr($header, 4, 12));
$bs_offset = 0;
$info_dts['raw']['frame_type'] = bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['deficit_samples'] = bindec(substr($fhBS, $bs_offset, 5));
$bs_offset += 5;
$info_dts['flags']['crc_present'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['pcm_sample_blocks'] = bindec(substr($fhBS, $bs_offset, 7));
$bs_offset += 7;
$info_dts['raw']['frame_byte_size'] = bindec(substr($fhBS, $bs_offset, 14));
$bs_offset += 14;
$info_dts['raw']['channel_arrangement'] = bindec(substr($fhBS, $bs_offset, 6));
$bs_offset += 6;
$info_dts['raw']['sample_frequency'] = bindec(substr($fhBS, $bs_offset, 4));
$bs_offset += 4;
$info_dts['raw']['bitrate'] = bindec(substr($fhBS, $bs_offset, 5));
$bs_offset += 5;
$info_dts['flags']['embedded_downmix'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['dynamicrange'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['timestamp'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['auxdata'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['hdcd'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['extension_audio'] = bindec(substr($fhBS, $bs_offset, 3));
$bs_offset += 3;
$info_dts['flags']['extended_coding'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['lfe_effects'] = bindec(substr($fhBS, $bs_offset, 2));
$bs_offset += 2;
$info_dts['flags']['predictor_history'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
if ($info_dts['flags']['crc_present']) {
$info_dts['raw']['crc16'] = bindec(substr($fhBS, $bs_offset, 16));
$bs_offset += 16;
}
$info_dts['flags']['mri_perfect_reconst'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['encoder_soft_version'] = bindec(substr($fhBS, $bs_offset, 4));
$bs_offset += 4;
$info_dts['raw']['copy_history'] = bindec(substr($fhBS, $bs_offset, 2));
$bs_offset += 2;
$info_dts['raw']['bits_per_sample'] = bindec(substr($fhBS, $bs_offset, 2));
$bs_offset += 2;
$info_dts['flags']['surround_es'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['front_sum_diff'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['flags']['surround_sum_diff'] = (bool) bindec(substr($fhBS, $bs_offset, 1));
$bs_offset += 1;
$info_dts['raw']['dialog_normalization'] = bindec(substr($fhBS, $bs_offset, 4));
$bs_offset += 4;
$info_dts['bitrate'] = $this->DTSbitrateLookup($info_dts['raw']['bitrate']);
$info_dts['bits_per_sample'] = $this->DTSbitPerSampleLookup($info_dts['raw']['bits_per_sample']);
$info_dts['sample_rate'] = $this->DTSsampleRateLookup($info_dts['raw']['sample_frequency']);
$info_dts['dialog_normalization'] = $this->DTSdialogNormalization($info_dts['raw']['dialog_normalization'], $info_dts['raw']['encoder_soft_version']);
$info_dts['flags']['lossless'] = $info_dts['raw']['bitrate'] == 31 ? true : false;
$info_dts['bitrate_mode'] = $info_dts['raw']['bitrate'] == 30 ? 'vbr' : 'cbr';
$info_dts['channels'] = $this->DTSnumChannelsLookup($info_dts['raw']['channel_arrangement']);
$info_dts['channel_arrangement'] = $this->DTSchannelArrangementLookup($info_dts['raw']['channel_arrangement']);
$getid3->info['audio']['dataformat'] = 'dts';
$getid3->info['audio']['lossless'] = $info_dts['flags']['lossless'];
$getid3->info['audio']['bitrate_mode'] = $info_dts['bitrate_mode'];
$getid3->info['audio']['bits_per_sample'] = $info_dts['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $info_dts['sample_rate'];
$getid3->info['audio']['channels'] = $info_dts['channels'];
$getid3->info['audio']['bitrate'] = $info_dts['bitrate'];
$getid3->info['playtime_seconds'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / ($info_dts['bitrate'] / 8);
return true;
}
示例14: parseSTREAMINFO
private function parseSTREAMINFO($BlockData)
{
$info =& $this->getid3->info;
$info['flac']['STREAMINFO'] = array();
$streaminfo =& $info['flac']['STREAMINFO'];
$streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
$streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
$streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
$streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3));
$SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8));
$streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20));
$streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1;
$streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1;
$streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));
$streaminfo['audio_signature'] = substr($BlockData, 18, 16);
if (!empty($streaminfo['sample_rate'])) {
$info['audio']['bitrate_mode'] = 'vbr';
$info['audio']['sample_rate'] = $streaminfo['sample_rate'];
$info['audio']['channels'] = $streaminfo['channels'];
$info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample'];
$info['playtime_seconds'] = $streaminfo['samples_stream'] / $streaminfo['sample_rate'];
if ($info['playtime_seconds'] > 0) {
if (!$this->isDependencyFor('matroska')) {
$info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds'];
} else {
$this->warning('Cannot determine audio bitrate because total stream size is unknown');
}
}
} else {
return $this->error('Corrupt METAdata block: STREAMINFO');
}
return true;
}
示例15: Analyze
public function Analyze()
{
$info =& $this->getid3->info;
$info['fileformat'] = 'dts';
$this->fseek($info['avdataoffset']);
$DTSheader = $this->fread(20);
// we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes
// check syncword
$sync = substr($DTSheader, 0, 4);
if (($encoding = array_search($sync, self::$syncwords)) !== false) {
$info['dts']['raw']['magic'] = $sync;
$this->readBinDataOffset = 32;
} elseif ($this->isDependencyFor('matroska')) {
// Matroska contains DTS without syncword encoded as raw big-endian format
$encoding = 0;
$this->readBinDataOffset = 0;
} else {
unset($info['fileformat']);
return $this->error('Expecting "' . implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)) . '" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes($sync) . '"');
}
// decode header
$fhBS = '';
for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) {
switch ($encoding) {
case 0:
// raw big-endian
$fhBS .= getid3_lib::BigEndian2Bin(substr($DTSheader, $word_offset, 2));
break;
case 1:
// raw little-endian
$fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2)));
break;
case 2:
// 14-bit big-endian
$fhBS .= substr(getid3_lib::BigEndian2Bin(substr($DTSheader, $word_offset, 2)), 2, 14);
break;
case 3:
// 14-bit little-endian
$fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14);
break;
}
}
$info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1);
$info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5);
$info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7);
$info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14);
$info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6);
$info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4);
$info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5);
$info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3);
$info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2);
$info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1);
if ($info['dts']['flags']['crc_present']) {
$info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16);
}
$info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4);
$info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2);
$info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2);
$info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
$info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4);
$info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
$info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
$info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
$info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
$info['dts']['flags']['lossless'] = $info['dts']['raw']['bitrate'] == 31 ? true : false;
$info['dts']['bitrate_mode'] = $info['dts']['raw']['bitrate'] == 30 ? 'vbr' : 'cbr';
$info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
$info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
$info['audio']['dataformat'] = 'dts';
$info['audio']['lossless'] = $info['dts']['flags']['lossless'];
$info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
$info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
$info['audio']['sample_rate'] = $info['dts']['sample_rate'];
$info['audio']['channels'] = $info['dts']['channels'];
$info['audio']['bitrate'] = $info['dts']['bitrate'];
if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) {
$info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
if ($encoding == 2 || $encoding == 3) {
// 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate
$info['playtime_seconds'] *= 14 / 16;
}
}
return true;
}