Coder Social home page Coder Social logo

phplame's Introduction

PHP LAME

Build Status Coverage Status

PHP LAME is a php wrapper for LAME MP3 encoder. It provides convenient interface to encode wav file(s) into mp3.

In order to use this library you will need to download & install LAME. Read here how to install it.

Installation


Install PHP LAME wrapper using Composer:

{
    "require": {
        "b-b3rn4rd/phplame": "dev-master"
    }
}

##Usage examples

Encode single file using preset settings

<?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());
} 

The example above executed following command: /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'

Encode multiple files using VBR encoding and additional settings

<?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());
} 

Lame command was executed for each file found in $inputfile path with following options: /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' etc...

Encode single file using manually specified settings and optional callback

<?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());
} 

This example uses optional callback to remove $inputfile after it was encoded. Callback is executed each time after a file has been encoded.

Encoding types


PHP LAME provides following encoding interfaces:

  • \Lame\Settings\Bitrate\ABR — Average Bitrate Encoding (ABR) related options
  • \Lame\Settings\Bitrate\CBR — Constant Bitrate Encoding (CBR) related options
  • \Lame\Settings\Encoding\VBR — \Lame\Settings\Encoding\VBR related options
  • \Lame\Settings\Encoding\Preset — Preconfigured settings
  • \Lame\Settings\Encoding\NullEncoding — no encoding

License

Unlicened

phplame's People

Contributors

b-b3rn4rd avatar perk11 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.