InBlock.gifInBlock.gifdefine("ROOT_DIR",dirname(__FILE__));    
InBlock.gifclass EcodeFlv {    
InBlock.gif    var $fromFile;     //上传来的文件    
InBlock.gif    var $toFilePath;    //保存文件路径    
InBlock.gif    var $toPicPath;    //保存图片路径    
InBlock.gif    var $mpeg; //ffmpeg.exe文件的路径    
InBlock.gif    var $mencode; //mencode.exe文件的路径    
InBlock.gif    var $cmdToFile; //转换文件命令    
InBlock.gif    var $cmdToPic;    //转换图片命令    
InBlock.gif    var $toFileName; //转换后的文件名    
InBlock.gif    var $mpegComm; //ffmpeg.exe的转换命令    
InBlock.gif    var $mencodeComm; //mencode.exe的命令    
InBlock.gif    var $mpegType;    
InBlock.gif    var $mencodeType;    
InBlock.gif    var $midi; //mdi.exe的路径    
InBlock.gif    var $cmdMidi; //mdi.exe的命令    
InBlock.gif//初始化类    
InBlock.gif    function EcodeFlv($fromFile,$toFilePath,$toPicPath,$mpeg,$mencode,$midi) {    
InBlock.gif     $this->mpegComm = false;    
InBlock.gif     $this->mencodeComm = false;    
InBlock.gif     $this->fromFile = $fromFile;    
InBlock.gif     $this->toFilePath = $toFilePath;    
InBlock.gif     $this->toPicPath = ROOT_DIR."/".$toPicPath;    
InBlock.gif     $this->mpeg = ROOT_DIR.$mpeg;    
InBlock.gif     $this->mencode = ROOT_DIR.$mencode;    
InBlock.gif     $this->midi = ROOT_DIR.$midi;    
InBlock.gif     $this->mpegType=array (    
InBlock.gif             "audio/x-mpeg"=>".mp3",    
InBlock.gif             "video/mpeg"=>".mpeg",    
InBlock.gif             "video/3gpp"=>".3gp",    
InBlock.gif             "video/x-ms-asf"=>".asf",    
InBlock.gif             "video/x-msvideo"=>".avi"    
InBlock.gif     );    
InBlock.gif     $this->mencodeType = array(    
InBlock.gif             "application/vnd.rn-realmedia"=>".rm",    
InBlock.gif             "audio/x-pn-realaudio"=>".rmvb",    
InBlock.gif             "audio/x-ms-wmv"=>".wmv",    
InBlock.gif     );    
InBlock.gif    }    
InBlock.gif    
InBlock.gif//检查文件类型    
InBlock.gif    
InBlock.gif    function checkType() {    
InBlock.gif        if(function_exists(mime_content_type)){    
InBlock.gif         return false;    
InBlock.gif        }else{    
InBlock.gif         //$contentType = mime_content_type($this->fromFile);    
InBlock.gif         $exe = "D:\server\php\extras\magic";    
InBlock.gif         $handel = new finfo(FILEINFO_MIME, $exe);    
InBlock.gif         $contentType =    $handel->file($this->fromFile);    
InBlock.gif        }    
InBlock.gif        foreach($this->mpegType as $index=>$key){    
InBlock.gif         if($contentType == $index){    
InBlock.gif            $name = md5(date("Ymd").tiime());    
InBlock.gif            $this->toFileName = $name;    
InBlock.gif            $this->$mpegComm = true;    
InBlock.gif            return true;    
InBlock.gif         }    
InBlock.gif        }    
InBlock.gif        foreach($this->mencodeType as $index=>$key){    
InBlock.gif            if($contentType == $index){    
InBlock.gif            $name = md5(date("Ymd").time());    
InBlock.gif            $this->toFileName = $name;    
InBlock.gif            $this->mencodeComm = true;    
InBlock.gif            return true;    
InBlock.gif                 }else{    
InBlock.gif             return false;    
InBlock.gif            }    
InBlock.gif        }    
InBlock.gif    }    
InBlock.gif    
InBlock.gif//设置文件,图片大小    
InBlock.gif    function setSize($flvSize,$picSize) {    
InBlock.gif        $flvWidth = $flvSize[0];    
InBlock.gif        $flvHeight = $flvSize[1];    
InBlock.gif        $picWidth = $picSize[0];    
InBlock.gif        $picHeight = $picSize[1];    
InBlock.gif        $picName = $this->toPicPath.$this->toFileName.".jpg";    
InBlock.gif        $flvName = $this->toFilePath.$this->toFileName.".flv";    
InBlock.gif        $toMdi = ROOT_DIR."/".$flvName;    
InBlock.gif        $size = $picWidth."x".$picHeight;    
InBlock.gif        if($this->mpegComm){    
InBlock.gif            $this->cmdToFile= "$this->mpeg -i $this->fromFile -y -ab 56 -ar 22050 -b 500 -r 15 -s $flvWith*$flvHeight $flvName";    
InBlock.gif        }    
InBlock.gif        elseif($this->mencodeComm){    
InBlock.gif            $this->cmdToFile = "$this->mencode $this->fromFile    -vf scale=$flvWidth:$flvHeight -ffourcc FLV1 -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=70:acodec=mp3:abitrate=56:dia=-1 -ofps 25 -srate 22050 -oac mp3lame -o $flvName";    
InBlock.gif        }    
InBlock.gif        $this->cmdToPic = "$this->mpeg -i $toMdi -y -f p_w_picpath2 -ss 8 -t 0.003 -s $size $picName";    
InBlock.gif        $this->cmdMidi = "$this->midi $toMdi /k";    
InBlock.gif        echo $this->cmdToPic;    
InBlock.gif    }    
InBlock.gif    
InBlock.gif//开始转换    
InBlock.gif    function toEcode() {    
InBlock.gif        set_time_limit(0);    
InBlock.gif        exec($this->cmdToFile,$flvStatus)    
InBlock.gif        exec($this->cmdToPic,$picStatus);    
InBlock.gif        exec($this->cmdMidi,$mStatus);    
InBlock.gif    }    
InBlock.gif    
InBlock.gif }    
InBlock.gif?>