33                $info = &$this->getid3->info;
 
   35                $info[
'fileformat'] = 
'mpeg';
 
   38                $MPEGstreamData = $this->
fread($this->getid3->option_fread_buffer_size);
 
   39                $MPEGstreamBaseOffset = 0; 
 
   40                $MPEGstreamDataOffset = 0; 
 
   42                $StartCodeValue     = 
false;
 
   43                $prevStartCodeValue = 
false;
 
   46                $FramesByGOP = array();
 
   47                $ParsedAVchannels = array();
 
   51                        if ($MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) {
 
   54                                $MPEGstreamData .= $this->
fread($this->getid3->option_fread_buffer_size);
 
   55                                if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) {
 
   56                                        $MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset);
 
   57                                        $MPEGstreamBaseOffset += $MPEGstreamDataOffset;
 
   58                                        $MPEGstreamDataOffset  = 0;
 
   61                        if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === 
false) {
 
   65                                $MPEGstreamDataOffset = $StartCodeOffset;
 
   66                                $prevStartCodeValue = $StartCodeValue;
 
   67                                $StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1));
 
   70                        $MPEGstreamDataOffset += 4;
 
   71                        switch ($StartCodeValue) {
 
   74                                        if (!empty(
$info[
'mpeg'][
'video'][
'bitrate_mode']) && (
$info[
'mpeg'][
'video'][
'bitrate_mode'] == 
'vbr')) {
 
   78                                                $PictureHeader = array();
 
   85                                                $FramesByGOP[$GOPcounter][] = $PictureHeader;
 
   95                                        $info[
'video'][
'codec'] = 
'MPEG-1'; 
 
  110                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'load_intra_quantiser_matrix']) {
 
  112                                                for (
$i = 0; 
$i < 64; 
$i++) {
 
  118                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'load_non_intra_quantiser_matrix']) {
 
  119                                                $bitstream .= 
getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + (
$info[
'mpeg'][
'video'][
'raw'][
'load_intra_quantiser_matrix'] ? 64 : 0), 64));
 
  120                                                for (
$i = 0; 
$i < 64; 
$i++) {
 
  128                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'bitrate'] == 0x3FFFF) { 
 
  130                                                $info[
'mpeg'][
'video'][
'bitrate_mode'] = 
'vbr';
 
  132                                                $info[
'mpeg'][
'video'][
'bitrate']      = 
$info[
'mpeg'][
'video'][
'raw'][
'bitrate'] * 400;
 
  133                                                $info[
'mpeg'][
'video'][
'bitrate_mode'] = 
'cbr';
 
  134                                                $info[
'video'][
'bitrate']              = 
$info[
'mpeg'][
'video'][
'bitrate'];
 
  136                                        $info[
'video'][
'resolution_x']       = 
$info[
'mpeg'][
'video'][
'raw'][
'horizontal_size_value'];
 
  137                                        $info[
'video'][
'resolution_y']       = 
$info[
'mpeg'][
'video'][
'raw'][
'vertical_size_value'];
 
  138                                        $info[
'video'][
'frame_rate']         = 
$info[
'mpeg'][
'video'][
'frame_rate'];
 
  139                                        $info[
'video'][
'bitrate_mode']       = 
$info[
'mpeg'][
'video'][
'bitrate_mode'];
 
  140                                        $info[
'video'][
'pixel_aspect_ratio'] = 
$info[
'mpeg'][
'video'][
'pixel_aspect_ratio'];
 
  141                                        $info[
'video'][
'lossless']           = 
false;
 
  142                                        $info[
'video'][
'bits_per_sample']    = 24;
 
  146                                        $info[
'video'][
'codec'] = 
'MPEG-2';
 
  149                                        $bitstreamoffset = 0;
 
  153                                        switch (
$info[
'mpeg'][
'video'][
'raw'][
'extension_start_code_identifier']) {
 
  167                                                        $info[
'video'][
'resolution_x']          = (
$info[
'mpeg'][
'video'][
'raw'][
'horizontal_size_extension'] << 12) | 
$info[
'mpeg'][
'video'][
'raw'][
'horizontal_size_value'];
 
  168                                                        $info[
'video'][
'resolution_y']          = (
$info[
'mpeg'][
'video'][
'raw'][
'vertical_size_extension']   << 12) | 
$info[
'mpeg'][
'video'][
'raw'][
'vertical_size_value'];
 
  169                                                        $info[
'video'][
'interlaced']            = !
$info[
'mpeg'][
'video'][
'raw'][
'progressive_sequence'];
 
  170                                                        $info[
'mpeg'][
'video'][
'interlaced']    = !
$info[
'mpeg'][
'video'][
'raw'][
'progressive_sequence'];
 
  177                                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'colour_description']) {
 
  195                                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'scalable_mode'] == 1) { 
 
  203                                                        } elseif (
$info[
'mpeg'][
'video'][
'raw'][
'scalable_mode'] == 3) { 
 
  205                                                                if (
$info[
'mpeg'][
'video'][
'raw'][
'picture_mux_enable']) {
 
  235                                                        if (
$info[
'mpeg'][
'video'][
'raw'][
'composite_display_flag']) {
 
  243                                                        $info[
'mpeg'][
'video'][
'intra_dc_precision_bits'] = 
$info[
'mpeg'][
'video'][
'raw'][
'intra_dc_precision'] + 8;
 
  253                                                        $this->
warning(
'Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.
$info[
'mpeg'][
'video'][
'raw'][
'extension_start_code_identifier']);
 
  261                                        if (
$info[
'mpeg'][
'video'][
'bitrate_mode'] == 
'vbr') {
 
  263                                                $bitstreamoffset = 0;
 
  265                                                $GOPheader = array();
 
  267                                                $GOPheader[
'byte_offset'] = $MPEGstreamBaseOffset + $StartCodeOffset;
 
  277                                                $time_code_separator = ($GOPheader[
'drop_frame_flag'] ? 
';' : 
':'); 
 
  278                                                $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']);
 
  280                                                $info[
'mpeg'][
'group_of_pictures'][] = $GOPheader;
 
  332                                        if (isset($ParsedAVchannels[$StartCodeValue])) {
 
  335                                        $ParsedAVchannels[$StartCodeValue] = $StartCodeValue;
 
  382                                        $getid3_temp = 
new getID3();
 
  383                                        $getid3_temp->openfile($this->getid3->filename);
 
  384                                        $getid3_temp->info = 
$info;
 
  386                                        for (
$i = 0; 
$i <= 7; 
$i++) {
 
  390                                                $getid3_temp->info = 
$info; 
 
  392                                                if ($getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + 
$i, $getid3_temp->info, 
false)) {
 
  394                                                        $info = $getid3_temp->info;
 
  395                                                        $info[
'audio'][
'bitrate_mode'] = 
'cbr';
 
  396                                                        $info[
'audio'][
'lossless']     = 
false;
 
  400                                        unset($getid3_temp, $getid3_mp3);
 
  490                if (!empty(
$info[
'mpeg'][
'video'][
'bitrate_mode']) && (
$info[
'mpeg'][
'video'][
'bitrate_mode'] == 
'vbr')) {
 
  491                        $last_GOP_id = max(array_keys($FramesByGOP));
 
  492                        $frames_in_last_GOP = count($FramesByGOP[$last_GOP_id]);
 
  493                        $gopdata = &
$info[
'mpeg'][
'group_of_pictures'][$last_GOP_id];
 
  494                        $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']);
 
  495                        if (!isset(
$info[
'video'][
'bitrate'])) {
 
  496                                $overall_bitrate = (
$info[
'avdataend'] - 
$info[
'avdataoffset']) * 8 / 
$info[
'playtime_seconds'];
 
  497                                $info[
'video'][
'bitrate'] = $overall_bitrate - (isset(
$info[
'audio'][
'bitrate']) ? 
$info[
'audio'][
'bitrate'] : 0);
 
  499                        unset(
$info[
'mpeg'][
'group_of_pictures']);
 
  505        private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=
true) {
 
  506                $return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read));
 
  507                $bitstreamoffset += $bits_to_read;
 
  508                if (($bits_to_read == 1) && $return_singlebit_as_boolean) {
 
  509                        $return = (bool) $return;
 
  516                $OverheadPercentage = 0;
 
  518                $AudioBitrate = max(min($AudioBitrate / 1000,   384), 32); 
 
  519                $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); 
 
  523                $OverheadMultiplierByBitrate[32]  = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940);
 
  524                $OverheadMultiplierByBitrate[48]  = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960);
 
  525                $OverheadMultiplierByBitrate[56]  = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340);
 
  526                $OverheadMultiplierByBitrate[64]  = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470);
 
  527                $OverheadMultiplierByBitrate[96]  = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690);
 
  528                $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050);
 
  529                $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570);
 
  530                $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620);
 
  531                $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480);
 
  532                $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790);
 
  533                $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190);
 
  534                $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890);
 
  536                $BitrateToUseMin = 32;
 
  537                $BitrateToUseMax = 32;
 
  538                $previousBitrate = 32;
 
  539                foreach ($OverheadMultiplierByBitrate as 
$key => $value) {
 
  540                        if ($AudioBitrate >= $previousBitrate) {
 
  541                                $BitrateToUseMin = $previousBitrate;
 
  543                        if ($AudioBitrate < 
$key) {
 
  544                                $BitrateToUseMax = 
$key;
 
  547                        $previousBitrate = 
$key;
 
  549                $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin);
 
  551                $VideoBitrateLog10 = log10($VideoBitrate);
 
  552                $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
 
  553                $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
 
  554                $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
 
  555                $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
 
  556                $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10);
 
  558                $OverheadPercentage  = $VideoFactorMin1 *      $FactorA  *      $FactorV;
 
  559                $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) *      $FactorV;
 
  560                $OverheadPercentage += $VideoFactorMax1 *      $FactorA  * (1 - $FactorV);
 
  561                $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV);
 
  563                return $OverheadPercentage;
 
  568                $lookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
 
  569                return (isset($lookup[$rawframerate]) ? (
float) $lookup[$rawframerate] : (
float) 0);
 
  573                $lookup = array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0);
 
  574                return (isset($lookup[$rawaspectratio]) ? (
float) $lookup[$rawaspectratio] : (
float) 0);
 
  578                $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');
 
  579                return (isset($lookup[$rawaspectratio]) ? $lookup[$rawaspectratio] : 
'');
 
  584                $lookup = array(
'component', 
'PAL', 
'NTSC', 
'SECAM', 
'MAC', 
'Unspecified video format', 
'reserved(6)', 
'reserved(7)');
 
  585                return (isset($lookup[$video_format]) ? $lookup[$video_format] : 
'');
 
  590                $lookup = array(
'data partitioning', 
'spatial scalability', 
'SNR scalability', 
'temporal scalability');
 
  591                return (isset($lookup[$scalable_mode]) ? $lookup[$scalable_mode] : 
'');
 
  596                $lookup = array(
'reserved', 
'Top Field', 
'Bottom Field', 
'Frame picture');
 
  597                return (isset($lookup[$picture_structure]) ? $lookup[$picture_structure] : 
'');
 
  602                $lookup = array(
'reserved', 
'4:2:0', 
'4:2:2', 
'4:4:4');
 
  603                return (isset($lookup[$chroma_format]) ? $lookup[$chroma_format] : 
'');
 
An exception for terminatinating execution or to throw for unit testing.
fseek($bytes, $whence=SEEK_SET)
static BigEndian2Bin($byteword)
static IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
static pictureStructureTextLookup($picture_structure)
static videoFormatTextLookup($video_format)
static chromaFormatTextLookup($chroma_format)
const VIDEO_EXTENSION_START
readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=true)
const VIDEO_PICTURE_START
const VIDEO_SEQUENCE_ERROR
static videoAspectRatioTextLookup($rawaspectratio)
static videoFramerateLookup($rawframerate)
const VIDEO_USER_DATA_START
static videoAspectRatioLookup($rawaspectratio)
const VIDEO_SEQUENCE_HEADER
static scalableModeTextLookup($scalable_mode)
static systemNonOverheadPercentage($VideoBitrate, $AudioBitrate)