82 {
83 $info = &$this->getid3->info;
84
86
87 $FLVdataLength =
$info[
'avdataend'] -
$info[
'avdataoffset'];
88 $FLVheader = $this->
fread(5);
89
90 $info['fileformat'] = 'flv';
91 $info[
'flv'][
'header'][
'signature'] = substr($FLVheader, 0, 3);
94
95 if (
$info[
'flv'][
'header'][
'signature'] != self::magic) {
98 return false;
99 }
100
101 $info[
'flv'][
'header'][
'hasAudio'] = (bool) ($TypeFlags & 0x04);
102 $info[
'flv'][
'header'][
'hasVideo'] = (bool) ($TypeFlags & 0x01);
103
105 $FLVheaderFrameLength = 9;
106 if ($FrameSizeDataLength > $FLVheaderFrameLength) {
107 $this->
fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
108 }
109 $Duration = 0;
110 $found_video = false;
111 $found_audio = false;
112 $found_meta = false;
113 $found_valid_meta_playtime = false;
114 $tagParseCount = 0;
115 $info[
'flv'][
'framecount'] = array(
'total'=>0,
'audio'=>0,
'video'=>0);
116 $flv_framecount = &
$info[
'flv'][
'framecount'];
117 while ((($this->
ftell() + 16) < $info[
'avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime)) {
118 $ThisTagHeader = $this->
fread(16);
119
125 $NextOffset = $this->
ftell() - 1 + $DataLength;
126 if ($Timestamp > $Duration) {
127 $Duration = $Timestamp;
128 }
129
130 $flv_framecount['total']++;
131 switch ($TagType) {
133 $flv_framecount['audio']++;
134 if (!$found_audio) {
135 $found_audio = true;
136 $info[
'flv'][
'audio'][
'audioFormat'] = ($LastHeaderByte >> 4) & 0x0F;
137 $info[
'flv'][
'audio'][
'audioRate'] = ($LastHeaderByte >> 2) & 0x03;
138 $info[
'flv'][
'audio'][
'audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01;
139 $info[
'flv'][
'audio'][
'audioType'] = $LastHeaderByte & 0x01;
140 }
141 break;
142
144 $flv_framecount['video']++;
145 if (!$found_video) {
146 $found_video = true;
147 $info[
'flv'][
'video'][
'videoCodec'] = $LastHeaderByte & 0x07;
148
149 $FLVvideoHeader = $this->
fread(11);
150
152
153
156
162
163 if (($numOfSequenceParameterSets & 0x1F) != 0) {
164
165
166
168
169 $sps = $this->
fread($spsSize);
170 if (strlen($sps) == $spsSize) {
172 $spsReader->readData();
173 $info[
'video'][
'resolution_x'] = $spsReader->getWidth();
174 $info[
'video'][
'resolution_y'] = $spsReader->getHeight();
175 }
176 }
177 }
178
179
181
183 $PictureSizeType = $PictureSizeType & 0x0007;
184 $info[
'flv'][
'header'][
'videoSizeType'] = $PictureSizeType;
185 switch ($PictureSizeType) {
186 case 0:
187
188
189
190
191
192
193
196 $info[
'video'][
'resolution_x'] = $PictureSizeEnc[
'x'] & 0xFF;
197 $info[
'video'][
'resolution_y'] = $PictureSizeEnc[
'y'] & 0xFF;
198 break;
199
200 case 1:
203 $info[
'video'][
'resolution_x'] = $PictureSizeEnc[
'x'] & 0xFFFF;
204 $info[
'video'][
'resolution_y'] = $PictureSizeEnc[
'y'] & 0xFFFF;
205 break;
206
207 case 2:
208 $info[
'video'][
'resolution_x'] = 352;
209 $info[
'video'][
'resolution_y'] = 288;
210 break;
211
212 case 3:
213 $info[
'video'][
'resolution_x'] = 176;
214 $info[
'video'][
'resolution_y'] = 144;
215 break;
216
217 case 4:
218 $info[
'video'][
'resolution_x'] = 128;
219 $info[
'video'][
'resolution_y'] = 96;
220 break;
221
222 case 5:
223 $info[
'video'][
'resolution_x'] = 320;
224 $info[
'video'][
'resolution_y'] = 240;
225 break;
226
227 case 6:
228 $info[
'video'][
'resolution_x'] = 160;
229 $info[
'video'][
'resolution_y'] = 120;
230 break;
231
232 default:
233 $info[
'video'][
'resolution_x'] = 0;
234 $info[
'video'][
'resolution_y'] = 0;
235 break;
236
237 }
238
240
241
242 if (!isset(
$info[
'video'][
'resolution_x'])) {
245 $info[
'video'][
'resolution_x'] = ($PictureSizeEnc[
'x'] & 0xFF) << 3;
246 $info[
'video'][
'resolution_y'] = ($PictureSizeEnc[
'y'] & 0xFF) << 3;
247 }
248
249
250 }
251 if (!empty(
$info[
'video'][
'resolution_x']) && !empty(
$info[
'video'][
'resolution_y'])) {
252 $info[
'video'][
'pixel_aspect_ratio'] =
$info[
'video'][
'resolution_x'] /
$info[
'video'][
'resolution_y'];
253 }
254 }
255 break;
256
257
259 if (!$found_meta) {
260 $found_meta = true;
261 $this->
fseek(-1, SEEK_CUR);
262 $datachunk = $this->
fread($DataLength);
265 $eventName =
$reader->readData();
268
269 $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate');
270 foreach ($copykeys as $sourcekey => $destkey) {
271 if (isset(
$info[
'flv'][
'meta'][
'onMetaData'][$sourcekey])) {
272 switch ($sourcekey) {
273 case 'width':
274 case 'height':
275 $info[
'video'][$destkey] = intval(round(
$info[
'flv'][
'meta'][
'onMetaData'][$sourcekey]));
276 break;
277 case 'audiodatarate':
279 break;
280 case 'videodatarate':
281 case 'frame_rate':
282 default:
283 $info[
'video'][$destkey] =
$info[
'flv'][
'meta'][
'onMetaData'][$sourcekey];
284 break;
285 }
286 }
287 }
288 if (!empty(
$info[
'flv'][
'meta'][
'onMetaData'][
'duration'])) {
289 $found_valid_meta_playtime = true;
290 }
291 }
292 break;
293
294 default:
295
296 break;
297 }
298 $this->
fseek($NextOffset);
299 }
300
301 $info[
'playtime_seconds'] = $Duration / 1000;
302 if (
$info[
'playtime_seconds'] > 0) {
303 $info[
'bitrate'] = ((
$info[
'avdataend'] -
$info[
'avdataoffset']) * 8) /
$info[
'playtime_seconds'];
304 }
305
306 if (
$info[
'flv'][
'header'][
'hasAudio']) {
310
311 $info[
'audio'][
'channels'] =
$info[
'flv'][
'audio'][
'audioType'] + 1;
312 $info[
'audio'][
'lossless'] = (
$info[
'flv'][
'audio'][
'audioFormat'] ? false :
true);
313 $info[
'audio'][
'dataformat'] =
'flv';
314 }
315 if (!empty(
$info[
'flv'][
'header'][
'hasVideo'])) {
317 $info[
'video'][
'dataformat'] =
'flv';
318 $info[
'video'][
'lossless'] =
false;
319 }
320
321
322 if (!empty(
$info[
'flv'][
'meta'][
'onMetaData'][
'duration'])) {
323 $info[
'playtime_seconds'] =
$info[
'flv'][
'meta'][
'onMetaData'][
'duration'];
324 $info[
'bitrate'] = ((
$info[
'avdataend'] -
$info[
'avdataoffset']) * 8) /
$info[
'playtime_seconds'];
325 }
326 if (isset(
$info[
'flv'][
'meta'][
'onMetaData'][
'audiocodecid'])) {
328 }
329 if (isset(
$info[
'flv'][
'meta'][
'onMetaData'][
'videocodecid'])) {
331 }
332 return true;
333 }
static audioBitDepthLookup($id)
static audioFormatLookup($id)
static videoCodecLookup($id)
static audioRateLookup($id)
fseek($bytes, $whence=SEEK_SET)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
static LittleEndian2Int($byteword, $signed=false)
static CastAsInt($floatnum)
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
const H264_AVC_SEQUENCE_HEADER
const GETID3_FLV_TAG_AUDIO
getID3() by James Heinrich info@getid3.org //
const GETID3_FLV_VIDEO_VP6FLV_ALPHA
const GETID3_FLV_TAG_VIDEO
const GETID3_FLV_VIDEO_H263
const GETID3_FLV_TAG_META
const GETID3_FLV_VIDEO_H264