Extension to php-ffmpeg to provide greater control over mapped output https://packagist.org/packages/danjones000/ffmpeg-mappable-media
Find a file
2013-07-03 18:24:20 +02:00
docs Fix typo 2013-04-21 18:08:29 +02:00
src/FFMpeg Remove unused namespace 2013-07-03 18:14:33 +02:00
tests Add ExecutableNotFoundException 2013-07-03 14:13:29 +02:00
.gitignore added support for retrieving progress information via helpers 2012-12-04 17:19:58 +01:00
.travis.yml Re-enable build on PHP 5.5 2013-07-03 18:24:20 +02:00
buildAPI.sh Add API tool and configuration 2012-05-31 12:19:23 +02:00
CHANGELOG.md Bump symfony dependency to 2.1 2013-05-30 16:58:14 +02:00
composer.json Add branch alias 2013-06-25 21:52:37 +02:00
composer.lock Remove unused dependencies 2013-06-25 10:08:47 +02:00
LICENSE Add License 2012-04-13 14:34:53 +02:00
phpunit-functional.xml.dist Version 0.3 2013-06-25 10:03:20 +02:00
phpunit.xml.dist Version 0.3 2013-06-25 10:03:20 +02:00
README.md Update README to version 0.3 2013-07-03 18:14:44 +02:00
sami_configuration.php Update API name 2012-05-31 12:29:33 +02:00
vendors.win.php Add vendors script for window CI 2012-04-17 20:32:30 +02:00

#PHP FFmpeg

Build Status

An Object Oriented library to convert video/audio files with FFmpeg / AVConv.

Check another amazing repo : PHP FFMpeg extras, you will find lots of Audio/Video formats there.

Installation

The recommended way to install PHP-FFMpeg is through Composer.

{
    "require": {
        "php-ffmpeg/php-ffmpeg": "~0.3.0"
    }
}

Basic Usage

Documentation

This documentation is an introduction to discover the API. It's recommended to browse the source code as it is self-documented.

FFMpeg

FFMpeg\FFMpeg is the main object to use to manipulate medias. To build it, use the static FFMpeg\FFMpeg::create :

$ffmpeg = FFMpeg\FFMpeg::create();

FFMpeg will autodetect ffmpeg and ffprobe binaries. If you want to give binary paths explicitely, you can pass an array as configuration. A Psr\Logger\LoggerInterface can also be passed to log binary executions.

$ffmpeg = FFMpeg\FFMpeg::create(array(
    'ffmpeg.binaries'  => '/opt/local/ffmpeg/bin/ffmpeg',
    'ffprobe.binaries' => '/opt/local/ffmpeg/bin/ffprobe',
    'timeout'          => 3600, // The timeout for the underlying process
    'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
), $logger);

Manipulate media

FFMpeg\FFMpeg creates media based on file paths. To open a file path, use the FFMpeg\FFMpeg::open method.

$ffmpeg->open('video.mpeg');

Two types of media can be resolved : FFMpeg\Media\Audio and FFMpeg\Media\Video. A third type, FFMpeg\Media\Frame, is available through videos.

Video

Transcoding

You can transcode videos using the FFMpeg\Media\Video:save method. You will pass a FFMpeg\Format\FormatInterface for that.

$format = new Format\Video\X264();
$format->on('progress', function ($video, $format, $percentage) {
    echo "$percentage % transcoded";
});

$video->save($format, 'video.avi');

Transcoding progress can be monitored in realtime, see Format documentation below for more informations.

Extracting image

You can extract a frame at any timecode using the FFMpeg\Media\Video::frame method.

This code return a FFMpeg\Media\Frame instance corresponding to the second 42. You can pass any FFMpeg\Coordinate\TimeCode as argument, see dedicated documentation below for more information.

$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42));
$frame->saveAs('image.jpg');
Filters

Audio

Transcoding
Filters

Frame

Filters

Formats

A format implements FFMpeg\Format\FormatInterface. To save to a video file, use FFMpeg\Format\VideoInterface, and FFMpeg\Format\AudioInterface for audio files.

Format can also extends FFMpeg\Format\ProgressableInterface to get realtime informations about the transcoding.

Predefined formats already provide progress informations as events.

$format = new Format\Video\X264();
$format->on('progress', function ($video, $format, $percentage) {
    echo "$percentage % transcoded";
});

$video->save($format, 'video.avi');

The callback provided for the event can be any callable.

Coordinates

FFMpeg use many units for time and space coordinates.

FFMpeg\Coordinate\AspectRatio

FFMpeg\Coordinate\Dimension

FFMpeg\Coordinate\FrameRate

FFMpeg\Coordinate\Point

FFMpeg\Coordinate\TimeCode

##Usage Example

$x264 = new X264();
$x264->setDimensions(320, 240);

$ffmpeg->open('Video.mpeg')
    ->encode($new WebM(), 'file.webm')
    ->encode($x264, 'file.mp4')
    ->encode($new Ogg(), 'file.ogv')
    ->close();

##Getting progress information

$progressHelper = new FFMpeg\Helper\AudioProgressHelper(function($percent, $remaining, $rate) {
	echo "Current progress: " . $percent "%\n";
	echo "Remaining time: " . $remaining " seconds\n";
});

$ffmpeg->open('Audio.wav')
	->attachHelper($progressHelper)
    ->encode(new Mp3(), 'file.mp3')
    ->close();

##Using with Silex Microframework

use FFMpeg\SilexServiceProvider;
use Silex\Application;

$app = new Application();
$app->register(new FFMpegServiceProvider());

API Browser

Browse the API

License

This project is licensed under the MIT license.