Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.flv.php @ 3:3f6b44aa6b35 judyates
[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author | rlm |
---|---|
date | Mon, 22 Feb 2010 08:02:39 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.flv.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,574 @@ 1.4 +<?php 1.5 +// +----------------------------------------------------------------------+ 1.6 +// | PHP version 5 | 1.7 +// +----------------------------------------------------------------------+ 1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | 1.9 +// +----------------------------------------------------------------------+ 1.10 +// | This source file is subject to version 2 of the GPL license, | 1.11 +// | that is bundled with this package in the file license.txt and is | 1.12 +// | available through the world-wide-web at the following url: | 1.13 +// | http://www.gnu.org/copyleft/gpl.html | 1.14 +// +----------------------------------------------------------------------+ 1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | 1.16 +// +----------------------------------------------------------------------+ 1.17 +// | Authors: James Heinrich <infoØgetid3*org> | 1.18 +// | Allan Hansen <ahØartemis*dk> | 1.19 +// +----------------------------------------------------------------------+ 1.20 +// | module.archive.gzip.php | 1.21 +// | module for analyzing GZIP files | 1.22 +// | dependencies: NONE | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// | FLV module by Seth Kaufman <sethØwhirl-i.gig*com> | 1.25 +// | | 1.26 +// | * version 0.1 (26 June 2005) | 1.27 +// | | 1.28 +// | minor modifications by James Heinrich <infoØgetid3*org> | 1.29 +// | * version 0.1.1 (15 July 2005) | 1.30 +// | | 1.31 +// | Support for On2 VP6 codec and meta information by | 1.32 +// | Steve Webster <steve.websterØfeaturecreep*com> | 1.33 +// | * version 0.2 (22 February 2006) | 1.34 +// | | 1.35 +// | Modified to not read entire file into memory | 1.36 +// | by James Heinrich <infoØgetid3*org> | 1.37 +// | * version 0.3 (15 June 2006) | 1.38 +// | | 1.39 +// | Modifications by Allan Hansen <ahØartemis*dk> | 1.40 +// | Adapted module for PHP5 and getID3 2.0.0. | 1.41 +// +----------------------------------------------------------------------+ 1.42 +// 1.43 +// $Id: module.audio-video.flv.php,v 1.7 2006/11/10 11:20:12 ah Exp $ 1.44 + 1.45 + 1.46 + 1.47 +class getid3_flv extends getid3_handler 1.48 +{ 1.49 + 1.50 + const TAG_AUDIO = 8; 1.51 + const TAG_VIDEO = 9; 1.52 + const TAG_META = 18; 1.53 + 1.54 + const VIDEO_H263 = 2; 1.55 + const VIDEO_SCREEN = 3; 1.56 + const VIDEO_VP6 = 4; 1.57 + 1.58 + 1.59 + public function Analyze() 1.60 + { 1.61 + $info = &$this->getid3->info; 1.62 + 1.63 + $info['flv'] = array (); 1.64 + $info_flv = &$info['flv']; 1.65 + 1.66 + fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); 1.67 + 1.68 + $flv_data_length = $info['avdataend'] - $info['avdataoffset']; 1.69 + $flv_header = fread($this->getid3->fp, 5); 1.70 + 1.71 + $info['fileformat'] = 'flv'; 1.72 + $info_flv['header']['signature'] = substr($flv_header, 0, 3); 1.73 + $info_flv['header']['version'] = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1)); 1.74 + $type_flags = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1)); 1.75 + 1.76 + $info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04); 1.77 + $info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01); 1.78 + 1.79 + $frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4)); 1.80 + $flv_header_frame_length = 9; 1.81 + if ($frame_size_data_length > $flv_header_frame_length) { 1.82 + fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR); 1.83 + } 1.84 + 1.85 + $duration = 0; 1.86 + while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) { 1.87 + 1.88 + $this_tag_header = fread($this->getid3->fp, 16); 1.89 + 1.90 + $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); 1.91 + $tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1)); 1.92 + $data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3)); 1.93 + $timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3)); 1.94 + $last_header_byte = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1)); 1.95 + $next_offset = ftell($this->getid3->fp) - 1 + $data_length; 1.96 + 1.97 + switch ($tag_type) { 1.98 + 1.99 + case getid3_flv::TAG_AUDIO: 1.100 + if (!isset($info_flv['audio']['audioFormat'])) { 1.101 + $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; 1.102 + $info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10; 1.103 + $info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40; 1.104 + $info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80; 1.105 + } 1.106 + break; 1.107 + 1.108 + 1.109 + case getid3_flv::TAG_VIDEO: 1.110 + if (!isset($info_flv['video']['videoCodec'])) { 1.111 + $info_flv['video']['videoCodec'] = $last_header_byte & 0x07; 1.112 + 1.113 + $flv_video_header = fread($this->getid3->fp, 11); 1.114 + 1.115 + if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) { 1.116 + 1.117 + $picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7; 1.118 + $picture_size_type = $picture_size_type & 0x0007; 1.119 + $info_flv['header']['videoSizeType'] = $picture_size_type; 1.120 + 1.121 + switch ($picture_size_type) { 1.122 + case 0: 1.123 + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2)); 1.124 + $picture_size_enc <<= 1; 1.125 + $info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8; 1.126 + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2)); 1.127 + $picture_size_enc <<= 1; 1.128 + $info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8; 1.129 + break; 1.130 + 1.131 + case 1: 1.132 + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4)); 1.133 + $picture_size_enc <<= 1; 1.134 + $info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16; 1.135 + 1.136 + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4)); 1.137 + $picture_size_enc <<= 1; 1.138 + $info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16; 1.139 + break; 1.140 + 1.141 + case 2: 1.142 + $info['video']['resolution_x'] = 352; 1.143 + $info['video']['resolution_y'] = 288; 1.144 + break; 1.145 + 1.146 + case 3: 1.147 + $info['video']['resolution_x'] = 176; 1.148 + $info['video']['resolution_y'] = 144; 1.149 + break; 1.150 + 1.151 + case 4: 1.152 + $info['video']['resolution_x'] = 128; 1.153 + $info['video']['resolution_y'] = 96; 1.154 + break; 1.155 + 1.156 + case 5: 1.157 + $info['video']['resolution_x'] = 320; 1.158 + $info['video']['resolution_y'] = 240; 1.159 + break; 1.160 + 1.161 + case 6: 1.162 + $info['video']['resolution_x'] = 160; 1.163 + $info['video']['resolution_y'] = 120; 1.164 + break; 1.165 + 1.166 + default: 1.167 + $info['video']['resolution_x'] = 0; 1.168 + $info['video']['resolution_y'] = 0; 1.169 + break; 1.170 + } 1.171 + } 1.172 + } 1.173 + break; 1.174 + 1.175 + 1.176 + // Meta tag 1.177 + case getid3_flv::TAG_META: 1.178 + 1.179 + fseek($this->getid3->fp, -1, SEEK_CUR); 1.180 + $reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length))); 1.181 + $event_name = $reader->readData(); 1.182 + $info['meta'][$event_name] = $reader->readData(); 1.183 + unset($reader); 1.184 + 1.185 + $info['video']['frame_rate'] = @$info['meta']['onMetaData']['framerate']; 1.186 + $info['video']['resolution_x'] = @$info['meta']['onMetaData']['width']; 1.187 + $info['video']['resolution_y'] = @$info['meta']['onMetaData']['height']; 1.188 + break; 1.189 + 1.190 + default: 1.191 + // noop 1.192 + break; 1.193 + } 1.194 + 1.195 + if ($timestamp > $duration) { 1.196 + $duration = $timestamp; 1.197 + } 1.198 + 1.199 + fseek($this->getid3->fp, $next_offset, SEEK_SET); 1.200 + } 1.201 + 1.202 + if ($info['playtime_seconds'] = $duration / 1000) { 1.203 + $info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']; 1.204 + } 1.205 + 1.206 + if ($info_flv['header']['hasAudio']) { 1.207 + $info['audio']['codec'] = $this->FLVaudioFormat($info_flv['audio']['audioFormat']); 1.208 + $info['audio']['sample_rate'] = $this->FLVaudioRate($info_flv['audio']['audioRate']); 1.209 + $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']); 1.210 + 1.211 + $info['audio']['channels'] = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo 1.212 + $info['audio']['lossless'] = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed 1.213 + $info['audio']['dataformat'] = 'flv'; 1.214 + } 1.215 + if (@$info_flv['header']['hasVideo']) { 1.216 + $info['video']['codec'] = $this->FLVvideoCodec($info_flv['video']['videoCodec']); 1.217 + $info['video']['dataformat'] = 'flv'; 1.218 + $info['video']['lossless'] = false; 1.219 + } 1.220 + 1.221 + return true; 1.222 + } 1.223 + 1.224 + 1.225 + public static function FLVaudioFormat($id) { 1.226 + 1.227 + static $lookup = array( 1.228 + 0 => 'uncompressed', 1.229 + 1 => 'ADPCM', 1.230 + 2 => 'mp3', 1.231 + 5 => 'Nellymoser 8kHz mono', 1.232 + 6 => 'Nellymoser', 1.233 + ); 1.234 + return (@$lookup[$id] ? @$lookup[$id] : false); 1.235 + } 1.236 + 1.237 + 1.238 + public static function FLVaudioRate($id) { 1.239 + 1.240 + static $lookup = array( 1.241 + 0 => 5500, 1.242 + 1 => 11025, 1.243 + 2 => 22050, 1.244 + 3 => 44100, 1.245 + ); 1.246 + return (@$lookup[$id] ? @$lookup[$id] : false); 1.247 + } 1.248 + 1.249 + 1.250 + public static function FLVaudioBitDepth($id) { 1.251 + 1.252 + static $lookup = array( 1.253 + 0 => 8, 1.254 + 1 => 16, 1.255 + ); 1.256 + return (@$lookup[$id] ? @$lookup[$id] : false); 1.257 + } 1.258 + 1.259 + 1.260 + public static function FLVvideoCodec($id) { 1.261 + 1.262 + static $lookup = array( 1.263 + getid3_flv::VIDEO_H263 => 'Sorenson H.263', 1.264 + getid3_flv::VIDEO_SCREEN => 'Screen video', 1.265 + getid3_flv::VIDEO_VP6 => 'On2 VP6', 1.266 + ); 1.267 + return (@$lookup[$id] ? @$lookup[$id] : false); 1.268 + } 1.269 +} 1.270 + 1.271 + 1.272 + 1.273 +class AMFStream 1.274 +{ 1.275 + public $bytes; 1.276 + public $pos; 1.277 + 1.278 + 1.279 + public function AMFStream($bytes) { 1.280 + 1.281 + $this->bytes = $bytes; 1.282 + $this->pos = 0; 1.283 + } 1.284 + 1.285 + 1.286 + public function readByte() { 1.287 + 1.288 + return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); 1.289 + } 1.290 + 1.291 + 1.292 + public function readInt() { 1.293 + 1.294 + return ($this->readByte() << 8) + $this->readByte(); 1.295 + } 1.296 + 1.297 + 1.298 + public function readLong() { 1.299 + 1.300 + return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); 1.301 + } 1.302 + 1.303 + 1.304 + public function readDouble() { 1.305 + 1.306 + return getid3_lib::BigEndian2Float($this->read(8)); 1.307 + } 1.308 + 1.309 + 1.310 + public function readUTF() { 1.311 + 1.312 + $length = $this->readInt(); 1.313 + return $this->read($length); 1.314 + } 1.315 + 1.316 + 1.317 + public function readLongUTF() { 1.318 + 1.319 + $length = $this->readLong(); 1.320 + return $this->read($length); 1.321 + } 1.322 + 1.323 + 1.324 + public function read($length) { 1.325 + 1.326 + $val = substr($this->bytes, $this->pos, $length); 1.327 + $this->pos += $length; 1.328 + return $val; 1.329 + } 1.330 + 1.331 + 1.332 + public function peekByte() { 1.333 + 1.334 + $pos = $this->pos; 1.335 + $val = $this->readByte(); 1.336 + $this->pos = $pos; 1.337 + return $val; 1.338 + } 1.339 + 1.340 + 1.341 + public function peekInt() { 1.342 + 1.343 + $pos = $this->pos; 1.344 + $val = $this->readInt(); 1.345 + $this->pos = $pos; 1.346 + return $val; 1.347 + } 1.348 + 1.349 + 1.350 + public function peekLong() { 1.351 + 1.352 + $pos = $this->pos; 1.353 + $val = $this->readLong(); 1.354 + $this->pos = $pos; 1.355 + return $val; 1.356 + } 1.357 + 1.358 + 1.359 + public function peekDouble() { 1.360 + 1.361 + $pos = $this->pos; 1.362 + $val = $this->readDouble(); 1.363 + $this->pos = $pos; 1.364 + return $val; 1.365 + } 1.366 + 1.367 + 1.368 + public function peekUTF() { 1.369 + 1.370 + $pos = $this->pos; 1.371 + $val = $this->readUTF(); 1.372 + $this->pos = $pos; 1.373 + return $val; 1.374 + } 1.375 + 1.376 + 1.377 + public function peekLongUTF() { 1.378 + 1.379 + $pos = $this->pos; 1.380 + $val = $this->readLongUTF(); 1.381 + $this->pos = $pos; 1.382 + return $val; 1.383 + } 1.384 +} 1.385 + 1.386 + 1.387 + 1.388 +class AMFReader 1.389 +{ 1.390 + public $stream; 1.391 + 1.392 + public function __construct($stream) { 1.393 + 1.394 + $this->stream = $stream; 1.395 + } 1.396 + 1.397 + 1.398 + public function readData() { 1.399 + 1.400 + $value = null; 1.401 + 1.402 + $type = $this->stream->readByte(); 1.403 + 1.404 + switch($type) { 1.405 + // Double 1.406 + case 0: 1.407 + $value = $this->readDouble(); 1.408 + break; 1.409 + 1.410 + // Boolean 1.411 + case 1: 1.412 + $value = $this->readBoolean(); 1.413 + break; 1.414 + 1.415 + // String 1.416 + case 2: 1.417 + $value = $this->readString(); 1.418 + break; 1.419 + 1.420 + // Object 1.421 + case 3: 1.422 + $value = $this->readObject(); 1.423 + break; 1.424 + 1.425 + // null 1.426 + case 6: 1.427 + return null; 1.428 + break; 1.429 + 1.430 + // Mixed array 1.431 + case 8: 1.432 + $value = $this->readMixedArray(); 1.433 + break; 1.434 + 1.435 + // Array 1.436 + case 10: 1.437 + $value = $this->readArray(); 1.438 + break; 1.439 + 1.440 + // Date 1.441 + case 11: 1.442 + $value = $this->readDate(); 1.443 + break; 1.444 + 1.445 + // Long string 1.446 + case 13: 1.447 + $value = $this->readLongString(); 1.448 + break; 1.449 + 1.450 + // XML (handled as string) 1.451 + case 15: 1.452 + $value = $this->readXML(); 1.453 + break; 1.454 + 1.455 + // Typed object (handled as object) 1.456 + case 16: 1.457 + $value = $this->readTypedObject(); 1.458 + break; 1.459 + 1.460 + // Long string 1.461 + default: 1.462 + $value = '(unknown or unsupported data type)'; 1.463 + break; 1.464 + } 1.465 + 1.466 + return $value; 1.467 + } 1.468 + 1.469 + 1.470 + public function readDouble() { 1.471 + 1.472 + return $this->stream->readDouble(); 1.473 + } 1.474 + 1.475 + 1.476 + public function readBoolean() { 1.477 + 1.478 + return $this->stream->readByte() == 1; 1.479 + } 1.480 + 1.481 + 1.482 + public function readString() { 1.483 + 1.484 + return $this->stream->readUTF(); 1.485 + } 1.486 + 1.487 + 1.488 + public function readObject() { 1.489 + 1.490 + // Get highest numerical index - ignored 1.491 + $highestIndex = $this->stream->readLong(); 1.492 + 1.493 + $data = array(); 1.494 + 1.495 + while ($key = $this->stream->readUTF()) { 1.496 + // Mixed array record ends with empty string (0x00 0x00) and 0x09 1.497 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { 1.498 + // Consume byte 1.499 + $this->stream->readByte(); 1.500 + break; 1.501 + } 1.502 + 1.503 + $data[$key] = $this->readData(); 1.504 + } 1.505 + 1.506 + return $data; 1.507 + } 1.508 + 1.509 + 1.510 + public function readMixedArray() { 1.511 + 1.512 + // Get highest numerical index - ignored 1.513 + $highestIndex = $this->stream->readLong(); 1.514 + 1.515 + $data = array(); 1.516 + 1.517 + while ($key = $this->stream->readUTF()) { 1.518 + // Mixed array record ends with empty string (0x00 0x00) and 0x09 1.519 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { 1.520 + // Consume byte 1.521 + $this->stream->readByte(); 1.522 + break; 1.523 + } 1.524 + 1.525 + if (is_numeric($key)) { 1.526 + $key = (float) $key; 1.527 + } 1.528 + 1.529 + $data[$key] = $this->readData(); 1.530 + } 1.531 + 1.532 + return $data; 1.533 + } 1.534 + 1.535 + 1.536 + public function readArray() { 1.537 + 1.538 + $length = $this->stream->readLong(); 1.539 + 1.540 + $data = array(); 1.541 + 1.542 + for ($i = 0; $i < count($length); $i++) { 1.543 + $data[] = $this->readData(); 1.544 + } 1.545 + 1.546 + return $data; 1.547 + } 1.548 + 1.549 + 1.550 + public function readDate() { 1.551 + 1.552 + $timestamp = $this->stream->readDouble(); 1.553 + $timezone = $this->stream->readInt(); 1.554 + return $timestamp; 1.555 + } 1.556 + 1.557 + 1.558 + public function readLongString() { 1.559 + 1.560 + return $this->stream->readLongUTF(); 1.561 + } 1.562 + 1.563 + 1.564 + public function readXML() { 1.565 + 1.566 + return $this->stream->readLongUTF(); 1.567 + } 1.568 + 1.569 + 1.570 + public function readTypedObject() { 1.571 + 1.572 + $className = $this->stream->readUTF(); 1.573 + return $this->readObject(); 1.574 + } 1.575 +} 1.576 + 1.577 +?> 1.578 \ No newline at end of file