PHPackages                             tbritz/ffmphp - 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. tbritz/ffmphp

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

tbritz/ffmphp
=============

Convert media, save previews, and more. All with clean, elegant syntax that won't get in your way.

v1.0.1(5y ago)028MITPHPPHP ^7.1.3CI failing

Since Aug 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Travis-Britz/FFmphp)[ Packagist](https://packagist.org/packages/tbritz/ffmphp)[ RSS](/packages/tbritz-ffmphp/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8e76344ddf144c1ecb4f2ab42971ee39a7b04506c18ad2bf1e3aac8f9f41024a/68747470733a2f2f7472617669732d63692e6f72672f5472617669732d427269747a2f46466d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Travis-Britz/FFmphp)

FFmphp
======

[](#ffmphp)

A simple, clean, and elegant way to run FFmpeg from your php applications.

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

[](#installation)

You will need a working install of FFmpeg (and FFprobe) in your system ().

This library can be installed via [composer](https://getcomposer.org/download/):

```
$ composer require tbritz/ffmphp
```

As long as `ffmpeg` and `ffprobe` are available from your system's PATH variable, this library should use them automatically. If not, you can configure FFmphp before using it:

```
FFmphp::configure([
    'ffmpeg' => 'C:\ffmpeg\ffmpeg.exe',
    'ffprobe' => 'C:\ffmpeg\ffprobe.exe',
    'timeout' => 0, // default, no timeout (in seconds)
]);
```

These settings will be applied to all FFmphp calls for the remainder of the script execution.

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

[](#basic-usage)

### Video Transcoding

[](#video-transcoding)

Getting started is easy. Converting a video can be as simple as this command:

```
FFmphp::load($infile)
    ->save('outfile.mp4')
    ->run();
```

FFmpeg will guess the output type based on the extension.

Most of the time, however, you will give `save()` the name of an `OutputFormat`:

```
FFmphp::load($infile)
    ->save('outfile.mp4', 'FFmphp\Formats\Video\MP4')
    ->run();
```

For the rest of the document we will use php's [`::class`](https://stackoverflow.com/a/42064777/6038111) syntax instead of providing the *fully qualified class name* of the format. Here is what the previous example looks like when it is rewritten:

```
use FFmphp\Formats\Video\MP4;

FFmphp::load($infile)
    ->save('outfile.mp4', MP4::class)
    ->run();
```

### Extracting Audio Tracks from Video

[](#extracting-audio-tracks-from-video)

Working with audio formats is just as easy:

```
FFmphp::load($infile)
    ->save('outfile.mp3', MP3::class)
    ->run();
```

### Saving Thumbnails

[](#saving-thumbnails)

Saving a video poster, or thumbnail image, works the same way:

```
FFmphp::load($file)
    ->save('thumbnail.jpg')
    ->run();

FFmphp::load($file)
    ->save('poster.jpg', Poster::class)
    ->run();
```

### Saving Tiled/Mosaic Images

[](#saving-tiledmosaic-images)

You guessed it:

```
FFmphp::load($file)
    ->save('preview-4x3.jpg', TileFourByThree::class)
    ->run();
```

### Save Multiple Files with One Command

[](#save-multiple-files-with-one-command)

You can add an arbitrary number of outputs with one command. For example:

```
FFmphp::load($input)
    ->save('output.mp4', MP4::class)
    ->save('output.webm', Webm::class)
    ->save('output-audio.mp3', MP3::class)
    ->save('poster.jpg', Poster::class)
    ->save('preview-5x5.jpg', TileFiveByFive::class)
    ->run();
```

The above command would run FFmpeg once and create 5 files.

Note: This is only provided as an example. Although the code may be more readable and make it easier to reason about the overall progress (or failures) during conversion, actual memory usage of FFmpeg increases for every output stream. In many cases the number of outputs you can chain on a single command instance will be limited by the available system memory and the resolution of your video streams.

Advanced Usage
--------------

[](#advanced-usage)

### Output Formats

[](#output-formats)

The best way to keep your project organized is to create an `OutputFormat` class for every type of file that you will save. An output format includes codecs, bitrate, container, resolution, and more. Don't worry, it's actually much simpler than it sounds!

To make it easier to start writing code, these formats are included:

- [`FFmphp\Formats\Video\MP4`](src/FFmphp/Formats/Video/MP4.php)
- [`FFmphp\Formats\Video\Webm`](src/FFmphp/Formats/Video/Webm.php)
- [`FFmphp\Formats\Video\HLS`](src/FFmphp/Formats/Video/HLS.php) (m3u8)
- [`FFmphp\Formats\Audio\MP3`](src/FFmphp/Formats/Audio/MP3.php)
- [`FFmphp\Formats\Image\Poster`](src/FFmphp/Formats/Image/Poster.php) (Thumbnail)
- [`FFmphp\Formats\Image\TileFiveByFive`](src/FFmphp/Formats/Image/TileFiveByFive.php)
- [`FFmphp\Formats\Image\TileFourByThree`](src/FFmphp/Formats/Image/TileFourByThree.php)

You are welcome to use these classes in your own application, however in most cases it is better to use them only as a reference, and instead create your own formats which are tuned to the unique requirements of your application.

You can either create your class from scratch, or you may *extend* another format. Your class must implement the [`FFmphp\Formats\OutputFormat`](src/FFmphp/Formats/OutputFormat.php) interface, which has one method: `build()`.

For example, you may wish to create a format which is specifically tuned for animation content by *extending* the existing MP4 class:

```
