Skip to main content
Back to packages
1,807 GitHub stars

protonemedia/laravel-ffmpeg

View on GitHub

Description

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files

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

Progress monitoring

You can monitor the transcoding progress. Use the onProgress method to provide a callback, which gives you the completed percentage. In previous versions of this package you had to pass the callback to the format object.

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

The callback may also expose $remaining (in seconds) and $rate:

FFMpeg::open('steve_howe.mp4')
->export()
->onProgress(function ($percentage, $remaining, $rate) {
echo "{$remaining} seconds left at rate: {$rate}";
});

Recent Courses on Laravel Daily