annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.swf.php @ 28:118cb614cf18 judyates tip

judy bio.
author Robert McIntyre <rlm@mit.edu>
date Tue, 29 Dec 2015 16:26:18 -0800
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio-video.swf.php |
rlm@3 18 // | module for analyzing Macromedia Shockwave Flash files. |
rlm@3 19 // | dependencies: zlib support in PHP |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio-video.swf.php,v 1.2 2006/11/02 10:48:00 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_swf extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 $getid3->info['fileformat'] = 'swf';
rlm@3 34 $getid3->info['video']['dataformat'] = 'swf';
rlm@3 35
rlm@3 36 // http://www.openswf.org/spec/SWFfileformat.html
rlm@3 37
rlm@3 38 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 39
rlm@3 40 $swf_file_data = fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
rlm@3 41
rlm@3 42 $getid3->info['swf']['header']['signature'] = substr($swf_file_data, 0, 3);
rlm@3 43 switch ($getid3->info['swf']['header']['signature']) {
rlm@3 44
rlm@3 45 case 'FWS':
rlm@3 46 $getid3->info['swf']['header']['compressed'] = false;
rlm@3 47 break;
rlm@3 48
rlm@3 49 case 'CWS':
rlm@3 50 $getid3->info['swf']['header']['compressed'] = true;
rlm@3 51 break;
rlm@3 52
rlm@3 53 default:
rlm@3 54 throw new getid3_exception('Expecting "FWS" or "CWS" at offset '.$getid3->info['avdataoffset'].', found "'.$getid3->info['swf']['header']['signature'].'"');
rlm@3 55 }
rlm@3 56 $getid3->info['swf']['header']['version'] = getid3_lib::LittleEndian2Int($swf_file_data{3});
rlm@3 57 $getid3->info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($swf_file_data, 4, 4));
rlm@3 58
rlm@3 59 if (!function_exists('gzuncompress')) {
rlm@3 60 throw new getid3_exception('getid3_swf requires --zlib support in PHP.');
rlm@3 61 }
rlm@3 62
rlm@3 63 if ($getid3->info['swf']['header']['compressed']) {
rlm@3 64
rlm@3 65 if ($uncompressed_file_data = @gzuncompress(substr($swf_file_data, 8))) {
rlm@3 66 $swf_file_data = substr($swf_file_data, 0, 8).$uncompressed_file_data;
rlm@3 67
rlm@3 68 } else {
rlm@3 69 throw new getid3_exception('Error decompressing compressed SWF data');
rlm@3 70 }
rlm@3 71
rlm@3 72 }
rlm@3 73
rlm@3 74 $frame_size_bits_per_value = (ord(substr($swf_file_data, 8, 1)) & 0xF8) >> 3;
rlm@3 75 $frame_size_data_length = ceil((5 + (4 * $frame_size_bits_per_value)) / 8);
rlm@3 76 $frame_size_data_string = str_pad(decbin(ord($swf_file_data[8]) & 0x07), 3, '0', STR_PAD_LEFT);
rlm@3 77
rlm@3 78 for ($i = 1; $i < $frame_size_data_length; $i++) {
rlm@3 79 $frame_size_data_string .= str_pad(decbin(ord(substr($swf_file_data, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
rlm@3 80 }
rlm@3 81
rlm@3 82 list($x1, $x2, $y1, $y2) = explode("\n", wordwrap($frame_size_data_string, $frame_size_bits_per_value, "\n", 1));
rlm@3 83 $getid3->info['swf']['header']['frame_width'] = bindec($x2);
rlm@3 84 $getid3->info['swf']['header']['frame_height'] = bindec($y2);
rlm@3 85
rlm@3 86 // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
rlm@3 87 // Next in the header is the frame rate, which is kind of weird.
rlm@3 88 // It is supposed to be stored as a 16bit integer, but the first byte
rlm@3 89 // (or last depending on how you look at it) is completely ignored.
rlm@3 90 // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps.
rlm@3 91
rlm@3 92 // Byte at (8 + $frame_size_data_length) is always zero and ignored
rlm@3 93 $getid3->info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int($swf_file_data[9 + $frame_size_data_length]);
rlm@3 94 $getid3->info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($swf_file_data, 10 + $frame_size_data_length, 2));
rlm@3 95
rlm@3 96 $getid3->info['video']['frame_rate'] = $getid3->info['swf']['header']['frame_rate'];
rlm@3 97 $getid3->info['video']['resolution_x'] = intval(round($getid3->info['swf']['header']['frame_width'] / 20));
rlm@3 98 $getid3->info['video']['resolution_y'] = intval(round($getid3->info['swf']['header']['frame_height'] / 20));
rlm@3 99 $getid3->info['video']['pixel_aspect_ratio'] = (float)1;
rlm@3 100
rlm@3 101 if (($getid3->info['swf']['header']['frame_count'] > 0) && ($getid3->info['swf']['header']['frame_rate'] > 0)) {
rlm@3 102 $getid3->info['playtime_seconds'] = $getid3->info['swf']['header']['frame_count'] / $getid3->info['swf']['header']['frame_rate'];
rlm@3 103 }
rlm@3 104
rlm@3 105
rlm@3 106 // SWF tags
rlm@3 107
rlm@3 108 $current_offset = 12 + $frame_size_data_length;
rlm@3 109 $swf_data_length = strlen($swf_file_data);
rlm@3 110
rlm@3 111 while ($current_offset < $swf_data_length) {
rlm@3 112
rlm@3 113 $tag_ID_tag_length = getid3_lib::LittleEndian2Int(substr($swf_file_data, $current_offset, 2));
rlm@3 114 $tag_ID = ($tag_ID_tag_length & 0xFFFC) >> 6;
rlm@3 115 $tag_length = ($tag_ID_tag_length & 0x003F);
rlm@3 116 $current_offset += 2;
rlm@3 117 if ($tag_length == 0x3F) {
rlm@3 118 $tag_length = getid3_lib::LittleEndian2Int(substr($swf_file_data, $current_offset, 4));
rlm@3 119 $current_offset += 4;
rlm@3 120 }
rlm@3 121
rlm@3 122 unset($tag_data);
rlm@3 123 $tag_data['offset'] = $current_offset;
rlm@3 124 $tag_data['size'] = $tag_length;
rlm@3 125 $tag_data['id'] = $tag_ID;
rlm@3 126 $tag_data['data'] = substr($swf_file_data, $current_offset, $tag_length);
rlm@3 127 switch ($tag_ID) {
rlm@3 128
rlm@3 129 case 0: // end of movie
rlm@3 130 break 2;
rlm@3 131
rlm@3 132 case 9: // Set background color
rlm@3 133 $getid3->info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($tag_data['data'])), 6, '0', STR_PAD_LEFT));
rlm@3 134 break;
rlm@3 135
rlm@3 136 default:
rlm@3 137 /*
rlm@3 138 if ($ReturnAllTagData) {
rlm@3 139 $getid3->info['swf']['tags'][] = $tag_data;
rlm@3 140 }
rlm@3 141 */
rlm@3 142 break;
rlm@3 143 }
rlm@3 144
rlm@3 145 $current_offset += $tag_length;
rlm@3 146 }
rlm@3 147
rlm@3 148 return true;
rlm@3 149 }
rlm@3 150
rlm@3 151 }
rlm@3 152
rlm@3 153
rlm@3 154 ?>