Felix Riesterer: FLV - Abmessungen und Aspect Ratio

Beitrag lesen

Lieber Klawischnigg,

ich habe mir das in eine handliche kleine Klasse verpackt. Falls es jemand außer mir einmal benutzen möchte, hier ist sie:

class FLVDimensionsChecker {  
  
    var $filename;  
    var $width;  
    var $height;  
    var $aspectRatio;  
    var $error = 'No video dimensions detected!';  
  
    function FLVDimensionsChecker($f) {  
        $this->filename = $f;  
  
        if (! file_exists($f)) {  
            $this->error = 'File not found!';  
            return;  
        }  
  
        $fh=fopen($f,'r');  
        $header=fread($fh,2048);  
        $w=strpos($header,'width');  
  
        if ($w !== false) {  
            $wString=substr($header,$w+7,4);  
            $width=$this->chr_num(dechex(ord(substr($wString,0,1))),2).$this->chr_num(dechex(ord(substr($wString,1,1))),2);  
            $h=strpos($header,'height');  
            $hString=substr($header,$h+8,4);  
            $height=$this->chr_num(dechex(ord(substr($hString,0,1))),2).$this->chr_num(dechex(ord(substr($hString,1,1))),2);  
            $wExp=hexdec(substr($this->chr_num($this->dec2hex(ord(substr($wString,0,1))),2),0,1))+1;  
            $wFaktor=pow(2,$wExp - 8);  
            $wA= pow(2,$wExp);  
            $wB= hexdec(substr($width,1,2)) * $wFaktor;  
            $hExp=hexdec(substr($this->chr_num($this->dec2hex(ord(substr($hString,0,1))),2),0,1))+1;  
            $hFaktor=pow(2,$hExp - 8);  
            $hA= pow(2,$hExp);  
            $hB= hexdec(substr($height,1,2)) * $hFaktor;  
            $this->width =$wA+$wB;  
            $this->height =$hA+$hB;  
            $this->aspectRatio =(($hA+$hB) != 0)?($wA+$wB)/($hA+$hB):0;  
            $this->error = '';  
        }  
    }  
  
    function dec2hex($_dec) {  
        $_hex=dechex($_dec);  
        if (strlen($_hex) < 2) {  
            $_hex='0'.$_hex;  
        }  
        return $_hex;  
    }  
  
    function chr_num($v,$hm){  
        $lv=strlen($v);  
        return $this->repl('0',$hm-$lv).$v;  
    }  
  
    function repl($_char,$_howmany){  
        $_tmpstr="";  
        for ($_i = 1;$_i <=$_howmany;$_i++) {  
            $_tmpstr=$_tmpstr.$_char;  
        }  
        return $_tmpstr;  
    }  
}

Liebe Grüße,

Felix Riesterer.

--
ie:% br:> fl:| va:) ls:[ fo:) rl:° n4:? de:> ss:| ch:? js:) mo:} zu:)