ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_swf Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_swf:
+ Collaboration diagram for getid3_swf:

Public Member Functions

 getid3_swf (&$fd, &$ThisFileInfo, $ReturnAllTagData=false)
 
 Analyze ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Data Fields

 $ReturnAllTagData = false
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio-video.swf.php.

Member Function Documentation

◆ Analyze()

getid3_swf::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 22 of file module.audio-video.swf.php.

22 {
23 $info = &$this->getid3->info;
24
25 $info['fileformat'] = 'swf';
26 $info['video']['dataformat'] = 'swf';
27
28 // http://www.openswf.org/spec/SWFfileformat.html
29
30 $this->fseek($info['avdataoffset']);
31
32 $SWFfileData = $this->fread($info['avdataend'] - $info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
33
34 $info['swf']['header']['signature'] = substr($SWFfileData, 0, 3);
35 switch ($info['swf']['header']['signature']) {
36 case 'FWS':
37 $info['swf']['header']['compressed'] = false;
38 break;
39
40 case 'CWS':
41 $info['swf']['header']['compressed'] = true;
42 break;
43
44 default:
45 $info['error'][] = 'Expecting "FWS" or "CWS" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['swf']['header']['signature']).'"';
46 unset($info['swf']);
47 unset($info['fileformat']);
48 return false;
49 break;
50 }
51 $info['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1));
52 $info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4));
53
54 if ($info['swf']['header']['compressed']) {
55 $SWFHead = substr($SWFfileData, 0, 8);
56 $SWFfileData = substr($SWFfileData, 8);
57 if ($decompressed = @gzuncompress($SWFfileData)) {
58 $SWFfileData = $SWFHead.$decompressed;
59 } else {
60 $info['error'][] = 'Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($info['swf']['header']['length'] - 8).' bytes uncompressed)';
61 return false;
62 }
63 }
64
65 $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3;
66 $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8);
67 $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT);
68 for ($i = 1; $i < $FrameSizeDataLength; $i++) {
69 $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
70 }
71 list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
72 $info['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2);
73 $info['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2);
74
75 // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
76 // Next in the header is the frame rate, which is kind of weird.
77 // It is supposed to be stored as a 16bit integer, but the first byte
78 // (or last depending on how you look at it) is completely ignored.
79 // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps.
80
81 // Byte at (8 + $FrameSizeDataLength) is always zero and ignored
82 $info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1));
83 $info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2));
84
85 $info['video']['frame_rate'] = $info['swf']['header']['frame_rate'];
86 $info['video']['resolution_x'] = intval(round($info['swf']['header']['frame_width'] / 20));
87 $info['video']['resolution_y'] = intval(round($info['swf']['header']['frame_height'] / 20));
88 $info['video']['pixel_aspect_ratio'] = (float) 1;
89
90 if (($info['swf']['header']['frame_count'] > 0) && ($info['swf']['header']['frame_rate'] > 0)) {
91 $info['playtime_seconds'] = $info['swf']['header']['frame_count'] / $info['swf']['header']['frame_rate'];
92 }
93//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
94
95
96 // SWF tags
97
98 $CurrentOffset = 12 + $FrameSizeDataLength;
99 $SWFdataLength = strlen($SWFfileData);
100
101 while ($CurrentOffset < $SWFdataLength) {
102//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>';
103
104 $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2));
105 $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
106 $TagLength = ($TagIDTagLength & 0x003F);
107 $CurrentOffset += 2;
108 if ($TagLength == 0x3F) {
109 $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4));
110 $CurrentOffset += 4;
111 }
112
113 unset($TagData);
114 $TagData['offset'] = $CurrentOffset;
115 $TagData['size'] = $TagLength;
116 $TagData['id'] = $TagID;
117 $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength);
118 switch ($TagID) {
119 case 0: // end of movie
120 break 2;
121
122 case 9: // Set background color
123 //$info['swf']['tags'][] = $TagData;
124 $info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT));
125 break;
126
127 default:
128 if ($this->ReturnAllTagData) {
129 $info['swf']['tags'][] = $TagData;
130 }
131 break;
132 }
133
134 $CurrentOffset += $TagLength;
135 }
136
137 return true;
138 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
Bin2Dec($binstring, $signed=false)
Definition: getid3.lib.php:316
$info
Definition: example_052.php:80

References $info, getid3_lib\BigEndian2Int(), getid3_lib\Bin2Dec(), getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\LittleEndian2Int(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ getid3_swf()

getid3_swf::getid3_swf ( $fd,
$ThisFileInfo,
  $ReturnAllTagData = false 
)

Definition at line 20 of file module.audio-video.swf.php.

20 {
21 $ThisFileInfo['fileformat'] = 'swf';
22 $ThisFileInfo['video']['dataformat'] = 'swf';
23
24 // http://www.openswf.org/spec/SWFfileformat.html
25
26 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
27
28//echo 'reading '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes<br>';
29 $SWFfileData = fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
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 }
48 $ThisFileInfo['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1));
49 $ThisFileInfo['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4));
50
51//echo '1<br>';
52 if ($ThisFileInfo['swf']['header']['compressed']) {
53
54//echo '2<br>';
55// $foo = substr($SWFfileData, 8, 4096);
56// echo '['.strlen($foo).']<br>';
57// $fee = gzuncompress($foo);
58// echo '('.strlen($fee).')<br>';
59//return false;
60//echo '<br>time: '.time().'<br>';
61//return false;
62 if ($UncompressedFileData = gzuncompress(substr($SWFfileData, 8))) {
63
64//echo '3<br>';
65 $SWFfileData = substr($SWFfileData, 0, 8).$UncompressedFileData;
66
67 } else {
68
69//echo '4<br>';
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));
84 $ThisFileInfo['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2);
85 $ThisFileInfo['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2);
86
87 // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
88 // Next in the header is the frame rate, which is kind of weird.
89 // It is supposed to be stored as a 16bit integer, but the first byte
90 // (or last depending on how you look at it) is completely ignored.
91 // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps.
92
93 // Byte at (8 + $FrameSizeDataLength) is always zero and ignored
94 $ThisFileInfo['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1));
95 $ThisFileInfo['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2));
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 // SWF tags
108
109 $CurrentOffset = 12 + $FrameSizeDataLength;
110 $SWFdataLength = strlen($SWFfileData);
111
112 while ($CurrentOffset < $SWFdataLength) {
113
114 $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2));
115 $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
116 $TagLength = ($TagIDTagLength & 0x003F);
117 $CurrentOffset += 2;
118 if ($TagLength == 0x3F) {
119 $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4));
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: // end of movie
130 break 2;
131
132 case 9: // Set background color
133 //$ThisFileInfo['swf']['tags'][] = $TagData;
134 $ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT));
135 break;
136
137 default:
138 if ($ReturnAllTagData) {
139 $ThisFileInfo['swf']['tags'][] = $TagData;
140 }
141 break;
142 }
143
144 $CurrentOffset += $TagLength;
145 }
146
147 return true;
148 }

References $ReturnAllTagData, getid3_lib\BigEndian2Int(), getid3_lib\Bin2Dec(), getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\LittleEndian2Int().

+ Here is the call graph for this function:

Field Documentation

◆ $ReturnAllTagData

getid3_swf::$ReturnAllTagData = false

Definition at line 20 of file module.audio-video.swf.php.

Referenced by getid3_swf().


The documentation for this class was generated from the following files: