服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > php教程 >

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

时间:2016-05-11 00:20来源: 作者: 点击:
本文章介绍了一个插件利用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. foreach($this->mpegType as $index=>$key){ 
  50. if($contentType == $index){ 
  51. $name = md5(date("Ymd").tiime()); 
  52. $this->toFileName = $name
  53. $this->$mpegComm = true; 
  54. return true; 
  55. foreach($this->mencodeType as $index=>$key){ 
  56. if($contentType == $index){ 
  57. $name = md5(date("Ymd").time()); 
  58. $this->toFileName = $name
  59. $this->mencodeComm = true; 
  60. return true; 
  61. }else
  62. return false; 
  63.  
  64. //设置文件,图片大小">图片大小 
  65. function setSize($flvSize,$picSize) { 
  66. $flvWidth = $flvSize[0]; 
  67. $flvHeight = $flvSize[1]; 
  68. $picWidth = $picSize[0]; 
  69. $picHeight = $picSize[1]; 
  70. $picName = $this->toPicPath.$this->toFileName.".jpg"
  71. $flvName = $this->toFilePath.$this->toFileName.".flv"
  72. $toMdi = ROOT_DIR."/".$flvName
  73. $size = $picWidth."x".$picHeight
  74. if($this->mpegComm){ 
  75. $this->cmdToFile= "$this->mpeg -i $this->fromFile -y -ab 56 -ar 22050 -b 500 -r 15 -s $flvWith*$flvHeight $flvName"
  76. elseif($this->mencodeComm){ 
  77. $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"
  78. $this->cmdToPic = "$this->mpeg -i $toMdi -y -f image2 -ss 8 -t 0.003 -s $size $picName"
  79. $this->cmdMidi = "$this->midi $toMdi /k"
  80. echo $this->cmdToPic; 
  81. }//开源代码最模板zuimoban.com 
  82.  
  83. //开始转换 
  84. function toEcode() { 
  85. set_time_limit(0); 
  86. exec($this->cmdToFile,$flvStatus
  87. exec($this->cmdToPic,$picStatus); 
  88. exec($this->cmdMidi,$mStatus); 
  89.  
  90.  
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容