<? <BR>define("ROOT_DIR",dirname(__FILE__)); <BR>class EcodeFlv { <BR>var $fromFile; //上传来的文件 <BR>var $toFilePath; //保存文件路径 <BR>var $toPicPath; //保存图片路径 <BR>var $mpeg; //ffmpeg.exe文件的路径 <BR>var $mencode; //mencode.exe文件的路径 <BR>var $cmdToFile; //转换文件命令 <BR>var $cmdToPic; //转换图片命令 <BR>var $toFileName; //转换后的文件名 <BR>var $mpegComm; //ffmpeg.exe的转换命令 <BR>var $mencodeComm; //mencode.exe的命令 <BR>var $mpegType; <BR>var $mencodeType; <BR>var $midi; //mdi.exe的路径 <BR>var $cmdMidi; //mdi.exe的命令 <BR>//初始化类 <BR>function EcodeFlv($fromFile,$toFilePath,$toPicPath,$mpeg,$mencode,$midi) { <BR>$this->mpegComm = false; <BR>$this->mencodeComm = false; <BR>$this->fromFile = $fromFile; <BR>$this->toFilePath = $toFilePath; <BR>$this->toPicPath = ROOT_DIR."/".$toPicPath; <BR>$this->mpeg = ROOT_DIR.$mpeg; <BR>$this->mencode = ROOT_DIR.$mencode; <BR>$this->midi = ROOT_DIR.$midi; <BR>$this->mpegType=array ( <BR>"audio/x-mpeg"=>".mp3", <BR>"video/mpeg"=>".mpeg", <BR>"video/3gpp"=>".3gp", <BR>"video/x-ms-asf"=>".asf", <BR>"video/x-msvideo"=>".avi" <BR>); <BR>$this->mencodeType = array( <BR>"application/vnd.rn-realmedia"=>".rm", <BR>"audio/x-pn-realaudio"=>".rmvb", <BR>"audio/x-ms-wmv"=>".wmv", <BR>); <BR>} <br><br>//检查文件类型 <br><br>function checkType() { <BR>if(function_exists(mime_content_type)){ <BR>return false; <BR>}else{ <BR>//$contentType = mime_content_type($this->fromFile); <BR>$exe = "D:\server\php\extras\magic"; <BR>$handel = new finfo(FILEINFO_MIME, $exe); <BR>$contentType = $handel->file($this->fromFile); <BR>} <BR>foreach($this->mpegType as $index=>$key){ <BR>if($contentType == $index){ <BR>$name = md5(date("Ymd").tiime()); <BR>$this->toFileName = $name; <BR>$this->$mpegComm = true; <BR>return true; <BR>} <BR>} <BR>foreach($this->mencodeType as $index=>$key){ <BR>if($contentType == $index){ <BR>$name = md5(date("Ymd").time()); <BR>$this->toFileName = $name; <BR>$this->mencodeComm = true; <BR>return true; <BR>}else<b>/本文来源gao@!dai!ma.com搞$$代^@码5网@</b><strong>搞代gaodaima码</strong>{ <BR>return false; <BR>} <BR>} <BR>} <br><br>//设置文件,图片大小 <BR>function setSize($flvSize,$picSize) { <BR>$flvWidth = $flvSize[0]; <BR>$flvHeight = $flvSize[1]; <BR>$picWidth = $picSize[0]; <BR>$picHeight = $picSize[1]; <BR>$picName = $this->toPicPath.$this->toFileName.".jpg"; <BR>$flvName = $this->toFilePath.$this->toFileName.".flv"; <BR>$toMdi = ROOT_DIR."/".$flvName; <BR>$size = $picWidth."x".$picHeight; <BR>if($this->mpegComm){ <BR>$this->cmdToFile= "$this->mpeg -i $this->fromFile -y -ab 56 -ar 22050 -b 500 -r 15 -s $flvWith*$flvHeight $flvName"; <BR>} <BR>elseif($this->mencodeComm){ <BR>$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"; <BR>} <BR>$this->cmdToPic = "$this->mpeg -i $toMdi -y -f image2 -ss 8 -t 0.003 -s $size $picName"; <BR>$this->cmdMidi = "$this->midi $toMdi /k"; <BR>echo $this->cmdToPic; <BR>} <br><br>//开始转换 <BR>function toEcode() { <BR>set_time_limit(0); <BR>exec($this->cmdToFile,$flvStatus) <BR>exec($this->cmdToPic,$picStatus); <BR>exec($this->cmdMidi,$mStatus); <BR>} <br><br>} <BR>?><BR>