This package provides an integration with FFmpeg for Laravel 5.6. The storage of the files is handled by Laravel's Filesystem.

pascalbaljet 0420c5024e Merge pull request #1 from pascalbaljetmedia/hls-stream il y a 8 ans
config e2b0875c76 Config for ubuntu testing il y a 8 ans
src 1addae7633 Added some return types il y a 8 ans
tests 884c648dcc Major refactor il y a 8 ans
.editorconfig 71023a5e92 first commit il y a 8 ans
.gitattributes 71023a5e92 first commit il y a 8 ans
.gitignore 71023a5e92 first commit il y a 8 ans
.scrutinizer.yml 71023a5e92 first commit il y a 8 ans
.travis.yml 3dde0dcf6c README.md update il y a 8 ans
CHANGELOG.md 71023a5e92 first commit il y a 8 ans
CONTRIBUTING.md 71023a5e92 first commit il y a 8 ans
LICENSE.md 71023a5e92 first commit il y a 8 ans
README.md 3589094027 Added ‘setSegmentLength’ to README.md il y a 8 ans
composer.json ae37ea0467 Removed TmpDir variable il y a 8 ans
phpunit.xml.dist 71023a5e92 first commit il y a 8 ans

README.md

Laravel FFMpeg

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

This package provides an integration with FFmpeg for Laravel 5.1 and higher. The storage of the files is handled by Laravel's Filesystem.

Features

Installation

You can install the package via composer:

composer require pbmedia/laravel-ffmpeg

Add the service provider and facade to your app.php config file:


// Laravel 5: config/app.php

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

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

Publish the config file using the artisan CLI tool:

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

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');

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');

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')

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);

Create a M3U8 playlist to do HLS:

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

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

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.