用php將任何格式視頻轉(zhuǎn)為flv的代碼
更新時(shí)間:2009年09月03日 00:19:22 作者:
用php將任何格式視頻轉(zhuǎn)為flv的實(shí)現(xiàn)代碼,大家可以參考下。
復(fù)制代碼 代碼如下:
<?
define("ROOT_DIR",dirname(__FILE__));
class EcodeFlv {
var $fromFile; //上傳來的文件
var $toFilePath; //保存文件路徑
var $toPicPath; //保存圖片路徑
var $mpeg; //ffmpeg.exe文件的路徑
var $mencode; //mencode.exe文件的路徑
var $cmdToFile; //轉(zhuǎn)換文件命令
var $cmdToPic; //轉(zhuǎn)換圖片命令
var $toFileName; //轉(zhuǎn)換后的文件名
var $mpegComm; //ffmpeg.exe的轉(zhuǎn)換命令
var $mencodeComm; //mencode.exe的命令
var $mpegType;
var $mencodeType;
var $midi; //mdi.exe的路徑
var $cmdMidi; //mdi.exe的命令
//初始化類
function EcodeFlv($fromFile,$toFilePath,$toPicPath,$mpeg,$mencode,$midi) {
$this->mpegComm = false;
$this->mencodeComm = false;
$this->fromFile = $fromFile;
$this->toFilePath = $toFilePath;
$this->toPicPath = ROOT_DIR."/".$toPicPath;
$this->mpeg = ROOT_DIR.$mpeg;
$this->mencode = ROOT_DIR.$mencode;
$this->midi = ROOT_DIR.$midi;
$this->mpegType=array (
"audio/x-mpeg"=>".mp3",
"video/mpeg"=>".mpeg",
"video/3gpp"=>".3gp",
"video/x-ms-asf"=>".asf",
"video/x-msvideo"=>".avi"
);
$this->mencodeType = array(
"application/vnd.rn-realmedia"=>".rm",
"audio/x-pn-realaudio"=>".rmvb",
"audio/x-ms-wmv"=>".wmv",
);
}
//檢查文件類型
function checkType() {
if(function_exists(mime_content_type)){
return false;
}else{
//$contentType = mime_content_type($this->fromFile);
$exe = "D:\server\php\extras\magic";
$handel = new finfo(FILEINFO_MIME, $exe);
$contentType = $handel->file($this->fromFile);
}
foreach($this->mpegType as $index=>$key){
if($contentType == $index){
$name = md5(date("Ymd").tiime());
$this->toFileName = $name;
$this->$mpegComm = true;
return true;
}
}
foreach($this->mencodeType as $index=>$key){
if($contentType == $index){
$name = md5(date("Ymd").time());
$this->toFileName = $name;
$this->mencodeComm = true;
return true;
}else{
return false;
}
}
}
//設(shè)置文件,圖片大小
function setSize($flvSize,$picSize) {
$flvWidth = $flvSize[0];
$flvHeight = $flvSize[1];
$picWidth = $picSize[0];
$picHeight = $picSize[1];
$picName = $this->toPicPath.$this->toFileName.".jpg";
$flvName = $this->toFilePath.$this->toFileName.".flv";
$toMdi = ROOT_DIR."/".$flvName;
$size = $picWidth."x".$picHeight;
if($this->mpegComm){
$this->cmdToFile= "$this->mpeg -i $this->fromFile -y -ab 56 -ar 22050 -b 500 -r 15 -s $flvWith*$flvHeight $flvName";
}
elseif($this->mencodeComm){
$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";
}
$this->cmdToPic = "$this->mpeg -i $toMdi -y -f image2 -ss 8 -t 0.003 -s $size $picName";
$this->cmdMidi = "$this->midi $toMdi /k";
echo $this->cmdToPic;
}
//開始轉(zhuǎn)換
function toEcode() {
set_time_limit(0);
exec($this->cmdToFile,$flvStatus)
exec($this->cmdToPic,$picStatus);
exec($this->cmdMidi,$mStatus);
}
}
?>
相關(guān)文章
PHP操作redis實(shí)現(xiàn)的分頁列表,新增,刪除功能封裝類與用法示例
這篇文章主要介紹了PHP操作redis實(shí)現(xiàn)的分頁列表,新增,刪除功能封裝類與用法,結(jié)合實(shí)例形式分析了php針對(duì)redis數(shù)據(jù)庫基本的連接、查詢、添加、分頁等操作封裝與使用技巧,需要的朋友可以參考下2018-08-08詳解phpmyadmin相關(guān)配置與錯(cuò)誤解決
這篇文章主要介紹了詳解phpmyadmin相關(guān)配置與錯(cuò)誤解決的相關(guān)資料,希望通過本文能幫助到大家,讓大家遇到這種問題可以解決,需要的朋友可以參考下2017-10-10PHP連接數(shù)據(jù)庫實(shí)現(xiàn)頁面增刪改查效果
這篇文章主要介紹了如何利用PHP實(shí)現(xiàn)連接SQL數(shù)據(jù)庫,從而對(duì)頁面進(jìn)行增刪改查功能,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-03-03