<Website>

getID3

PHK Home

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

Size:22420
Storage flags:strip

<?php















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

class 
getid3_mpeg extends getid3_handler {

const 
START_CODE_BASE "\x00\x00\x01";
const 
VIDEO_PICTURE_START "\x00\x00\x01\x00";
const 
VIDEO_USER_DATA_START "\x00\x00\x01\xB2";
const 
VIDEO_SEQUENCE_HEADER "\x00\x00\x01\xB3";
const 
VIDEO_SEQUENCE_ERROR "\x00\x00\x01\xB4";
const 
VIDEO_EXTENSION_START "\x00\x00\x01\xB5";
const 
VIDEO_SEQUENCE_END "\x00\x00\x01\xB7";
const 
VIDEO_GROUP_START "\x00\x00\x01\xB8";
const 
AUDIO_START "\x00\x00\x01\xC0";


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
 
$MPEGstreamDataOffset 0

$StartCodeValue false;
$prevStartCodeValue false;

$GOPcounter = -1;
$FramesByGOP = array();
$ParsedAVchannels = array();

do {

 if (
$MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) {


 
$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($MPEGstreamDataself::START_CODE_BASE$MPEGstreamDataOffset)) === false) {

 break;
} else {
$MPEGstreamDataOffset $StartCodeOffset;
$prevStartCodeValue $StartCodeValue;
$StartCodeValue ord(substr($MPEGstreamData$StartCodeOffset 31));

 }
$MPEGstreamDataOffset += 4;
switch (
$StartCodeValue) {

case 
0x00
 if (!empty(
$info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) {
$bitstream getid3_lib::BigEndian2Bin(substr($MPEGstreamData$StartCodeOffset 44));
$bitstreamoffset 0;

$PictureHeader = array();

$PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream$bitstreamoffset10); 
 
$PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream$bitstreamoffset3); 
 
$PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream$bitstreamoffset16); 
 

$FramesByGOP[$GOPcounter][] = $PictureHeader;
}
break;

case 
0xB3
 




$info['video']['codec'] = 'MPEG-1'

$bitstream getid3_lib::BigEndian2Bin(substr($MPEGstreamData$StartCodeOffset 48));
$bitstreamoffset 0;

$info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream$bitstreamoffset12); 
 
$info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream$bitstreamoffset12); 
 
$info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream$bitstreamoffset18); 
 
$marker_bit self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream$bitstreamoffset10); 
 
$info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 

if (
$info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) {
$bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData$StartCodeOffset 1264));
for (
$i 0$i 64$i++) {
$info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream$bitstreamoffset8);
}
}
$info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream$bitstreamoffset1);

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$bitstreamoffset8);
}
}

$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) { 
 
 
$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']['raw']['horizontal_size_value'];
$info['video']['resolution_y'] = $info['mpeg']['video']['raw']['vertical_size_value'];
$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;
break;

case 
0xB5
 
$info['video']['codec'] = 'MPEG-2';

$bitstream getid3_lib::BigEndian2Bin(substr($MPEGstreamData$StartCodeOffset 48)); 
 
$bitstreamoffset 0;

$info['mpeg']['video']['raw']['extension_start_code_identifier'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 

 switch (
$info['mpeg']['video']['raw']['extension_start_code_identifier']) {
case 
1
 
$info['mpeg']['video']['raw']['profile_and_level_indication'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 
$info['mpeg']['video']['raw']['progressive_sequence'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['chroma_format'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['horizontal_size_extension'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['vertical_size_extension'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['bit_rate_extension'] = self::readBitsFromStream($bitstream$bitstreamoffset12); 
 
$marker_bit self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['vbv_buffer_size_extension'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 
$info['mpeg']['video']['raw']['low_delay'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['frame_rate_extension_n'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['frame_rate_extension_d'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 

$info['video']['resolution_x'] = ($info['mpeg']['video']['raw']['horizontal_size_extension'] << 12) | $info['mpeg']['video']['raw']['horizontal_size_value'];
$info['video']['resolution_y'] = ($info['mpeg']['video']['raw']['vertical_size_extension'] << 12) | $info['mpeg']['video']['raw']['vertical_size_value'];
$info['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence'];
$info['mpeg']['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence'];
$info['mpeg']['video']['chroma_format'] = self::chromaFormatTextLookup($info['mpeg']['video']['raw']['chroma_format']);
break;

case 
2
 
$info['mpeg']['video']['raw']['video_format'] = self::readBitsFromStream($bitstream$bitstreamoffset3); 
 
$info['mpeg']['video']['raw']['colour_description'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 if (
$info['mpeg']['video']['raw']['colour_description']) {
$info['mpeg']['video']['raw']['colour_primaries'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 
$info['mpeg']['video']['raw']['transfer_characteristics'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 
$info['mpeg']['video']['raw']['matrix_coefficients'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 }
$info['mpeg']['video']['raw']['display_horizontal_size'] = self::readBitsFromStream($bitstream$bitstreamoffset14); 
 
$marker_bit self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['display_vertical_size'] = self::readBitsFromStream($bitstream$bitstreamoffset14); 

$info['mpeg']['video']['video_format'] = self::videoFormatTextLookup($info['mpeg']['video']['raw']['video_format']);
break;

case 
3
 break;

case 
5
 
$info['mpeg']['video']['raw']['scalable_mode'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['layer_id'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 if (
$info['mpeg']['video']['raw']['scalable_mode'] == 1) { 
 
$info['mpeg']['video']['raw']['lower_layer_prediction_horizontal_size'] = self::readBitsFromStream($bitstream$bitstreamoffset14); 
 
$marker_bit self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['lower_layer_prediction_vertical_size'] = self::readBitsFromStream($bitstream$bitstreamoffset14); 
 
$info['mpeg']['video']['raw']['horizontal_subsampling_factor_m'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 
 
$info['mpeg']['video']['raw']['horizontal_subsampling_factor_n'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 
 
$info['mpeg']['video']['raw']['vertical_subsampling_factor_m'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 
 
$info['mpeg']['video']['raw']['vertical_subsampling_factor_n'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 
 } elseif (
$info['mpeg']['video']['raw']['scalable_mode'] == 3) { 
 
$info['mpeg']['video']['raw']['picture_mux_enable'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 if (
$info['mpeg']['video']['raw']['picture_mux_enable']) {
$info['mpeg']['video']['raw']['mux_to_progressive_sequence'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 }
$info['mpeg']['video']['raw']['picture_mux_order'] = self::readBitsFromStream($bitstream$bitstreamoffset3); 
 
$info['mpeg']['video']['raw']['picture_mux_factor'] = self::readBitsFromStream($bitstream$bitstreamoffset3); 
 }

$info['mpeg']['video']['scalable_mode'] = self::scalableModeTextLookup($info['mpeg']['video']['raw']['scalable_mode']);
break;

case 
7
 break;

case 
8
 
$info['mpeg']['video']['raw']['f_code_00'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['f_code_01'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['f_code_10'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['f_code_11'] = self::readBitsFromStream($bitstream$bitstreamoffset4); 
 
$info['mpeg']['video']['raw']['intra_dc_precision'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['picture_structure'] = self::readBitsFromStream($bitstream$bitstreamoffset2); 
 
$info['mpeg']['video']['raw']['top_field_first'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['frame_pred_frame_dct'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['concealment_motion_vectors'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['q_scale_type'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['intra_vlc_format'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['alternate_scan'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['repeat_first_field'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['chroma_420_type'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['progressive_frame'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['composite_display_flag'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 if (
$info['mpeg']['video']['raw']['composite_display_flag']) {
$info['mpeg']['video']['raw']['v_axis'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['field_sequence'] = self::readBitsFromStream($bitstream$bitstreamoffset3); 
 
$info['mpeg']['video']['raw']['sub_carrier'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$info['mpeg']['video']['raw']['burst_amplitude'] = self::readBitsFromStream($bitstream$bitstreamoffset7); 
 
$info['mpeg']['video']['raw']['sub_carrier_phase'] = self::readBitsFromStream($bitstream$bitstreamoffset8); 
 }

$info['mpeg']['video']['intra_dc_precision_bits'] = $info['mpeg']['video']['raw']['intra_dc_precision'] + 8;
$info['mpeg']['video']['picture_structure'] = self::pictureStructureTextLookup($info['mpeg']['video']['raw']['picture_structure']);
break;

case 
9
 break;
case 
10
 break;

default:
$this->warning('Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.$info['mpeg']['video']['raw']['extension_start_code_identifier']);
break;
}
break;


case 
0xB8
 
$GOPcounter++;
if (
$info['mpeg']['video']['bitrate_mode'] == 'vbr') {
$bitstream getid3_lib::BigEndian2Bin(substr($MPEGstreamData$StartCodeOffset 44)); 
 
$bitstreamoffset 0;

$GOPheader = array();

$GOPheader['byte_offset'] = $MPEGstreamBaseOffset $StartCodeOffset;
$GOPheader['drop_frame_flag'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$GOPheader['time_code_hours'] = self::readBitsFromStream($bitstream$bitstreamoffset5); 
 
$GOPheader['time_code_minutes'] = self::readBitsFromStream($bitstream$bitstreamoffset6); 
 
$marker_bit self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$GOPheader['time_code_seconds'] = self::readBitsFromStream($bitstream$bitstreamoffset6); 
 
$GOPheader['time_code_pictures'] = self::readBitsFromStream($bitstream$bitstreamoffset6); 
 
$GOPheader['closed_gop'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 
 
$GOPheader['broken_link'] = self::readBitsFromStream($bitstream$bitstreamoffset1); 

$time_code_separator = ($GOPheader['drop_frame_flag'] ? ';' ':'); 
 
$GOPheader['time_code'] = sprintf('%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d'$GOPheader['time_code_hours'], $GOPheader['time_code_minutes'], $GOPheader['time_code_seconds'], $GOPheader['time_code_pictures']);

$info['mpeg']['group_of_pictures'][] = $GOPheader;
}
break;

case 
0xC0
 case 
0xC1
 case 
0xC2
 case 
0xC3
 case 
0xC4
 case 
0xC5
 case 
0xC6
 case 
0xC7
 case 
0xC8
 case 
0xC9
 case 
0xCA
 case 
0xCB
 case 
0xCC
 case 
0xCD
 case 
0xCE
 case 
0xCF
 case 
0xD0
 case 
0xD1
 case 
0xD2
 case 
0xD3
 case 
0xD4
 case 
0xD5
 case 
0xD6
 case 
0xD7
 case 
0xD8
 case 
0xD9
 case 
0xDA
 case 
0xDB
 case 
0xDC
 case 
0xDD
 case 
0xDE
 case 
0xDF
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 if (isset(
$ParsedAVchannels[$StartCodeValue])) {
break;
}
$ParsedAVchannels[$StartCodeValue] = $StartCodeValue;

 












































$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->info $info;
$getid3_mp3 = new getid3_mp3($getid3_temp);
for (
$i 0$i <= 7$i++) {

 
 
 
$getid3_temp->info $info

 if (
$getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset $StartCodeOffset $i$getid3_temp->infofalse)) {

 
$info $getid3_temp->info;
$info['audio']['bitrate_mode'] = 'cbr';
$info['audio']['lossless'] = false;
break;
}
}
unset(
$getid3_temp$getid3_mp3);
break;

case 
0xBC
 case 
0xBD
 case 
0xBE
 case 
0xBF
 case 
0xF0
 case 
0xF1
 case 
0xF2
 case 
0xF3
 case 
0xF4
 case 
0xF5
 case 
0xF6
 case 
0xF7
 case 
0xF8
 case 
0xF9
 case 
0xFA
 case 
0xFB
 case 
0xFC
 case 
0xFD
 case 
0xFE
 case 
0xFF
 
 break;

default:

 break;
}
} while (
true);



























































 if (!empty(
$info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) {
$last_GOP_id max(array_keys($FramesByGOP));
$frames_in_last_GOP count($FramesByGOP[$last_GOP_id]);
$gopdata = &$info['mpeg']['group_of_pictures'][$last_GOP_id];
$info['playtime_seconds'] = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + (($gopdata['time_code_pictures'] + $frames_in_last_GOP 1) / $info['mpeg']['video']['frame_rate']);
if (!isset(
$info['video']['bitrate'])) {
$overall_bitrate = ($info['avdataend'] - $info['avdataoffset']) * $info['playtime_seconds'];
$info['video']['bitrate'] = $overall_bitrate - (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0);
}
unset(
$info['mpeg']['group_of_pictures']);
}

return 
true;
}

private function 
readBitsFromStream(&$bitstream, &$bitstreamoffset$bits_to_read$return_singlebit_as_boolean=true) {
$return bindec(substr($bitstream$bitstreamoffset$bits_to_read));
$bitstreamoffset += $bits_to_read;
if ((
$bits_to_read == 1) && $return_singlebit_as_boolean) {
$return = (bool) $return;
}
return 
$return;
}


public static function 
systemNonOverheadPercentage($VideoBitrate$AudioBitrate) {
$OverheadPercentage 0;

$AudioBitrate max(min($AudioBitrate 1000384), 32); 
 
$VideoBitrate max(min($VideoBitrate 100010000), 10); 



 
$OverheadMultiplierByBitrate[32] = array(00.96762879443685300.98022762643603100.98449161832444600.9852821845179940);
$OverheadMultiplierByBitrate[48] = array(00.97791000892098300.97877700353593200.98467386640761300.9852683013799960);
$OverheadMultiplierByBitrate[56] = array(00.97312498553676000.97766243089380400.98326063618521300.9843922606633340);
$OverheadMultiplierByBitrate[64] = array(00.97556426832757600.97952567054933900.98365730091931700.9851122539404470);
$OverheadMultiplierByBitrate[96] = array(00.97880252474972900.97985533141487000.98229568697925600.9834815119124690);
$OverheadMultiplierByBitrate[128] = array(00.98169400509254800.98216759360721200.98297569274708700.9839763420152050);
$OverheadMultiplierByBitrate[160] = array(00.98258940945611800.98209133990739600.98239071432539700.9832821783651570);
$OverheadMultiplierByBitrate[192] = array(00.98320384743362600.98257316943179600.98210286227124000.9828262076447620);
$OverheadMultiplierByBitrate[224] = array(00.98365162985387700.98247186018238900.98183021806253800.9823735101626480);
$OverheadMultiplierByBitrate[256] = array(00.98458630220949200.98372294119675400.98245216622108300.9828645172100790);
$OverheadMultiplierByBitrate[320] = array(00.98495652802631800.98376831428051100.98228852759604000.9824424382727190);
$OverheadMultiplierByBitrate[384] = array(00.98560947743576000.98445733944327200.98259703998373300.9824673808303890);

$BitrateToUseMin 32;
$BitrateToUseMax 32;
$previousBitrate 32;
foreach (
$OverheadMultiplierByBitrate as $key => $value) {
if (
$AudioBitrate >= $previousBitrate) {
$BitrateToUseMin $previousBitrate;
}
if (
$AudioBitrate $key) {
$BitrateToUseMax $key;
break;
}
$previousBitrate $key;
}
$FactorA = ($BitrateToUseMax $AudioBitrate) / ($BitrateToUseMax $BitrateToUseMin);

$VideoBitrateLog10 log10($VideoBitrate);
$VideoFactorMin1 $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
$VideoFactorMin2 $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
$VideoFactorMax1 $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
$VideoFactorMax2 $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
$FactorV $VideoBitrateLog10 floor($VideoBitrateLog10);

$OverheadPercentage $VideoFactorMin1 $FactorA $FactorV;
$OverheadPercentage += $VideoFactorMin2 * ($FactorA) * $FactorV;
$OverheadPercentage += $VideoFactorMax1 $FactorA * ($FactorV);
$OverheadPercentage += $VideoFactorMax2 * ($FactorA) * ($FactorV);

return 
$OverheadPercentage;
}


public static function 
videoFramerateLookup($rawframerate) {
$lookup = array(023.976242529.97305059.9460);
return (isset(
$lookup[$rawframerate]) ? (float) $lookup[$rawframerate] : (float) 0);
}

public static function 
videoAspectRatioLookup($rawaspectratio) {
$lookup = array(010.67350.70310.76150.80550.84370.89350.91570.98151.02551.06951.09501.15751.20150);
return (isset(
$lookup[$rawaspectratio]) ? (float) $lookup[$rawaspectratio] : (float) 0);
}

public static function 
videoAspectRatioTextLookup($rawaspectratio) {
$lookup = array('forbidden''square pixels''0.6735''16:9, 625 line, PAL''0.7615''0.8055''16:9, 525 line, NTSC''0.8935''4:3, 625 line, PAL, CCIR601''0.9815''1.0255''1.0695''4:3, 525 line, NTSC, CCIR601''1.1575''1.2015''reserved');
return (isset(
$lookup[$rawaspectratio]) ? $lookup[$rawaspectratio] : '');
}

public static function 
videoFormatTextLookup($video_format) {

 
$lookup = array('component''PAL''NTSC''SECAM''MAC''Unspecified video format''reserved(6)''reserved(7)');
return (isset(
$lookup[$video_format]) ? $lookup[$video_format] : '');
}

public static function 
scalableModeTextLookup($scalable_mode) {

 
$lookup = array('data partitioning''spatial scalability''SNR scalability''temporal scalability');
return (isset(
$lookup[$scalable_mode]) ? $lookup[$scalable_mode] : '');
}

public static function 
pictureStructureTextLookup($picture_structure) {

 
$lookup = array('reserved''Top Field''Bottom Field''Frame picture');
return (isset(
$lookup[$picture_structure]) ? $lookup[$picture_structure] : '');
}

public static function 
chromaFormatTextLookup($chroma_format) {

 
$lookup = array('reserved''4:2:0''4:2:2''4:4:4');
return (isset(
$lookup[$chroma_format]) ? $lookup[$chroma_format] : '');
}

}

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