30 define(
'GETID3_FLV_TAG_AUDIO', 8);
31 define(
'GETID3_FLV_TAG_VIDEO', 9);
32 define(
'GETID3_FLV_TAG_META', 18);
34 define(
'GETID3_FLV_VIDEO_H263', 2);
35 define(
'GETID3_FLV_VIDEO_SCREEN', 3);
36 define(
'GETID3_FLV_VIDEO_VP6', 4);
41 function getid3_flv(&$fd, &$ThisFileInfo, $ReturnAllTagData=
false) {
42 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
44 $FLVdataLength = $ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset'];
45 $FLVheader = fread($fd, 5);
47 $ThisFileInfo[
'fileformat'] =
'flv';
48 $ThisFileInfo[
'flv'][
'header'][
'signature'] = substr($FLVheader, 0, 3);
52 if ($ThisFileInfo[
'flv'][
'header'][
'signature'] !=
'FLV') {
53 $ThisFileInfo[
'error'][] =
'Expecting "FLV" at offset '.$ThisFileInfo[
'avdataoffset'].
', found "'.$ThisFileInfo[
'flv'][
'header'][
'signature'].
'"';
54 unset($ThisFileInfo[
'flv']);
55 unset($ThisFileInfo[
'fileformat']);
59 $ThisFileInfo[
'flv'][
'header'][
'hasAudio'] = (bool) ($TypeFlags & 0x04);
60 $ThisFileInfo[
'flv'][
'header'][
'hasVideo'] = (bool) ($TypeFlags & 0x01);
63 $FLVheaderFrameLength = 9;
64 if ($FrameSizeDataLength > $FLVheaderFrameLength) {
65 fseek($fd, $FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
69 while ((ftell($fd) + 1) < $ThisFileInfo[
'avdataend']) {
76 $ThisTagHeader = fread($fd, 16);
83 $NextOffset = ftell($fd) - 1 + $DataLength;
87 if (!isset($ThisFileInfo[
'flv'][
'audio'][
'audioFormat'])) {
88 $ThisFileInfo[
'flv'][
'audio'][
'audioFormat'] = $LastHeaderByte & 0x07;
89 $ThisFileInfo[
'flv'][
'audio'][
'audioRate'] = ($LastHeaderByte & 0x30) / 0x10;
90 $ThisFileInfo[
'flv'][
'audio'][
'audioSampleSize'] = ($LastHeaderByte & 0x40) / 0x40;
91 $ThisFileInfo[
'flv'][
'audio'][
'audioType'] = ($LastHeaderByte & 0x80) / 0x80;
96 if (!isset($ThisFileInfo[
'flv'][
'video'][
'videoCodec'])) {
97 $ThisFileInfo[
'flv'][
'video'][
'videoCodec'] = $LastHeaderByte & 0x07;
99 $FLVvideoHeader = fread($fd, 11);
104 $PictureSizeType = $PictureSizeType & 0x0007;
105 $ThisFileInfo[
'flv'][
'header'][
'videoSizeType'] = $PictureSizeType;
106 switch ($PictureSizeType) {
109 $PictureSizeEnc <<= 1;
110 $ThisFileInfo[
'video'][
'resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8;
112 $PictureSizeEnc <<= 1;
113 $ThisFileInfo[
'video'][
'resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8;
118 $PictureSizeEnc <<= 1;
119 $ThisFileInfo[
'video'][
'resolution_x'] = ($PictureSizeEnc & 0xFFFF0000) >> 16;
122 $PictureSizeEnc <<= 1;
123 $ThisFileInfo[
'video'][
'resolution_y'] = ($PictureSizeEnc & 0xFFFF0000) >> 16;
127 $ThisFileInfo[
'video'][
'resolution_x'] = 352;
128 $ThisFileInfo[
'video'][
'resolution_y'] = 288;
132 $ThisFileInfo[
'video'][
'resolution_x'] = 176;
133 $ThisFileInfo[
'video'][
'resolution_y'] = 144;
137 $ThisFileInfo[
'video'][
'resolution_x'] = 128;
138 $ThisFileInfo[
'video'][
'resolution_y'] = 96;
142 $ThisFileInfo[
'video'][
'resolution_x'] = 320;
143 $ThisFileInfo[
'video'][
'resolution_y'] = 240;
147 $ThisFileInfo[
'video'][
'resolution_x'] = 160;
148 $ThisFileInfo[
'video'][
'resolution_y'] = 120;
152 $ThisFileInfo[
'video'][
'resolution_x'] = 0;
153 $ThisFileInfo[
'video'][
'resolution_y'] = 0;
164 fseek($fd, -1, SEEK_CUR);
166 $eventName =
$reader->readData();
167 $ThisFileInfo[
'meta'][$eventName] =
$reader->readData();
170 $ThisFileInfo[
'video'][
'frame_rate'] = $ThisFileInfo[
'meta'][
'onMetaData'][
'framerate'];
171 $ThisFileInfo[
'video'][
'resolution_x'] = $ThisFileInfo[
'meta'][
'onMetaData'][
'width'];
172 $ThisFileInfo[
'video'][
'resolution_y'] = $ThisFileInfo[
'meta'][
'onMetaData'][
'height'];
180 if ($Timestamp > $Duration) {
181 $Duration = $Timestamp;
184 fseek($fd, $NextOffset, SEEK_SET);
187 $ThisFileInfo[
'playtime_seconds'] = $Duration / 1000;
188 $ThisFileInfo[
'bitrate'] = ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) / $ThisFileInfo[
'playtime_seconds'];
190 if ($ThisFileInfo[
'flv'][
'header'][
'hasAudio']) {
191 $ThisFileInfo[
'audio'][
'codec'] = $this->
FLVaudioFormat($ThisFileInfo[
'flv'][
'audio'][
'audioFormat']);
192 $ThisFileInfo[
'audio'][
'sample_rate'] = $this->
FLVaudioRate($ThisFileInfo[
'flv'][
'audio'][
'audioRate']);
193 $ThisFileInfo[
'audio'][
'bits_per_sample'] = $this->
FLVaudioBitDepth($ThisFileInfo[
'flv'][
'audio'][
'audioSampleSize']);
195 $ThisFileInfo[
'audio'][
'channels'] = $ThisFileInfo[
'flv'][
'audio'][
'audioType'] + 1;
196 $ThisFileInfo[
'audio'][
'lossless'] = ($ThisFileInfo[
'flv'][
'audio'][
'audioFormat'] ?
false :
true);
197 $ThisFileInfo[
'audio'][
'dataformat'] =
'flv';
199 if (@$ThisFileInfo[
'flv'][
'header'][
'hasVideo']) {
200 $ThisFileInfo[
'video'][
'codec'] = $this->
FLVvideoCodec($ThisFileInfo[
'flv'][
'video'][
'videoCodec']);
201 $ThisFileInfo[
'video'][
'dataformat'] =
'flv';
202 $ThisFileInfo[
'video'][
'lossless'] =
false;
210 $FLVaudioFormat = array(
214 5 =>
'Nellymoser 8kHz mono',
217 return (@$FLVaudioFormat[$id] ? @$FLVaudioFormat[$id] :
false);
221 $FLVaudioRate = array(
227 return (@$FLVaudioRate[$id] ? @$FLVaudioRate[$id] :
false);
231 $FLVaudioBitDepth = array(
235 return (@$FLVaudioBitDepth[$id] ? @$FLVaudioBitDepth[$id] :
false);
239 $FLVvideoCodec = array(
244 return (@$FLVvideoCodec[$id] ? @$FLVvideoCodec[$id] :
false);
275 return $this->
read($length);
280 return $this->
read($length);
284 $val = substr($this->bytes, $this->pos, $length);
285 $this->pos += $length;
342 $type = $this->stream->readByte();
402 $value =
'(unknown or unsupported data type)';
410 return $this->stream->readDouble();
414 return $this->stream->readByte() == 1;
418 return $this->stream->readUTF();
423 $highestIndex = $this->stream->readLong();
427 while ($key = $this->stream->readUTF()) {
429 if (($key ==
'') && ($this->stream->peekByte() == 0x09)) {
431 $this->stream->readByte();
443 $highestIndex = $this->stream->readLong();
447 while ($key = $this->stream->readUTF()) {
449 if (($key ==
'') && ($this->stream->peekByte() == 0x09)) {
451 $this->stream->readByte();
455 if (is_numeric($key)) {
466 $length = $this->stream->readLong();
470 for ($i = 0; $i < count($length); $i++) {
479 $timezone = $this->stream->readInt();
484 return $this->stream->readLongUTF();
488 return $this->stream->readLongUTF();
492 $className = $this->stream->readUTF();