PHPackages                             christyoga123/video-optimizer - 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. christyoga123/video-optimizer

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

christyoga123/video-optimizer
=============================

A fluent Laravel package for optimizing videos - resize, convert formats (MP4, WebM, AVI), compress and reduce file size while maintaining quality

v1.1.0(5mo ago)0849MITPHPPHP ^8.1

Since Jan 20Pushed 5mo agoCompare

[ Source](https://github.com/ChristYoga123/video-optimizer)[ Packagist](https://packagist.org/packages/christyoga123/video-optimizer)[ Docs](https://github.com/christyoga123/laravel-video-optimizer)[ RSS](/packages/christyoga123-video-optimizer/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel Video Optimizer
=======================

[](#laravel-video-optimizer)

A fluent Laravel package for optimizing videos - resize, convert formats (MP4, WebM, AVI), compress and reduce file size while maintaining quality.

[![Latest Version on Packagist](https://camo.githubusercontent.com/fe122ee5b1ef9ae196ba5fc505eadc6ed729a8b8e6bf607034507331f4ab7b66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636872697374796f67613132332f766964656f2d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/christyoga123/video-optimizer)[![License](https://camo.githubusercontent.com/468f5c0ee2dbf0defd24e2c31c850ba3f7880333680934edb4d152bb18b0e911/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636872697374796f67613132332f766964656f2d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/christyoga123/video-optimizer)

Features
--------

[](#features)

- 🎬 **Format Conversion** - Convert videos to MP4, WebM, OGG, MOV, MKV, AVI
- 📐 **Smart Resize** - Resize with max width/height while maintaining aspect ratio
- 🎚️ **Quality Control** - Adjustable bitrate, CRF, and preset settings
- 🔧 **Fluent API** - Chain methods for clean, readable code
- ⚙️ **Configurable** - Publish and customize default settings
- 🖼️ **Thumbnail Generation** - Extract thumbnails from videos
- 🔇 **Audio Control** - Option to remove or keep audio
- 🎵 **Smart Audio Codecs** - Auto-detects best audio codecs (fixes WebM/Ogg issues on macOS/Homebrew)
- 📊 **Video Info** - Get duration, dimensions, codec info
- 🧹 **Auto Cleanup** - Automatic temporary file cleanup with `dontCleanup()` option
- 📦 **Queueable Job** - Built-in job for background processing

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.x, 11.x, or 12.x
- FFmpeg installed on your server

### Installing FFmpeg

[](#installing-ffmpeg)

**macOS:**

```
brew install ffmpeg
```

**Ubuntu/Debian:**

```
sudo apt update
sudo apt install ffmpeg
```

**Windows:**Download from [ffmpeg.org](https://ffmpeg.org/download.html) and add to PATH.

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

[](#installation)

Install the package via Composer:

```
composer require christyoga123/video-optimizer
```

The package will automatically register its service provider.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=video-optimizer-config
```

This will create a `config/video-optimizer.php` file with all available options.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Christyoga123\VideoOptimizer\VideoOptimizer;

// Process uploaded file and get optimized temp path
$tempPath = VideoOptimizer::make()
    ->toMp4()
    ->maxDimensions(1920, 1080)
    ->videoBitrate(1500)
    ->process($uploadedFile);

// Do something with the optimized file
Storage::disk('public')->put('videos/video.mp4', file_get_contents($tempPath));
```

### Using Facade

[](#using-facade)

```
use Christyoga123\VideoOptimizer\Facades\VideoOptimizer;

$tempPath = VideoOptimizer::make()
    ->toMp4()
    ->crf(23)
    ->preset('fast')
    ->process($request->file('video'));
```

### From Request Input

[](#from-request-input)

```
$tempPath = VideoOptimizer::make()
    ->toWebm()
    ->videoBitrate(2000)
    ->processFromRequest('video');

if ($tempPath) {
    // File was uploaded and processed
    $post->update(['video' => Storage::putFile('videos', $tempPath)]);
}
```

### From File Path

[](#from-file-path)

```
$tempPath = VideoOptimizer::make()
    ->toMp4()
    ->maxDimensions(1280, 720)
    ->crf(28)
    ->processFromPath('/path/to/original/video.mov');
```

### With Default Settings

[](#with-default-settings)

Apply all defaults from config at once:

```
$tempPath = VideoOptimizer::make()
    ->withDefaults()
    ->process($uploadedFile);
```

### With Thumbnail Generation

[](#with-thumbnail-generation)

```
$optimizer = VideoOptimizer::make()
    ->toMp4()
    ->withThumbnail(5); // Capture at 5 seconds

$videoPath = $optimizer->process($uploadedFile);
$thumbnailPath = $optimizer->getThumbnailPath();

// Store both video and thumbnail
Storage::disk('public')->put('videos/video.mp4', file_get_contents($videoPath));
Storage::disk('public')->put('thumbnails/thumb.jpg', file_get_contents($thumbnailPath));
```

### Remove Audio

[](#remove-audio)

```
$tempPath = VideoOptimizer::make()
    ->toMp4()
    ->noAudio()
    ->process($uploadedFile);
```

### Get Video Information

[](#get-video-information)

```
$optimizer = VideoOptimizer::make();

// Get video info before processing
$info = $optimizer->getVideoInfo($uploadedFile->getRealPath());

// Result:
// [
//     'duration' => 120.5,
//     'bitrate' => 2500000,
//     'size' => 37500000,
//     'format' => 'mov,mp4,m4a,3gp,3g2,mj2',
//     'width' => 1920,
//     'height' => 1080,
//     'video_codec' => 'h264',
//     'audio_codec' => 'aac',
//     'frame_rate' => '30/1',
// ]
```

### Get Size Comparison

[](#get-size-comparison)

```
$optimizer = VideoOptimizer::make()
    ->toMp4()
    ->crf(28)
    ->maxDimensions(1280, 720);

$tempPath = $optimizer->process($uploadedFile);

$comparison = $optimizer->getSizeComparison($uploadedFile->getRealPath());

// Result:
// [
//     'original_size' => 50000000,
//     'optimized_size' => 12500000,
//     'saved_bytes' => 37500000,
//     'saved_percentage' => 75.0
// ]

echo "Saved: " . $optimizer->formatFileSize($comparison['saved_bytes']);
// Output: "Saved: 35.76 MB"
```

### Helper Methods

[](#helper-methods)

```
$optimizer = VideoOptimizer::make();

// Get sanitized filename for storage
$filename = $optimizer->getOptimizedFilename($uploadedFile);
// "my_video.mp4"

// Get current format
$format = $optimizer->getFormat();
// "mp4"

// Get temp file path
$path = $optimizer->getTempPath();

// Get thumbnail path (if generated)
$thumbnail = $optimizer->getThumbnailPath();

// Get video duration
$duration = $optimizer->getDuration($uploadedFile->getRealPath());

// Get video dimensions
$dimensions = $optimizer->getDimensions($uploadedFile->getRealPath());
// ['width' => 1920, 'height' => 1080]

// Manual cleanup (usually not needed - destructor handles this)
$optimizer->cleanup();
```

Available Methods
-----------------

[](#available-methods)

### Format Methods

[](#format-methods)

MethodDescription`format(string $format)`Set output format (mp4, webm, ogg, etc.)`toMp4()`Convert to MP4 format (H.264 + AAC)`toWebm()`Convert to WebM format (VP9 + Vorbis)`toOgg()`Convert to OGG format (Theora + Vorbis)`toMov()`Convert to MOV format (H.264 + AAC)`toMkv()`Convert to MKV format (H.264 + AAC)`toAvi()`Convert to AVI format (H.264 + MP3)### Codec Methods

[](#codec-methods)

MethodDescription`videoCodec(string $codec)`Set video codec`audioCodec(string $codec)`Set audio codec### Resize Methods

[](#resize-methods)

MethodDescription`maxWidth(int $width)`Set maximum width (maintains aspect ratio)`maxHeight(int $height)`Set maximum height (maintains aspect ratio)`maxDimensions(int $width, int $height)`Set both max width and height### Quality &amp; Settings

[](#quality--settings)

MethodDescription`videoBitrate(int $kbps)`Set video bitrate in kbps`audioBitrate(int $kbps)`Set audio bitrate in kbps`crf(int $value)`Set CRF (0-51, lower = better quality)`preset(string $preset)`Set encoding preset (ultrafast to veryslow)`tempDir(string $path)`Set custom temporary directory`timeout(int $seconds)`Set processing timeout`threads(int $count)`Set number of threads`withDefaults()`Apply all defaults from config### Audio Control

[](#audio-control)

MethodDescription`noAudio()`Remove audio from video`withAudio()`Keep audio in video### Thumbnail Methods

[](#thumbnail-methods)

MethodDescription`withThumbnail(int $atSecond)`Enable thumbnail generation at specific time`getThumbnailPath()`Get generated thumbnail path### Process Methods

[](#process-methods)

MethodDescription`process(UploadedFile $file)`Process uploaded file`processUploadedFile(UploadedFile $file)`Alias for process()`processFromPath(string $path)`Process from file path`processFromRequest(string $inputName)`Process from request input name### Info Methods

[](#info-methods)

MethodDescription`getDuration(string $path)`Get video duration in seconds`getDimensions(string $path)`Get video width and height`getVideoInfo(string $path)`Get complete video infoConfiguration
-------------

[](#configuration)

After publishing, you can customize these options in `config/video-optimizer.php`:

```
return [
    // FFmpeg binary paths (null = auto-detect)
    'ffmpeg_path' => env('VIDEO_OPTIMIZER_FFMPEG_PATH', null),
    'ffprobe_path' => env('VIDEO_OPTIMIZER_FFPROBE_PATH', null),

    // Processing timeout in seconds
    'timeout' => env('VIDEO_OPTIMIZER_TIMEOUT', 3600),

    // Number of threads (0 = auto)
    'threads' => env('VIDEO_OPTIMIZER_THREADS', 0),

    // Default output format
    'format' => env('VIDEO_OPTIMIZER_FORMAT', 'mp4'),

    // Default codecs
    'video_codec' => env('VIDEO_OPTIMIZER_VIDEO_CODEC', 'libx264'),
    'audio_codec' => env('VIDEO_OPTIMIZER_AUDIO_CODEC', 'aac'),

    // Default bitrates
    'video_bitrate' => env('VIDEO_OPTIMIZER_VIDEO_BITRATE', 1500),
    'audio_bitrate' => env('VIDEO_OPTIMIZER_AUDIO_BITRATE', 128),

    // Default max dimensions
    'max_width' => env('VIDEO_OPTIMIZER_MAX_WIDTH', 1920),
    'max_height' => env('VIDEO_OPTIMIZER_MAX_HEIGHT', 1080),

    // CRF (Constant Rate Factor) - lower = better quality
    'crf' => env('VIDEO_OPTIMIZER_CRF', 23),

    // Encoding preset
    'preset' => env('VIDEO_OPTIMIZER_PRESET', 'medium'),

    // Temporary directory
    'temp_dir' => env('VIDEO_OPTIMIZER_TEMP_DIR', storage_path('app/temp')),

    // Thumbnail generation
    'generate_thumbnail' => env('VIDEO_OPTIMIZER_GENERATE_THUMBNAIL', false),
    'thumbnail_time' => env('VIDEO_OPTIMIZER_THUMBNAIL_TIME', 1),
];
```

Recommended Settings
--------------------

[](#recommended-settings)

### For Web Streaming (Balance)

[](#for-web-streaming-balance)

```
VideoOptimizer::make()
    ->toMp4()
    ->crf(23)
    ->preset('medium')
    ->maxDimensions(1920, 1080)
    ->process($file);
```

### For Small File Size

[](#for-small-file-size)

```
VideoOptimizer::make()
    ->toMp4()
    ->crf(28)
    ->preset('slow')
    ->maxDimensions(1280, 720)
    ->videoBitrate(1000)
    ->process($file);
```

### For High Quality

[](#for-high-quality)

```
VideoOptimizer::make()
    ->toMp4()
    ->crf(18)
    ->preset('slower')
    ->videoBitrate(4000)
    ->process($file);
```

### For Fast Processing

[](#for-fast-processing)

```
VideoOptimizer::make()
    ->toMp4()
    ->preset('ultrafast')
    ->process($file);
```

Integration Examples
--------------------

[](#integration-examples)

### With Spatie Media Library

[](#with-spatie-media-library)

```
use Christyoga123\VideoOptimizer\VideoOptimizer;

// Optimize before adding to media collection
$tempPath = VideoOptimizer::make()
    ->toMp4()
    ->maxDimensions(1920, 1080)
    ->crf(23)
    ->process($request->file('video'));

$model->addMedia($tempPath)
    ->usingFileName('optimized-video.mp4')
    ->toMediaCollection('videos');
```

### With Laravel Storage

[](#with-laravel-storage)

```
$optimizer = VideoOptimizer::make()
    ->toMp4()
    ->crf(23)
    ->withThumbnail(3);

$tempPath = $optimizer->process($request->file('video'));
$filename = $optimizer->getOptimizedFilename($request->file('video'));

// Store video
$videoPath = Storage::disk('public')->putFileAs('uploads/videos', $tempPath, $filename);

// Store thumbnail
$thumbnailFilename = pathinfo($filename, PATHINFO_FILENAME) . '.jpg';
$thumbnailPath = Storage::disk('public')->putFileAs('uploads/thumbnails', $optimizer->getThumbnailPath(), $thumbnailFilename);

return response()->json([
    'video' => $videoPath,
    'thumbnail' => $thumbnailPath,
]);
```

### In Form Request

[](#in-form-request)

```
// app/Http/Requests/StoreVideoRequest.php
public function passedValidation()
{
    if ($this->hasFile('video')) {
        $optimizer = VideoOptimizer::make()
            ->withDefaults()
            ->withThumbnail(1);

        $tempPath = $optimizer->process($this->file('video'));

        $this->merge([
            'optimized_video_path' => $tempPath,
            'thumbnail_path' => $optimizer->getThumbnailPath(),
        ]);
    }
}
    }
}
```

### Queueable Job

[](#queueable-job)

The package includes a ready-to-use job for background processing:

```
use Christyoga123\VideoOptimizer\Jobs\OptimizeVideoJob;

// Dispatch job
OptimizeVideoJob::dispatch(
    $sourcePath,           // Full path to source file
    $destinationPath,      // Full path to save result (optional, overwrites source if null)
    [                      // Options array
        'format' => 'mp4',
        'crf' => 23,
        'preset' => 'fast'
    ],
    true                   // Delete source file after optimization? (default: false)
);
```

### Manual Cleanup Control

[](#manual-cleanup-control)

By default, the optimizer cleans up temporary files when the object is destroyed. If you need to keep the file longer (e.g., passing between jobs), use `dontCleanup()`:

```
$optimizer = VideoOptimizer::make()
    ->toMp4()
    ->dontCleanup() // Prevent auto-deletion
    ->process($file);

// ... do something time consuming ...

// Manually cleanup when done
$optimizer->cleanup();
```

### Custom Job Implementation

[](#custom-job-implementation)

### In Queue Job

[](#in-queue-job)

```
// app/Jobs/OptimizeVideo.php
class OptimizeVideo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(
        public string $videoPath,
        public int $postId
    ) {}

    public function handle(): void
    {
        $optimizer = VideoOptimizer::make()
            ->toMp4()
            ->crf(23)
            ->maxDimensions(1920, 1080)
            ->withThumbnail(3);

        $tempPath = $optimizer->processFromPath($this->videoPath);

        // Store optimized video
        $filename = 'video_' . $this->postId . '.mp4';
        Storage::disk('public')->put('videos/' . $filename, file_get_contents($tempPath));

        // Store thumbnail
        $thumbFilename = 'thumb_' . $this->postId . '.jpg';
        Storage::disk('public')->put('thumbnails/' . $thumbFilename, file_get_contents($optimizer->getThumbnailPath()));

        // Update post
        Post::find($this->postId)->update([
            'video_path' => 'videos/' . $filename,
            'thumbnail_path' => 'thumbnails/' . $thumbFilename,
            'video_processed' => true,
        ]);

        // Delete original file
        @unlink($this->videoPath);
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [ChristYoga123](https://github.com/christyoga123)
- [PHP-FFMpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance71

Regular maintenance activity

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b01c6d4bb784d243e2c31c0e28d6bcc0c668cc2bc415e6d64a087c365442b86a?d=identicon)[ChristYoga123](/maintainers/ChristYoga123)

---

Top Contributors

[![ChristYoga123](https://avatars.githubusercontent.com/u/93587043?v=4)](https://github.com/ChristYoga123 "ChristYoga123 (2 commits)")

---

Tags

laravelresizevideoffmpegcompressoptimizermp4webm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/christyoga123-video-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/christyoga123-video-optimizer/health.svg)](https://phpackages.com/packages/christyoga123-video-optimizer)
```

###  Alternatives

[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M182](/packages/intervention-image-laravel)[mostafaznv/larupload

Larupload is a ORM based file uploader for laravel to upload image, video, audio and other known files.

75462.1k6](/packages/mostafaznv-larupload)[lakshmaji/thumbnail

Thumbnails for videos

108123.2k](/packages/lakshmaji-thumbnail)[lakshmajim/thumbnail

Thumbnails for videos

1088.0k](/packages/lakshmajim-thumbnail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
