
Automatically optimize and convert videos uploaded through Filament forms using FFmpeg. Reduce file sizes and standardize formats without any manual intervention.
See the dramatic file size reduction:
Original MP4: 17.8 MB

Optimized WebM: 679 KB (96% reduction!)

🎯 Result: Same video quality, 96% smaller file size - from 17.8 MB down to just 679 KB!
# Ubuntu/Debian
sudo apt-get install ffmpeg
# macOS
brew install ffmpeg
# Verify installation
ffmpeg -version
Install the package via Composer:
composer require tonymans33/video-optimizer
Publish the configuration file (optional):
php artisan vendor:publish --tag="video-optimizer-config"
Replace Filament's FileUpload with VideoOptimizer:
use Tonymans33\VideoOptimizer\Components\VideoOptimizer;
VideoOptimizer::make('video')
->disk('public')
->directory('videos')
->optimize('medium') // 'low', 'medium', 'high', or null
->format('webm'); // 'webm', 'mp4', or null
For projects using Spatie Media Library:
use Tonymans33\VideoOptimizer\Components\SpatieMediaLibraryFileUpload;
SpatieMediaLibraryFileUpload::make('videos')
->collection('videos')
->multiple()
->optimize('medium')
->format('webm');
use Tonymans33\VideoOptimizer\Facades\VideoOptimizer;
VideoOptimizer::make('video')
->optimize('high')
->format('mp4');
Set global defaults in config/video-optimizer.php:
return [
// Default optimization level: null, 'low', 'medium', 'high'
'optimize' => null,
// Default output format: null, 'webm', 'mp4'
'format' => null,
];
Component-level settings override these defaults.
| Level | CRF | File Size | Quality | Use Case |
|---|---|---|---|---|
low |
36 | Smallest | Lower | Web previews, thumbnails |
medium |
28 | Balanced | Good | Recommended for most use cases |
high |
20 | Larger | Best | High-quality content, archives |
null |
- | Original | Original | No optimization |
CRF = Constant Rate Factor (lower = better quality, larger file)
use Tonymans33\VideoOptimizer\Components\VideoOptimizer;
VideoOptimizer::make('promotional_video')
->label('Promotional Video')
->disk('s3')
->directory('marketing/videos')
->visibility('public')
->optimize('high')
->format('mp4')
->maxSize(512000) // 500MB
->acceptedFileTypes(['video/mp4', 'video/quicktime', 'video/x-msvideo'])
->downloadable()
->openable()
->deletable();
// Queue jobs for async processing
VideoOptimizer::make('video')
->optimize('medium')
->format('webm')
// Process after form submission using queued jobs
->saveUploadedFileUsing(function ($file) {
dispatch(new OptimizeVideoJob($file));
});
Error: Binary not found
Solution: Install FFmpeg and ensure it's in your system PATH
# Check if FFmpeg is installed
which ffmpeg
ffmpeg -version
storage/logs/laravel.lognull)local disk exists in config/filesystems.phpThe package falls back to original file upload if optimization fails. Check logs for error details.
For large videos, increase PHP memory:
// In your service provider or config
ini_set('memory_limit', '512M');
composer test
Please see CHANGELOG for more information on recent changes.
Contributions are welcome! Please feel free to submit a Pull Request.
If you discover any security issues, please email mansourtony44@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?