ffmpeg-mappable-media/README.md

192 lines
4.5 KiB
Markdown
Raw Normal View History

2012-04-13 12:12:24 +02:00
#PHP FFmpeg
[![Build Status](https://secure.travis-ci.org/alchemy-fr/PHP-FFmpeg.png?branch=master)](http://travis-ci.org/alchemy-fr/PHP-FFmpeg)
2013-07-03 18:14:44 +02:00
An Object Oriented library to convert video/audio files with FFmpeg / AVConv.
2012-04-13 14:16:50 +02:00
2012-06-21 11:42:45 +03:00
Check another amazing repo : [PHP FFMpeg extras](https://github.com/alchemy-fr/PHP-FFMpeg-Extras), you will find lots of Audio/Video formats there.
2013-07-03 18:14:44 +02:00
## Installation
2012-05-31 16:07:30 +02:00
2013-07-03 18:14:44 +02:00
The recommended way to install PHP-FFMpeg is through [Composer](https://getcomposer.org).
2012-05-31 16:25:42 +02:00
2013-07-03 18:14:44 +02:00
```json
{
"require": {
"php-ffmpeg/php-ffmpeg": "~0.3.0"
}
}
```
2012-05-31 16:25:42 +02:00
2013-07-03 18:14:44 +02:00
## 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` :
```php
$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.
```php
$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.
```php
$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.
```php
$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.
```php
$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.
```php
$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`
2012-05-31 16:07:30 +02:00
##Usage Example
```php
2012-05-31 16:10:16 +02:00
$x264 = new X264();
2012-05-31 16:07:30 +02:00
$x264->setDimensions(320, 240);
$ffmpeg->open('Video.mpeg')
2012-05-31 16:10:16 +02:00
->encode($new WebM(), 'file.webm')
->encode($x264, 'file.mp4')
->encode($new Ogg(), 'file.ogv')
2012-05-31 16:07:30 +02:00
->close();
```
##Getting progress information
```php
$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();
```
2012-09-03 14:55:04 +02:00
##Using with Silex Microframework
```php
use FFMpeg\SilexServiceProvider;
use Silex\Application;
$app = new Application();
$app->register(new FFMpegServiceProvider());
```
2013-07-03 18:14:44 +02:00
## API Browser
Browse the [API](http://readthedocs.org/docs/ffmpeg-php/en/latest/_static/API/)
## License
2012-05-31 16:07:30 +02:00
This project is licensed under the [MIT license](http://opensource.org/licenses/MIT).