| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 ///////////////////////////////////////////////////////////////// 3 /// getID3() by James Heinrich <info@getid3.org> // 4 // available at http://getid3.sourceforge.net // 5 // or http://www.getid3.org // 6 ///////////////////////////////////////////////////////////////// 7 // See readme.txt for more details // 8 ///////////////////////////////////////////////////////////////// 9 // // 10 // module.audio-video.swf.php // 11 // module for analyzing Shockwave Flash files // 12 // dependencies: NONE // 13 // /// 14 ///////////////////////////////////////////////////////////////// 15 16 17 class getid3_swf 18 { 19 20 function getid3_swf(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) { 21 //$start_time = microtime(true); 22 $ThisFileInfo['fileformat'] = 'swf'; 23 $ThisFileInfo['video']['dataformat'] = 'swf'; 24 25 // http://www.openswf.org/spec/SWFfileformat.html 26 27 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); 28 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 __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; 52 53 if ($ThisFileInfo['swf']['header']['compressed']) { 54 55 $SWFHead = substr($SWFfileData, 0, 8); 56 $SWFfileData = substr($SWFfileData, 8); 57 if ($decompressed = @gzuncompress($SWFfileData)) { 58 59 $SWFfileData = $SWFHead.$decompressed; 60 61 } else { 62 63 $ThisFileInfo['error'][] = 'Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($ThisFileInfo['swf']['header']['length'] - 8).' bytes uncompressed)'; 64 return false; 65 66 } 67 68 } 69 //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; 70 71 $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3; 72 $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8); 73 $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT); 74 for ($i = 1; $i < $FrameSizeDataLength; $i++) { 75 $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); 76 } 77 list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); 78 $ThisFileInfo['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); 79 $ThisFileInfo['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); 80 81 // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm 82 // Next in the header is the frame rate, which is kind of weird. 83 // It is supposed to be stored as a 16bit integer, but the first byte 84 // (or last depending on how you look at it) is completely ignored. 85 // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. 86 87 // Byte at (8 + $FrameSizeDataLength) is always zero and ignored 88 $ThisFileInfo['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); 89 $ThisFileInfo['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); 90 91 $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['swf']['header']['frame_rate']; 92 $ThisFileInfo['video']['resolution_x'] = intval(round($ThisFileInfo['swf']['header']['frame_width'] / 20)); 93 $ThisFileInfo['video']['resolution_y'] = intval(round($ThisFileInfo['swf']['header']['frame_height'] / 20)); 94 $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; 95 96 if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) { 97 $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate']; 98 } 99 //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; 100 101 102 // SWF tags 103 104 $CurrentOffset = 12 + $FrameSizeDataLength; 105 $SWFdataLength = strlen($SWFfileData); 106 107 while ($CurrentOffset < $SWFdataLength) { 108 //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'<br>'; 109 110 $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); 111 $TagID = ($TagIDTagLength & 0xFFFC) >> 6; 112 $TagLength = ($TagIDTagLength & 0x003F); 113 $CurrentOffset += 2; 114 if ($TagLength == 0x3F) { 115 $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); 116 $CurrentOffset += 4; 117 } 118 119 unset($TagData); 120 $TagData['offset'] = $CurrentOffset; 121 $TagData['size'] = $TagLength; 122 $TagData['id'] = $TagID; 123 $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); 124 switch ($TagID) { 125 case 0: // end of movie 126 break 2; 127 128 case 9: // Set background color 129 //$ThisFileInfo['swf']['tags'][] = $TagData; 130 $ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); 131 break; 132 133 default: 134 if ($ReturnAllTagData) { 135 $ThisFileInfo['swf']['tags'][] = $TagData; 136 } 137 break; 138 } 139 140 $CurrentOffset += $TagLength; 141 } 142 143 return true; 144 } 145 146 } 147 148 149 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |