⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.audio.aac.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		// layer                                           2    always: '00'		// protection_absent                               1		// profile                                         2		// sampling_frequency_index                        4		// private_bit                                     1		// channel_configuration                           3		// original/copy                                   1		// home                                            1		// emphasis                                        2    only if ID == 0 (ie MPEG-4)		// * ADTS Variable Header: these can change from frame to frame		// copyright_identification_bit                    1		// copyright_identification_start                  1		// aac_frame_length                               13    length of the frame including header (in bytes)		// adts_buffer_fullness                           11    0x7FF indicates VBR		// no_raw_data_blocks_in_frame                     2		// * ADTS Error check		// crc_check                                      16    only if protection_absent == 0		$byteoffset  = 0;		$framenumber = 0;		// Init bit pattern array		static $decbin = array();		// Populate $bindec		for ($i = 0; $i < 256; $i++) {			$decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);		}		// used to calculate bitrate below		$BitrateCache = array();		while (true) {			// breaks out when end-of-file encountered, or invalid data found,			// or MaxFramesToScan frames have been scanned			fseek($fd, $byteoffset, SEEK_SET);			// First get substring			$substring = fread($fd, 10);			$substringlength = strlen($substring);			if ($substringlength != 10) {				$ThisFileInfo['error'][] = 'Failed to read 10 bytes at offset '.(ftell($fd) - $substringlength).' (only read '.$substringlength.' bytes)';				return false;			}			// Initialise $AACheaderBitstream			$AACheaderBitstream = '';			// Loop thru substring chars			for ($i = 0; $i < 10; $i++) {				$AACheaderBitstream .= $decbin[$substring{$i}];			}			$bitoffset = 0;			$synctest = bindec(substr($AACheaderBitstream, $bitoffset, 12));			$bitoffset += 12;			if ($synctest != 0x0FFF) {				$ThisFileInfo['error'][] = 'Synch pattern (0x0FFF) not found at offset '.(ftell($fd) - 10).' (found 0x0'.strtoupper(dechex($synctest)).' instead)';				if ($ThisFileInfo['fileformat'] == 'aac') {					return true;				}				return false;			}			// Gather info for first frame only - this takes time to do 1000 times!			if ($framenumber > 0) {				if (!$AACheaderBitstream[$bitoffset]) {					// MPEG-4					$bitoffset += 20;				} else {					// MPEG-2					$bitoffset += 18;				}			} else {				$ThisFileInfo['aac']['header_type']                      = 'ADTS';				$ThisFileInfo['aac']['header']['synch']                  = $synctest;				$ThisFileInfo['fileformat']                              = 'aac';				$ThisFileInfo['audio']['dataformat']                     = 'aac';				$ThisFileInfo['aac']['header']['mpeg_version']           = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? 4 : 2);				$bitoffset += 1;				$ThisFileInfo['aac']['header']['layer']                  = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));				$bitoffset += 2;				if ($ThisFileInfo['aac']['header']['layer'] != 0) {					$ThisFileInfo['error'][] = 'Layer error - expected 0x00, found 0x'.dechex($ThisFileInfo['aac']['header']['layer']).' instead';					return false;				}				$ThisFileInfo['aac']['header']['crc_present']            = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? true : false);				$bitoffset += 1;				$ThisFileInfo['aac']['header']['profile_id']             = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));				$bitoffset += 2;				$ThisFileInfo['aac']['header']['profile_text']           = $this->AACprofileLookup($ThisFileInfo['aac']['header']['profile_id'], $ThisFileInfo['aac']['header']['mpeg_version']);				$ThisFileInfo['aac']['header']['sample_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));				$bitoffset += 4;				$ThisFileInfo['aac']['header']['sample_frequency']       = $this->AACsampleRateLookup($ThisFileInfo['aac']['header']['sample_frequency_index']);				if ($ThisFileInfo['aac']['header']['sample_frequency'] == 0) {					$ThisFileInfo['error'][] = 'Corrupt AAC file: sample_frequency == zero';					return false;				}				$ThisFileInfo['audio']['sample_rate']                    = $ThisFileInfo['aac']['header']['sample_frequency'];				$ThisFileInfo['aac']['header']['private']                = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));				$bitoffset += 1;				$ThisFileInfo['aac']['header']['channel_configuration']  = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));				$bitoffset += 3;				$ThisFileInfo['audio']['channels']                       = $ThisFileInfo['aac']['header']['channel_configuration'];				$ThisFileInfo['aac']['header']['original']               = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));				$bitoffset += 1;				$ThisFileInfo['aac']['header']['home']                   = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));				$bitoffset += 1;				if ($ThisFileInfo['aac']['header']['mpeg_version'] == 4) {					$ThisFileInfo['aac']['header']['emphasis']           = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));					$bitoffset += 2;				}				if ($ReturnExtendedInfo) {					$ThisFileInfo['aac'][$framenumber]['copyright_id_bit']   = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));					$bitoffset += 1;					$ThisFileInfo['aac'][$framenumber]['copyright_id_start'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));					$bitoffset += 1;				} else {					$bitoffset += 2;				}			}			$FrameLength = bindec(substr($AACheaderBitstream, $bitoffset, 13));			if (!isset($BitrateCache[$FrameLength])) {				$BitrateCache[$FrameLength] = ($ThisFileInfo['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8;			}			@$ThisFileInfo['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]]++;			$ThisFileInfo['aac'][$framenumber]['aac_frame_length']     = $FrameLength;			$bitoffset += 13;			$ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] = bindec(substr($AACheaderBitstream, $bitoffset, 11));			$bitoffset += 11;			if ($ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) {				$ThisFileInfo['audio']['bitrate_mode'] = 'vbr';			} else {				$ThisFileInfo['audio']['bitrate_mode'] = 'cbr';			}			$ThisFileInfo['aac'][$framenumber]['num_raw_data_blocks']  = bindec(substr($AACheaderBitstream, $bitoffset, 2));			$bitoffset += 2;			if ($ThisFileInfo['aac']['header']['crc_present']) {				//$ThisFileInfo['aac'][$framenumber]['crc']              = bindec(substr($AACheaderBitstream, $bitoffset, 16));				$bitoffset += 16;			}			if (!$ReturnExtendedInfo) {				unset($ThisFileInfo['aac'][$framenumber]);			}			$byteoffset += $FrameLength;			if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $ThisFileInfo['avdataend'])) {				// keep scanning			} else {				$ThisFileInfo['aac']['frames']    = $framenumber;				$ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] / $byteoffset) * (($framenumber * 1024) / $ThisFileInfo['aac']['header']['sample_frequency']);  // (1 / % of file scanned) * (samples / (samples/sec)) = seconds				if ($ThisFileInfo['playtime_seconds'] == 0) {					$ThisFileInfo['error'][] = 'Corrupt AAC file: playtime_seconds == zero';					return false;				}				$ThisFileInfo['audio']['bitrate']    = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];				ksort($ThisFileInfo['aac']['bitrate_distribution']);				$ThisFileInfo['audio']['encoder_options'] = $ThisFileInfo['aac']['header_type'].' '.$ThisFileInfo['aac']['header']['profile_text'];				return true;			}		}		// should never get here.	}	function AACsampleRateLookup($samplerateid) {		static $AACsampleRateLookup = array();		if (empty($AACsampleRateLookup)) {			$AACsampleRateLookup[0]  = 96000;			$AACsampleRateLookup[1]  = 88200;			$AACsampleRateLookup[2]  = 64000;			$AACsampleRateLookup[3]  = 48000;			$AACsampleRateLookup[4]  = 44100;			$AACsampleRateLookup[5]  = 32000;			$AACsampleRateLookup[6]  = 24000;			$AACsampleRateLookup[7]  = 22050;			$AACsampleRateLookup[8]  = 16000;			$AACsampleRateLookup[9]  = 12000;			$AACsampleRateLookup[10] = 11025;			$AACsampleRateLookup[11] = 8000;			$AACsampleRateLookup[12] = 0;			$AACsampleRateLookup[13] = 0;			$AACsampleRateLookup[14] = 0;			$AACsampleRateLookup[15] = 0;		}		return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid');	}	function AACprofileLookup($profileid, $mpegversion) {		static $AACprofileLookup = array();		if (empty($AACprofileLookup)) {			$AACprofileLookup[2][0]  = 'Main profile';			$AACprofileLookup[2][1]  = 'Low Complexity profile (LC)';			$AACprofileLookup[2][2]  = 'Scalable Sample Rate profile (SSR)';			$AACprofileLookup[2][3]  = '(reserved)';			$AACprofileLookup[4][0]  = 'AAC_MAIN';			$AACprofileLookup[4][1]  = 'AAC_LC';			$AACprofileLookup[4][2]  = 'AAC_SSR';			$AACprofileLookup[4][3]  = 'AAC_LTP';		}		return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid');	}	function AACchannelCountCalculate($program_configs) {		$channels = 0;		for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) {			$channels++;			if ($program_configs['front_element_is_cpe'][$i]) {				// each front element is channel pair (CPE = Channel Pair Element)				$channels++;			}		}		for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) {			$channels++;			if ($program_configs['side_element_is_cpe'][$i]) {				// each side element is channel pair (CPE = Channel Pair Element)				$channels++;			}		}		for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) {			$channels++;			if ($program_configs['back_element_is_cpe'][$i]) {				// each back element is channel pair (CPE = Channel Pair Element)				$channels++;			}		}		for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) {			$channels++;		}		return $channels;	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -