download getid3.swf.php
Language: PHP
LOC: 82
Project Info
Tunez
Server: SourceForge
Type: cvs
...tunez\tunez\tunez\html\id3\
   getid3.aac.php
   getid3.ape.php
   getid3.asf.php
   getid3.au.php
   getid3.avr.php
   getid3.bmp.php
   getid3.bonk.php
   getid3.check.php
   getid3.exe.php
   getid3.flac.php
   getid3.frames.php
   getid3.functions.php
   getid3.getimagesize.php
   getid3.gif.php
   getid3.id3v1.php
   getid3.id3v2.php
   getid3.iso.php
   getid3.jpg.php
   getid3.la.php
   getid3.lookup.php
   getid3.lpac.php
   getid3.lyrics3.php
   getid3.matroska.php
   getid3.midi.php
   getid3.mod.php
   getid3.monkey.php
   getid3.mp3.php
   getid3.mpc.php
   getid3.mpeg.php
   getid3.nsv.php
   getid3.ogg.php
   getid3.ogginfo.php
   getid3.optimfrog.php
   getid3.php
   getid3.png.php
   getid3.putid3.php
   getid3.quicktime.php
   getid3.rar.php
   getid3.real.php
   getid3.rgad.php
   getid3.riff.php
   getid3.shorten.php
   getid3.swf.php
   getid3.thumbnail.php
   getid3.voc.php
   getid3.vqf.php
   getid3.write.php
   getid3.zip.php

<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org>               //
//  available at http://getid3.sourceforge.net                ///
//            or http://www.getid3.org                        ///
/////////////////////////////////////////////////////////////////
//                                                             //
// getid3.swf.php - part of getID3()                           //
// See getid3.readme.txt for more details                      //
//                                                             //
/////////////////////////////////////////////////////////////////

function getSWFHeaderFilepointer(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) {
	$ThisFileInfo['fileformat']          = 'swf';
	$ThisFileInfo['video']['dataformat'] = 'swf';

	// http://www.openswf.org/spec/SWFfileformat.html

	fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);

	$SWFfileData = fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data

	$ThisFileInfo['swf']['header']['signature']   = substr($SWFfileData, 0, 3);
	switch ($ThisFileInfo['swf']['header']['signature']) {
		case 'FWS':
			$ThisFileInfo['swf']['header']['compressed'] = false;
			break;

		case 'CWS':
			$ThisFileInfo['swf']['header']['compressed'] = true;
			break;

		default:
			$ThisFileInfo['error'] .= "\n".'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['swf']['header']['signature'].'"';
			unset($ThisFileInfo['swf']);
			unset($ThisFileInfo['fileformat']);
			return false;
			break;
	}
	$ThisFileInfo['swf']['header']['version']      = LittleEndian2Int(substr($SWFfileData, 3, 1));
	$ThisFileInfo['swf']['header']['length']       = LittleEndian2Int(substr($SWFfileData, 4, 4));

	if ($ThisFileInfo['swf']['header']['compressed']) {

		if ($UncompressedFileData = @gzuncompress(substr($SWFfileData, 8))) {

			$SWFfileData = substr($SWFfileData, 0, 8).$UncompressedFileData;

		} else {

			$ThisFileInfo['error'] .= "\n".'Error decompressing compressed SWF data';
			return false;

		}

	}

	$FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3;
	$FrameSizeDataLength   = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8);
	$FrameSizeDataString   = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT);
	for ($i = 1; $i < $FrameSizeDataLength; $i++) {
		$FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
	}
	list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
	$ThisFileInfo['swf']['header']['frame_width']  = Bin2Dec($X2);
	$ThisFileInfo['swf']['header']['frame_height'] = Bin2Dec($Y2);

	// http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
	// Next in the header is the frame rate, which is kind of weird.
	// It is supposed to be stored as a 16bit integer, but the first byte
	// (or last depending on how you look at it) is completely ignored.
	// Example: 0x000C  ->  0x0C  ->  12     So the frame rate is 12 fps.

	// Byte at (8 + $FrameSizeDataLength) is always zero and ignored
	$ThisFileInfo['swf']['header']['frame_rate']  = LittleEndian2Int(substr($SWFfileData,  9 + $FrameSizeDataLength, 1));
	$ThisFileInfo['swf']['header']['frame_count'] = LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2));

	$ThisFileInfo['video']['frame_rate']         = $ThisFileInfo['swf']['header']['frame_rate'];
	$ThisFileInfo['video']['resolution_x']       = round($ThisFileInfo['swf']['header']['frame_width']  / 20);
	$ThisFileInfo['video']['resolution_y']       = round($ThisFileInfo['swf']['header']['frame_height'] / 20);
	$ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;

	if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) {
		$ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate'];
	}


	// SWF tags

	$CurrentOffset = 12 + $FrameSizeDataLength;
	$SWFdataLength = strlen($SWFfileData);

	while ($CurrentOffset < $SWFdataLength) {

		$TagIDTagLength = LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2));
		$TagID     = ($TagIDTagLength & 0xFFFC) >> 6;
		$TagLength = ($TagIDTagLength & 0x003F);
		$CurrentOffset += 2;
		if ($TagLength == 0x3F) {
			$TagLength = LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4));
			$CurrentOffset += 4;
		}

		unset($TagData);
		$TagData['offset'] = $CurrentOffset;
		$TagData['size']   = $TagLength;
		$TagData['id']     = $TagID;
		$TagData['data']   = substr($SWFfileData, $CurrentOffset, $TagLength);
		switch ($TagID) {
			case 0: // end of movie
				break 2;

			case 9: // Set background color
				//$ThisFileInfo['swf']['tags'][] = $TagData;
				$ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT));
				break;

			default:
				if ($ReturnAllTagData) {
					$ThisFileInfo['swf']['tags'][] = $TagData;
				}
				break;
		}

		$CurrentOffset += $TagLength;
	}

	return true;
}

?>

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us