PHPackages                             sormagec/laravel-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. sormagec/laravel-ffmpeg

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

sormagec/laravel-ffmpeg
=======================

FFMpeg for Laravel

2.1.0(8y ago)323MITPHPPHP ^7.1

Since Aug 10Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bsormagec/laravel-ffmpeg)[ Packagist](https://packagist.org/packages/sormagec/laravel-ffmpeg)[ Docs](https://github.com/sormagec/laravel-ffmpeg)[ RSS](/packages/sormagec-laravel-ffmpeg/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (8)Versions (26)Used By (0)

Laravel FFMpeg
==============

[](#laravel-ffmpeg)

[![Latest Version on Packagist](https://camo.githubusercontent.com/72793a92780133aa669fc1c4f8872e04fba9a79c9f8b129a5a701d1069323559/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70626d656469612f6c61726176656c2d66666d7065672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pbmedia/laravel-ffmpeg)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/033e6a79ae5451523037d336cb1598e04bf0e9fb9d1552b5dc7a5ec0bda0bcce/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f70617363616c62616c6a65746d656469612f6c61726176656c2d66666d7065672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/pascalbaljetmedia/laravel-ffmpeg)[![Quality Score](https://camo.githubusercontent.com/727eda58dab66d37cb31d76f602892aff672d1f7149d1b4db2b4a3095d739edc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70617363616c62616c6a65746d656469612f6c61726176656c2d66666d7065672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/pascalbaljetmedia/laravel-ffmpeg)[![Total Downloads](https://camo.githubusercontent.com/a82d9ad3fcb0823af3b2bc320441070e0115feb73e6577c8c736c5db4f154510/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70626d656469612f6c61726176656c2d66666d7065672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pbmedia/laravel-ffmpeg)

This package provides an integration with FFmpeg for Laravel 5.6. The storage of the files is handled by [Laravel's Filesystem](http://laravel.com/docs/5.6/filesystem).

Features
--------

[](#features)

- Super easy wrapper around [PHP-FFMpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg), including support for filters and other advanced features.
- Integration with [Laravel's Filesystem](http://laravel.com/docs/5.6/filesystem), [configuration system](https://laravel.com/docs/5.6/configuration) and [logging handling](https://laravel.com/docs/5.6/errors).
- Compatible with Laravel 5.6.
- Support for [Package Discovery](https://laravel.com/docs/5.6/packages#package-discovery).
- PHP 7.1 and 7.2 only.

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

[](#installation)

This version of the package is only compatible with Laravel 5.6. If you're still using Laravel 5.1 - 5.5, please use version 1.3 (which is not maintained anymore).

You can install the package via composer:

```
composer require pbmedia/laravel-ffmpeg
```

Add the Service Provider and Facade to your `app.php` config file if you're not using Package Discovery.

```
// Laravel 5: config/app.php

'providers' => [
    ...
    Sormagec\LaravelFFMpeg\FFMpegServiceProvider::class,
    ...
];

'aliases' => [
    ...
    'FFMpeg' => Sormagec\LaravelFFMpeg\FFMpegFacade::class
    ...
];
```

Publish the config file using the artisan CLI tool:

```
php artisan vendor:publish --provider="Sormagec\LaravelFFMpeg\FFMpegServiceProvider"
```

Usage
-----

[](#usage)

Convert an audio or video file:

```
FFMpeg::fromDisk('songs')
    ->open('yesterday.mp3')
    ->export()
    ->toDisk('converted_songs')
    ->inFormat(new \FFMpeg\Format\Audio\Aac)
    ->save('yesterday.aac');
```

Instead of the `fromDisk()` method you can also use the `fromFilesystem()` method, where `$filesystem` is an instance of `Illuminate\Contracts\Filesystem\Filesystem`.

```
$media = FFMpeg::fromFilesystem($filesystem)->open('yesterday.mp3');
```

You can add filters through a `Closure` or by using PHP-FFMpeg's Filter objects:

```
FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->addFilter(function ($filters) {
        $filters->resize(new \FFMpeg\Coordinate\Dimension(640, 480));
    })
    ->export()
    ->toDisk('converted_videos')
    ->inFormat(new \FFMpeg\Format\Video\X264)
    ->save('small_steve.mkv');

// or

$start = \FFMpeg\Coordinate\TimeCode::fromSeconds(5)
$clipFilter = new \FFMpeg\Filters\Video\ClipFilter($start);

FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->addFilter($clipFilter)
    ->export()
    ->toDisk('converted_videos')
    ->inFormat(new \FFMpeg\Format\Video\X264)
    ->save('short_steve.mkv');
```

Sometimes you don't want to use the built-in filters. You can apply your own filter by providing a set of options. This can be an array or multiple strings as arguments:

```
FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->addFilter(['-itsoffset', 1]);

// or

FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->addFilter('-itsoffset', 1);
```

Chain multiple convertions:

```
// The 'fromDisk()' method is not required, the file will now
// be opened from the default 'disk', as specified in
// the config file.

FFMpeg::open('my_movie.mov')

    // export to FTP, converted in WMV
    ->export()
    ->toDisk('ftp')
    ->inFormat(new \FFMpeg\Format\Video\WMV)
    ->save('my_movie.wmv')

    // export to Amazon S3, converted in X264
    ->export()
    ->toDisk('s3')
    ->inFormat(new \FFMpeg\Format\Video\X264)
    ->save('my_movie.mkv');

    // you could even discard the 'toDisk()' method,
    // now the converted file will be saved to
    // the same disk as the source!
    ->export()
    ->inFormat(new FFMpeg\Format\Video\WebM)
    ->save('my_movie.webm')

    // optionally you could set the visibility
    // of the exported file
    ->export()
    ->inFormat(new FFMpeg\Format\Video\WebM)
    ->withVisibility('public')
    ->save('my_movie.webm')
```

Create a frame from a video:

```
FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->getFrameFromSeconds(10)
    ->export()
    ->toDisk('thumnails')
    ->save('FrameAt10sec.png');

// Instead of the 'getFrameFromSeconds()' method, you could
// also use the 'getFrameFromString()' or the
// 'getFrameFromTimecode()' methods:

$media = FFMpeg::open('steve_howe.mp4');
$frame = $media->getFrameFromString('00:00:13.37');

// or

$timecode = new FMpeg\Coordinate\TimeCode(...);
$frame = $media->getFrameFromTimecode($timecode);
```

With the `Media` class you can determinate the duration of a file:

```
$media = FFMpeg::open('wwdc_2006.mp4');

$durationInSeconds = $media->getDurationInSeconds(); // returns an int
$durationInMiliseconds = $media->getDurationInMiliseconds(); // returns a float
```

When opening or saving files from or to a remote disk, temporary files will be created on your server. After you're done exporting or processing these files, you could clean them up by calling the `cleanupTemporaryFiles()` method:

```
FFMpeg::cleanupTemporaryFiles();
```

HLS
---

[](#hls)

You can create a M3U8 playlist to do [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming). Exporting is currently only supported on local disks.

```
$lowBitrate = (new X264)->setKiloBitrate(250);
$midBitrate = (new X264)->setKiloBitrate(500);
$highBitrate = (new X264)->setKiloBitrate(1000);

FFMpeg::fromDisk('videos')
    ->open('steve_howe.mp4')
    ->exportForHLS()
    ->setSegmentLength(10) // optional
    ->addFormat($lowBitrate)
    ->addFormat($midBitrate)
    ->addFormat($highBitrate)
    ->save('adaptive_steve.m3u8');
```

As of version 1.2.0 the `addFormat` method of the HLS exporter takes an optional second parameter which can be a callback method. This allows you to add different filters per format:

```
$lowBitrate = (new X264)->setKiloBitrate(250);
$highBitrate = (new X264)->setKiloBitrate(1000);

FFMpeg::open('steve_howe.mp4')
    ->exportForHLS()
    ->addFormat($lowBitrate, function($media) {
        $media->addFilter(function ($filters) {
            $filters->resize(new \FFMpeg\Coordinate\Dimension(640, 480));
        });
    })
    ->addFormat($highBitrate, function($media) {
        $media->addFilter(function ($filters) {
            $filters->resize(new \FFMpeg\Coordinate\Dimension(1280, 960));
        });
    })
    ->save('adaptive_steve.m3u8');
```

As of version 1.3.0 you can monitor the transcoding progress of a HLS export. Use the `onProgress` method to provide a callback which gives you the completed percentage.

```
$exporter = FFMpeg::open('steve_howe.mp4')
    ->exportForHLS()
    ->onProgress(function ($percentage) {
        echo "$percentage % transcoded";
    });
```

Advanced
--------

[](#advanced)

The Media object you get when you 'open' a file, actually holds the Media object that belongs to the [underlying driver](https://github.com/PHP-FFMpeg/PHP-FFMpeg). It handles dynamic method calls as you can see [here](https://github.com/pascalbaljetmedia/laravel-ffmpeg/blob/master/src/Media.php#L114-L117). This way all methods of the underlying driver are still available to you.

```
// This gives you an instance of Sormagec\LaravelFFMpeg\Media
$media = FFMpeg::fromDisk('videos')->open('video.mp4');

// The 'getStreams' method will be called on the underlying Media object since
// it doesn't exists on this object.
$codec = $media->getStreams()->first()->get('codec_name');
```

If you want direct access to the underlying object, call the object as a function (invoke):

```
// This gives you an instance of Sormagec\LaravelFFMpeg\Media
$media = FFMpeg::fromDisk('videos')->open('video.mp4');

// This gives you an instance of FFMpeg\Media\MediaTypeInterface
$baseMedia = $media();
```

Example app
-----------

[](#example-app)

Here's a blogpost that will help you get started with this package:

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Pascal Baljet](https://github.com/pascalbaljet)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~26 days

Recently: every ~0 days

Total

24

Last Release

2963d ago

Major Versions

1.3.0 → 2.0.02018-02-19

PHP version history (2 changes)1.0.0PHP ^7.0

2.0.0PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/46748527?v=4)[sormagec](/maintainers/sormagec)[@sormagec](https://github.com/sormagec)

---

Top Contributors

[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (97 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (2 commits)")[![Dylan-DPC](https://avatars.githubusercontent.com/u/99973273?v=4)](https://github.com/Dylan-DPC "Dylan-DPC (2 commits)")

---

Tags

laravel-ffmpegsormagec

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sormagec-laravel-ffmpeg/health.svg)

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[pbmedia/laravel-ffmpeg

FFMpeg for Laravel

1.8k4.8M23](/packages/pbmedia-laravel-ffmpeg)[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[sammyjo20/lasso

Lasso - Asset wrangling for Laravel made simple.

355347.9k](/packages/sammyjo20-lasso)

PHPackages © 2026

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