用php将任何格式视频转为flv的代码

 更新时间:2009年09月03日 00:19:22   作者:  
用php将任何格式视频转为flv的实现代码,大家可以参考下。
复制代码 代码如下:

<?
define("ROOT_DIR",dirname(__FILE__));
class EcodeFlv {
var $fromFile; //上传来的文件
var $toFilePath; //保存文件路径
var $toPicPath; //保存图片路径
var $mpeg; //ffmpeg.exe文件的路径
var $mencode; //mencode.exe文件的路径
var $cmdToFile; //转换文件命令
var $cmdToPic; //转换图片命令
var $toFileName; //转换后的文件名
var $mpegComm; //ffmpeg.exe的转换命令
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;
}
}
}

//设置文件,图片大小
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;
}

//开始转换
function toEcode() {
set_time_limit(0);
exec($this->cmdToFile,$flvStatus)
exec($this->cmdToPic,$picStatus);
exec($this->cmdMidi,$mStatus);
}

}
?>

相关文章

  • 有关phpmailer的详细介绍及使用方法

    有关phpmailer的详细介绍及使用方法

    有关phpmailer的用法,有需要的朋友不妨参考下
    2013-01-01
  • PHP中round()函数对浮点数进行四舍五入的方法

    PHP中round()函数对浮点数进行四舍五入的方法

    这篇文章主要介绍了PHP中round()函数对浮点数进行四舍五入的方法,通过详尽的实例对round()函数的各种常见用法进行了归纳整理,是非常实用的技巧,需要的朋友可以参考下
    2014-11-11
  • php计算两个日期相差天数的方法

    php计算两个日期相差天数的方法

    这篇文章主要介绍了php计算两个日期相差天数的方法,实例分析了php操作日期的技巧,需要的朋友可以参考下
    2015-03-03
  • PHP使用mysql_fetch_object从查询结果中获取对象集的方法

    PHP使用mysql_fetch_object从查询结果中获取对象集的方法

    这篇文章主要介绍了PHP使用mysql_fetch_object从查询结果中获取对象集的方法,实例分析了php操作mysql_fetch_object查询数据库的技巧,非常具有实用价值,需要的朋友可以参考下
    2015-03-03
  • 几个有用的php字符串过滤,转换函数代码

    几个有用的php字符串过滤,转换函数代码

    几个有用的php字符串过滤,转换函数,主要是一些字符的安全处理与字符串处理
    2012-05-05
  • PHP 之Section与Cookie使用总结

    PHP 之Section与Cookie使用总结

    Session 将信息保存在服务器上.服务器在接受到唯一的SESSION_ID后,根据这个ID获取相关数据,然后将信息传递到客户端(浏览器).Cookie 是将所有信息以文本的形式存在本地文件,并由客户端(浏览器)进行管理与维护
    2012-09-09
  • php开启多进程的方法

    php开启多进程的方法

    这篇文章主要介绍了php开启多进程的方法,实例分析了php线程的使用技巧,需要的朋友可以参考下
    2015-03-03
  • PHP+swoole+linux实现系统监控和性能优化操作示例

    PHP+swoole+linux实现系统监控和性能优化操作示例

    这篇文章主要介绍了PHP+swoole+linux实现系统监控和性能优化操作,结合实例形式分析了php启动swoole及Linux性能监控相关操作技巧,需要的朋友可以参考下
    2019-04-04
  • php的$_FILES的临时储存文件与回收机制实测过程

    php的$_FILES的临时储存文件与回收机制实测过程

    上传文件是怎么个原理,大概的想了下,应该是一种回收机制:点击了临时文件空间,那么,php自身应该自己维护这块空间的回收,具体的测试过程如下,感兴趣的朋友可以参考下哈
    2013-07-07
  • PHP编程函数安全篇

    PHP编程函数安全篇

    关于脚本安全这个话题好像永远没完没了,如果你经常到国外的各种各样的bugtraq上,你会发现有一半以上都和脚本相关,诸如SQL injection,XSS,Path Disclosure,Remote commands execution这样的字眼比比皆是,我们看了之后的用途难道仅仅是抓肉鸡?
    2013-01-01

最新评论