20 function getid3_swf(&$fd, &$ThisFileInfo, $ReturnAllTagData=
false) {
21 $ThisFileInfo[
'fileformat'] =
'swf';
22 $ThisFileInfo[
'video'][
'dataformat'] =
'swf';
26 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
29 $SWFfileData = fread($fd, $ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']);
31 $ThisFileInfo[
'swf'][
'header'][
'signature'] = substr($SWFfileData, 0, 3);
32 switch ($ThisFileInfo[
'swf'][
'header'][
'signature']) {
34 $ThisFileInfo[
'swf'][
'header'][
'compressed'] =
false;
38 $ThisFileInfo[
'swf'][
'header'][
'compressed'] =
true;
42 $ThisFileInfo[
'error'][] =
'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo[
'avdataoffset'].
', found "'.$ThisFileInfo[
'swf'][
'header'][
'signature'].
'"';
43 unset($ThisFileInfo[
'swf']);
44 unset($ThisFileInfo[
'fileformat']);
52 if ($ThisFileInfo[
'swf'][
'header'][
'compressed']) {
62 if ($UncompressedFileData = gzuncompress(substr($SWFfileData, 8))) {
65 $SWFfileData = substr($SWFfileData, 0, 8).$UncompressedFileData;
70 $ThisFileInfo[
'error'][] =
'Error decompressing compressed SWF data';
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);
83 list($X1, $X2, $Y1, $Y2) = explode(
"\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue,
"\n", 1));
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;
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'];
109 $CurrentOffset = 12 + $FrameSizeDataLength;
110 $SWFdataLength = strlen($SWFfileData);
112 while ($CurrentOffset < $SWFdataLength) {
115 $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
116 $TagLength = ($TagIDTagLength & 0x003F);
118 if ($TagLength == 0x3F) {
124 $TagData[
'offset'] = $CurrentOffset;
125 $TagData[
'size'] = $TagLength;
126 $TagData[
'id'] = $TagID;
127 $TagData[
'data'] = substr($SWFfileData, $CurrentOffset, $TagLength);
134 $ThisFileInfo[
'swf'][
'bgcolor'] = strtoupper(str_pad(dechex(
getid3_lib::BigEndian2Int($TagData[
'data'])), 6,
'0', STR_PAD_LEFT));
138 if ($ReturnAllTagData) {
139 $ThisFileInfo[
'swf'][
'tags'][] = $TagData;
144 $CurrentOffset += $TagLength;