How to Use FFMpeg with Docker × Laravel
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
⇨ Click here for the table of contents of Laravel articles
Summary of using FFMpeg when setting up Laravel environment with Docker.
How to Use FFMpeg
Dockerfile for the application container
FROM php:7.4-fpm-buster
RUN apt-get update
RUN apt-get install -y ffmpeg
Install using composer in the application container
// Enter the app container
docker compose exec app bash
// Install pbmedia/laravel-ffmpeg
composer require pbmedia/laravel-ffmpeg
Add to config/app.php
Add to the providers and aliases arrays.
// config/app.php
'providers' => [
...
ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider::class,
...
];
'aliases' => [
...
'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class
...
];
After changing the config
Run the command
php artisan config:cache
to apply the changes.
Now, FFMpeg is available in the Laravel project set up with Docker.
Implementation Environment
docker-compose version
version: "3"
Dockerfile for the application container
FROM php:7.4-fpm-buster
If an error occurs stating that FFMpeg or FFprobe cannot be found?
If errors occur, such as the binary not being found,
Identify the location of the binary data
Enter the application container and search with the which command.
// Assuming the "app" container
docker compose exec app bash
which ffmpeg
// Assume /usr/bin/ffmpeg is output
Specify the path in config
In the app container
php artisan vendor:publish --provider="Pbmedia\LaravelFFMpeg\FFMpegServiceProvider"
This generates config/laravel-ffmpeg.php with contents like...
<?php
return [
'default_disk' => 'local',
'ffmpeg' => [
'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
'threads' => 12,
],
'ffprobe' => [
'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
],
'timeout' => 3600,
];
So, input the path to the binary as an environment variable.
docker-compose.yml
Add to the environment in the app container.
environment:
// Added
- FFMPEG_BINARIES=/usr/bin/ffmpeg
- FFPROBE_BINARIES=/usr/bin/ffprobe
After adding, rebuild.
docker compose up -d --build
It should work now.
Implementation
The compression method may vary, but the basic form is...
use FFMpeg
~~~~~~
FFMpeg::fromDisk('local')
->open('movie.mp4')
->exportForHLS()
->setSegmentLength(10)
->toDisk('local')
->save('movie2.mp4');
Like this,
- Specify the original file
- Specify compression or editing
- Specify the destination
If you want to do more, the part where you specify compression and editing may become longer.
For what you can do, refer to the documentation.
Summary
That's all. I hope it can be of help to someone.
This blog is supported by clicks on advertisements. Thank you.
Until next time!
Popular Articles
Deploying PHP7.4 + Laravel6 Project to AWS EC2
Implementing Breadcrumbs in Laravel with laravel-breadcrumbs