48 $info = &$this->getid3->info;
50 if (
$info[
'avdataend'] <=
$info[
'avdataoffset']) {
51 $info[
'error'][] =
'"avdataend" (' .
$info[
'avdataend'] .
') is unexpectedly less-than-or-equal-to "avdataoffset" (' .
$info[
'avdataoffset'] .
')';
55 $info[
'fileformat'] =
'mpeg';
56 fseek($this->getid3->fp,
$info[
'avdataoffset'], SEEK_SET);
57 $MPEGstreamData =
fread($this->getid3->fp,
60 $MPEGstreamDataLength = strlen($MPEGstreamData);
63 $VideoChunkOffset = 0;
64 while (substr($MPEGstreamData, $VideoChunkOffset++, 4) !== self::GETID3_MPEG_VIDEO_SEQUENCE_HEADER) {
65 if ($VideoChunkOffset >= $MPEGstreamDataLength) {
86 $info[
'video'][
'dataformat'] =
'mpeg';
88 $VideoChunkOffset += (strlen(self::GETID3_MPEG_VIDEO_SEQUENCE_HEADER) - 1);
93 $VideoChunkOffset += 3;
98 $VideoChunkOffset += 1;
103 $VideoChunkOffset += 4;
105 $info[
'mpeg'][
'video'][
'raw'][
'framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12;
106 $info[
'mpeg'][
'video'][
'raw'][
'framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF);
107 $info[
'mpeg'][
'video'][
'raw'][
'pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4;
108 $info[
'mpeg'][
'video'][
'raw'][
'frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F);
110 $info[
'mpeg'][
'video'][
'framesize_horizontal'] =
$info[
'mpeg'][
'video'][
'raw'][
'framesize_horizontal'];
111 $info[
'mpeg'][
'video'][
'framesize_vertical'] =
$info[
'mpeg'][
'video'][
'raw'][
'framesize_vertical'];
120 $info[
'mpeg'][
'video'][
'raw'][
'marker_bit'] = (bool)
Helper::Bin2Dec(substr($assortedinformation,
126 $info[
'mpeg'][
'video'][
'raw'][
'constrained_param_flag'] = (bool)
Helper::Bin2Dec(substr($assortedinformation,
129 $info[
'mpeg'][
'video'][
'raw'][
'intra_quant_flag'] = (bool)
Helper::Bin2Dec(substr($assortedinformation,
132 if (
$info[
'mpeg'][
'video'][
'raw'][
'intra_quant_flag']) {
138 $VideoChunkOffset += 64;
140 $info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag'] = (bool)
Helper::Bin2Dec(substr(
$info[
'mpeg'][
'video'][
'raw'][
'intra_quant'],
151 if (
$info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag']) {
152 $info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant'] = substr($MPEGstreamData,
155 $VideoChunkOffset += 64;
159 $info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag'] = (bool)
Helper::Bin2Dec(substr($assortedinformation,
162 if (
$info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag']) {
163 $info[
'mpeg'][
'video'][
'raw'][
'non_intra_quant'] = substr($MPEGstreamData,
166 $VideoChunkOffset += 64;
170 if (
$info[
'mpeg'][
'video'][
'raw'][
'bitrate'] == 0x3FFFF) {
171 $info[
'warning'][] =
'This version of GetId3Core() [' . $this->getid3->version() .
'] cannot determine average bitrate of VBR MPEG video files';
172 $info[
'mpeg'][
'video'][
'bitrate_mode'] =
'vbr';
175 $info[
'mpeg'][
'video'][
'bitrate'] =
$info[
'mpeg'][
'video'][
'raw'][
'bitrate'] * 400;
176 $info[
'mpeg'][
'video'][
'bitrate_mode'] =
'cbr';
177 $info[
'video'][
'bitrate'] =
$info[
'mpeg'][
'video'][
'bitrate'];
180 $info[
'video'][
'resolution_x'] =
$info[
'mpeg'][
'video'][
'framesize_horizontal'];
181 $info[
'video'][
'resolution_y'] =
$info[
'mpeg'][
'video'][
'framesize_vertical'];
182 $info[
'video'][
'frame_rate'] =
$info[
'mpeg'][
'video'][
'frame_rate'];
183 $info[
'video'][
'bitrate_mode'] =
$info[
'mpeg'][
'video'][
'bitrate_mode'];
184 $info[
'video'][
'pixel_aspect_ratio'] =
$info[
'mpeg'][
'video'][
'pixel_aspect_ratio'];
185 $info[
'video'][
'lossless'] =
false;
186 $info[
'video'][
'bits_per_sample'] = 24;
189 $info[
'error'][] =
'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?';
199 if (substr($MPEGstreamData, $VideoChunkOffset, 4) == self::GETID3_MPEG_VIDEO_EXTENSION_START) {
200 $info[
'video'][
'codec'] =
'MPEG-2';
202 $info[
'video'][
'codec'] =
'MPEG-1';
205 $AudioChunkOffset = 0;
207 while (substr($MPEGstreamData, $AudioChunkOffset++, 4) !== self::GETID3_MPEG_AUDIO_START) {
208 if ($AudioChunkOffset >= $MPEGstreamDataLength) {
214 $getid3_temp->openfile($this->getid3->filename);
215 $getid3_temp->info =
$info;
216 $getid3_mp3 =
new Mp3($getid3_temp);
217 for ($i = 0; $i <= 7; $i++) {
221 fseek($getid3_temp->fp,
ftell($this->getid3->fp), SEEK_SET);
222 $getid3_temp->info =
$info;
223 if ($getid3_mp3->decodeMPEGaudioHeader(($AudioChunkOffset + 3) + 8 + $i,
224 $getid3_temp->info,
false)) {
225 $info = $getid3_temp->info;
226 $info[
'audio'][
'bitrate_mode'] =
'cbr';
227 $info[
'audio'][
'lossless'] =
false;
228 unset($getid3_temp, $getid3_mp3);
232 unset($getid3_temp, $getid3_mp3);
236 if (!empty(
$info[
'video'][
'bitrate']) && !empty(
$info[
'audio'][
'bitrate'])) {
237 $info[
'playtime_seconds'] = ((
$info[
'avdataend'] -
$info[
'avdataoffset']) * 8) / (
$info[
'video'][
'bitrate'] +
$info[
'audio'][
'bitrate']);
244 $info[
'audio'][
'bitrate']);
265 if (
$info[
'video'][
'bitrate'] < 50000) {
266 $info[
'warning'][] =
'Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.';
281 $OverheadPercentage = 0;
283 $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32);
284 $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10);
286 $OverheadMultiplierByBitrate[32] =
array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940);
287 $OverheadMultiplierByBitrate[48] =
array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960);
288 $OverheadMultiplierByBitrate[56] =
array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340);
289 $OverheadMultiplierByBitrate[64] =
array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470);
290 $OverheadMultiplierByBitrate[96] =
array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690);
291 $OverheadMultiplierByBitrate[128] =
array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050);
292 $OverheadMultiplierByBitrate[160] =
array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570);
293 $OverheadMultiplierByBitrate[192] =
array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620);
294 $OverheadMultiplierByBitrate[224] =
array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480);
295 $OverheadMultiplierByBitrate[256] =
array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790);
296 $OverheadMultiplierByBitrate[320] =
array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190);
297 $OverheadMultiplierByBitrate[384] =
array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890);
299 $BitrateToUseMin = 32;
300 $BitrateToUseMax = 32;
301 $previousBitrate = 32;
302 foreach ($OverheadMultiplierByBitrate as $key => $value) {
303 if ($AudioBitrate >= $previousBitrate) {
304 $BitrateToUseMin = $previousBitrate;
306 if ($AudioBitrate < $key) {
307 $BitrateToUseMax = $key;
310 $previousBitrate = $key;
312 $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin);
314 $VideoBitrateLog10 = log10($VideoBitrate);
315 $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
316 $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
317 $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
318 $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
319 $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10);
321 $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV;
322 $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV;
323 $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV);
324 $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV);
326 return $OverheadPercentage;
336 $MPEGvideoFramerateLookup =
array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
338 return (isset($MPEGvideoFramerateLookup[$rawframerate]) ? (
float) $MPEGvideoFramerateLookup[$rawframerate] : (
float) 0);
348 $MPEGvideoAspectRatioLookup =
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);
350 return (isset($MPEGvideoAspectRatioLookup[$rawaspectratio]) ? (
float) $MPEGvideoAspectRatioLookup[$rawaspectratio] : (
float) 0);
360 $MPEGvideoAspectRatioTextLookup =
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');
362 return (isset($MPEGvideoAspectRatioTextLookup[$rawaspectratio]) ? $MPEGvideoAspectRatioTextLookup[$rawaspectratio] :
'');
static BigEndian2Bin($byteword)
const GETID3_MPEG_VIDEO_PICTURE_START
GetId3() by James Heinrich info@getid3.org //.
MPEGvideoAspectRatioTextLookup($rawaspectratio)
const GETID3_MPEG_AUDIO_START
fseek($bytes, $whence=SEEK_SET)
const GETID3_MPEG_VIDEO_USER_DATA_START
const GETID3_MPEG_VIDEO_GROUP_START
const GETID3_MPEG_VIDEO_SEQUENCE_END
GetId3() by James Heinrich info@getid3.org //.
GetId3() by James Heinrich info@getid3.org //.
GetId3() by James Heinrich info@getid3.org //.
MPEGvideoFramerateLookup($rawframerate)
Create styles array
The data for the language used.
const GETID3_MPEG_VIDEO_SEQUENCE_ERROR
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
const GETID3_MPEG_VIDEO_SEQUENCE_HEADER
static Bin2Dec($binstring, $signed=false)
MPEGsystemNonOverheadPercentage($VideoBitrate, $AudioBitrate)
MPEGvideoAspectRatioLookup($rawaspectratio)
const GETID3_MPEG_VIDEO_EXTENSION_START