Php-ffmpeg Windows 上的“未知编码器 libfaac”
Php-ffmpeg “Unknown encoder libfaac” on Windows
我正在使用 laravel 4.2。
我正在开发一个用户可以上传视频的项目,我需要对其进行转码,使其可以在所有类型的设备上播放。
为了转码,我在我的项目中添加了来自 git hub 的 php-ffmpeg 包。根据说明,我从 http://ffmpeg.zeranoe.com/builds 下载了 ffmpeg 包,并将 ffmpeg.exe 的路径设置到环境变量 Path 中。
现在,我尝试使用以下代码对上传的视频进行转码:
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new FFMpeg\Format\Video\X264();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);
但它给出如下错误:
[ERROR] ffmpeg version N-70767-gd24af70 Copyright (c) 2000-2015 the FFmpeg developers
[ERROR] built with gcc 4.9.2 (GCC)
[ERROR] configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
[ERROR] libavutil 54. 20.100 / 54. 20.100
[ERROR] libavcodec 56. 28.100 / 56. 28.100
[ERROR] libavformat 56. 25.101 / 56. 25.101
[ERROR] libavdevice 56. 4.100 / 56. 4.100
[ERROR] libavfilter 5. 12.100 / 5. 12.100
[ERROR] libswscale 3. 1.101 / 3. 1.101
[ERROR] libswresample 1. 1.100 / 1. 1.100
[ERROR] libpostproc 53. 3.100 / 53. 3.100
[ERROR]
[ERROR] Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://localhost/ohvideo-ftp/public/temp/5ZPlIuU1AIgz8RR4p0bs.mp4':
[ERROR] Metadata:
[ERROR] major_brand : mp42
[ERROR] minor_version : 0
[ERROR] compatible_brands: mp42mp41isomavc1
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] Duration: 00:00:30.12, start: 0.000000, bitrate: 417 kb/s
[ERROR] Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 381 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Video Handler
[ERROR] encoder : AVC Coding
[ERROR] Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Audio Handler
[ERROR] Unknown encoder 'libfaac'
[ERROR]
{"error":{"type":"FFMpeg\Exception\RuntimeException","message":"Encoding failed","file":"F:\wamp\www\ohvideo-ftp\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\Video.php","line":168}}
经过大量搜索后,我找到了解决方案 here 的 link,请注意
Zeranoe's ffmpeg does not contain libfaac support due to that encoder
requiring --enable-nonfree which would result in a non-redistributable
build.
我没有得到解决方案。任何人都可以帮助我克服这个问题吗?
编辑:(工作代码如下)
我创建了一个 CustomVideo
class 和 class FFMpeg\Format\Video\X264()
一样的,如下所示:
class CustomVideo extends FFMpeg\Format\Video\DefaultVideo
{
/** @var boolean */
private $bframesSupport = true;
public function __construct($audioCodec = 'libmp3lame', $videoCodec = 'libx264')
{
$this
->setAudioCodec($audioCodec)
->setVideoCodec($videoCodec);
}
/**
* {@inheritDoc}
*/
public function supportBFrames()
{
return $this->bframesSupport;
}
/**
* @param $support
*
* @return X264
*/
public function setBFramesSupport($support)
{
$this->bframesSupport = $support;
return $this;
}
/**
* {@inheritDoc}
*/
public function getAvailableAudioCodecs()
{
return array('libmp3lame');
}
/**
* {@inheritDoc}
*/
public function getAvailableVideoCodecs()
{
return array('libx264');
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 2;
}
/**
* @return int
*/
public function getModulus()
{
return 2;
}
}
并更新了代码以对视频进行转码,如下所示:
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new CustomVideo();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);
已解决 Unknown encoder libfaac
错误。
由于许可问题,未包含所需的库。
Zeranoe FFmpeg - Why dont the builds include FAAC, FDK-AAC, libaacplus?
These libraries are not compatible with the GPL license and cannot be
included without licensing the build as nonfree. A nonfree build
cannot be publicly distributed.
您有以下解决方案:
- 使用其他音频编解码器而不是 AAC。例如,有一个 LAME MP3 编码器。
- 编译你自己的 FFmpeg 版本,添加你想要的所有库
参见 FFmpeg Compilation Guide
我刚刚遇到了一些问题,但通过在构造函数中定义一个新的音频编解码器解决了它。而不是问题中的这一行...
$format = new FFMpeg\Format\Video\X264();
我用过...
$format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');
official recommendation是使用原生的FFmpeg AAC编码器或者libfdk_aac代替:
$format = new FFMpeg\Format\Video\X264('aac', 'libx264');
我正在使用 laravel 4.2。
我正在开发一个用户可以上传视频的项目,我需要对其进行转码,使其可以在所有类型的设备上播放。
为了转码,我在我的项目中添加了来自 git hub 的 php-ffmpeg 包。根据说明,我从 http://ffmpeg.zeranoe.com/builds 下载了 ffmpeg 包,并将 ffmpeg.exe 的路径设置到环境变量 Path 中。
现在,我尝试使用以下代码对上传的视频进行转码:
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new FFMpeg\Format\Video\X264();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);
但它给出如下错误:
[ERROR] ffmpeg version N-70767-gd24af70 Copyright (c) 2000-2015 the FFmpeg developers
[ERROR] built with gcc 4.9.2 (GCC)
[ERROR] configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
[ERROR] libavutil 54. 20.100 / 54. 20.100
[ERROR] libavcodec 56. 28.100 / 56. 28.100
[ERROR] libavformat 56. 25.101 / 56. 25.101
[ERROR] libavdevice 56. 4.100 / 56. 4.100
[ERROR] libavfilter 5. 12.100 / 5. 12.100
[ERROR] libswscale 3. 1.101 / 3. 1.101
[ERROR] libswresample 1. 1.100 / 1. 1.100
[ERROR] libpostproc 53. 3.100 / 53. 3.100
[ERROR]
[ERROR] Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://localhost/ohvideo-ftp/public/temp/5ZPlIuU1AIgz8RR4p0bs.mp4':
[ERROR] Metadata:
[ERROR] major_brand : mp42
[ERROR] minor_version : 0
[ERROR] compatible_brands: mp42mp41isomavc1
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] Duration: 00:00:30.12, start: 0.000000, bitrate: 417 kb/s
[ERROR] Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 381 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Video Handler
[ERROR] encoder : AVC Coding
[ERROR] Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Audio Handler
[ERROR] Unknown encoder 'libfaac'
[ERROR]
{"error":{"type":"FFMpeg\Exception\RuntimeException","message":"Encoding failed","file":"F:\wamp\www\ohvideo-ftp\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\Video.php","line":168}}
经过大量搜索后,我找到了解决方案 here 的 link,请注意
Zeranoe's ffmpeg does not contain libfaac support due to that encoder requiring --enable-nonfree which would result in a non-redistributable build.
我没有得到解决方案。任何人都可以帮助我克服这个问题吗?
编辑:(工作代码如下)
我创建了一个 CustomVideo
class 和 class FFMpeg\Format\Video\X264()
一样的,如下所示:
class CustomVideo extends FFMpeg\Format\Video\DefaultVideo
{
/** @var boolean */
private $bframesSupport = true;
public function __construct($audioCodec = 'libmp3lame', $videoCodec = 'libx264')
{
$this
->setAudioCodec($audioCodec)
->setVideoCodec($videoCodec);
}
/**
* {@inheritDoc}
*/
public function supportBFrames()
{
return $this->bframesSupport;
}
/**
* @param $support
*
* @return X264
*/
public function setBFramesSupport($support)
{
$this->bframesSupport = $support;
return $this;
}
/**
* {@inheritDoc}
*/
public function getAvailableAudioCodecs()
{
return array('libmp3lame');
}
/**
* {@inheritDoc}
*/
public function getAvailableVideoCodecs()
{
return array('libx264');
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 2;
}
/**
* @return int
*/
public function getModulus()
{
return 2;
}
}
并更新了代码以对视频进行转码,如下所示:
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new CustomVideo();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);
已解决 Unknown encoder libfaac
错误。
由于许可问题,未包含所需的库。
Zeranoe FFmpeg - Why dont the builds include FAAC, FDK-AAC, libaacplus?
These libraries are not compatible with the GPL license and cannot be included without licensing the build as nonfree. A nonfree build cannot be publicly distributed.
您有以下解决方案:
- 使用其他音频编解码器而不是 AAC。例如,有一个 LAME MP3 编码器。
- 编译你自己的 FFmpeg 版本,添加你想要的所有库 参见 FFmpeg Compilation Guide
我刚刚遇到了一些问题,但通过在构造函数中定义一个新的音频编解码器解决了它。而不是问题中的这一行...
$format = new FFMpeg\Format\Video\X264();
我用过...
$format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');
official recommendation是使用原生的FFmpeg AAC编码器或者libfdk_aac代替:
$format = new FFMpeg\Format\Video\X264('aac', 'libx264');