PHPackages                             iakumai/php-ffmpeg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. iakumai/php-ffmpeg

ActiveLibrary[Image &amp; Media](/categories/media)

iakumai/php-ffmpeg
==================

FFMpeg PHP, an Object Oriented library to communicate with AVconv / ffmpeg. Now supports Qt-faststart

0.5.3(12y ago)41793MITPHPPHP &gt;=5.3.3

Since Oct 30Pushed 12y ago2 watchersCompare

[ Source](https://github.com/IAkumaI/PHP-FFmpeg)[ Packagist](https://packagist.org/packages/iakumai/php-ffmpeg)[ RSS](/packages/iakumai-php-ffmpeg/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (6)Versions (20)Used By (0)

\#PHP FFmpeg (Fork)

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

Check another amazing repo: [PHP FFMpeg extras](https://github.com/alchemy-fr/PHP-FFMpeg-Extras), you will find lots of Audio/Video formats there.

Installation
------------

[](#installation)

The recommended way to install PHP-FFMpeg is through [Composer](https://getcomposer.org).

```
{
    "require": {
        "iakumai/php-ffmpeg": "0.5.*@dev"
    }
}
```

Basic Usage
-----------

[](#basic-usage)

```
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$video
    ->filters()
    ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('frame.jpg');
$video
    ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
    ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
    ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');
```

Documentation
-------------

[](#documentation)

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

### Qt-Faststart

[](#qt-faststart)

`FFMpeg\QtFaststart` can make MP4 files progressive. This helps the video to playback as early as possible.

```
$qtfaststart = FFMpeg\QtFaststart::create();
$qtfaststart->process('path/to/file.mp4');
```

If you want to give binary paths explicitely, you can pass an array as configuration.

```
$qtfaststart = FFMpeg\QtFaststart::create(array(
    'qtfaststart.binaries' => '/opt/local/ffmpeg/bin/qt-faststart'
));
```

### FFMpeg

[](#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

[](#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

[](#video)

`FFMpeg\Media\Video` can be transcoded, ie : change codec, isolate audio or video. Frames can be extracted.

##### Transcoding

[](#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.

You can use an extra parameters in save() method.

```
$format = new Format\Video\X264();
$video->save($format, 'video.avi', array('-qdiff', '4'));
```

##### Extracting image

[](#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->save('image.jpg');
```

##### Filters

[](#filters)

You can apply filters on `FFMpeg\Media\Video` with the `FFMpeg\Media\Video::addFilter`method. Video accepts Audio and Video filters.

You can build your own filters and some are bundled in PHP-FFMpeg - they are accessible through the `FFMpeg\Media\Video::filters` method.

Filters are chainable

```
$video
    ->filters()
    ->resize($dimension, $mode, $useStandards)
    ->framerate($framerate, $gop)
    ->synchronize();
```

###### Resize

[](#resize)

Resizes a video to a given size.

```
$video->filters()->resize($dimension, $mode, $useStandards);
```

The resize filter takes three parameters :

- `$dimension`, an instance of `FFMpeg\Coordinate\Dimension`
- `$mode`, one of the constants `FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_*` constants
- `$useStandards`, a boolean to force the use of the nearest aspect ratio standard.

###### Framerate

[](#framerate)

Changes the frame rate of the video.

```
$video->filters()->framerate($framerate, $gop);
```

The framerate filter takes two parameters :

- `$framerate`, an instance of `FFMpeg\Coordinate\Framerate`
- `$gop`, a [GOP](https://wikipedia.org/wiki/Group_of_pictures) value (integer)

###### Synchronize

[](#synchronize)

Synchronizes audio and video.

Some containers may use a delay that results in desynchronized outputs. This filters solves this issue.

```
$video->filters()->synchronize();
```

#### Audio

[](#audio)

`FFMpeg\Media\Audio` can be transcoded, ie : change codec, isolate audio or video. Frames can be extracted.

##### Transcoding

[](#transcoding-1)

You can transcode audios using the `FFMpeg\Media\Audio:save` method. You will pass a `FFMpeg\Format\FormatInterface` for that.

```
$format = new Format\Audio\Flac();
$format->on('progress', function ($$audio, $format, $percentage) {
    echo "$percentage % transcoded";
});

$audio->save($format, 'track.flac');
```

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

##### Filters

[](#filters-1)

You can apply filters on `FFMpeg\Media\Audio` with the `FFMpeg\Media\Audio::addFilter`method. It only accepts audio filters.

You can build your own filters and some are bundled in PHP-FFMpeg - they are accessible through the `FFMpeg\Media\Audio::filters` method.

###### Resample

[](#resample)

Resamples an audio file.

```
$audio->filters()->resample($rate);
```

The resample filter takes two parameters :

- `$rate`, a valid audio sample rate value (integer)

#### Frame

[](#frame)

A frame is a image at a timecode of a video ; see documentation above about frame extraction.

You can save frames using the `FFMpeg\Media\Frame::save` method.

```
$frame->save('target.jpg');
```

This method has a second optional boolean parameter. Set it to true to get accurate images ; it takes more time to execute.

#### Formats

[](#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.

##### Create your own format

[](#create-your-own-format)

The easiest way to create a format is to extend the abstract `FFMpeg\Format\Video\DefaultVideo` and `FFMpeg\Format\Audio\DefaultAudio`. and implement the following methods.

```
class CustomWMVFormat extends FFMpeg\Format\Video\DefaultVideo
{
    public function __construct($audioCodec = 'wmav2', $videoCodec = 'wmv2')
    {
        $this
            ->setAudioCodec($audioCodec)
            ->setVideoCodec($videoCodec);
    }

    public function supportBFrames()
    {
        return false;
    }

    public function getAvailableAudioCodecs()
    {
        return array('wmav2');
    }

    public function getAvailableVideoCodecs()
    {
        return array('wmv2');
    }
}
```

#### Coordinates

[](#coordinates)

FFMpeg use many units for time and space coordinates.

- `FFMpeg\Coordinate\AspectRatio` represents an aspect ratio.
- `FFMpeg\Coordinate\Dimension` represent a dimension.
- `FFMpeg\Coordinate\FrameRate` represent a framerate.
- `FFMpeg\Coordinate\Point` represent a point.
- `FFMpeg\Coordinate\TimeCode` represent a timecode.

### FFProbe

[](#ffprobe)

`FFMpeg\FFProbe` is used internally by `FFMpeg\FFMpeg` to probe medias. You can also use it to extract media metadata.

```
$ffprobe = FFMpeg\FFProbe::create();
$ffprobe
    ->streams('/path/to/video/mp4') // extracts streams informations
    ->videos()                      // filters video streams
    ->first()                       // returns the first video stream
    ->get('duration');              // returns the duration property
```

\##Using with Silex Microframework

Service provider is easy to set up :

```
$app = new Silex\Application();
$app->register(new FFMpeg\FFMpegServiceProvider());

$video = $app['ffmpeg']->open('video.mpeg');
```

Available options are as follow :

```
$app->register(new FFMpeg\FFMpegServiceProvider(), array(
    'ffmpeg.configuration' => array(
        'ffmpeg.threads'   => 4,
        'ffmpeg.timeout'   => 300,
        'ffmpeg.binaries'  => '/opt/local/ffmpeg/bin/ffmpeg',
        'ffprobe.timeout'  => 30,
        'ffprobe.binaries' => '/opt/local/ffmpeg/bin/ffprobe',
    ),
    'ffmpeg.logger' => $logger,
));
```

API Browser
-----------

[](#api-browser)

Browse the [API](http://readthedocs.org/docs/ffmpeg-php/en/latest/_static/API/)

License
-------

[](#license)

This project is licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~1 days

Total

19

Last Release

4623d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/907560?v=4)[Valerii Ozarnichuk](/maintainers/IAkumaI)[@IAkumaI](https://github.com/IAkumaI)

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (226 commits)")[![IAkumaI](https://avatars.githubusercontent.com/u/907560?v=4)](https://github.com/IAkumaI "IAkumaI (16 commits)")[![nlegoff](https://avatars.githubusercontent.com/u/511494?v=4)](https://github.com/nlegoff "nlegoff (6 commits)")[![pulse00](https://avatars.githubusercontent.com/u/185278?v=4)](https://github.com/pulse00 "pulse00 (4 commits)")[![ak76](https://avatars.githubusercontent.com/u/736596?v=4)](https://github.com/ak76 "ak76 (1 commits)")[![tgabi333](https://avatars.githubusercontent.com/u/187022?v=4)](https://github.com/tgabi333 "tgabi333 (1 commits)")

---

Tags

audiovideo processingvideoaudio processingavconvffmpegavprobeffprobe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iakumai-php-ffmpeg/health.svg)

```
[![Health](https://phpackages.com/badges/iakumai-php-ffmpeg/health.svg)](https://phpackages.com/packages/iakumai-php-ffmpeg)
```

###  Alternatives

[php-ffmpeg/php-ffmpeg

FFMpeg PHP, an Object Oriented library to communicate with AVconv / ffmpeg

5.0k21.7M165](/packages/php-ffmpeg-php-ffmpeg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
