1<?php 2 3///////////////////////////////////////////////////////////////// 4/// getID3() by James Heinrich <info@getid3.org> // 5// available at https://github.com/JamesHeinrich/getID3 // 6// or https://www.getid3.org // 7// or http://getid3.sourceforge.net // 8// see readme.txt for more details // 9///////////////////////////////////////////////////////////////// 10// // 11// module.audio-video.mpeg.php // 12// module for analyzing MPEG files // 13// dependencies: module.audio.mp3.php // 14// /// 15///////////////////////////////////////////////////////////////// 16 17if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers 18 exit; 19} 20getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); 21 22class getid3_mpeg extends getid3_handler 23{ 24 25 const START_CODE_BASE = "\x00\x00\x01"; 26 const VIDEO_PICTURE_START = "\x00\x00\x01\x00"; 27 const VIDEO_USER_DATA_START = "\x00\x00\x01\xB2"; 28 const VIDEO_SEQUENCE_HEADER = "\x00\x00\x01\xB3"; 29 const VIDEO_SEQUENCE_ERROR = "\x00\x00\x01\xB4"; 30 const VIDEO_EXTENSION_START = "\x00\x00\x01\xB5"; 31 const VIDEO_SEQUENCE_END = "\x00\x00\x01\xB7"; 32 const VIDEO_GROUP_START = "\x00\x00\x01\xB8"; 33 const AUDIO_START = "\x00\x00\x01\xC0"; 34 35 /** 36 * @return bool 37 */ 38 public function Analyze() { 39 $info = &$this->getid3->info; 40 41 $info['fileformat'] = 'mpeg'; 42 $this->fseek($info['avdataoffset']); 43 44 $MPEGstreamData = $this->fread($this->getid3->option_fread_buffer_size); 45 $MPEGstreamBaseOffset = 0; // how far are we from the beginning of the file data ($info['avdataoffset']) 46 $MPEGstreamDataOffset = 0; // how far are we from the beginning of the buffer data (~32kB) 47 48 $StartCodeValue = false; 49 $prevStartCodeValue = false; 50 51 $GOPcounter = -1; 52 $FramesByGOP = array(); 53 $ParsedAVchannels = array(); 54 55 do { 56//echo $MPEGstreamDataOffset.' vs '.(strlen($MPEGstreamData) - 1024).'<Br>'; 57 if ($MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) { 58 // buffer running low, get more data 59//echo 'reading more data<br>'; 60 $MPEGstreamData .= $this->fread($this->getid3->option_fread_buffer_size); 61 if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) { 62 $MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset); 63 $MPEGstreamBaseOffset += $MPEGstreamDataOffset; 64 $MPEGstreamDataOffset = 0; 65 } 66 } 67 if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === false) { 68//echo 'no more start codes found.<br>'; 69 break; 70 } else { 71 $MPEGstreamDataOffset = $StartCodeOffset; 72 $prevStartCodeValue = $StartCodeValue; 73 $StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1)); 74//echo 'Found "'.strtoupper(dechex($StartCodeValue)).'" at offset '.($MPEGstreamBaseOffset + $StartCodeOffset).' ($MPEGstreamDataOffset = '.$MPEGstreamDataOffset.')<br>'; 75 } 76 $MPEGstreamDataOffset += 4; 77 switch ($StartCodeValue) { 78 79 case 0x00: // picture_start_code 80 if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { 81 $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); 82 $bitstreamoffset = 0; 83 84 $PictureHeader = array(); 85 86 $PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10-bit unsigned integer associated with each input picture. It is incremented by one, modulo 1024, for each input frame. When a frame is coded as two fields the temporal reference in the picture header of both fields is the same. Following a group start header the temporal reference of the earliest picture (in display order) shall be reset to zero. 87 $PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_coding_type 88 $PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 16); // 16 bits for vbv_delay 89 //... etc 90 91 $FramesByGOP[$GOPcounter][] = $PictureHeader; 92 } 93 break; 94 95 case 0xB3: // sequence_header_code 96 // Note: purposely doing the less-pretty (and probably a bit slower) method of using string of bits rather than bitwise operations. 97 // Mostly because PHP 32-bit doesn't handle unsigned integers well for bitwise operation. 98 // Also the MPEG stream is designed as a bitstream and often doesn't align nicely with byte boundaries. 99 $info['video']['codec'] = 'MPEG-1'; // will be updated if extension_start_code found 100 101 $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); 102 $bitstreamoffset = 0; 103 104 $info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for horizontal frame size. Note: horizontal_size_extension, if present, will add 2 most-significant bits to this value 105 $info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for vertical frame size. Note: vertical_size_extension, if present, will add 2 most-significant bits to this value 106 $info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for aspect_ratio_information 107 $info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for Frame Rate id code 108 $info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 18); // 18 bits for bit_rate_value (18 set bits = VBR, otherwise bitrate = this value * 400) 109 $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. 110 $info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10 bits vbv_buffer_size_value 111 $info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: constrained_param_flag 112 $info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: load_intra_quantiser_matrix 113 114 if ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) { 115 $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12, 64)); 116 for ($i = 0; $i < 64; $i++) { 117 $info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); 118 } 119 } 120 $info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); 121 122 if ($info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix']) { 123 $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] ? 64 : 0), 64)); 124 for ($i = 0; $i < 64; $i++) { 125 $info['mpeg']['video']['raw']['non_intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); 126 } 127 } 128 129 $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); // may be overridden later if file turns out to be MPEG-2 130 $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); // may be overridden later if file turns out to be MPEG-2 131 $info['mpeg']['video']['frame_rate'] = self::videoFramerateLookup($info['mpeg']['video']['raw']['frame_rate_code']); 132 if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits = VBR 133 //$this->warning('This version of getID3() ['.$this->getid3->version().'] cannot determine average bitrate of VBR MPEG video files'); 134 $info['mpeg']['video']['bitrate_mode'] = 'vbr'; 135 } else { 136 $info['mpeg']['video']['bitrate'] = $info['mpeg']['video']['raw']['bitrate'] * 400; 137 $info['mpeg']['video']['bitrate_mode'] = 'cbr'; 138 $info['video']['bitrate'] = $info['mpeg']['video']['bitrate']; 139 } 140 $info['video']['resolution_x'] = $info['mpeg']['video']['raw']['horizontal_size_value']; 141 $info['video']['resolution_y'] = $info['mpeg']['video']['raw']['vertical_size_value']; 142 $info['video']['frame_rate'] = $info['mpeg']['video']['frame_rate']; 143 $info['video']['bitrate_mode'] = $info['mpeg']['video']['bitrate_mode']; 144 $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; 145 $info['video']['lossless'] = false; 146 $info['video']['bits_per_sample'] = 24; 147 break; 148 149 case 0xB5: // extension_start_code 150 $info['video']['codec'] = 'MPEG-2'; 151 152 $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); // 48 bits for Sequence Extension ID; 61 bits for Sequence Display Extension ID; 59 bits for Sequence Scalable Extension ID 153 $bitstreamoffset = 0; 154 155 $info['mpeg']['video']['raw']['extension_start_code_identifier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for extension_start_code_identifier 156//echo $info['mpeg']['video']['raw']['extension_start_code_identifier'].'<br>'; 157 switch ($info['mpeg']['video']['raw']['extension_start_code_identifier']) { 158 case 1: // 0001 Sequence Extension ID 159 $info['mpeg']['video']['raw']['profile_and_level_indication'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for profile_and_level_indication 160 $info['mpeg']['video']['raw']['progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_sequence 161 $info['mpeg']['video']['raw']['chroma_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for chroma_format 162 $info['mpeg']['video']['raw']['horizontal_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for horizontal_size_extension 163 $info['mpeg']['video']['raw']['vertical_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for vertical_size_extension 164 $info['mpeg']['video']['raw']['bit_rate_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for bit_rate_extension 165 $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. 166 $info['mpeg']['video']['raw']['vbv_buffer_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for vbv_buffer_size_extension 167 $info['mpeg']['video']['raw']['low_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: low_delay 168 $info['mpeg']['video']['raw']['frame_rate_extension_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for frame_rate_extension_n 169 $info['mpeg']['video']['raw']['frame_rate_extension_d'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for frame_rate_extension_d 170 171 $info['video']['resolution_x'] = ($info['mpeg']['video']['raw']['horizontal_size_extension'] << 12) | $info['mpeg']['video']['raw']['horizontal_size_value']; 172 $info['video']['resolution_y'] = ($info['mpeg']['video']['raw']['vertical_size_extension'] << 12) | $info['mpeg']['video']['raw']['vertical_size_value']; 173 $info['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; 174 $info['mpeg']['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; 175 $info['mpeg']['video']['chroma_format'] = self::chromaFormatTextLookup($info['mpeg']['video']['raw']['chroma_format']); 176 177 if (isset($info['mpeg']['video']['raw']['aspect_ratio_information'])) { 178 // MPEG-2 defines the aspect ratio flag differently from MPEG-1, but the MPEG-2 extension start code may occur after we've already looked up the aspect ratio assuming it was MPEG-1, so re-lookup assuming MPEG-2 179 // This must be done after the extended size is known, so the display aspect ratios can be converted to pixel aspect ratios. 180 $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information'], 2, $info['video']['resolution_x'], $info['video']['resolution_y']); 181 $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information'], 2); 182 $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; 183 $info['video']['pixel_aspect_ratio_text'] = $info['mpeg']['video']['pixel_aspect_ratio_text']; 184 } 185 186 break; 187 188 case 2: // 0010 Sequence Display Extension ID 189 $info['mpeg']['video']['raw']['video_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for video_format 190 $info['mpeg']['video']['raw']['colour_description'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: colour_description 191 if ($info['mpeg']['video']['raw']['colour_description']) { 192 $info['mpeg']['video']['raw']['colour_primaries'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for colour_primaries 193 $info['mpeg']['video']['raw']['transfer_characteristics'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for transfer_characteristics 194 $info['mpeg']['video']['raw']['matrix_coefficients'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for matrix_coefficients 195 } 196 $info['mpeg']['video']['raw']['display_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_horizontal_size 197 $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. 198 $info['mpeg']['video']['raw']['display_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_vertical_size 199 200 $info['mpeg']['video']['video_format'] = self::videoFormatTextLookup($info['mpeg']['video']['raw']['video_format']); 201 break; 202 203 case 3: // 0011 Quant Matrix Extension ID 204 break; 205 206 case 5: // 0101 Sequence Scalable Extension ID 207 $info['mpeg']['video']['raw']['scalable_mode'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scalable_mode 208 $info['mpeg']['video']['raw']['layer_id'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for layer_id 209 if ($info['mpeg']['video']['raw']['scalable_mode'] == 1) { // "spatial scalability" 210 $info['mpeg']['video']['raw']['lower_layer_prediction_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_horizontal_size 211 $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. 212 $info['mpeg']['video']['raw']['lower_layer_prediction_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_vertical_size 213 $info['mpeg']['video']['raw']['horizontal_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_m 214 $info['mpeg']['video']['raw']['horizontal_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_n 215 $info['mpeg']['video']['raw']['vertical_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_m 216 $info['mpeg']['video']['raw']['vertical_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_n 217 } elseif ($info['mpeg']['video']['raw']['scalable_mode'] == 3) { // "temporal scalability" 218 $info['mpeg']['video']['raw']['picture_mux_enable'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: picture_mux_enable 219 if ($info['mpeg']['video']['raw']['picture_mux_enable']) { 220 $info['mpeg']['video']['raw']['mux_to_progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: mux_to_progressive_sequence 221 } 222 $info['mpeg']['video']['raw']['picture_mux_order'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_order 223 $info['mpeg']['video']['raw']['picture_mux_factor'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_factor 224 } 225 226 $info['mpeg']['video']['scalable_mode'] = self::scalableModeTextLookup($info['mpeg']['video']['raw']['scalable_mode']); 227 break; 228 229 case 7: // 0111 Picture Display Extension ID 230 break; 231 232 case 8: // 1000 Picture Coding Extension ID 233 $info['mpeg']['video']['raw']['f_code_00'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][0] (forward horizontal) 234 $info['mpeg']['video']['raw']['f_code_01'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][1] (forward vertical) 235 $info['mpeg']['video']['raw']['f_code_10'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][0] (backward horizontal) 236 $info['mpeg']['video']['raw']['f_code_11'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][1] (backward vertical) 237 $info['mpeg']['video']['raw']['intra_dc_precision'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for intra_dc_precision 238 $info['mpeg']['video']['raw']['picture_structure'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for picture_structure 239 $info['mpeg']['video']['raw']['top_field_first'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: top_field_first 240 $info['mpeg']['video']['raw']['frame_pred_frame_dct'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: frame_pred_frame_dct 241 $info['mpeg']['video']['raw']['concealment_motion_vectors'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: concealment_motion_vectors 242 $info['mpeg']['video']['raw']['q_scale_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: q_scale_type 243 $info['mpeg']['video']['raw']['intra_vlc_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: intra_vlc_format 244 $info['mpeg']['video']['raw']['alternate_scan'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: alternate_scan 245 $info['mpeg']['video']['raw']['repeat_first_field'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: repeat_first_field 246 $info['mpeg']['video']['raw']['chroma_420_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: chroma_420_type 247 $info['mpeg']['video']['raw']['progressive_frame'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_frame 248 $info['mpeg']['video']['raw']['composite_display_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: composite_display_flag 249 if ($info['mpeg']['video']['raw']['composite_display_flag']) { 250 $info['mpeg']['video']['raw']['v_axis'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: v_axis 251 $info['mpeg']['video']['raw']['field_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for field_sequence 252 $info['mpeg']['video']['raw']['sub_carrier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: sub_carrier 253 $info['mpeg']['video']['raw']['burst_amplitude'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 7); // 7 bits for burst_amplitude 254 $info['mpeg']['video']['raw']['sub_carrier_phase'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for sub_carrier_phase 255 } 256 257 $info['mpeg']['video']['intra_dc_precision_bits'] = $info['mpeg']['video']['raw']['intra_dc_precision'] + 8; 258 $info['mpeg']['video']['picture_structure'] = self::pictureStructureTextLookup($info['mpeg']['video']['raw']['picture_structure']); 259 break; 260 261 case 9: // 1001 Picture Spatial Scalable Extension ID 262 break; 263 case 10: // 1010 Picture Temporal Scalable Extension ID 264 break; 265 266 default: 267 $this->warning('Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.$info['mpeg']['video']['raw']['extension_start_code_identifier']); 268 break; 269 } 270 break; 271 272 273 case 0xB8: // group_of_pictures_header 274 $GOPcounter++; 275 if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { 276 $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); // 27 bits needed for group_of_pictures_header 277 $bitstreamoffset = 0; 278 279 $GOPheader = array(); 280 281 $GOPheader['byte_offset'] = $MPEGstreamBaseOffset + $StartCodeOffset; 282 $GOPheader['drop_frame_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: drop_frame_flag 283 $GOPheader['time_code_hours'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for time_code_hours 284 $GOPheader['time_code_minutes'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_minutes 285 $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. 286 $GOPheader['time_code_seconds'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_seconds 287 $GOPheader['time_code_pictures'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_pictures 288 $GOPheader['closed_gop'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: closed_gop 289 $GOPheader['broken_link'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: broken_link 290 291 $time_code_separator = ($GOPheader['drop_frame_flag'] ? ';' : ':'); // While non-drop time code is displayed with colons separating the digit pairs "HH:MM:SS:FF" drop frame is usually represented with a semi-colon (;) or period (.) as the divider between all the digit pairs "HH;MM;SS;FF", "HH.MM.SS.FF" 292 $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']); 293 294 $info['mpeg']['group_of_pictures'][] = $GOPheader; 295 } 296 break; 297 298 case 0xC0: // audio stream 299 case 0xC1: // audio stream 300 case 0xC2: // audio stream 301 case 0xC3: // audio stream 302 case 0xC4: // audio stream 303 case 0xC5: // audio stream 304 case 0xC6: // audio stream 305 case 0xC7: // audio stream 306 case 0xC8: // audio stream 307 case 0xC9: // audio stream 308 case 0xCA: // audio stream 309 case 0xCB: // audio stream 310 case 0xCC: // audio stream 311 case 0xCD: // audio stream 312 case 0xCE: // audio stream 313 case 0xCF: // audio stream 314 case 0xD0: // audio stream 315 case 0xD1: // audio stream 316 case 0xD2: // audio stream 317 case 0xD3: // audio stream 318 case 0xD4: // audio stream 319 case 0xD5: // audio stream 320 case 0xD6: // audio stream 321 case 0xD7: // audio stream 322 case 0xD8: // audio stream 323 case 0xD9: // audio stream 324 case 0xDA: // audio stream 325 case 0xDB: // audio stream 326 case 0xDC: // audio stream 327 case 0xDD: // audio stream 328 case 0xDE: // audio stream 329 case 0xDF: // audio stream 330 //case 0xE0: // video stream 331 //case 0xE1: // video stream 332 //case 0xE2: // video stream 333 //case 0xE3: // video stream 334 //case 0xE4: // video stream 335 //case 0xE5: // video stream 336 //case 0xE6: // video stream 337 //case 0xE7: // video stream 338 //case 0xE8: // video stream 339 //case 0xE9: // video stream 340 //case 0xEA: // video stream 341 //case 0xEB: // video stream 342 //case 0xEC: // video stream 343 //case 0xED: // video stream 344 //case 0xEE: // video stream 345 //case 0xEF: // video stream 346 if (isset($ParsedAVchannels[$StartCodeValue])) { 347 break; 348 } 349 $ParsedAVchannels[$StartCodeValue] = $StartCodeValue; 350 // http://en.wikipedia.org/wiki/Packetized_elementary_stream 351 // http://dvd.sourceforge.net/dvdinfo/pes-hdr.html 352/* 353 $PackedElementaryStream = array(); 354 if ($StartCodeValue >= 0xE0) { 355 $PackedElementaryStream['stream_type'] = 'video'; 356 $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xE0; 357 } else { 358 $PackedElementaryStream['stream_type'] = 'audio'; 359 $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xC0; 360 } 361 $PackedElementaryStream['packet_length'] = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $StartCodeOffset + 4, 2)); 362 363 $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 6, 3)); // more may be needed below 364 $bitstreamoffset = 0; 365 366 $PackedElementaryStream['marker_bits'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for marker_bits -- should be "10" = 2 367echo 'marker_bits = '.$PackedElementaryStream['marker_bits'].'<br>'; 368 $PackedElementaryStream['scrambling_control'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scrambling_control -- 00 implies not scrambled 369 $PackedElementaryStream['priority'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: priority 370 $PackedElementaryStream['data_alignment_indicator'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: data_alignment_indicator -- 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword 371 $PackedElementaryStream['copyright'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: copyright -- 1 implies copyrighted 372 $PackedElementaryStream['original_or_copy'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: original_or_copy -- 1 implies original 373 $PackedElementaryStream['pts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: pts_flag -- Presentation Time Stamp 374 $PackedElementaryStream['dts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dts_flag -- Decode Time Stamp 375 $PackedElementaryStream['escr_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: escr_flag -- Elementary Stream Clock Reference 376 $PackedElementaryStream['es_rate_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: es_rate_flag -- Elementary Stream [data] Rate 377 $PackedElementaryStream['dsm_trick_mode_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dsm_trick_mode_flag -- DSM trick mode - not used by DVD 378 $PackedElementaryStream['additional_copy_info_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: additional_copy_info_flag 379 $PackedElementaryStream['crc_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: crc_flag 380 $PackedElementaryStream['extension_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: extension_flag 381 $PackedElementaryStream['pes_remain_header_length'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 1 bit flag: priority 382 383 $additional_header_bytes = 0; 384 $additional_header_bytes += ($PackedElementaryStream['pts_flag'] ? 5 : 0); 385 $additional_header_bytes += ($PackedElementaryStream['dts_flag'] ? 5 : 0); 386 $additional_header_bytes += ($PackedElementaryStream['escr_flag'] ? 6 : 0); 387 $additional_header_bytes += ($PackedElementaryStream['es_rate_flag'] ? 3 : 0); 388 $additional_header_bytes += ($PackedElementaryStream['additional_copy_info_flag'] ? 1 : 0); 389 $additional_header_bytes += ($PackedElementaryStream['crc_flag'] ? 2 : 0); 390 $additional_header_bytes += ($PackedElementaryStream['extension_flag'] ? 1 : 0); 391$PackedElementaryStream['additional_header_bytes'] = $additional_header_bytes; 392 $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 9, $additional_header_bytes)); 393 394 $info['mpeg']['packed_elementary_streams'][$PackedElementaryStream['stream_type']][$PackedElementaryStream['stream_id']][] = $PackedElementaryStream; 395*/ 396 $getid3_temp = new getID3(); 397 $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); 398 $getid3_temp->info = $info; 399 $getid3_mp3 = new getid3_mp3($getid3_temp); 400 for ($i = 0; $i <= 7; $i++) { 401 // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after 402 // I have no idea why or what the difference is, so this is a stupid hack. 403 // If anybody has any better idea of what's going on, please let me know - info@getid3.org 404 $getid3_temp->info = $info; // only overwrite real data if valid header found 405//echo 'audio at? '.($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i).'<br>'; 406 if ($getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i, $getid3_temp->info, false)) { 407//echo 'yes!<br>'; 408 $info = $getid3_temp->info; 409 $info['audio']['bitrate_mode'] = 'cbr'; 410 $info['audio']['lossless'] = false; 411 break; 412 } 413 } 414 unset($getid3_temp, $getid3_mp3); 415 break; 416 417 case 0xBC: // Program Stream Map 418 case 0xBD: // Private stream 1 (non MPEG audio, subpictures) 419 case 0xBE: // Padding stream 420 case 0xBF: // Private stream 2 (navigation data) 421 case 0xF0: // ECM stream 422 case 0xF1: // EMM stream 423 case 0xF2: // DSM-CC stream 424 case 0xF3: // ISO/IEC_13522_stream 425 case 0xF4: // ITU-I Rec. H.222.1 type A 426 case 0xF5: // ITU-I Rec. H.222.1 type B 427 case 0xF6: // ITU-I Rec. H.222.1 type C 428 case 0xF7: // ITU-I Rec. H.222.1 type D 429 case 0xF8: // ITU-I Rec. H.222.1 type E 430 case 0xF9: // ancilliary stream 431 case 0xFA: // ISO/IEC 14496-1 SL-packtized stream 432 case 0xFB: // ISO/IEC 14496-1 FlexMux stream 433 case 0xFC: // metadata stream 434 case 0xFD: // extended stream ID 435 case 0xFE: // reserved data stream 436 case 0xFF: // program stream directory 437 // ignore 438 break; 439 440 default: 441 // ignore 442 break; 443 } 444 } while (true); 445 446 447 448// // Temporary hack to account for interleaving overhead: 449// if (!empty($info['video']['bitrate']) && !empty($info['audio']['bitrate'])) { 450// $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['video']['bitrate'] + $info['audio']['bitrate']); 451// 452// // Interleaved MPEG audio/video files have a certain amount of overhead that varies 453// // by both video and audio bitrates, and not in any sensible, linear/logarithmic pattern 454// // Use interpolated lookup tables to approximately guess how much is overhead, because 455// // playtime is calculated as filesize / total-bitrate 456// $info['playtime_seconds'] *= self::systemNonOverheadPercentage($info['video']['bitrate'], $info['audio']['bitrate']); 457// 458// //switch ($info['video']['bitrate']) { 459// // case('5000000'): 460// // $multiplier = 0.93292642112380355828048824319889; 461// // break; 462// // case('5500000'): 463// // $multiplier = 0.93582895375200989965359777343219; 464// // break; 465// // case('6000000'): 466// // $multiplier = 0.93796247714820932532911373859139; 467// // break; 468// // case('7000000'): 469// // $multiplier = 0.9413264083635103463010117778776; 470// // break; 471// // default: 472// // $multiplier = 1; 473// // break; 474// //} 475// //$info['playtime_seconds'] *= $multiplier; 476// //$this->warning('Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'); 477// if ($info['video']['bitrate'] < 50000) { 478// $this->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.'); 479// } 480// } 481// 482/* 483$time_prev = 0; 484$byte_prev = 0; 485$vbr_bitrates = array(); 486foreach ($info['mpeg']['group_of_pictures'] as $gopkey => $gopdata) { 487 $time_this = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + ($gopdata['time_code_seconds'] / 30); 488 $byte_this = $gopdata['byte_offset']; 489 if ($gopkey > 0) { 490 if ($time_this > $time_prev) { 491 $bytedelta = $byte_this - $byte_prev; 492 $timedelta = $time_this - $time_prev; 493 $this_bitrate = ($bytedelta * 8) / $timedelta; 494echo $gopkey.': ('.number_format($time_prev, 2).'-'.number_format($time_this, 2).') '.number_format($bytedelta).' bytes over '.number_format($timedelta, 3).' seconds = '.number_format($this_bitrate / 1000, 2).'kbps<br>'; 495 $time_prev = $time_this; 496 $byte_prev = $byte_this; 497 $vbr_bitrates[] = $this_bitrate; 498 } 499 } 500} 501echo 'average_File_bitrate = '.number_format(array_sum($vbr_bitrates) / count($vbr_bitrates), 1).'<br>'; 502*/ 503//echo '<pre>'.print_r($FramesByGOP, true).'</pre>'; 504 if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { 505 $last_GOP_id = max(array_keys($FramesByGOP)); 506 $frames_in_last_GOP = count($FramesByGOP[$last_GOP_id]); 507 $gopdata = &$info['mpeg']['group_of_pictures'][$last_GOP_id]; 508 $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']); 509 if (!isset($info['video']['bitrate'])) { 510 $overall_bitrate = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; 511 $info['video']['bitrate'] = $overall_bitrate - (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); 512 } 513 unset($info['mpeg']['group_of_pictures']); 514 } 515 516 return true; 517 } 518 519 /** 520 * @param string $bitstream 521 * @param int $bitstreamoffset 522 * @param int $bits_to_read 523 * @param bool $return_singlebit_as_boolean 524 * 525 * @return bool|int 526 */ 527 private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=true) { 528 $return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read)); 529 $bitstreamoffset += $bits_to_read; 530 if (($bits_to_read == 1) && $return_singlebit_as_boolean) { 531 $return = (bool) $return; 532 } 533 return $return; 534 } 535 536 /** 537 * @param int $VideoBitrate 538 * @param int $AudioBitrate 539 * 540 * @return float|int 541 */ 542 public static function systemNonOverheadPercentage($VideoBitrate, $AudioBitrate) { 543 $OverheadPercentage = 0; 544 545 $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) 546 $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss) 547 548 549 //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps) 550 $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940); 551 $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960); 552 $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340); 553 $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470); 554 $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690); 555 $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050); 556 $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570); 557 $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620); 558 $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480); 559 $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790); 560 $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190); 561 $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890); 562 563 $BitrateToUseMin = 32; 564 $BitrateToUseMax = 32; 565 $previousBitrate = 32; 566 foreach ($OverheadMultiplierByBitrate as $key => $value) { 567 if ($AudioBitrate >= $previousBitrate) { 568 $BitrateToUseMin = $previousBitrate; 569 } 570 if ($AudioBitrate < $key) { 571 $BitrateToUseMax = $key; 572 break; 573 } 574 $previousBitrate = $key; 575 } 576 $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin); 577 578 $VideoBitrateLog10 = log10($VideoBitrate); 579 $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)]; 580 $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)]; 581 $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)]; 582 $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)]; 583 $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10); 584 585 $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV; 586 $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV; 587 $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV); 588 $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV); 589 590 return $OverheadPercentage; 591 } 592 593 /** 594 * @param int $rawframerate 595 * 596 * @return float 597 */ 598 public static function videoFramerateLookup($rawframerate) { 599 $lookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60); 600 return (float) (isset($lookup[$rawframerate]) ? $lookup[$rawframerate] : 0); 601 } 602 603 /** 604 * @param int $rawaspectratio 605 * @param int $mpeg_version 606 * @param int $width 607 * @param int $height 608 * 609 * @return float 610 */ 611 public static function videoAspectRatioLookup($rawaspectratio, $mpeg_version=1, $width=0, $height=0) { 612 $lookup = array( 613 1 => 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), 614 2 => array(0, 1, 1.3333, 1.7778, 2.2100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 615 ); 616 $ratio = (float) (isset($lookup[$mpeg_version][$rawaspectratio]) ? $lookup[$mpeg_version][$rawaspectratio] : 0); 617 if ($mpeg_version == 2 && $ratio != 1) { 618 // Calculate pixel aspect ratio from MPEG-2 display aspect ratio 619 $ratio = $ratio * $height / $width; 620 } 621 return $ratio; 622 } 623 624 /** 625 * @param int $rawaspectratio 626 * @param int $mpeg_version 627 * 628 * @return string 629 */ 630 public static function videoAspectRatioTextLookup($rawaspectratio, $mpeg_version=1) { 631 $lookup = array( 632 1 => 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'), 633 2 => array('forbidden', 'square pixels', '4:3', '16:9', '2.21:1', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved'), // http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html 634 ); 635 return (isset($lookup[$mpeg_version][$rawaspectratio]) ? $lookup[$mpeg_version][$rawaspectratio] : ''); 636 } 637 638 /** 639 * @param int $video_format 640 * 641 * @return string 642 */ 643 public static function videoFormatTextLookup($video_format) { 644 // ISO/IEC 13818-2, section 6.3.6, Table 6-6. Meaning of video_format 645 $lookup = array('component', 'PAL', 'NTSC', 'SECAM', 'MAC', 'Unspecified video format', 'reserved(6)', 'reserved(7)'); 646 return (isset($lookup[$video_format]) ? $lookup[$video_format] : ''); 647 } 648 649 /** 650 * @param int $scalable_mode 651 * 652 * @return string 653 */ 654 public static function scalableModeTextLookup($scalable_mode) { 655 // ISO/IEC 13818-2, section 6.3.8, Table 6-10. Definition of scalable_mode 656 $lookup = array('data partitioning', 'spatial scalability', 'SNR scalability', 'temporal scalability'); 657 return (isset($lookup[$scalable_mode]) ? $lookup[$scalable_mode] : ''); 658 } 659 660 /** 661 * @param int $picture_structure 662 * 663 * @return string 664 */ 665 public static function pictureStructureTextLookup($picture_structure) { 666 // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure 667 $lookup = array('reserved', 'Top Field', 'Bottom Field', 'Frame picture'); 668 return (isset($lookup[$picture_structure]) ? $lookup[$picture_structure] : ''); 669 } 670 671 /** 672 * @param int $chroma_format 673 * 674 * @return string 675 */ 676 public static function chromaFormatTextLookup($chroma_format) { 677 // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure 678 $lookup = array('reserved', '4:2:0', '4:2:2', '4:4:4'); 679 return (isset($lookup[$chroma_format]) ? $lookup[$chroma_format] : ''); 680 } 681 682} 683