juzaweb/laravel-hls-converter

There is no license information available for the latest version (1.0.0) of this package.

Convert video to HLS with optional multi-resolution support.

1.0.0 2025-05-16 15:14 UTC

This package is auto-updated.

Last update: 2025-05-16 15:22:27 UTC


README

Tests License

A Laravel-friendly package to convert video files to HLS format (.m3u8 + .ts), with support for multiple resolutions. Built on top of FFMpeg and Laravel.

๐Ÿš€ Features

  • Convert a video to HLS format
  • Support multiple quality outputs (adaptive bitrate streaming)
  • Automatically generate master.m3u8
  • Laravel-friendly structure with job support

๐Ÿงฐ Requirements

  • PHP 8.1 or higher
  • Laravel 9 / 10 / 11
  • FFmpeg installed on the server

Install FFmpeg:

sudo apt-get install ffmpeg

๐Ÿ“ฆ Installation Package

composer require juzaweb/laravel-hls-converter

๐Ÿ“ Usage

Basic HLS Conversion

use Juzaweb\HLSConverter\HLSConverter;

$input = storage_path('app/videos/sample.mp4');
$output = storage_path('app/hls/single');

app(HLSConverter::class)->convert($input, $output);

Convert with multiple resolutions

use Juzaweb\HLSConverter\HLSConverter;

$input = storage_path('app/videos/sample.mp4');
$output = storage_path('app/hls/multi');

$resolutions = [
    '360p' => ['w' => 640,  'h' => 360,  'bitrate' => '800k'],
    '480p' => ['w' => 854,  'h' => 480,  'bitrate' => '1200k'],
    '720p' => ['w' => 1280, 'h' => 720,  'bitrate' => '2500k'],
];

app(HLSConverter::class)->convert($input, $output, $resolutions);

This will generate:

output/
โ”œโ”€โ”€ 360p/
โ”‚   โ”œโ”€โ”€ seg_000.ts
โ”‚   โ””โ”€โ”€ index.m3u8
โ”œโ”€โ”€ 480p/
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ 720p/
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ master.m3u8

๐Ÿงช Running Tests

composer test

๐Ÿ“ Example Laravel Job

use Juzaweb\HLSConverter\HLSConverter;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ConvertVideoToHLSJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 3;

    public $timeout = 120;

    public function __construct(
        protected string $input,
        protected string $output,
        protected ?array $resolutions = null
    ) {}

    public function handle()
    {
        app(HLSConverter::class)->convert($this->input, $this->output, $this->resolutions);
    }
}

๐Ÿ“ License

The HLS Converter is released under the MIT License.