最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

ffmpeg-php将视频格式转为flv格式实现代码

时间:2014-09-03 11:12来源:未知 作者:最模板zuimoban 点击: 次
本文章介绍了一个插件利用ffmpeg-php将视频格式转为flv格式,这样很多格式的视频我们都可以利用这个插件来实现格式转换,以下是一个参考类,平台使用windows,代码如下: define( ROOT_DIR ,dirn

本文章介绍了一个插件利用ffmpeg-php将视频格式转为flv格式,这样很多格式的视频我们都可以利用这个插件来实现格式转换,以下是一个参考类,平台使用windows,代码如下:

  1. define("ROOT_DIR",dirname(__FILE__)); 
  2. class EcodeFlv { 
  3. var $fromFile;   //上传来的文件 
  4. var $toFilePath;  //保存文件路径 
  5. var $toPicPath;  //保存图片路径 
  6. var $mpeg; //ffmpeg程序文件的路径 
  7. var $mencode; //mencode程序文件的路径 
  8. var $cmdToFile; //转换文件命令 
  9. var $cmdToPic;  //转换图片命令 
  10. var $toFileName; //转换后的文件名 
  11. var $mpegComm; //ffmpeg.exe的转换命令 
  12. var $mencodeComm; //mencode.exe的命令 
  13. var $mpegType; 
  14. var $mencodeType; 
  15. var $midi; //mdi.exe的路径 
  16. var $cmdMidi; //mdi.exe的命令 
  17. //初始化类 
  18. function EcodeFlv($fromFile,$toFilePath,$toPicPath,$mpeg,$mencode,$midi) { 
  19. $this->mpegComm = false; 
  20. $this->mencodeComm = false; 
  21. $this->fromFile = $fromFile; 
  22. $this->toFilePath = $toFilePath; 
  23. $this->toPicPath = ROOT_DIR."/".$toPicPath; 
  24. $this->mpeg = ROOT_DIR.$mpeg; 
  25. $this->mencode = ROOT_DIR.$mencode; 
  26. $this->midi = ROOT_DIR.$midi; 
  27. $this->mpegType=array ( 
  28. "audio/x-mpeg"=>".mp3", 
  29. "video/mpeg"=>".mpeg", 
  30. "video/3gpp"=>".3gp", 
  31. "video/x-ms-asf"=>".asf", 
  32. "video/x-msvideo"=>".avi" 
  33. ); 
  34. $this->mencodeType = array( 
  35. "application/vnd.rn-realmedia"=>".rm", 
  36. "audio/x-pn-realaudio"=>".rmvb", 
  37. "audio/x-ms-wmv"=>".wmv", 
  38. ); 
  39. } //检查文件类型 
  40.  
  41. function checkType() { 
  42. if(function_exists(mime_content_type)){ 
  43. return false; 
  44. }else{ 
  45. //$contentType = mime_content_type($this->fromFile); 
  46. $exe = "D:serverphpextrasmagic"; 
  47. $handel = new finfo(FILEINFO_MIME, $exe); 
  48. $contentType =  $handel->file($this->fromFile); 
  49. } 
  50. foreach($this->mpegType as $index=>$key){ 
  51. if($contentType == $index){ 
  52. $name = md5(date("Ymd").tiime()); 
  53. $this->toFileName = $name; 
  54. $this->$mpegComm = true; 
  55. return true; 
  56. } 
  57. } 
  58. foreach($this->mencodeType as $index=>$key){ 
  59. if($contentType == $index){ 
  60. $name = md5(date("Ymd").time()); 
  61. $this->toFileName = $name; 
  62. $this->mencodeComm = true; 
  63. return true; 
  64. }else{ 
  65. return false; 
  66. } 
  67. } 
  68. } 
  69.  
  70. //设置文件,图片大小">图片大小 
  71. function setSize($flvSize,$picSize) { 
  72. $flvWidth = $flvSize[0]; 
  73. $flvHeight = $flvSize[1]; 
  74. $picWidth = $picSize[0]; 
  75. $picHeight = $picSize[1]; 
  76. $picName = $this->toPicPath.$this->toFileName.".jpg"; 
  77. $flvName = $this->toFilePath.$this->toFileName.".flv"; 
  78. $toMdi = ROOT_DIR."/".$flvName; 
  79. $size = $picWidth."x".$picHeight; 
  80. if($this->mpegComm){ 
  81. $this->cmdToFile= "$this->mpeg -i $this->fromFile -y -ab 56 -ar 22050 -b 500 -r 15 -s $flvWith*$flvHeight $flvName"; 
  82. } 
  83. elseif($this->mencodeComm){ 
  84. $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"; 
  85. } 
  86. $this->cmdToPic = "$this->mpeg -i $toMdi -y -f image2 -ss 8 -t 0.003 -s $size $picName"; 
  87. $this->cmdMidi = "$this->midi $toMdi /k"; 
  88. echo $this->cmdToPic; 
  89. }//开源代码vcphp.com 
  90.  
  91. //开始转换 
  92. function toEcode() { 
  93. set_time_limit(0); 
  94. exec($this->cmdToFile,$flvStatus) 
  95. exec($this->cmdToPic,$picStatus); 
  96. exec($this->cmdMidi,$mStatus); 
  97. } 
  98.  
  99. } 
  100.  
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容