b-b3rn4rd / phplame
此包的最新版本(dev-master)没有可用的许可证信息。
PHP LAME 是 LAME (MP3 编码器) 的 PHP 封装。
dev-master
2014-12-23 08:49 UTC
Requires
- php: >=5.3
Requires (Dev)
- mikey179/vfsstream: >=1
- phpunit/phpunit: >=3.7
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2020-01-10 15:02:18 UTC
README
PHP LAME 是 LAME MP3 编码器的 PHP 封装。它提供了一个方便的接口将 wav 文件编码为 mp3。
为了使用这个库,您需要下载并安装 LAME。请在此处阅读安装说明:http://wiki.audacityteam.org/wiki/Lame_Installation#GNU.2FLinux.2FUnix_instructions。
安装
使用 Composer 安装 PHP LAME 封装
{ "require": { "b-b3rn4rd/phplame": "dev-master" } }
##使用示例
使用预设设置编码单个文件
<?php require 'vendor/autoload.php'; use Lame\Lame; use Lame\Settings; // encoding type $encoding = new Settings\Encoding\Preset(); $encoding->setType(Settings\Encoding\Preset::TYPE_STANDARD); // lame settings $settings = new Settings\Settings($encoding); // lame wrapper $lame = new Lame('/usr/bin/lame', $settings); try { $lame->encode("/home/bernard/Music/B.W. Souls - Marvin's Groove.wav", "/home/bernard/Music/mp3/B.W. Souls - Marvin's Groove.mp3"); } catch(\RuntimeException $e) { var_dump($e->getMessage()); }
上面的示例执行了以下命令:/usr/bin/lame --preset standard '/home/bernard/Music/B.W. Souls - Marvin'\\''s Groove.wav' '/home/bernard/Music/mp3/B.W. Souls - Marvin'\\''s Groove.mp3'
使用 VBR 编码和附加设置编码多个文件
<?php require 'vendor/autoload.php'; use Lame\Lame; use Lame\Settings; // encoding type $encoding = new Settings\Encoding\VBR(); $encoding->setMinBitrate(320); // lame settings $settings = new Settings\Settings($encoding); $settings->setAlgorithmQuality(0); // lame wrapper $lame = new Lame('/usr/bin/lame', $settings); try { $lame->encode("/home/bernard/Music/*.wav", "/home/bernard/Music/mp3/"); } catch(\RuntimeException $e) { var_dump($e->getMessage()); }
对于在 $inputfile
路径中找到的每个文件,都执行了 Lame 命令,以下选项:/usr/bin/lame -q 0 -b 320 '/home/bernard/Music/B.W. Souls - Marvin'\\''s Groove.wav' '/home/bernard/Music/mp3/B.W. Souls - Marvin'\\''s Groove.mp3'
等...
使用手动指定的设置和可选回调编码单个文件
<?php require 'vendor/autoload.php'; use Lame\Lame; use Lame\Settings; // encoding type $encoding = new Settings\Encoding\NullEncoding(); // lame settings $settings = new Settings\Settings($encoding, array( '-V' => 0, '--vbr-new' => true, '-q' => 0, '-m' => 's' )); // lame wrapper $lame = new Lame('/usr/bin/lame', $settings); try { $lame->encode("/home/bernard/Music/Benny Gordon - Give A Damn.wav", "/home/bernard/Music/mp3/", function($inputfile, $outputfile) { unlink($inputfile); }); } catch(\RuntimeException $e) { var_dump($e->getMessage()); }
此示例使用可选回调在编码后删除 $inputfile
。回调在每个文件编码后执行。
编码类型
PHP LAME 提供以下编码接口
- \Lame\Settings\Bitrate\ABR — 平均比特率编码 (ABR) 相关选项
- \Lame\Settings\Bitrate\CBR — 恒定比特率编码 (CBR) 相关选项
- \Lame\Settings\Encoding\VBR — \Lame\Settings\Encoding\VBR 相关选项
- \Lame\Settings\Encoding\Preset — 预配置设置
- \Lame\Settings\Encoding\NullEncoding — 无编码