All pastes #485000 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-05-12 20:27 UTC
rendered paste body
function _readframe() {	if ($this->debug) print($this->debugbeg . "_readframe()<HR>\n");	$file = $this->file;	if (! ($f = fopen($file, 'rb')) ) {	    $this->error = 'Unable to open ' . $file;	    if ($this->debug) print($this->debugend);	    return false;	}	$this->filesize = filesize($file);	do {	    while (fread($f,1) != Chr(255)) { // Find the first frame		//if ($this->debug) echo "Find...\n";		if (feof($f)) {		    $this->error = 'No mpeg frame found';		    if ($this->debug) print($this->debugend);		    return false;		}	    }	    fseek($f, ftell($f) - 1); // back up one byte	    $frameoffset = ftell($f);	    $r = fread($f, 4);	    // Binary to Hex to a binary sting. ugly but best I can think of.	    $bits = unpack('H*bits', $r);	    $bits =  base_convert($bits['bits'],16,2);	} while (!$bits[8] and !$bits[9] and !$bits[10]); // 1st 8 bits true from the while	if ($this->debug) print('Bits: ' . $bits . "\n");	$this->frameoffset = $frameoffset;	fclose($f);	if ($bits[11] == 0) {	    $this->mpeg_ver = "2.5";	    $bitrates = array(		    '1' => array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0),		    '2' => array(0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0),		    '3' => array(0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0),			     );	} else if ($bits[12] == 0) {	    $this->mpeg_ver = "2";	    $bitrates = array(		    '1' => array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0),		    '2' => array(0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0),		    '3' => array(0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0),			     );	} else {	    $this->mpeg_ver = "1";	    $bitrates = array(		    '1' => array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0),		    '2' => array(0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384, 0),		    '3' => array(0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 0),			     );	}	if ($this->debug) print('MPEG' . $this->mpeg_ver . "\n");	$layer = array(		array(0,3),		array(2,1),		      );	$this->layer = $layer[$bits[13]][$bits[14]];	if ($this->debug) print('layer: ' . $this->layer . "\n");	if ($bits[15] == 0) {	    // It's backwards, if the bit is not set then it is protected.	    if ($this->debug) print("protected (crc)\n");	    $this->crc = true;	}	$bitrate = 0;	if ($bits[16] == 1) $bitrate += 8;	if ($bits[17] == 1) $bitrate += 4;	if ($bits[18] == 1) $bitrate += 2;	if ($bits[19] == 1) $bitrate += 1;	$this->bitrate = $bitrates[$this->layer][$bitrate];	$frequency = array(		'1' => array(		    '0' => array(44100, 48000),		    '1' => array(32000, 0),			    ),		'2' => array(		    '0' => array(22050, 24000),		    '1' => array(16000, 0),			    ),		'2.5' => array(		    '0' => array(11025, 12000),		    '1' => array(8000, 0),			      ),		  );	$this->frequency = $frequency[$this->mpeg_ver][$bits[20]][$bits[21]];	$this->padding = $bits[22];	$this->private = $bits[23];	$mode = array(		array('Stereo', 'Joint Stereo'),		array('Dual Channel', 'Mono'),		     );	$this->mode = $mode[$bits[24]][$bits[25]];	// XXX: I dunno what the mode extension is for bits 26,27	$this->copyright = $bits[28];	$this->original = $bits[29];	$emphasis = array(		array('none', '50/15ms'),		array('', 'CCITT j.17'),			 );	$this->emphasis = $emphasis[$bits[30]][$bits[31]];	if ($this->bitrate == 0) {	    $s = -1;	} else {	    $s = ((8*filesize($this->file))/1000) / $this->bitrate;        	}	$this->length = sprintf('%02d:%02d',floor($s/60),floor($s-(floor($s/60)*60)));	$this->lengths = (int)$s;	if ($this->debug) print($this->debugend);    } // _readframe()