PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/osflvplayer/flash/module.audio-video.swf.php

https://bitbucket.org/chamilo/chamilo/
PHP | 153 lines | 85 code | 34 blank | 34 comment | 12 complexity | 436161d8a0223a0d834c9610ac1abec0 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  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. class getid3_swf
  16. {
  17. function getid3_swf(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) {
  18. $ThisFileInfo['fileformat'] = 'swf';
  19. $ThisFileInfo['video']['dataformat'] = 'swf';
  20. // http://www.openswf.org/spec/SWFfileformat.html
  21. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  22. //echo 'reading '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes<br>';
  23. $SWFfileData = fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
  24. $ThisFileInfo['swf']['header']['signature'] = substr($SWFfileData, 0, 3);
  25. switch ($ThisFileInfo['swf']['header']['signature']) {
  26. case 'FWS':
  27. $ThisFileInfo['swf']['header']['compressed'] = false;
  28. break;
  29. case 'CWS':
  30. $ThisFileInfo['swf']['header']['compressed'] = true;
  31. break;
  32. default:
  33. $ThisFileInfo['error'][] = 'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['swf']['header']['signature'].'"';
  34. unset($ThisFileInfo['swf']);
  35. unset($ThisFileInfo['fileformat']);
  36. return false;
  37. break;
  38. }
  39. $ThisFileInfo['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1));
  40. $ThisFileInfo['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4));
  41. //echo '1<br>';
  42. if ($ThisFileInfo['swf']['header']['compressed']) {
  43. //echo '2<br>';
  44. // $foo = substr($SWFfileData, 8, 4096);
  45. // echo '['.strlen($foo).']<br>';
  46. // $fee = gzuncompress($foo);
  47. // echo '('.strlen($fee).')<br>';
  48. //return false;
  49. //echo '<br>time: '.time().'<br>';
  50. //return false;
  51. if ($UncompressedFileData = gzuncompress(substr($SWFfileData, 8))) {
  52. //echo '3<br>';
  53. $SWFfileData = substr($SWFfileData, 0, 8).$UncompressedFileData;
  54. } else {
  55. //echo '4<br>';
  56. $ThisFileInfo['error'][] = 'Error decompressing compressed SWF data';
  57. return false;
  58. }
  59. }
  60. $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3;
  61. $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8);
  62. $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT);
  63. for ($i = 1; $i < $FrameSizeDataLength; $i++) {
  64. $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
  65. }
  66. list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
  67. $ThisFileInfo['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2);
  68. $ThisFileInfo['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2);
  69. // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
  70. // Next in the header is the frame rate, which is kind of weird.
  71. // It is supposed to be stored as a 16bit integer, but the first byte
  72. // (or last depending on how you look at it) is completely ignored.
  73. // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps.
  74. // Byte at (8 + $FrameSizeDataLength) is always zero and ignored
  75. $ThisFileInfo['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1));
  76. $ThisFileInfo['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2));
  77. $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['swf']['header']['frame_rate'];
  78. $ThisFileInfo['video']['resolution_x'] = intval(round($ThisFileInfo['swf']['header']['frame_width'] / 20));
  79. $ThisFileInfo['video']['resolution_y'] = intval(round($ThisFileInfo['swf']['header']['frame_height'] / 20));
  80. $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
  81. if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) {
  82. $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate'];
  83. }
  84. // SWF tags
  85. $CurrentOffset = 12 + $FrameSizeDataLength;
  86. $SWFdataLength = strlen($SWFfileData);
  87. while ($CurrentOffset < $SWFdataLength) {
  88. $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2));
  89. $TagID = ($TagIDTagLength & 0xFFFC) >> 6;
  90. $TagLength = ($TagIDTagLength & 0x003F);
  91. $CurrentOffset += 2;
  92. if ($TagLength == 0x3F) {
  93. $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4));
  94. $CurrentOffset += 4;
  95. }
  96. unset($TagData);
  97. $TagData['offset'] = $CurrentOffset;
  98. $TagData['size'] = $TagLength;
  99. $TagData['id'] = $TagID;
  100. $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength);
  101. switch ($TagID) {
  102. case 0: // end of movie
  103. break 2;
  104. case 9: // Set background color
  105. //$ThisFileInfo['swf']['tags'][] = $TagData;
  106. $ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT));
  107. break;
  108. default:
  109. if ($ReturnAllTagData) {
  110. $ThisFileInfo['swf']['tags'][] = $TagData;
  111. }
  112. break;
  113. }
  114. $CurrentOffset += $TagLength;
  115. }
  116. return true;
  117. }
  118. }
  119. ?>