在Windows上安装php ffmpeg

时间:2017-06-21 06:27:39

标签: php video ffmpeg

我下载了ffmpeg并安装了作曲家。当我尝试使用基本使用代码时,我收到此错误。在bin文件夹中,我有ffmpegffplayffprobe个exe文件。我还为c:ffmpeg\bin设置了环境变量。

  

致命错误:未捕获的异常
  '炼金\ BinaryDriver \异常\ ExecutableNotFoundException'如果找不到消息'可执行文件,建议:c:\ ffmpeg \ bin \ binffprobe.exe'在C:\ xampp \ htdocs \ core \ vendor \ alchemy \ binary-driver \ src \ Alchemy \ BinaryDriver \ AbstractBinary.php:160堆栈跟踪:#0
   C:\ xampp \ htdocs \ core \ vendor \ php-ffmpeg \ php-ffmpeg \ src \ FFMpeg \ Driver \ FFProbeDriver.php(48):Alchemy \ BinaryDriver \ AbstractBinary :: load(' c:\ ffmpeg \ bin \ b ...',NULL,Object(Alchemy \ BinaryDriver \ Configuration))#1 C:\ xampp \ htdocs \ core \ vendor \ php-ffmpeg \ php-ffmpeg \ src \ FFMpeg \ FFProbe.php (207):FFMpeg \ Driver \ FFProbeDriver :: create(Array,NULL)#2 C:\ xampp \ htdocs \ core \ vendor \ php-ffmpeg \ php-ffmpeg \ src \ FFMpeg \ FFMpeg.php(117):FFMpeg \ FFProbe :: create(Array,NULL,NULL)#3 C:\ xampp \ htdocs \ core \ demo2.php(9):FFMpeg \ FFMpeg :: create(Array)#4 {main}下一个异常' FFmpeg的\异常\ ExecutableNotFoundException'消息'无法加载FFProbe'在C:\ xampp \ htdocs \ core \ vendor \ php-ffmpeg \ php-ffmpeg \ src \ FFMpeg \ Driver \ FFProbeDriver.php:50堆栈跟踪:#0 C:在C:\ xampp \ htdocs \ core \ vendor \第50行的php-ffmpeg \ php-ffmpeg \ src \ FFMpeg \ Driver \ FFProbeDriver.php

这是我的PHP代码;

  require_once 'vendor/autoload.php';
  $ffmpeg = \FFMpeg\FFMpeg::create([
'ffmpeg.binaries'  => 'c:\ffmpeg\bin\binffmpeg.exe',
'ffprobe.binaries' => 'c:\ffmpeg\bin\binffprobe.exe' 
  ]);

  $video = $ffmpeg->open('video.mpg');
 $video
->filters()
->resize(new FFMpeg\Coordinate\Dimension(320, 240))
->synchronize();
 $video
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
->save('frame.jpg');
$video
->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');`

1 个答案:

答案 0 :(得分:1)

确保您提供正确的二进制路径,此错误只是因为脚本无法找到二进制文件,

所以也许如果没有错,你给的是错误的exe文件名

只需更改此

$ffmpeg = \FFMpeg\FFMpeg::create([
    'ffmpeg.binaries'  => 'c:\ffmpeg\bin\binffmpeg.exe',
    'ffprobe.binaries' => 'c:\ffmpeg\bin\binffprobe.exe' 
]);

进入这个

$ffmpeg = \FFMpeg\FFMpeg::create([
    'ffmpeg.binaries'  => 'c:\ffmpeg\bin\ffmpeg.exe',
    'ffprobe.binaries' => 'c:\ffmpeg\bin\ffprobe.exe' 
]);

你要重复bin \ bin两次,

  

C:\ ffmpeg的\ BIN \ binffprobe.exe

祝你好运,

这里只是一个将视频转换为mp3的示例代码

require_once 'vendor/autoload.php';
$ffmpeg = \FFMpeg\FFMpeg::create([
     'ffmpeg.binaries'  => 'ffmpeg\bin\ffmpeg.exe',
     'ffprobe.binaries' => 'ffmpeg\bin\ffprobe.exe' 
]);

$video = $ffmpeg->open('video.mp4');
//just in case you want to save thumbnail from video
$video
   ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(300))
   ->save('frame.jpg');
//extract audio
$video->save(new FFMpeg\Format\Audio\Mp3, 'audio.mp3');