宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应

[FFmpeg]ffmpeg基于phpcms程序的在线转换视频exec函数版

2016-10-13 00:16:48 点击量:31 标签: 收藏本文

[FFmpeg]ffmpeg基于phpcms程序的在线转换视频exec函数版

程序为phpcms,你可以修改下做到你的项目中.此为在线转换,非上一版本的bat批处理版

  1. <?php 
  2. require dirname(__FILE__).'/include/common.inc.php'; 
  3. if($PHPSESSID)  
  4. { 
  5.     session_id($PHPSESSID); 
  6.     session_start(); 
  7. } 
  8. if($auth) set_cookie('auth', $auth); 
  9. if(!get_cookie('cookietime') && $cookietime) set_cookie('cookietime', $cookietime); 
  10. require_once 'admin/model_field.class.php'; 
  11. $field = new model_field($modelid); 
  12. $info = $field->get($fieldid); 
  13. if(!$info) showmessage('指定的字段不存在!'); 
  14. $upload_allowext = $info['upload_allowext']; 
  15. $upload_maxsize = $info['upload_maxsize']*1024; 
  16.  
  17. require_once 'attachment.class.php'; 
  18. $attachment = new attachment(); 
  19.  
  20. if($dosubmit) 
  21. { 
  22.     $aid = $attachment->upload('Filedata', $upload_allowext, $upload_maxsize); 
  23.     if($aid) 
  24.     { 
  25.     $filename = $attachment->uploadedfiles[0]['filename']; 
  26.         $fileurl = UPLOAD_URL.$attachment->uploadedfiles[0]['filepath']; 
  27.         $houzhui = $attachment->uploadedfiles[0]['fileext']; 
  28. /*      if($houzhui == 'rmvb' || $houzhui == 'rm'){ 
  29.         exit($filename.'|'.$fileurl); 
  30.         }*/ 
  31.         if($houzhui != 'flv') 
  32.         { 
  33.         $mpeg = PHPCMS_ROOT."FFmpeg/ffmpeg.exe"; 
  34.         $fromFile = PHPCMS_ROOT.$fileurl; 
  35.         //$time = date("Y",TIME).'/'.date("md",TIME).'/'; 
  36.         $file = $attachment->uploadedfiles[0]['filepath']; 
  37.         $name = explode('.',$file); 
  38.         $filename1 = $name[0]; 
  39.         $flvName = PHPCMS_ROOT.UPLOAD_URL.$filename1.".flv"; 
  40.         $flvWith = 320;  
  41.         $flvHeight = 240; 
  42. set_time_limit(0); 
  43.         exec("$mpeg -i $fromFile -y -ab 28 -ar 22050 -b 200000 -r 24 -s $flvWith*$flvHeight $flvName",$mStatus,$status); 
  44. $image =  PHPCMS_ROOT.UPLOAD_URL.$filename1.".jpg"; 
  45. exec("$mpeg -i $fromFile -y -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 $image"); 
  46.         if($status == 0){ 
  47.          unlink(PHPCMS_ROOT.$fileurl); 
  48.          exit($filename.'|'.UPLOAD_URL.$filename1.".flv$".UPLOAD_URL.$filename1.".jpg"); 
  49.          } 
  50.          else{ 
  51.          exit("sorry!Conversion failed!!"); 
  52.          } 
  53.          } 
  54.         else{ 
  55.         exit($filename.'|'.$fileurl); 
  56.         } 
  57.     } 
  58.     else 
  59.     { 
  60.         if (isset($_FILES["Filedata"])) { 
  61.             echo $_FILES["Filedata"]["error"]; 
  62.             exit; 
  63.         } 
  64.     }    
  65. } 
  66. else  
  67. { 
  68.     include template('phpcms','flash_upload'); 
  69. } 
  70. ?> 

 主要看思路哈.说实话,php的exec相当难用,涉及到系统权限等一大堆乱七八糟的东西.有时候真是让人崩溃,最近严重崩溃中,把以前一个项目的代码拷贝来,防止电脑挂了或者电脑没在身边的时候看看.也给大家参考下,有不对的地方还望斧正.