Laravel HLS is a package for generating HTTP Live Streaming (HLS) playlists and segments with AES-128 encryption. HLS in an HTTP-based adaptive bitrate streaming protocol developed by Apple and widely supported on most devices. HLS also has the benefit of adapting the quality (and size) of a video based on network speeds.
Using this package, you can quickly add an HLS conversion process to an Eloquent model. This package works by adding the ConvertToHls trait to your model(s) with video, which listens on the model's created and updated events and dispatches HLS conversion to a queue job:
namespace App\Models; use AchyutN\LaravelHLS\Traits\ConvertsToHls;use Illuminate\Database\Eloquent\Model; class Video extends Model{ use ConvertsToHls;} // Created job processes video$video = Video::create([/* ... */]);
Through the created job, this package converts the video file to HLS format with the help of FFMpeg.
For example, to fetch the HLS playlist for a model, the readme outlines the following code to use the package's hls.playlist route:
use App\Models\Video; // Fetch the HLS playlist for a video$video = Video::findOrFail($id);$playlistUrl = route('hls.playlist', ['model' => 'video', 'id' => $video->id]);
This package has nice organization, and is an excellent learning example if you are working with PHP and FFMpeg. You can check out laravel-hls. on GitHub.
You can use Composer to install this in your Laravel >= 10.x project:
composer require achyutn/laravel-hlsphp artisan vendor:publish --provider="AchyutN\LaravelHLS\HLSProvider" --tag="hls-config"
You are required to set up the model aliases that will use HLS conversion. Check out the project's readme for usage details.