18 define(
'GETID3_MPEG_VIDEO_PICTURE_START',
"\x00\x00\x01\x00");
19 define(
'GETID3_MPEG_VIDEO_USER_DATA_START',
"\x00\x00\x01\xB2");
20 define(
'GETID3_MPEG_VIDEO_SEQUENCE_HEADER',
"\x00\x00\x01\xB3");
21 define(
'GETID3_MPEG_VIDEO_SEQUENCE_ERROR',
"\x00\x00\x01\xB4");
22 define(
'GETID3_MPEG_VIDEO_EXTENSION_START',
"\x00\x00\x01\xB5");
23 define(
'GETID3_MPEG_VIDEO_SEQUENCE_END',
"\x00\x00\x01\xB7");
24 define(
'GETID3_MPEG_VIDEO_GROUP_START',
"\x00\x00\x01\xB8");
25 define(
'GETID3_MPEG_AUDIO_START',
"\x00\x00\x01\xC0");
32 if ($ThisFileInfo[
'avdataend'] <= $ThisFileInfo[
'avdataoffset']) {
33 $ThisFileInfo[
'error'][] =
'"avdataend" ('.$ThisFileInfo[
'avdataend'].
') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$ThisFileInfo[
'avdataoffset'].
')';
36 $ThisFileInfo[
'fileformat'] =
'mpeg';
37 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
38 $MPEGstreamData = fread($fd, min(100000, $ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']));
39 $MPEGstreamDataLength = strlen($MPEGstreamData);
42 $VideoChunkOffset = 0;
44 if ($VideoChunkOffset >= $MPEGstreamDataLength) {
65 $ThisFileInfo[
'video'][
'dataformat'] =
'mpeg';
70 $VideoChunkOffset += 3;
73 $VideoChunkOffset += 1;
76 $VideoChunkOffset += 4;
78 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12;
79 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF);
80 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4;
81 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F);
83 $ThisFileInfo[
'mpeg'][
'video'][
'framesize_horizontal'] = $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'framesize_horizontal'];
84 $ThisFileInfo[
'mpeg'][
'video'][
'framesize_vertical'] = $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'framesize_vertical'];
86 $ThisFileInfo[
'mpeg'][
'video'][
'pixel_aspect_ratio'] = $this->
MPEGvideoAspectRatioLookup($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'pixel_aspect_ratio']);
87 $ThisFileInfo[
'mpeg'][
'video'][
'pixel_aspect_ratio_text'] = $this->
MPEGvideoAspectRatioTextLookup($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'pixel_aspect_ratio']);
88 $ThisFileInfo[
'mpeg'][
'video'][
'frame_rate'] = $this->
MPEGvideoFramerateLookup($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'frame_rate']);
90 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'bitrate'] =
getid3_lib::Bin2Dec(substr($assortedinformation, 0, 18));
91 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'marker_bit'] = (bool)
getid3_lib::Bin2Dec(substr($assortedinformation, 18, 1));
92 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'vbv_buffer_size'] =
getid3_lib::Bin2Dec(substr($assortedinformation, 19, 10));
93 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'constrained_param_flag'] = (bool)
getid3_lib::Bin2Dec(substr($assortedinformation, 29, 1));
94 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'intra_quant_flag'] = (bool)
getid3_lib::Bin2Dec(substr($assortedinformation, 30, 1));
95 if ($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'intra_quant_flag']) {
98 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'intra_quant'] =
getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64));
99 $VideoChunkOffset += 64;
101 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag'] = (bool)
getid3_lib::Bin2Dec(substr($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'intra_quant'], 511, 1));
104 if ($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag']) {
105 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
106 $VideoChunkOffset += 64;
111 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag'] = (bool)
getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1));
112 if ($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant_flag']) {
113 $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
114 $VideoChunkOffset += 64;
119 if ($ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'bitrate'] == 0x3FFFF) {
121 $ThisFileInfo[
'warning'][] =
'This version of getID3() ['.GETID3_VERSION.
'] cannot determine average bitrate of VBR MPEG video files';
122 $ThisFileInfo[
'mpeg'][
'video'][
'bitrate_mode'] =
'vbr';
126 $ThisFileInfo[
'mpeg'][
'video'][
'bitrate'] = $ThisFileInfo[
'mpeg'][
'video'][
'raw'][
'bitrate'] * 400;
127 $ThisFileInfo[
'mpeg'][
'video'][
'bitrate_mode'] =
'cbr';
128 $ThisFileInfo[
'video'][
'bitrate'] = $ThisFileInfo[
'mpeg'][
'video'][
'bitrate'];
132 $ThisFileInfo[
'video'][
'resolution_x'] = $ThisFileInfo[
'mpeg'][
'video'][
'framesize_horizontal'];
133 $ThisFileInfo[
'video'][
'resolution_y'] = $ThisFileInfo[
'mpeg'][
'video'][
'framesize_vertical'];
134 $ThisFileInfo[
'video'][
'frame_rate'] = $ThisFileInfo[
'mpeg'][
'video'][
'frame_rate'];
135 $ThisFileInfo[
'video'][
'bitrate_mode'] = $ThisFileInfo[
'mpeg'][
'video'][
'bitrate_mode'];
136 $ThisFileInfo[
'video'][
'pixel_aspect_ratio'] = $ThisFileInfo[
'mpeg'][
'video'][
'pixel_aspect_ratio'];
137 $ThisFileInfo[
'video'][
'lossless'] =
false;
138 $ThisFileInfo[
'video'][
'bits_per_sample'] = 24;
142 $ThisFileInfo[
'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?';
154 $ThisFileInfo[
'video'][
'codec'] =
'MPEG-2';
156 $ThisFileInfo[
'video'][
'codec'] =
'MPEG-1';
160 $AudioChunkOffset = 0;
163 if ($AudioChunkOffset >= $MPEGstreamDataLength) {
168 for ($i = 0; $i <= 7; $i++) {
173 $dummy = $ThisFileInfo;
175 $ThisFileInfo = $dummy;
176 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'cbr';
177 $ThisFileInfo[
'audio'][
'lossless'] =
false;
185 if (!empty($ThisFileInfo[
'video'][
'bitrate']) && !empty($ThisFileInfo[
'audio'][
'bitrate'])) {
186 $ThisFileInfo[
'playtime_seconds'] = (($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) * 8) / ($ThisFileInfo[
'video'][
'bitrate'] + $ThisFileInfo[
'audio'][
'bitrate']);
213 if ($ThisFileInfo[
'video'][
'bitrate'] < 50000) {
214 $ThisFileInfo[
'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.';
223 $OverheadPercentage = 0;
225 $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32);
226 $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10);
230 $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940);
231 $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960);
232 $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340);
233 $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470);
234 $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690);
235 $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050);
236 $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570);
237 $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620);
238 $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480);
239 $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790);
240 $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190);
241 $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890);
243 $BitrateToUseMin = 32;
244 $BitrateToUseMax = 32;
245 $previousBitrate = 32;
246 foreach ($OverheadMultiplierByBitrate as $key => $value) {
247 if ($AudioBitrate >= $previousBitrate) {
248 $BitrateToUseMin = $previousBitrate;
250 if ($AudioBitrate < $key) {
251 $BitrateToUseMax = $key;
254 $previousBitrate = $key;
256 $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin);
258 $VideoBitrateLog10 = log10($VideoBitrate);
259 $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)];
260 $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)];
261 $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)];
262 $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)];
263 $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10);
265 $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV;
266 $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV;
267 $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV);
268 $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV);
270 return $OverheadPercentage;
275 $MPEGvideoFramerateLookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
276 return (isset($MPEGvideoFramerateLookup[$rawframerate]) ? (
float) $MPEGvideoFramerateLookup[$rawframerate] : (
float) 0);
280 $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);
281 return (isset($MPEGvideoAspectRatioLookup[$rawaspectratio]) ? (
float) $MPEGvideoAspectRatioLookup[$rawaspectratio] : (
float) 0);
285 $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');
286 return (isset($MPEGvideoAspectRatioTextLookup[$rawaspectratio]) ? $MPEGvideoAspectRatioTextLookup[$rawaspectratio] :
'');