20 {
21 $ThisFileInfo['fileformat'] = 'swf';
22 $ThisFileInfo['video']['dataformat'] = 'swf';
23
24
25
26 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
27
28
29 $SWFfileData =
fread($fd, $ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']);
30
31 $ThisFileInfo['swf']['header']['signature'] = substr($SWFfileData, 0, 3);
32 switch ($ThisFileInfo['swf']['header']['signature']) {
33 case 'FWS':
34 $ThisFileInfo['swf']['header']['compressed'] = false;
35 break;
36
37 case 'CWS':
38 $ThisFileInfo['swf']['header']['compressed'] = true;
39 break;
40
41 default:
42 $ThisFileInfo['error'][] = 'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['swf']['header']['signature'].'"';
43 unset($ThisFileInfo['swf']);
44 unset($ThisFileInfo['fileformat']);
45 return false;
46 break;
47 }
50
51
52 if ($ThisFileInfo['swf']['header']['compressed']) {
53
54
55
56
57
58
59
60
61
62 if ($UncompressedFileData = gzuncompress(substr($SWFfileData, 8))) {
63
64
65 $SWFfileData = substr($SWFfileData, 0, 8).$UncompressedFileData;
66
67 } else {
68
69
70 $ThisFileInfo['error'][] = 'Error decompressing compressed SWF data';
71 return false;
72
73 }
74
75 }
76
77 $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3;
78 $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8);
79 $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT);
80 for ($i = 1; $i < $FrameSizeDataLength; $i++) {
81 $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
82 }
83 list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
86
87
88
89
90
91
92
93
96
97 $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['swf']['header']['frame_rate'];
98 $ThisFileInfo['video']['resolution_x'] = intval(round($ThisFileInfo['swf']['header']['frame_width'] / 20));
99 $ThisFileInfo['video']['resolution_y'] = intval(round($ThisFileInfo['swf']['header']['frame_height'] / 20));
100 $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
101
102 if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) {
103 $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate'];
104 }
105
106
107
108
109 $CurrentOffset = 12 + $FrameSizeDataLength;
110 $SWFdataLength = strlen($SWFfileData);
111
112 while ($CurrentOffset < $SWFdataLength) {
113
115 $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
116 $TagLength = ($TagIDTagLength & 0x003F);
117 $CurrentOffset += 2;
118 if ($TagLength == 0x3F) {
120 $CurrentOffset += 4;
121 }
122
123 unset($TagData);
124 $TagData['offset'] = $CurrentOffset;
125 $TagData['size'] = $TagLength;
126 $TagData['id'] = $TagID;
127 $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength);
128 switch ($TagID) {
129 case 0:
130 break 2;
131
132 case 9:
133
134 $ThisFileInfo[
'swf'][
'bgcolor'] = strtoupper(str_pad(dechex(
getid3_lib::BigEndian2Int($TagData[
'data'])), 6,
'0', STR_PAD_LEFT));
135 break;
136
137 default:
139 $ThisFileInfo['swf']['tags'][] = $TagData;
140 }
141 break;
142 }
143
144 $CurrentOffset += $TagLength;
145 }
146
147 return true;
148 }