关闭

所有视频格式转换为flv

576人阅读 评论(0) 收藏 举报

class EncodeFlv{
 
 private static $instance;
 
 private $config;
 
 private $ffmpeg,$mdi;
 
 private $strResult = array(),$runningResult = array();
 
 private $from,$to;
 
 private $cmd = array();
 
 public static function instance($from = '',$to = ''){
  if (!function_exists('exec')){
   die('视频转换需求函数被禁用');
  }
  if (!$from){
   die('未提供来源文件');
  }elseif(!is_file($from)){
   die('无效来源文件');
  }
  if (!$to){
   $filedir = dirname($from);
   $filename = basename($from,'.'.pathinfo($from,PATHINFO_EXTENSION));
   $to = $filedir.DIRECTORY_SEPARATOR.$filename.'.flv';
  }elseif('flv' != pathinfo($to,PATHINFO_EXTENSION)){
   $to .= '.flv';
  }
  if(is_file($to)){
   die('目标同名文件已存在');
  }
  
  self::$instance = new self;
  list(self::$instance->from,self::$instance->to) = array($from,$to);
  return self::$instance;
 }
 
 public function config(array $config){
  //var_dump($config);
  //echo is_file($config['ffmpeg']);
  if (isset($config['ffmpeg']) && is_file($config['ffmpeg'])){
   $this->ffmpeg = $config['ffmpeg'];
  }else{
   die('请传入正确的ffmpeg.exe工具路径');
  }
  if (isset($config['mdi']) && is_file($config['mdi'])){
   $this->mdi = $config['mdi'];
  }else{
   die('请传入正确的mdi.exe工具路径');
  }
  $this->config = $config;
  return $this;
 }
 
 public function encode($del = true){
  set_time_limit(0);
  
  if (!is_array($this->config)){
   $config = array(
    'ffmpeg'=>'exec'.DIRECTORY_SEPARATOR.'ffmpeg.exe',
    'mdi'=>'exec'.DIRECTORY_SEPARATOR.'flvmdi.exe'
   );
   $this->config($config);
  }
  
  $this->cmd['ffmpeg'] = $this->ffmpeg.' -i '.$this->from.' '.$this->to;
  $this->cmd['mdi'] = $this->mdi.' '.$this->to;
  
  $strResult[] = exec($this->cmd['ffmpeg'],$runningResul[]);
  if (!is_file($this->to)){
   die(var_dump($strResult,$runningResul));
  }
  $strResult[] = exec($this->cmd['mdi'],$runningResul[]);
  
  if ($del){
   @unlink($this->from);
  }
  
  return $this->to;
 }
}

 

用法:

$content = EncodeFlv::instance(源文件路径)->config(array(

'ffmpeg'=>ffmpeg.exe的路径,

'mdi'=>flvmdi.exe的路径

))->encode();

 

ffmpeg.exe和flvmdi.exe另请下载,

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1173577次
    • 积分:10620
    • 等级:
    • 排名:第1589名
    • 原创:186篇
    • 转载:96篇
    • 译文:1篇
    • 评论:88条
    最新评论